rmagick 4.2.2 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  set -euox pipefail
4
4
 
5
- gem install bundler
5
+ gem install bundler -v 2.3.26 # Bundler 2.4.x has dropped support for Ruby 2.3
6
6
 
7
7
  if [ -v STYLE_CHECKS ]; then
8
8
  set +ux
@@ -16,10 +16,11 @@ if [ ! -v IMAGEMAGICK_VERSION ]; then
16
16
  fi
17
17
 
18
18
  export HOMEBREW_NO_AUTO_UPDATE=true
19
- brew install wget pkg-config ghostscript freetype jpeg little-cms2 libomp libpng libtiff liblqr libtool libxml2 zlib webp
19
+ brew uninstall --force imagemagick imagemagick@6
20
+ brew install wget ghostscript freetype jpeg little-cms2 openexr libomp libpng libtiff liblqr libtool zlib webp
20
21
 
21
- export LDFLAGS="-L/usr/local/opt/libxml2/lib -L/usr/local/opt/zlib/lib"
22
- export CPPFLAGS="-I/usr/local/opt/libxml2/include/libxml2 -I/usr/local/opt/zlib/include"
22
+ export LDFLAGS="-L$(brew --prefix libxml2)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix glib)/lib -L$(brew --prefix openexr)/lib"
23
+ export CPPFLAGS="-I$(brew --prefix libxml2)/include -I$(brew --prefix zlib)/include -I$(brew --prefix glib)/include/glib-2.0 -I$(brew --prefix glib)/lib/glib-2.0/include -I$(brew --prefix openexr)/include/OpenEXR"
23
24
 
24
25
  project_dir=$(pwd)
25
26
  build_dir="${project_dir}/build-ImageMagick/ImageMagick-${IMAGEMAGICK_VERSION}"
@@ -31,7 +32,7 @@ build_imagemagick() {
31
32
  mkdir -p build-ImageMagick
32
33
 
33
34
  version=(${IMAGEMAGICK_VERSION//./ })
34
- wget "https://imagemagick.org/download/releases/ImageMagick-${IMAGEMAGICK_VERSION}.tar.xz"
35
+ wget "https://imagemagick.org/archive/releases/ImageMagick-${IMAGEMAGICK_VERSION}.tar.xz"
35
36
  tar -xf "ImageMagick-${IMAGEMAGICK_VERSION}.tar.xz"
36
37
  rm "ImageMagick-${IMAGEMAGICK_VERSION}.tar.xz"
37
38
  mv "ImageMagick-${IMAGEMAGICK_VERSION}" "${build_dir}"
@@ -42,7 +43,7 @@ build_imagemagick() {
42
43
  fi
43
44
 
44
45
  cd "${build_dir}"
45
- ./configure --prefix=/usr/local "${options}"
46
+ ./configure --prefix=/usr/local "${options}" --without-raw
46
47
  make -j
47
48
  }
48
49
 
@@ -2,6 +2,7 @@ lib_dir = File.expand_path('../../lib', File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
3
3
  require 'rubygems'
4
4
  require 'mkmf'
5
+ require 'pkg-config'
5
6
 
6
7
  module RMagick
7
8
  class Extconf
@@ -9,6 +10,33 @@ module RMagick
9
10
  RMAGICK_VERS = ::Magick::VERSION
10
11
  MIN_RUBY_VERS = ::Magick::MIN_RUBY_VERSION
11
12
 
13
+ # ImageMagick 6.7 package
14
+ IM6_7_PACKAGES = ['ImageMagick'].freeze
15
+
16
+ # ImageMagick 6.8+ packages
17
+ IM6_PACKAGES = %w[
18
+ ImageMagick-6.Q64HDRI
19
+ ImageMagick-6.Q32HDRI
20
+ ImageMagick-6.Q16HDRI
21
+ ImageMagick-6.Q8HDRI
22
+ ImageMagick-6.Q64
23
+ ImageMagick-6.Q32
24
+ ImageMagick-6.Q16
25
+ ImageMagick-6.Q8
26
+ ].freeze
27
+
28
+ # ImageMagick 7 packages
29
+ IM7_PACKAGES = %w[
30
+ ImageMagick-7.Q64HDRI
31
+ ImageMagick-7.Q32HDRI
32
+ ImageMagick-7.Q16HDRI
33
+ ImageMagick-7.Q8HDRI
34
+ ImageMagick-7.Q64
35
+ ImageMagick-7.Q32
36
+ ImageMagick-7.Q16
37
+ ImageMagick-7.Q8
38
+ ].freeze
39
+
12
40
  attr_reader :headers
13
41
 
14
42
  def initialize
@@ -41,7 +69,6 @@ module RMagick
41
69
  {
42
70
  magick_version: $magick_version,
43
71
  local_libs: $LOCAL_LIBS,
44
- cflags: $CFLAGS,
45
72
  cppflags: $CPPFLAGS,
46
73
  ldflags: $LDFLAGS,
47
74
  defs: $defs,
@@ -68,19 +95,29 @@ module RMagick
68
95
  check_multiple_imagemagick_versions
69
96
  check_partial_imagemagick_versions
70
97
 
98
+ original_ldflags = $LDFLAGS.dup
99
+
100
+ libdir = PKGConfig.libs_only_L($magick_package).chomp.sub('-L', '')
101
+ ldflags = "#{ENV['LDFLAGS']} " + PKGConfig.libs($magick_package).chomp
102
+ rpath = libdir.empty? ? '' : "-Wl,-rpath,#{libdir}"
103
+
71
104
  # Save flags
72
- $CFLAGS = "#{ENV['CFLAGS']} " + `pkg-config --cflags #{$magick_package}`.chomp
73
- $CPPFLAGS = "#{ENV['CPPFLAGS']} " + `pkg-config --cflags #{$magick_package}`.chomp
74
- $LDFLAGS = "#{ENV['LDFLAGS']} " + `pkg-config --libs #{$magick_package}`.chomp
75
- $LOCAL_LIBS = "#{ENV['LIBS']} " + `pkg-config --libs #{$magick_package}`.chomp
105
+ $CPPFLAGS += " #{ENV['CPPFLAGS']} " + PKGConfig.cflags($magick_package).chomp
106
+ $LOCAL_LIBS += " #{ENV['LIBS']} " + PKGConfig.libs($magick_package).chomp
107
+ $LDFLAGS += " #{ldflags} #{rpath}"
108
+
109
+ unless try_link("int main() { }")
110
+ # if linker does not recognizes '-Wl,-rpath,somewhere' option, it revert to original option
111
+ $LDFLAGS = "#{original_ldflags} #{ldflags}"
112
+ end
76
113
 
77
114
  configure_archflags_for_osx($magick_package) if RUBY_PLATFORM =~ /darwin/ # osx
78
115
 
79
116
  elsif RUBY_PLATFORM =~ /mingw/ # mingw
80
117
 
81
118
  dir_paths = search_paths_for_library_for_windows
82
- $CPPFLAGS = %(-I"#{dir_paths[:include]}")
83
- $LDFLAGS = %(-L"#{dir_paths[:lib]}")
119
+ $CPPFLAGS += %( -I"#{dir_paths[:include]}")
120
+ $LDFLAGS += %( -L"#{dir_paths[:lib]}")
84
121
  $LDFLAGS << ' -lucrt' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
85
122
 
86
123
  have_library(im_version_at_least?('7.0.0') ? 'CORE_RL_MagickCore_' : 'CORE_RL_magick_')
@@ -92,11 +129,15 @@ module RMagick
92
129
  $LDFLAGS << %( -libpath:"#{dir_paths[:lib]}")
93
130
  $LDFLAGS << ' -libpath:ucrt' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
94
131
 
95
- $LOCAL_LIBS = im_version_at_least?('7.0.0') ? 'CORE_RL_MagickCore_.lib' : 'CORE_RL_magick_.lib'
132
+ $LOCAL_LIBS += ' ' + (im_version_at_least?('7.0.0') ? 'CORE_RL_MagickCore_.lib' : 'CORE_RL_magick_.lib')
96
133
 
97
134
  end
98
135
 
99
- $CFLAGS << (have_macro('__GNUC__') ? ' -std=gnu99' : ' -std=c99')
136
+ $CPPFLAGS << if have_macro('__GNUC__')
137
+ ' -std=gnu99 -Wno-void-pointer-to-int-cast -Wno-void-pointer-to-enum-cast -Wno-pointer-to-int-cast'
138
+ else
139
+ ' -std=c99'
140
+ end
100
141
  end
101
142
 
102
143
  def exit_failure(msg)
@@ -116,31 +157,40 @@ module RMagick
116
157
  exit(1)
117
158
  end
118
159
 
160
+ def detect_imagemagick_packages(packages)
161
+ packages.select do |package|
162
+ PKGConfig.exist?(package)
163
+ end
164
+ end
165
+
166
+ def installed_im6_packages
167
+ @installed_im6_packages ||= detect_imagemagick_packages(IM6_PACKAGES)
168
+ end
169
+
170
+ def installed_im7_packages
171
+ @installed_im7_packages ||= detect_imagemagick_packages(IM7_PACKAGES)
172
+ end
173
+
119
174
  def determine_imagemagick_package
120
- packages = `pkg-config --list-all`.scan(/(ImageMagick\-[\.A-Z0-9]+) .*/).flatten
175
+ packages = [installed_im7_packages, installed_im6_packages].flatten
121
176
 
122
- # For ancient version of ImageMagick 6 we need a different regex
123
177
  if packages.empty?
124
- packages = `pkg-config --list-all`.scan(/(ImageMagick) .*/).flatten
178
+ # ImageMagick 6.7 does not have package file like ImageMagick-6.Q16.pc
179
+ packages = detect_imagemagick_packages(IM6_7_PACKAGES)
125
180
  end
126
181
 
127
182
  if packages.empty?
128
183
  exit_failure "Can't install RMagick #{RMAGICK_VERS}. Can't find ImageMagick with pkg-config\n"
129
184
  end
130
185
 
131
- if packages.length > 1
132
-
133
- im7_packages = packages.grep(/\AImageMagick-7/)
134
-
135
- if im7_packages.any?
136
- checking_for('forced use of ImageMagick 6') do
137
- if ENV['USE_IMAGEMAGICK_6']
138
- packages -= im7_packages
139
- true
140
- else
141
- packages = im7_packages
142
- false
143
- end
186
+ if installed_im6_packages.any? && installed_im7_packages.any?
187
+ checking_for('forced use of ImageMagick 6') do
188
+ if ENV['USE_IMAGEMAGICK_6']
189
+ packages = installed_im6_packages
190
+ true
191
+ else
192
+ packages = installed_im7_packages
193
+ false
144
194
  end
145
195
  end
146
196
  end
@@ -212,7 +262,7 @@ module RMagick
212
262
  # issue #169
213
263
  # set ARCHFLAGS appropriately for OSX
214
264
  def configure_archflags_for_osx(magick_package)
215
- return unless `pkg-config #{magick_package} --libs-only-L`.match(%r{-L(.+)/lib})
265
+ return unless PKGConfig.libs_only_L(magick_package).match(%r{-L(.+)/lib})
216
266
 
217
267
  imagemagick_dir = Regexp.last_match(1)
218
268
  command = Dir.glob(File.join(imagemagick_dir, "bin/*")).select { |file| File.executable? file }.first
@@ -258,7 +308,7 @@ module RMagick
258
308
  Retry with '--with-opt-dir' option.
259
309
  Usage: gem install rmagick -- '--with-opt-dir=\"[path to ImageMagick]\"'
260
310
  e.g.
261
- gem install rmagick -- '--with-opt-dir=\"C:\Program Files\ImageMagick-6.9.1-Q16\"'
311
+ gem install rmagick -- '--with-opt-dir=\"C:\\Program Files\\ImageMagick-6.9.1-Q16\"'
262
312
  END_MINGW
263
313
  end
264
314
 
@@ -287,16 +337,12 @@ module RMagick
287
337
  END_FAILURE
288
338
 
289
339
  if RUBY_PLATFORM !~ /mswin|mingw/
290
- unless find_executable('pkg-config')
291
- exit_failure "Can't install RMagick #{RMAGICK_VERS}. Can't find pkg-config in #{ENV['PATH']}\n"
292
- end
293
-
294
- unless `pkg-config --libs MagickCore`[/\bl\s*(MagickCore|Magick)6?\b/]
340
+ unless PKGConfig.libs('MagickCore')[/\bl\s*(MagickCore|Magick)6?\b/]
295
341
  exit_failure failure_message
296
342
  end
297
343
 
298
344
  $magick_package = determine_imagemagick_package
299
- $magick_version = `pkg-config #{$magick_package} --modversion`[/^(\d+\.\d+\.\d+)/]
345
+ $magick_version = PKGConfig.modversion($magick_package)[/^(\d+\.\d+\.\d+)/]
300
346
  else
301
347
  `#{magick_command} -version` =~ /Version: ImageMagick (\d+\.\d+\.\d+)-+\d+ /
302
348
  $magick_version = Regexp.last_match(1)
@@ -314,7 +360,8 @@ module RMagick
314
360
 
315
361
  def create_header_file
316
362
  ruby_api = [
317
- 'rb_gc_adjust_memory_usage' # Ruby 2.4.0
363
+ 'rb_gc_adjust_memory_usage', # Ruby 2.4.0
364
+ 'rb_gc_mark_movable' # Ruby 2.7.0
318
365
  ]
319
366
  memory_api = %w[
320
367
  posix_memalign
@@ -353,9 +400,6 @@ module RMagick
353
400
 
354
401
  def create_makefile_file
355
402
  create_header_file
356
- # Prior to 1.8.5 mkmf duplicated the symbols on the command line and in the
357
- # extconf.h header. Suppress that behavior by removing the symbol array.
358
- $defs = []
359
403
 
360
404
  # Force re-compilation if the generated Makefile changed.
361
405
  $config_h = 'Makefile'
@@ -24,6 +24,7 @@
24
24
  #include <sys/types.h>
25
25
  #include "ruby.h"
26
26
  #include "ruby/io.h"
27
+ #include "rmagick_gvl.h"
27
28
 
28
29
  #if defined(__MINGW32__)
29
30
  // Ruby defines wrong format specifiers for MinGW. So this defines original macro in here.
@@ -61,6 +62,11 @@
61
62
  #undef PACKAGE_TARNAME
62
63
  #undef WORDS_BIGENDIAN
63
64
 
65
+ #ifndef HAVE_RB_EXT_RACTOR_SAFE
66
+ #undef RUBY_TYPED_FROZEN_SHAREABLE
67
+ #define RUBY_TYPED_FROZEN_SHAREABLE 0
68
+ #endif
69
+
64
70
  #include "extconf.h"
65
71
 
66
72
  #if defined(IMAGEMAGICK_7)
@@ -90,8 +96,8 @@
90
96
 
91
97
  //! Trace new image creation in bang methods
92
98
  #define UPDATE_DATA_PTR(_obj_, _new_) \
93
- do { (void) rm_trace_creation(_new_);\
94
- DATA_PTR(_obj_) = (void *)(_new_);\
99
+ do { \
100
+ DATA_PTR(_obj_) = (void *)(_new_); \
95
101
  } while(0)
96
102
 
97
103
 
@@ -396,7 +402,6 @@ EXTERN VALUE Class_KernelInfoType;
396
402
  /**
397
403
  * Commonly-used IDs
398
404
  */
399
- EXTERN ID rm_ID_trace_proc; /**< "@trace_proc" */
400
405
  EXTERN ID rm_ID_call; /**< "call" */
401
406
  EXTERN ID rm_ID_changed; /**< "changed" */
402
407
  EXTERN ID rm_ID_cur_image; /**< "cur_image" */
@@ -411,7 +416,13 @@ EXTERN ID rm_ID_push; /**< "push" */
411
416
  EXTERN ID rm_ID_values; /**< "values" */
412
417
  EXTERN ID rm_ID_width; /**< "width" */
413
418
 
414
- EXTERN unsigned long long rm_main_thread_id;
419
+ extern const rb_data_type_t rm_enum_data_type;
420
+ extern const rb_data_type_t rm_info_data_type;
421
+ extern const rb_data_type_t rm_image_data_type;
422
+ extern const rb_data_type_t rm_draw_data_type;
423
+ extern const rb_data_type_t rm_pixel_data_type;
424
+ extern const rb_data_type_t rm_montage_data_type;
425
+ extern const rb_data_type_t rm_kernel_info_data_type;
415
426
 
416
427
  #if !defined(min)
417
428
  #define min(a, b) ((a)<(b)?(a):(b)) /**< min of two values */
@@ -434,56 +445,56 @@ EXTERN unsigned long long rm_main_thread_id;
434
445
  #define R_boolean_to_C_boolean(attr) RTEST(attr) /**< C boolean <- Ruby boolean */
435
446
  #define C_int_to_R_int(attr) INT2FIX(attr) /**< C int -> Ruby int */
436
447
  #define R_int_to_C_int(attr) NUM2INT(attr) /**< C int <- Ruby int */
437
- #define C_long_to_R_long(attr) INT2NUM(attr) /**< C long -> Ruby long */
448
+ #define C_long_to_R_long(attr) LONG2NUM(attr) /**< C long -> Ruby long */
438
449
  #define R_long_to_C_long(attr) NUM2LONG(attr) /**< C long <- Ruby long */
439
- #define C_ulong_to_R_ulong(attr) UINT2NUM(attr) /**< C unsigned long -> Ruby unsigned long */
450
+ #define C_ulong_to_R_ulong(attr) ULONG2NUM(attr) /**< C unsigned long -> Ruby unsigned long */
440
451
  #define R_ulong_to_C_ulong(attr) NUM2ULONG(attr) /**< C unsigned long <- Ruby unsigned long */
441
452
  #define C_str_to_R_str(attr) attr ? rb_str_new2(attr) : Qnil /**< C string -> Ruby string */
442
453
  #define C_dbl_to_R_dbl(attr) rb_float_new(attr) /**< C double -> Ruby double */
443
454
  #define R_dbl_to_C_dbl(attr) NUM2DBL(attr) /**< C double <- Ruby double */
444
455
 
445
456
  //! define attribute reader
446
- #define IMPLEMENT_ATTR_READER(class, attr, type) \
457
+ #define IMPLEMENT_TYPED_ATTR_READER(class, attr, type, data_type) \
447
458
  {\
448
459
  class *ptr;\
449
460
  if (rb_obj_is_kind_of(self, Class_Image) == Qtrue) {\
450
461
  rm_check_destroyed(self); \
451
462
  }\
452
- Data_Get_Struct(self, class, ptr);\
463
+ TypedData_Get_Struct(self, class, data_type, ptr);\
453
464
  return C_##type##_to_R_##type(ptr->attr);\
454
465
  }
455
466
 
456
467
  //! define attribute reader when attribute name is different from the field name
457
- #define IMPLEMENT_ATTR_READERF(class, attr, field, type) \
468
+ #define IMPLEMENT_TYPED_ATTR_READERF(class, attr, field, type, data_type) \
458
469
  {\
459
470
  class *ptr;\
460
471
  rm_check_destroyed(self); \
461
- Data_Get_Struct(self, class, ptr);\
472
+ TypedData_Get_Struct(self, class, data_type, ptr);\
462
473
  return C_##type##_to_R_##type(ptr->field);\
463
474
  }
464
475
 
465
476
  //! define attribute writer
466
- #define IMPLEMENT_ATTR_WRITER(class, attr, type) \
477
+ #define IMPLEMENT_TYPED_ATTR_WRITER(class, attr, type, data_type) \
467
478
  {\
468
479
  class *ptr;\
469
480
  if (rb_obj_is_kind_of(self, Class_Image) == Qtrue) {\
470
481
  rm_check_destroyed(self); \
471
482
  }\
472
483
  rb_check_frozen(self);\
473
- Data_Get_Struct(self, class, ptr);\
484
+ TypedData_Get_Struct(self, class, data_type, ptr);\
474
485
  ptr->attr = R_##type##_to_C_##type(val);\
475
486
  return val;\
476
487
  }
477
488
 
478
489
  //! define attribute writer when attribute name is different from the field name
479
- #define IMPLEMENT_ATTR_WRITERF(class, attr, field, type) \
490
+ #define IMPLEMENT_TYPED_ATTR_WRITERF(class, attr, field, type, data_type) \
480
491
  {\
481
492
  class *ptr;\
482
493
  if (rb_obj_is_kind_of(self, Class_Image) == Qtrue) {\
483
494
  rm_check_destroyed(self); \
484
495
  }\
485
496
  rb_check_frozen(self);\
486
- Data_Get_Struct(self, class, ptr);\
497
+ TypedData_Get_Struct(self, class, data_type, ptr);\
487
498
  ptr->field = R_##type##_to_C_##type(val);\
488
499
  return self;\
489
500
  }
@@ -513,7 +524,6 @@ EXTERN unsigned long long rm_main_thread_id;
513
524
  #define DEF_CONSTV(constant, val) rb_define_const(Module_Magick, #constant, UINT2NUM(val))
514
525
  #endif
515
526
 
516
-
517
527
  //! Convert a Ruby enum constant back to a C enum member.
518
528
  #define VALUE_TO_ENUM(value, e, type) \
519
529
  do {\
@@ -521,7 +531,7 @@ EXTERN unsigned long long rm_main_thread_id;
521
531
  if (CLASS_OF(value) != Class_##type)\
522
532
  rb_raise(rb_eTypeError, "wrong enumeration type - expected %s, got %s", \
523
533
  rb_class2name(Class_##type), rb_class2name(CLASS_OF(value)));\
524
- Data_Get_Struct(value, MagickEnum, magick_enum);\
534
+ TypedData_Get_Struct(value, MagickEnum, &rm_enum_data_type, magick_enum);\
525
535
  e = (type)(magick_enum->val);\
526
536
  } while(0)
527
537
 
@@ -1019,7 +1029,6 @@ extern VALUE Image_write(VALUE, VALUE);
1019
1029
 
1020
1030
  extern VALUE rm_image_new(Image *);
1021
1031
  extern void rm_image_destroy(void *);
1022
- extern void rm_trace_creation(Image *);
1023
1032
 
1024
1033
 
1025
1034
  // rmfill.c
@@ -1043,7 +1052,6 @@ ATTR_ACCESSOR(Pixel, cyan)
1043
1052
  ATTR_ACCESSOR(Pixel, magenta)
1044
1053
  ATTR_ACCESSOR(Pixel, yellow)
1045
1054
  ATTR_ACCESSOR(Pixel, black)
1046
- extern void destroy_Pixel(Pixel *);
1047
1055
  extern VALUE Pixel_alloc(VALUE);
1048
1056
  extern VALUE Pixel_case_eq(VALUE, VALUE);
1049
1057
  extern VALUE Pixel_clone(VALUE);
@@ -1173,6 +1181,9 @@ extern void rm_set_user_artifact(Image *, Info *);
1173
1181
  extern void rm_sync_image_options(Image *, Info *);
1174
1182
  extern void rm_split(Image *);
1175
1183
  extern void rm_magick_error(const char *);
1184
+ #if defined(IMAGEMAGICK_7)
1185
+ extern void rm_set_pixelinfo_alpha(PixelInfo *, const MagickRealType);
1186
+ #endif
1176
1187
 
1177
1188
  //! whether to retain on errors
1178
1189
  typedef enum
@@ -1190,7 +1201,6 @@ typedef enum
1190
1201
  extern void rm_check_exception(ExceptionInfo *, Image *, ErrorRetention);
1191
1202
  extern void rm_ensure_result(Image *);
1192
1203
  extern Image *rm_clone_image(Image *);
1193
- extern MagickBooleanType rm_progress_monitor(const char *, const MagickOffsetType, const MagickSizeType, void *);
1194
1204
  extern VALUE rm_exif_by_entry(Image *);
1195
1205
  extern VALUE rm_exif_by_number(Image *);
1196
1206
  extern void rm_get_optional_arguments(VALUE);
@@ -1199,7 +1209,6 @@ extern void rm_error_handler(const ExceptionType, const char *, const char *);
1199
1209
  extern void rm_warning_handler(const ExceptionType, const char *, const char *);
1200
1210
  extern MagickBooleanType rm_should_raise_exception(ExceptionInfo *, const ExceptionRetention);
1201
1211
  extern void rm_raise_exception(ExceptionInfo *);
1202
- extern unsigned long long rm_current_thread_id();
1203
1212
  #if defined(IMAGEMAGICK_6)
1204
1213
  extern void rm_check_image_exception(Image *, ErrorRetention);
1205
1214
  #endif
@@ -0,0 +1,224 @@
1
+ #ifndef _RMAGICK_GVL_H_
2
+ #define _RMAGICK_GVL_H_
3
+
4
+ #include "ruby/thread.h"
5
+
6
+ typedef void *(gvl_function_t)(void *);
7
+
8
+ #define GVL_FUNC(name) name##_gvl
9
+ #define GVL_STRUCT_TYPE(name) name##_args_t
10
+ #define CALL_FUNC_WITHOUT_GVL(fp, args) \
11
+ rb_thread_call_without_gvl(fp, args, RUBY_UBF_PROCESS, NULL)
12
+
13
+
14
+ #define DEFINE_GVL_STRUCT1(name, type1) \
15
+ typedef struct { \
16
+ type1 arg1; \
17
+ } GVL_STRUCT_TYPE(name)
18
+ #define DEFINE_GVL_FUNC1(func_name, struct_name) \
19
+ static void *func_name##_gvl(void *p) \
20
+ { \
21
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
22
+ return (void *)func_name(args->arg1); \
23
+ }
24
+
25
+ #define DEFINE_GVL_STUB1(name, type1) \
26
+ DEFINE_GVL_STRUCT1(name, type1); \
27
+ DEFINE_GVL_FUNC1(name, name)
28
+
29
+
30
+ #define DEFINE_GVL_STRUCT2(name, type1, type2) \
31
+ typedef struct { \
32
+ type1 arg1; \
33
+ type2 arg2; \
34
+ } GVL_STRUCT_TYPE(name)
35
+ #define DEFINE_GVL_FUNC2(func_name, struct_name) \
36
+ static void *func_name##_gvl(void *p) \
37
+ { \
38
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
39
+ return (void *)func_name(args->arg1, args->arg2); \
40
+ }
41
+
42
+ #define DEFINE_GVL_STUB2(name, type1, type2) \
43
+ DEFINE_GVL_STRUCT2(name, type1, type2); \
44
+ DEFINE_GVL_FUNC2(name, name)
45
+
46
+
47
+ #define DEFINE_GVL_STRUCT3(name, type1, type2, type3) \
48
+ typedef struct { \
49
+ type1 arg1; \
50
+ type2 arg2; \
51
+ type3 arg3; \
52
+ } GVL_STRUCT_TYPE(name)
53
+ #define DEFINE_GVL_FUNC3(func_name, struct_name) \
54
+ static void *func_name##_gvl(void *p) \
55
+ { \
56
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
57
+ return (void *)func_name(args->arg1, args->arg2, args->arg3); \
58
+ }
59
+
60
+ #define DEFINE_GVL_STUB3(name, type1, type2, type3) \
61
+ DEFINE_GVL_STRUCT3(name, type1, type2, type3); \
62
+ DEFINE_GVL_FUNC3(name, name)
63
+
64
+
65
+ #define DEFINE_GVL_STRUCT4(name, type1, type2, type3, type4) \
66
+ typedef struct { \
67
+ type1 arg1; \
68
+ type2 arg2; \
69
+ type3 arg3; \
70
+ type4 arg4; \
71
+ } GVL_STRUCT_TYPE(name)
72
+ #define DEFINE_GVL_FUNC4(func_name, struct_name) \
73
+ static void *func_name##_gvl(void *p) \
74
+ { \
75
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
76
+ return (void *)func_name(args->arg1, args->arg2, args->arg3, args->arg4); \
77
+ }
78
+
79
+ #define DEFINE_GVL_STUB4(name, type1, type2, type3, type4) \
80
+ DEFINE_GVL_STRUCT4(name, type1, type2, type3, type4); \
81
+ DEFINE_GVL_FUNC4(name, name)
82
+
83
+
84
+ #define DEFINE_GVL_STRUCT5(name, type1, type2, type3, type4, type5) \
85
+ typedef struct { \
86
+ type1 arg1; \
87
+ type2 arg2; \
88
+ type3 arg3; \
89
+ type4 arg4; \
90
+ type5 arg5; \
91
+ } GVL_STRUCT_TYPE(name)
92
+ #define DEFINE_GVL_FUNC5(func_name, struct_name) \
93
+ static void *func_name##_gvl(void *p) \
94
+ { \
95
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
96
+ return (void *)func_name(args->arg1, args->arg2, args->arg3, args->arg4, args->arg5); \
97
+ }
98
+ #define DEFINE_GVL_STUB5(name, type1, type2, type3, type4, type5) \
99
+ DEFINE_GVL_STRUCT5(name, type1, type2, type3, type4, type5); \
100
+ DEFINE_GVL_FUNC5(name, name)
101
+
102
+
103
+ #define DEFINE_GVL_STRUCT6(name, type1, type2, type3, type4, type5, type6) \
104
+ typedef struct { \
105
+ type1 arg1; \
106
+ type2 arg2; \
107
+ type3 arg3; \
108
+ type4 arg4; \
109
+ type5 arg5; \
110
+ type6 arg6; \
111
+ } GVL_STRUCT_TYPE(name)
112
+ #define DEFINE_GVL_FUNC6(func_name, struct_name) \
113
+ static void *func_name##_gvl(void *p) \
114
+ { \
115
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
116
+ return (void *)func_name(args->arg1, args->arg2, args->arg3, args->arg4, args->arg5, args->arg6); \
117
+ }
118
+ #define DEFINE_GVL_STUB6(name, type1, type2, type3, type4, type5, type6) \
119
+ DEFINE_GVL_STRUCT6(name, type1, type2, type3, type4, type5, type6); \
120
+ DEFINE_GVL_FUNC6(name, name)
121
+
122
+
123
+ #define DEFINE_GVL_STRUCT7(name, type1, type2, type3, type4, type5, type6, type7) \
124
+ typedef struct { \
125
+ type1 arg1; \
126
+ type2 arg2; \
127
+ type3 arg3; \
128
+ type4 arg4; \
129
+ type5 arg5; \
130
+ type6 arg6; \
131
+ type7 arg7; \
132
+ } GVL_STRUCT_TYPE(name)
133
+ #define DEFINE_GVL_FUNC7(func_name, struct_name) \
134
+ static void *func_name##_gvl(void *p) \
135
+ { \
136
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
137
+ return (void *)func_name(args->arg1, args->arg2, args->arg3, args->arg4, args->arg5, args->arg6, args->arg7); \
138
+ }
139
+ #define DEFINE_GVL_STUB7(name, type1, type2, type3, type4, type5, type6, type7) \
140
+ DEFINE_GVL_STRUCT7(name, type1, type2, type3, type4, type5, type6, type7); \
141
+ DEFINE_GVL_FUNC7(name, name)
142
+
143
+
144
+ #define DEFINE_GVL_STRUCT8(name, type1, type2, type3, type4, type5, type6, type7, type8) \
145
+ typedef struct { \
146
+ type1 arg1; \
147
+ type2 arg2; \
148
+ type3 arg3; \
149
+ type4 arg4; \
150
+ type5 arg5; \
151
+ type6 arg6; \
152
+ type7 arg7; \
153
+ type8 arg8; \
154
+ } GVL_STRUCT_TYPE(name)
155
+ #define DEFINE_GVL_FUNC8(func_name, struct_name) \
156
+ static void *func_name##_gvl(void *p) \
157
+ { \
158
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
159
+ return (void *)func_name(args->arg1, args->arg2, args->arg3, args->arg4, args->arg5, args->arg6, args->arg7, args->arg8); \
160
+ }
161
+ #define DEFINE_GVL_STUB8(name, type1, type2, type3, type4, type5, type6, type7, type8) \
162
+ DEFINE_GVL_STRUCT8(name, type1, type2, type3, type4, type5, type6, type7, type8); \
163
+ DEFINE_GVL_FUNC8(name, name)
164
+
165
+
166
+ #define DEFINE_GVL_STRUCT9(name, type1, type2, type3, type4, type5, type6, type7, type8, type9) \
167
+ typedef struct { \
168
+ type1 arg1; \
169
+ type2 arg2; \
170
+ type3 arg3; \
171
+ type4 arg4; \
172
+ type5 arg5; \
173
+ type6 arg6; \
174
+ type7 arg7; \
175
+ type8 arg8; \
176
+ type9 arg9; \
177
+ } GVL_STRUCT_TYPE(name)
178
+ #define DEFINE_GVL_FUNC9(func_name, struct_name) \
179
+ static void *func_name##_gvl(void *p) \
180
+ { \
181
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
182
+ return (void *)func_name(args->arg1, args->arg2, args->arg3, args->arg4, args->arg5, args->arg6, args->arg7, args->arg8, args->arg9); \
183
+ }
184
+ #define DEFINE_GVL_STUB9(name, type1, type2, type3, type4, type5, type6, type7, type8, type9) \
185
+ DEFINE_GVL_STRUCT9(name, type1, type2, type3, type4, type5, type6, type7, type8, type9); \
186
+ DEFINE_GVL_FUNC9(name, name)
187
+
188
+
189
+ #define DEFINE_GVL_VOID_FUNC2(func_name, struct_name) \
190
+ static void *func_name##_gvl(void *p) \
191
+ { \
192
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
193
+ func_name(args->arg1, args->arg2); \
194
+ return NULL; \
195
+ }
196
+ #define DEFINE_GVL_VOID_STUB2(name, type1, type2) \
197
+ DEFINE_GVL_STRUCT2(name, type1, type2); \
198
+ DEFINE_GVL_VOID_FUNC2(name, name)
199
+
200
+
201
+ #define DEFINE_GVL_VOID_FUNC3(func_name, struct_name) \
202
+ static void *func_name##_gvl(void *p) \
203
+ { \
204
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
205
+ func_name(args->arg1, args->arg2, args->arg3); \
206
+ return NULL; \
207
+ }
208
+ #define DEFINE_GVL_VOID_STUB3(name, type1, type2, type3) \
209
+ DEFINE_GVL_STRUCT3(name, type1, type2, type3); \
210
+ DEFINE_GVL_VOID_FUNC3(name, name)
211
+
212
+
213
+ #define DEFINE_GVL_VOID_FUNC6(func_name, struct_name) \
214
+ static void *func_name##_gvl(void *p) \
215
+ { \
216
+ GVL_STRUCT_TYPE(struct_name) *args = (GVL_STRUCT_TYPE(struct_name) *)p; \
217
+ func_name(args->arg1, args->arg2, args->arg3, args->arg4, args->arg5, args->arg6); \
218
+ return NULL; \
219
+ }
220
+ #define DEFINE_GVL_VOID_STUB6(name, type1, type2, type3, type4, type5, type6) \
221
+ DEFINE_GVL_STRUCT6(name, type1, type2, type3, type4, type5, type6); \
222
+ DEFINE_GVL_VOID_FUNC6(name, name)
223
+
224
+ #endif