Skip to content

Commit

Permalink
Merge pull request #31 from envato/viraptor/fix-0-28-compat
Browse files Browse the repository at this point in the history
Fix exiv2 0.28 compatibility
  • Loading branch information
viraptor authored Jan 8, 2024
2 parents 5306a87 + 7b8a736 commit 7386c89
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ are welcome.

## Compatibility

Tested on 2.4.x, 2.5.x and 2.6.x with Exiv2 0.27.1
Tested on 2.6.x, 2.7.x, 3.0.x, 3.1.x and 3.2.x with Exiv2 0.27.1 and 0.28.0.

## Developing

Expand Down
33 changes: 23 additions & 10 deletions ext/exiv2/exiv2.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
#include "exiv2/image.hpp"
#include "exiv2/error.hpp"
#include "exiv2/exiv2.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 +134,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 +148,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 +191,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 +220,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 +253,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 +287,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
25 changes: 21 additions & 4 deletions ext/exiv2/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
require 'mkmf'

RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
RbConfig::MAKEFILE_CONFIG['CCFLAGS'] = ENV['CCFLAGS'] if ENV['CCFLAGS']
RbConfig::MAKEFILE_CONFIG['CXX'] = ENV['CXX'] if ENV['CXX']
RbConfig::MAKEFILE_CONFIG['CXXFLAGS'] = ENV['CXXFLAGS'] if ENV['CXXFLAGS']
$CXXFLAGS += " -std=c++11"
RbConfig::CONFIG['PKG_CONFIG'] = 'pkg-config'

if dir_config("exiv2") == [nil, nil]
pkg_config("exiv2")
end
have_library("exiv2")

# Some extensions are optional in versions <= 0.27 and also don't exist in
# versions >= 0.28.
# Check if they're enabled in the existing exiv2 headers
# configuration and include the relevant libraries.
if have_macro("EXV_USE_SSH", "exiv2/exv_conf.h")
if dir_config("libssh") == [nil, nil]
pkg_config("libssh")
end
have_library("libssh")
end

if have_macro("EXV_USE_CURL", "exiv2/exv_conf.h")
if dir_config("libcurl") == [nil, nil]
pkg_config("libcurl")
end
have_library("libcurl")
end

create_makefile("exiv2/exiv2")
2 changes: 1 addition & 1 deletion lib/exiv2/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# coding: utf-8
module Exiv2
VERSION = "0.1.1"
VERSION = "0.1.2"
end

0 comments on commit 7386c89

Please sign in to comment.