Skip to content

Commit

Permalink
Fix exiv2 0.28 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
viraptor committed Jan 5, 2024
1 parent 5306a87 commit 20b99d4
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions ext/exiv2/exiv2.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
#include "exiv2/exiv2.hpp"
#include "exiv2/image.hpp"
#include "exiv2/error.hpp"
#include "ruby.h"

#if EXIV2_MAJOR_VERSION == 0 && EXIV2_MINOR_VERSION <= 27
#define ExivImagePtr Exiv2::Image::AutoPtr
#define ExivValuePtr Exiv2::Value::AutoPtr
#else
#define ExivImagePtr Exiv2::Image::UniquePtr
#define ExivValuePtr Exiv2::Value::UniquePtr
#endif

#if EXIV2_MAJOR_VERSION == 0 && EXIV2_MINOR_VERSION <= 27
#define ExivError Exiv2::BasicError<char>
#else
#define ExivError Exiv2::Error
#endif

// Create a Ruby string from a C++ std::string.
static VALUE to_ruby_string(const std::string& string) {
VALUE str = rb_str_new(string.data(), string.length());
Expand Down Expand Up @@ -121,7 +136,7 @@ static VALUE image_read_metadata(VALUE self) {
try {
image->readMetadata();
}
catch (Exiv2::BasicError<char> error) {
catch (ExivError error) {
rb_raise(basic_error_class, "%s", error.what());
}

Expand All @@ -135,7 +150,7 @@ static VALUE image_write_metadata(VALUE self) {
try {
image->writeMetadata();
}
catch (Exiv2::BasicError<char> error) {
catch (ExivError error) {
rb_raise(basic_error_class, "%s", error.what());
}

Expand Down Expand Up @@ -178,10 +193,10 @@ static VALUE image_factory_open(VALUE klass, VALUE path) {
Exiv2::Image* image;

try {
Exiv2::Image::AutoPtr image_auto_ptr = Exiv2::ImageFactory::open(to_std_string(path));
image = image_auto_ptr.release(); // Release the AutoPtr, so we can keep the image around.
ExivImagePtr image_ptr = Exiv2::ImageFactory::open(to_std_string(path));
image = image_ptr.release(); // Release the pointer, so we can keep the image around.
}
catch (Exiv2::BasicError<char> error) {
catch (ExivError error) {
rb_raise(basic_error_class, "%s", error.what());
}

Expand All @@ -207,7 +222,7 @@ static VALUE exif_data_add(VALUE self, VALUE key, VALUE value) {
Exiv2::TypeId typeId = exifKey.defaultTypeId();
#endif

Exiv2::Value::AutoPtr v = Exiv2::Value::create(typeId);
ExivValuePtr v = Exiv2::Value::create(typeId);
v->read(to_std_string(value));

data->add(exifKey, v.get());
Expand Down Expand Up @@ -240,7 +255,7 @@ static VALUE iptc_data_add(VALUE self, VALUE key, VALUE value) {
Exiv2::IptcKey iptcKey = Exiv2::IptcKey(to_std_string(key));
Exiv2::TypeId typeId = Exiv2::IptcDataSets::dataSetType(iptcKey.tag(), iptcKey.record());

Exiv2::Value::AutoPtr v = Exiv2::Value::create(typeId);
ExivValuePtr v = Exiv2::Value::create(typeId);
v->read(to_std_string(value));

if(data->add(iptcKey, v.get())) {
Expand Down Expand Up @@ -274,7 +289,7 @@ static VALUE xmp_data_add(VALUE self, VALUE key, VALUE value) {
Exiv2::XmpKey xmpKey = Exiv2::XmpKey(to_std_string(key));
Exiv2::TypeId typeId = Exiv2::XmpProperties::propertyType(xmpKey);

Exiv2::Value::AutoPtr v = Exiv2::Value::create(typeId);
ExivValuePtr v = Exiv2::Value::create(typeId);
v->read(to_std_string(value));

if(data->add(xmpKey, v.get())) {
Expand Down

0 comments on commit 20b99d4

Please sign in to comment.