rmagick 4.1.0.rc1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rmagick might be problematic. Click here for more details.

Files changed (414) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +63 -0
  3. data/.editorconfig +3 -0
  4. data/.github/ISSUE_TEMPLATE.md +17 -0
  5. data/.github/workflows/ci.yml +108 -0
  6. data/.gitignore +3 -1
  7. data/.rspec +1 -0
  8. data/.rubocop.yml +24 -0
  9. data/.rubocop_todo.yml +151 -297
  10. data/.yardopts +5 -0
  11. data/CHANGELOG.md +94 -0
  12. data/CODE_OF_CONDUCT.md +122 -7
  13. data/CONTRIBUTING.md +14 -10
  14. data/README.md +324 -0
  15. data/Rakefile +16 -22
  16. data/before_install_linux.sh +22 -32
  17. data/before_install_osx.sh +57 -2
  18. data/ext/RMagick/extconf.rb +108 -95
  19. data/ext/RMagick/rmagick.c +77 -104
  20. data/ext/RMagick/rmagick.h +77 -70
  21. data/ext/RMagick/rmdraw.c +289 -446
  22. data/ext/RMagick/rmenum.c +96 -113
  23. data/ext/RMagick/rmfill.c +49 -77
  24. data/ext/RMagick/rmilist.c +144 -244
  25. data/ext/RMagick/rmimage.c +3416 -4169
  26. data/ext/RMagick/rminfo.c +540 -738
  27. data/ext/RMagick/rmkinfo.c +21 -87
  28. data/ext/RMagick/rmmain.c +419 -246
  29. data/ext/RMagick/rmmontage.c +60 -126
  30. data/ext/RMagick/rmpixel.c +401 -345
  31. data/ext/RMagick/rmstruct.c +62 -88
  32. data/ext/RMagick/rmutil.c +148 -228
  33. data/lib/rmagick/version.rb +1 -1
  34. data/lib/rmagick_internal.rb +128 -77
  35. data/lib/rvg/clippath.rb +2 -1
  36. data/lib/rvg/container.rb +10 -5
  37. data/lib/rvg/describable.rb +1 -1
  38. data/lib/rvg/embellishable.rb +5 -4
  39. data/lib/rvg/misc.rb +15 -12
  40. data/lib/rvg/paint.rb +2 -1
  41. data/lib/rvg/pathdata.rb +12 -11
  42. data/lib/rvg/rvg.rb +8 -4
  43. data/lib/rvg/stylable.rb +9 -7
  44. data/lib/rvg/text.rb +11 -6
  45. data/lib/rvg/transformable.rb +3 -2
  46. data/lib/rvg/units.rb +1 -1
  47. data/rmagick.gemspec +8 -6
  48. metadata +46 -421
  49. data/.appveyor.yml +0 -57
  50. data/.circleci/config.yml +0 -56
  51. data/.ruby-version +0 -1
  52. data/.simplecov +0 -27
  53. data/.travis.yml +0 -64
  54. data/Doxyfile +0 -1514
  55. data/README.textile +0 -259
  56. data/benchmarks/memory/README.md +0 -50
  57. data/benchmarks/memory/image_new.rb +0 -8
  58. data/benchmarks/memory/rmagick.gnuplot +0 -16
  59. data/doc/.cvsignore +0 -1
  60. data/doc/comtasks.html +0 -287
  61. data/doc/constants.html +0 -1581
  62. data/doc/css/doc.css +0 -299
  63. data/doc/css/popup.css +0 -34
  64. data/doc/css/ref.css +0 -67
  65. data/doc/draw.html +0 -3272
  66. data/doc/ex/InitialCoords.rb +0 -22
  67. data/doc/ex/NewCoordSys.rb +0 -30
  68. data/doc/ex/OrigCoordSys.rb +0 -16
  69. data/doc/ex/PreserveAspectRatio.rb +0 -204
  70. data/doc/ex/RotateScale.rb +0 -36
  71. data/doc/ex/Skew.rb +0 -38
  72. data/doc/ex/Use01.rb +0 -15
  73. data/doc/ex/Use02.rb +0 -20
  74. data/doc/ex/Use03.rb +0 -16
  75. data/doc/ex/ViewBox.rb +0 -31
  76. data/doc/ex/adaptive_threshold.rb +0 -9
  77. data/doc/ex/add_noise.rb +0 -16
  78. data/doc/ex/affine.rb +0 -48
  79. data/doc/ex/affine_transform.rb +0 -20
  80. data/doc/ex/arc.rb +0 -49
  81. data/doc/ex/arcpath.rb +0 -32
  82. data/doc/ex/arcs01.rb +0 -28
  83. data/doc/ex/arcs02.rb +0 -59
  84. data/doc/ex/average.rb +0 -15
  85. data/doc/ex/axes.rb +0 -64
  86. data/doc/ex/baseline_shift01.rb +0 -17
  87. data/doc/ex/bilevel_channel.rb +0 -8
  88. data/doc/ex/blur_image.rb +0 -12
  89. data/doc/ex/border.rb +0 -10
  90. data/doc/ex/bounding_box.rb +0 -42
  91. data/doc/ex/cbezier1.rb +0 -41
  92. data/doc/ex/cbezier2.rb +0 -41
  93. data/doc/ex/cbezier3.rb +0 -41
  94. data/doc/ex/cbezier4.rb +0 -42
  95. data/doc/ex/cbezier5.rb +0 -42
  96. data/doc/ex/cbezier6.rb +0 -53
  97. data/doc/ex/channel.rb +0 -25
  98. data/doc/ex/charcoal.rb +0 -12
  99. data/doc/ex/chop.rb +0 -29
  100. data/doc/ex/circle.rb +0 -33
  101. data/doc/ex/circle01.rb +0 -16
  102. data/doc/ex/clip_path.rb +0 -60
  103. data/doc/ex/coalesce.rb +0 -57
  104. data/doc/ex/color_fill_to_border.rb +0 -29
  105. data/doc/ex/color_floodfill.rb +0 -28
  106. data/doc/ex/color_histogram.rb +0 -47
  107. data/doc/ex/color_reset.rb +0 -11
  108. data/doc/ex/colorize.rb +0 -16
  109. data/doc/ex/colors.rb +0 -64
  110. data/doc/ex/compose_mask.rb +0 -22
  111. data/doc/ex/composite.rb +0 -133
  112. data/doc/ex/composite_layers.rb +0 -52
  113. data/doc/ex/composite_tiled.rb +0 -21
  114. data/doc/ex/contrast.rb +0 -36
  115. data/doc/ex/crop.rb +0 -31
  116. data/doc/ex/crop_with_gravity.rb +0 -42
  117. data/doc/ex/cubic01.rb +0 -43
  118. data/doc/ex/cubic02.rb +0 -91
  119. data/doc/ex/cycle_colormap.rb +0 -21
  120. data/doc/ex/dissolve.rb +0 -12
  121. data/doc/ex/drawcomp.rb +0 -41
  122. data/doc/ex/drop_shadow.rb +0 -60
  123. data/doc/ex/edge.rb +0 -11
  124. data/doc/ex/ellipse.rb +0 -45
  125. data/doc/ex/ellipse01.rb +0 -21
  126. data/doc/ex/emboss.rb +0 -11
  127. data/doc/ex/enhance.rb +0 -28
  128. data/doc/ex/equalize.rb +0 -11
  129. data/doc/ex/evenodd.rb +0 -42
  130. data/doc/ex/fill_pattern.rb +0 -23
  131. data/doc/ex/flatten_images.rb +0 -36
  132. data/doc/ex/flip.rb +0 -11
  133. data/doc/ex/flop.rb +0 -11
  134. data/doc/ex/font_styles.rb +0 -32
  135. data/doc/ex/fonts.rb +0 -16
  136. data/doc/ex/frame.rb +0 -12
  137. data/doc/ex/gaussian_blur.rb +0 -11
  138. data/doc/ex/get_multiline_type_metrics.rb +0 -41
  139. data/doc/ex/get_pixels.rb +0 -45
  140. data/doc/ex/get_type_metrics.rb +0 -142
  141. data/doc/ex/gradientfill.rb +0 -27
  142. data/doc/ex/grav.rb +0 -45
  143. data/doc/ex/gravity.rb +0 -78
  144. data/doc/ex/group.rb +0 -26
  145. data/doc/ex/hatchfill.rb +0 -27
  146. data/doc/ex/image.rb +0 -44
  147. data/doc/ex/images/Apple.miff +0 -0
  148. data/doc/ex/images/Ballerina.jpg +0 -0
  149. data/doc/ex/images/Ballerina3.jpg +0 -0
  150. data/doc/ex/images/Button_0.gif +0 -0
  151. data/doc/ex/images/Button_1.gif +0 -0
  152. data/doc/ex/images/Button_2.gif +0 -0
  153. data/doc/ex/images/Button_3.gif +0 -0
  154. data/doc/ex/images/Button_4.gif +0 -0
  155. data/doc/ex/images/Button_5.gif +0 -0
  156. data/doc/ex/images/Button_6.gif +0 -0
  157. data/doc/ex/images/Button_7.gif +0 -0
  158. data/doc/ex/images/Button_8.gif +0 -0
  159. data/doc/ex/images/Button_9.gif +0 -0
  160. data/doc/ex/images/Button_A.gif +0 -0
  161. data/doc/ex/images/Button_B.gif +0 -0
  162. data/doc/ex/images/Button_C.gif +0 -0
  163. data/doc/ex/images/Button_D.gif +0 -0
  164. data/doc/ex/images/Button_E.gif +0 -0
  165. data/doc/ex/images/Button_F.gif +0 -0
  166. data/doc/ex/images/Button_G.gif +0 -0
  167. data/doc/ex/images/Button_H.gif +0 -0
  168. data/doc/ex/images/Button_I.gif +0 -0
  169. data/doc/ex/images/Button_J.gif +0 -0
  170. data/doc/ex/images/Button_K.gif +0 -0
  171. data/doc/ex/images/Button_L.gif +0 -0
  172. data/doc/ex/images/Button_M.gif +0 -0
  173. data/doc/ex/images/Button_N.gif +0 -0
  174. data/doc/ex/images/Button_O.gif +0 -0
  175. data/doc/ex/images/Button_P.gif +0 -0
  176. data/doc/ex/images/Button_Q.gif +0 -0
  177. data/doc/ex/images/Button_R.gif +0 -0
  178. data/doc/ex/images/Button_S.gif +0 -0
  179. data/doc/ex/images/Button_T.gif +0 -0
  180. data/doc/ex/images/Button_U.gif +0 -0
  181. data/doc/ex/images/Button_V.gif +0 -0
  182. data/doc/ex/images/Button_W.gif +0 -0
  183. data/doc/ex/images/Button_X.gif +0 -0
  184. data/doc/ex/images/Button_Y.gif +0 -0
  185. data/doc/ex/images/Button_Z.gif +0 -0
  186. data/doc/ex/images/Cheetah.jpg +0 -0
  187. data/doc/ex/images/Coffee.png +0 -0
  188. data/doc/ex/images/Flower_Hat.jpg +0 -0
  189. data/doc/ex/images/Gold_Statue.jpg +0 -0
  190. data/doc/ex/images/Hot_Air_Balloons.jpg +0 -0
  191. data/doc/ex/images/Hot_Air_Balloons_H.jpg +0 -0
  192. data/doc/ex/images/Leaf.miff +0 -0
  193. data/doc/ex/images/No.png +0 -0
  194. data/doc/ex/images/Polynesia.jpg +0 -0
  195. data/doc/ex/images/Red_Rocks.jpg +0 -0
  196. data/doc/ex/images/Rocks_On_Beach.miff +0 -0
  197. data/doc/ex/images/Shorts.jpg +0 -0
  198. data/doc/ex/images/Snake.png +0 -0
  199. data/doc/ex/images/Violin.jpg +0 -0
  200. data/doc/ex/images/Yellow_Rose.miff +0 -0
  201. data/doc/ex/images/big-duck.gif +0 -0
  202. data/doc/ex/images/duck.gif +0 -0
  203. data/doc/ex/images/duck0.gif +0 -0
  204. data/doc/ex/images/duck1.gif +0 -0
  205. data/doc/ex/images/duck10.gif +0 -0
  206. data/doc/ex/images/duck11.gif +0 -0
  207. data/doc/ex/images/duck12.gif +0 -0
  208. data/doc/ex/images/duck13.gif +0 -0
  209. data/doc/ex/images/duck14.gif +0 -0
  210. data/doc/ex/images/duck15.gif +0 -0
  211. data/doc/ex/images/duck2.gif +0 -0
  212. data/doc/ex/images/duck3.gif +0 -0
  213. data/doc/ex/images/duck4.gif +0 -0
  214. data/doc/ex/images/duck5.gif +0 -0
  215. data/doc/ex/images/duck6.gif +0 -0
  216. data/doc/ex/images/duck7.gif +0 -0
  217. data/doc/ex/images/duck8.gif +0 -0
  218. data/doc/ex/images/duck9.gif +0 -0
  219. data/doc/ex/images/graydient230x6.gif +0 -0
  220. data/doc/ex/images/image_with_profile.jpg +0 -0
  221. data/doc/ex/images/logo400x83.gif +0 -0
  222. data/doc/ex/images/model.miff +0 -0
  223. data/doc/ex/images/notimplemented.gif +0 -0
  224. data/doc/ex/images/smile.miff +0 -0
  225. data/doc/ex/images/spin.gif +0 -0
  226. data/doc/ex/implode.rb +0 -34
  227. data/doc/ex/level.rb +0 -11
  228. data/doc/ex/level_colors.rb +0 -11
  229. data/doc/ex/line.rb +0 -41
  230. data/doc/ex/line01.rb +0 -21
  231. data/doc/ex/mask.rb +0 -35
  232. data/doc/ex/matte_fill_to_border.rb +0 -39
  233. data/doc/ex/matte_floodfill.rb +0 -32
  234. data/doc/ex/matte_replace.rb +0 -39
  235. data/doc/ex/median_filter.rb +0 -28
  236. data/doc/ex/modulate.rb +0 -11
  237. data/doc/ex/mono.rb +0 -23
  238. data/doc/ex/morph.rb +0 -25
  239. data/doc/ex/mosaic.rb +0 -37
  240. data/doc/ex/motion_blur.rb +0 -11
  241. data/doc/ex/negate.rb +0 -11
  242. data/doc/ex/negate_channel.rb +0 -9
  243. data/doc/ex/nested_rvg.rb +0 -21
  244. data/doc/ex/nonzero.rb +0 -42
  245. data/doc/ex/normalize.rb +0 -11
  246. data/doc/ex/oil_paint.rb +0 -11
  247. data/doc/ex/opacity.rb +0 -37
  248. data/doc/ex/ordered_dither.rb +0 -11
  249. data/doc/ex/path.rb +0 -63
  250. data/doc/ex/pattern1.rb +0 -25
  251. data/doc/ex/pattern2.rb +0 -26
  252. data/doc/ex/polaroid.rb +0 -26
  253. data/doc/ex/polygon.rb +0 -23
  254. data/doc/ex/polygon01.rb +0 -21
  255. data/doc/ex/polyline.rb +0 -22
  256. data/doc/ex/polyline01.rb +0 -21
  257. data/doc/ex/posterize.rb +0 -8
  258. data/doc/ex/preview.rb +0 -8
  259. data/doc/ex/qbezierpath.rb +0 -52
  260. data/doc/ex/quad01.rb +0 -34
  261. data/doc/ex/quantize-m.rb +0 -25
  262. data/doc/ex/radial_blur.rb +0 -9
  263. data/doc/ex/raise.rb +0 -8
  264. data/doc/ex/random_threshold_channel.rb +0 -13
  265. data/doc/ex/rect01.rb +0 -14
  266. data/doc/ex/rect02.rb +0 -20
  267. data/doc/ex/rectangle.rb +0 -34
  268. data/doc/ex/reduce_noise.rb +0 -28
  269. data/doc/ex/remap.rb +0 -11
  270. data/doc/ex/remap_images.rb +0 -19
  271. data/doc/ex/resize_to_fill.rb +0 -8
  272. data/doc/ex/resize_to_fit.rb +0 -8
  273. data/doc/ex/roll.rb +0 -9
  274. data/doc/ex/rotate.rb +0 -44
  275. data/doc/ex/rotate_f.rb +0 -14
  276. data/doc/ex/roundrect.rb +0 -33
  277. data/doc/ex/rubyname.rb +0 -30
  278. data/doc/ex/rvg_clippath.rb +0 -12
  279. data/doc/ex/rvg_linecap.rb +0 -42
  280. data/doc/ex/rvg_linejoin.rb +0 -40
  281. data/doc/ex/rvg_opacity.rb +0 -18
  282. data/doc/ex/rvg_pattern.rb +0 -26
  283. data/doc/ex/rvg_stroke_dasharray.rb +0 -11
  284. data/doc/ex/segment.rb +0 -11
  285. data/doc/ex/sepiatone.rb +0 -7
  286. data/doc/ex/shade.rb +0 -11
  287. data/doc/ex/shadow.rb +0 -30
  288. data/doc/ex/shave.rb +0 -15
  289. data/doc/ex/shear.rb +0 -10
  290. data/doc/ex/sketch.rb +0 -17
  291. data/doc/ex/skewx.rb +0 -51
  292. data/doc/ex/skewy.rb +0 -47
  293. data/doc/ex/smile.rb +0 -126
  294. data/doc/ex/solarize.rb +0 -11
  295. data/doc/ex/sparse_color.rb +0 -55
  296. data/doc/ex/splice.rb +0 -8
  297. data/doc/ex/spread.rb +0 -11
  298. data/doc/ex/stegano.rb +0 -54
  299. data/doc/ex/stroke_dasharray.rb +0 -42
  300. data/doc/ex/stroke_fill.rb +0 -10
  301. data/doc/ex/stroke_linecap.rb +0 -44
  302. data/doc/ex/stroke_linejoin.rb +0 -48
  303. data/doc/ex/stroke_width.rb +0 -49
  304. data/doc/ex/swirl.rb +0 -17
  305. data/doc/ex/text.rb +0 -37
  306. data/doc/ex/text01.rb +0 -16
  307. data/doc/ex/text_align.rb +0 -36
  308. data/doc/ex/text_antialias.rb +0 -37
  309. data/doc/ex/text_styles.rb +0 -19
  310. data/doc/ex/text_undercolor.rb +0 -28
  311. data/doc/ex/texture_fill_to_border.rb +0 -34
  312. data/doc/ex/texture_floodfill.rb +0 -32
  313. data/doc/ex/texturefill.rb +0 -24
  314. data/doc/ex/threshold.rb +0 -13
  315. data/doc/ex/to_blob.rb +0 -13
  316. data/doc/ex/translate.rb +0 -39
  317. data/doc/ex/transparent.rb +0 -38
  318. data/doc/ex/transpose.rb +0 -9
  319. data/doc/ex/transverse.rb +0 -9
  320. data/doc/ex/tref01.rb +0 -24
  321. data/doc/ex/triangle01.rb +0 -15
  322. data/doc/ex/trim.rb +0 -23
  323. data/doc/ex/tspan01.rb +0 -17
  324. data/doc/ex/tspan02.rb +0 -17
  325. data/doc/ex/tspan03.rb +0 -19
  326. data/doc/ex/unsharp_mask.rb +0 -28
  327. data/doc/ex/viewex.rb +0 -33
  328. data/doc/ex/vignette.rb +0 -12
  329. data/doc/ex/watermark.rb +0 -27
  330. data/doc/ex/wave.rb +0 -9
  331. data/doc/ex/wet_floor.rb +0 -58
  332. data/doc/ex/writing_mode01.rb +0 -26
  333. data/doc/ex/writing_mode02.rb +0 -26
  334. data/doc/ilist.html +0 -2056
  335. data/doc/image1.html +0 -4680
  336. data/doc/image2.html +0 -3665
  337. data/doc/image3.html +0 -4522
  338. data/doc/imageattrs.html +0 -1638
  339. data/doc/imusage.html +0 -514
  340. data/doc/index.html +0 -416
  341. data/doc/info.html +0 -1499
  342. data/doc/magick.html +0 -570
  343. data/doc/optequiv.html +0 -2435
  344. data/doc/rvg.html +0 -975
  345. data/doc/rvgclip.html +0 -248
  346. data/doc/rvggroup.html +0 -305
  347. data/doc/rvgimage.html +0 -289
  348. data/doc/rvgpattern.html +0 -475
  349. data/doc/rvgshape.html +0 -406
  350. data/doc/rvgstyle.html +0 -270
  351. data/doc/rvgtext.html +0 -465
  352. data/doc/rvgtspan.html +0 -238
  353. data/doc/rvgtut.html +0 -530
  354. data/doc/rvguse.html +0 -145
  355. data/doc/rvgxform.html +0 -294
  356. data/doc/scripts/doc.js +0 -22
  357. data/doc/scripts/stripeTables.js +0 -23
  358. data/doc/struct.html +0 -1339
  359. data/doc/usage.html +0 -1621
  360. data/examples/constitute.rb +0 -7
  361. data/examples/crop_with_gravity.rb +0 -43
  362. data/examples/demo.rb +0 -323
  363. data/examples/describe.rb +0 -41
  364. data/examples/find_similar_region.rb +0 -34
  365. data/examples/histogram.rb +0 -312
  366. data/examples/identify.rb +0 -174
  367. data/examples/image_opacity.rb +0 -28
  368. data/examples/import_export.rb +0 -31
  369. data/examples/pattern_fill.rb +0 -37
  370. data/examples/rotating_text.rb +0 -45
  371. data/examples/spinner.rb +0 -49
  372. data/examples/thumbnail.rb +0 -64
  373. data/examples/vignette.rb +0 -78
  374. data/spec/rmagick/ImageList1_spec.rb +0 -24
  375. data/spec/rmagick/draw_spec.rb +0 -155
  376. data/spec/rmagick/image/blue_shift_spec.rb +0 -14
  377. data/spec/rmagick/image/channel_entropy_spec.rb +0 -9
  378. data/spec/rmagick/image/composite_spec.rb +0 -72
  379. data/spec/rmagick/image/constitute_spec.rb +0 -13
  380. data/spec/rmagick/image/dispatch_spec.rb +0 -16
  381. data/spec/rmagick/image/dissolve_spec.rb +0 -54
  382. data/spec/rmagick/image/from_blob_spec.rb +0 -12
  383. data/spec/rmagick/image/ping_spec.rb +0 -12
  384. data/spec/rmagick/image/properties_spec.rb +0 -27
  385. data/spec/rmagick/image/read_spec.rb +0 -28
  386. data/spec/spec_helper.rb +0 -9
  387. data/spec/support/issue_200/app.rb +0 -8
  388. data/test/Draw.rb +0 -351
  389. data/test/Enum.rb +0 -228
  390. data/test/Fill.rb +0 -93
  391. data/test/Image1.rb +0 -606
  392. data/test/Image2.rb +0 -1408
  393. data/test/Image3.rb +0 -1086
  394. data/test/ImageList1.rb +0 -858
  395. data/test/ImageList2.rb +0 -375
  396. data/test/Image_attributes.rb +0 -635
  397. data/test/Import_Export.rb +0 -111
  398. data/test/Info.rb +0 -436
  399. data/test/KernelInfo.rb +0 -59
  400. data/test/Magick.rb +0 -311
  401. data/test/Pixel.rb +0 -259
  402. data/test/PolaroidOptions.rb +0 -23
  403. data/test/Preview.rb +0 -26
  404. data/test/Struct.rb +0 -45
  405. data/test/appearance/Montage.rb +0 -26
  406. data/test/appearance/appearance_assertion.rb +0 -13
  407. data/test/appearance/expected/montage_border_color.jpg +0 -0
  408. data/test/cmyk.icm +0 -0
  409. data/test/lib/internal/Draw.rb +0 -811
  410. data/test/lib/internal/Geometry.rb +0 -98
  411. data/test/lib/internal/Magick.rb +0 -40
  412. data/test/srgb.icm +0 -0
  413. data/test/test_all_basic.rb +0 -49
  414. data/test/tmpnam_test.rb +0 -50
@@ -82,7 +82,7 @@ Export_AffineMatrix(AffineMatrix *am, VALUE st)
82
82
 
83
83
 
84
84
  /**
85
- * Create a Magick::ChromaticityInfo object from a ChromaticityInfo structure.
85
+ * Create a {Magick::ChromaticityInfo} object from a ChromaticityInfo structure.
86
86
  *
87
87
  * No Ruby usage (internal function)
88
88
  *
@@ -107,8 +107,8 @@ ChromaticityInfo_new(ChromaticityInfo *ci)
107
107
  RB_GC_GUARD(blue_primary);
108
108
  RB_GC_GUARD(white_point);
109
109
 
110
- return rb_funcall(Class_Chromaticity, rm_ID_new, 4
111
- , red_primary, green_primary, blue_primary, white_point);
110
+ return rb_funcall(Class_Chromaticity, rm_ID_new, 4,
111
+ red_primary, green_primary, blue_primary, white_point);
112
112
  }
113
113
 
114
114
 
@@ -127,24 +127,22 @@ Export_ChromaticityInfo(ChromaticityInfo *ci, VALUE chrom)
127
127
  VALUE chrom_members;
128
128
  VALUE red_primary, green_primary, blue_primary, white_point;
129
129
  VALUE entry_members, x, y;
130
- ID values_id;
131
130
 
132
131
  if (CLASS_OF(chrom) != Class_Chromaticity)
133
132
  {
134
133
  rb_raise(rb_eTypeError, "type mismatch: %s given",
135
134
  rb_class2name(CLASS_OF(chrom)));
136
135
  }
137
- values_id = rm_ID_values;
138
136
 
139
137
  // Get the struct members in an array
140
- chrom_members = rb_funcall(chrom, values_id, 0);
138
+ chrom_members = rb_funcall(chrom, rm_ID_values, 0);
141
139
  red_primary = rb_ary_entry(chrom_members, 0);
142
140
  green_primary = rb_ary_entry(chrom_members, 1);
143
141
  blue_primary = rb_ary_entry(chrom_members, 2);
144
142
  white_point = rb_ary_entry(chrom_members, 3);
145
143
 
146
144
  // Get the red_primary PrimaryInfo members in an array
147
- entry_members = rb_funcall(red_primary, values_id, 0);
145
+ entry_members = rb_funcall(red_primary, rm_ID_values, 0);
148
146
  x = rb_ary_entry(entry_members, 0); // red_primary.x
149
147
  ci->red_primary.x = x == Qnil ? 0.0 : NUM2DBL(x);
150
148
  y = rb_ary_entry(entry_members, 1); // red_primary.y
@@ -152,7 +150,7 @@ Export_ChromaticityInfo(ChromaticityInfo *ci, VALUE chrom)
152
150
  ci->red_primary.z = 0.0;
153
151
 
154
152
  // Get the green_primary PrimaryInfo members in an array
155
- entry_members = rb_funcall(green_primary, values_id, 0);
153
+ entry_members = rb_funcall(green_primary, rm_ID_values, 0);
156
154
  x = rb_ary_entry(entry_members, 0); // green_primary.x
157
155
  ci->green_primary.x = x == Qnil ? 0.0 : NUM2DBL(x);
158
156
  y = rb_ary_entry(entry_members, 1); // green_primary.y
@@ -160,7 +158,7 @@ Export_ChromaticityInfo(ChromaticityInfo *ci, VALUE chrom)
160
158
  ci->green_primary.z = 0.0;
161
159
 
162
160
  // Get the blue_primary PrimaryInfo members in an array
163
- entry_members = rb_funcall(blue_primary, values_id, 0);
161
+ entry_members = rb_funcall(blue_primary, rm_ID_values, 0);
164
162
  x = rb_ary_entry(entry_members, 0); // blue_primary.x
165
163
  ci->blue_primary.x = x == Qnil ? 0.0 : NUM2DBL(x);
166
164
  y = rb_ary_entry(entry_members, 1); // blue_primary.y
@@ -168,7 +166,7 @@ Export_ChromaticityInfo(ChromaticityInfo *ci, VALUE chrom)
168
166
  ci->blue_primary.z = 0.0;
169
167
 
170
168
  // Get the white_point PrimaryInfo members in an array
171
- entry_members = rb_funcall(white_point, values_id, 0);
169
+ entry_members = rb_funcall(white_point, rm_ID_values, 0);
172
170
  x = rb_ary_entry(entry_members, 0); // white_point.x
173
171
  ci->white_point.x = x == Qnil ? 0.0 : NUM2DBL(x);
174
172
  y = rb_ary_entry(entry_members, 1); // white_point.y
@@ -187,13 +185,9 @@ Export_ChromaticityInfo(ChromaticityInfo *ci, VALUE chrom)
187
185
 
188
186
 
189
187
  /**
190
- * Create a string representation of a Magick::Chromaticity.
188
+ * Return a string representation of a {Magick::Chromaticity} object.
191
189
  *
192
- * Ruby usage:
193
- * - @verbatim Magick::Chromaticity#to_s @endverbatim
194
- *
195
- * @param self this object
196
- * @return the string
190
+ * @return [String] the string
197
191
  */
198
192
  VALUE
199
193
  ChromaticityInfo_to_s(VALUE self)
@@ -202,7 +196,8 @@ ChromaticityInfo_to_s(VALUE self)
202
196
  char buff[200];
203
197
 
204
198
  Export_ChromaticityInfo(&ci, self);
205
- sprintf(buff, "red_primary=(x=%g,y=%g) "
199
+ snprintf(buff, sizeof(buff),
200
+ "red_primary=(x=%g,y=%g) "
206
201
  "green_primary=(x=%g,y=%g) "
207
202
  "blue_primary=(x=%g,y=%g) "
208
203
  "white_point=(x=%g,y=%g) ",
@@ -240,8 +235,8 @@ Import_ColorInfo(const ColorInfo *ci)
240
235
  RB_GC_GUARD(compliance);
241
236
  RB_GC_GUARD(color);
242
237
 
243
- return rb_funcall(Class_Color, rm_ID_new, 3
244
- , name, compliance, color);
238
+ return rb_funcall(Class_Color, rm_ID_new, 3,
239
+ name, compliance, color);
245
240
  }
246
241
 
247
242
 
@@ -272,7 +267,7 @@ Export_ColorInfo(ColorInfo *ci, VALUE st)
272
267
  m = rb_ary_entry(members, 0);
273
268
  if (m != Qnil)
274
269
  {
275
- (void) CloneString((char **)&(ci->name), StringValuePtr(m));
270
+ CloneString((char **)&(ci->name), StringValueCStr(m));
276
271
  }
277
272
  m = rb_ary_entry(members, 1);
278
273
  if (m != Qnil)
@@ -351,13 +346,9 @@ destroy_ColorInfo(ColorInfo *ci)
351
346
 
352
347
 
353
348
  /**
354
- * Return a string representation of a Magick::Color object.
355
- *
356
- * Ruby usage:
357
- * - @verbatim Color#to_s @endverbatim
349
+ * Return a string representation of a {Magick::Color} object.
358
350
  *
359
- * @param self this object
360
- * @return the string
351
+ * @return [String] the string
361
352
  */
362
353
  VALUE
363
354
  Color_to_s(VALUE self)
@@ -367,7 +358,8 @@ Color_to_s(VALUE self)
367
358
 
368
359
  Export_ColorInfo(&ci, self);
369
360
 
370
- sprintf(buff, "name=%s, compliance=%s, "
361
+ snprintf(buff, sizeof(buff),
362
+ "name=%s, compliance=%s, "
371
363
  #if (MAGICKCORE_QUANTUM_DEPTH == 32 || MAGICKCORE_QUANTUM_DEPTH == 64) && defined(HAVE_TYPE_LONG_DOUBLE)
372
364
  "color.red=%Lg, color.green=%Lg, color.blue=%Lg, color.alpha=%Lg ",
373
365
  #else
@@ -421,9 +413,9 @@ Import_TypeInfo(const TypeInfo *ti)
421
413
  RB_GC_GUARD(foundry);
422
414
  RB_GC_GUARD(format);
423
415
 
424
- return rb_funcall(Class_Font, rm_ID_new, 9
425
- , name, description, family, style
426
- , stretch, weight, encoding, foundry, format);
416
+ return rb_funcall(Class_Font, rm_ID_new, 9,
417
+ name, description, family, style,
418
+ stretch, weight, encoding, foundry, format);
427
419
  }
428
420
 
429
421
 
@@ -452,17 +444,17 @@ Export_TypeInfo(TypeInfo *ti, VALUE st)
452
444
  m = rb_ary_entry(members, 0);
453
445
  if (m != Qnil)
454
446
  {
455
- (void) CloneString((char **)&(ti->name), StringValuePtr(m));
447
+ CloneString((char **)&(ti->name), StringValueCStr(m));
456
448
  }
457
449
  m = rb_ary_entry(members, 1);
458
450
  if (m != Qnil)
459
451
  {
460
- (void) CloneString((char **)&(ti->description), StringValuePtr(m));
452
+ CloneString((char **)&(ti->description), StringValueCStr(m));
461
453
  }
462
454
  m = rb_ary_entry(members, 2);
463
455
  if (m != Qnil)
464
456
  {
465
- (void) CloneString((char **)&(ti->family), StringValuePtr(m));
457
+ CloneString((char **)&(ti->family), StringValueCStr(m));
466
458
  }
467
459
  m = rb_ary_entry(members, 3); ti->style = m == Qnil ? 0 : FIX2INT(Enum_to_i(m));
468
460
  m = rb_ary_entry(members, 4); ti->stretch = m == Qnil ? 0 : FIX2INT(Enum_to_i(m));
@@ -470,13 +462,13 @@ Export_TypeInfo(TypeInfo *ti, VALUE st)
470
462
 
471
463
  m = rb_ary_entry(members, 6);
472
464
  if (m != Qnil)
473
- (void) CloneString((char **)&(ti->encoding), StringValuePtr(m));
465
+ CloneString((char **)&(ti->encoding), StringValueCStr(m));
474
466
  m = rb_ary_entry(members, 7);
475
467
  if (m != Qnil)
476
- (void) CloneString((char **)&(ti->foundry), StringValuePtr(m));
468
+ CloneString((char **)&(ti->foundry), StringValueCStr(m));
477
469
  m = rb_ary_entry(members, 8);
478
470
  if (m != Qnil)
479
- (void) CloneString((char **)&(ti->format), StringValuePtr(m));
471
+ CloneString((char **)&(ti->format), StringValueCStr(m));
480
472
 
481
473
  RB_GC_GUARD(members);
482
474
  RB_GC_GUARD(m);
@@ -510,12 +502,9 @@ destroy_TypeInfo(TypeInfo *ti)
510
502
 
511
503
 
512
504
  /**
513
- * Implement the Font#to_s method.
514
- *
515
- * No Ruby usage (internal function)
505
+ * Return a string representation of a {Magick::Font} object.
516
506
  *
517
- * @param self this object
518
- * @return the string
507
+ * @return [String] the string
519
508
  */
520
509
  VALUE
521
510
  Font_to_s(VALUE self)
@@ -535,11 +524,12 @@ Font_to_s(VALUE self)
535
524
  strcpy(weight, "BoldWeight");
536
525
  break;
537
526
  default:
538
- sprintf(weight, "%lu", ti.weight);
527
+ snprintf(weight, sizeof(weight), "%"RMIuSIZE"", ti.weight);
539
528
  break;
540
529
  }
541
530
 
542
- sprintf(buff, "name=%s, description=%s, "
531
+ snprintf(buff, sizeof(buff),
532
+ "name=%s, description=%s, "
543
533
  "family=%s, style=%s, stretch=%s, weight=%s, "
544
534
  "encoding=%s, foundry=%s, format=%s",
545
535
  ti.name,
@@ -569,8 +559,8 @@ Font_to_s(VALUE self)
569
559
  VALUE
570
560
  Import_PointInfo(PointInfo *p)
571
561
  {
572
- return rb_funcall(Class_Point, rm_ID_new, 2
573
- , INT2FIX(p->x), INT2FIX(p->y));
562
+ return rb_funcall(Class_Point, rm_ID_new, 2,
563
+ INT2FIX(p->x), INT2FIX(p->y));
574
564
  }
575
565
 
576
566
 
@@ -614,8 +604,8 @@ Export_PointInfo(PointInfo *pi, VALUE sp)
614
604
  VALUE
615
605
  Import_PrimaryInfo(PrimaryInfo *p)
616
606
  {
617
- return rb_funcall(Class_Primary, rm_ID_new, 3
618
- , INT2FIX(p->x), INT2FIX(p->y), INT2FIX(p->z));
607
+ return rb_funcall(Class_Primary, rm_ID_new, 3,
608
+ INT2FIX(p->x), INT2FIX(p->y), INT2FIX(p->z));
619
609
  }
620
610
 
621
611
 
@@ -651,13 +641,9 @@ Export_PrimaryInfo(PrimaryInfo *pi, VALUE sp)
651
641
 
652
642
 
653
643
  /**
654
- * Create a string representation of a Magick::PrimaryInfo.
644
+ * Return a string representation of a {Magick::PrimaryInfo} object.
655
645
  *
656
- * Ruby usage:
657
- * - @verbatim Magick::PrimaryInfo#to_s @endverbatim
658
- *
659
- * @param self this object
660
- * @return the string
646
+ * @return [String] the string
661
647
  */
662
648
  VALUE
663
649
  PrimaryInfo_to_s(VALUE self)
@@ -666,7 +652,7 @@ PrimaryInfo_to_s(VALUE self)
666
652
  char buff[100];
667
653
 
668
654
  Export_PrimaryInfo(&pi, self);
669
- sprintf(buff, "x=%g, y=%g, z=%g", pi.x, pi.y, pi.z);
655
+ snprintf(buff, sizeof(buff), "x=%g, y=%g, z=%g", pi.x, pi.y, pi.z);
670
656
  return rb_str_new2(buff);
671
657
  }
672
658
 
@@ -696,8 +682,8 @@ Import_RectangleInfo(RectangleInfo *rect)
696
682
  RB_GC_GUARD(x);
697
683
  RB_GC_GUARD(y);
698
684
 
699
- return rb_funcall(Class_Rectangle, rm_ID_new, 4
700
- , width, height, x, y);
685
+ return rb_funcall(Class_Rectangle, rm_ID_new, 4,
686
+ width, height, x, y);
701
687
  }
702
688
 
703
689
 
@@ -735,13 +721,9 @@ Export_RectangleInfo(RectangleInfo *rect, VALUE sr)
735
721
 
736
722
 
737
723
  /**
738
- * Create a string representation of a Magick::Rectangle.
739
- *
740
- * Ruby usage:
741
- * - @verbatim Magick::Rectangle#to_s @endverbatim
724
+ * Return a string representation of a {Magick::Rectangle} object.
742
725
  *
743
- * @param self this object
744
- * @return the string
726
+ * @return [String] the string
745
727
  */
746
728
  VALUE
747
729
  RectangleInfo_to_s(VALUE self)
@@ -750,8 +732,8 @@ RectangleInfo_to_s(VALUE self)
750
732
  char buff[100];
751
733
 
752
734
  Export_RectangleInfo(&rect, self);
753
- sprintf(buff, "width=%lu, height=%lu, x=%ld, y=%ld"
754
- , rect.width, rect.height, rect.x, rect.y);
735
+ snprintf(buff, sizeof(buff), "width=%"RMIuSIZE", height=%"RMIuSIZE", x=%"RMIdSIZE", y=%"RMIdSIZE"",
736
+ rect.width, rect.height, rect.x, rect.y);
755
737
  return rb_str_new2(buff);
756
738
  }
757
739
 
@@ -818,13 +800,9 @@ Export_SegmentInfo(SegmentInfo *segment, VALUE s)
818
800
 
819
801
 
820
802
  /**
821
- * Create a string representation of a Magick::Segment.
803
+ * Return a string representation of a {Magick::Segment} object.
822
804
  *
823
- * Ruby usage:
824
- * - @verbatim Magick::SegmentInfo#to_s @endverbatim
825
- *
826
- * @param self this object
827
- * @return the string
805
+ * @return [String] the string
828
806
  */
829
807
  VALUE
830
808
  SegmentInfo_to_s(VALUE self)
@@ -833,8 +811,8 @@ SegmentInfo_to_s(VALUE self)
833
811
  char buff[100];
834
812
 
835
813
  Export_SegmentInfo(&segment, self);
836
- sprintf(buff, "x1=%g, y1=%g, x2=%g, y2=%g"
837
- , segment.x1, segment.y1, segment.x2, segment.y2);
814
+ snprintf(buff, sizeof(buff), "x1=%g, y1=%g, x2=%g, y2=%g",
815
+ segment.x1, segment.y1, segment.x2, segment.y2);
838
816
  return rb_str_new2(buff);
839
817
  }
840
818
 
@@ -875,10 +853,10 @@ Import_TypeMetric(TypeMetric *tm)
875
853
  RB_GC_GUARD(underline_position);
876
854
  RB_GC_GUARD(underline_thickness);
877
855
 
878
- return rb_funcall(Class_TypeMetric, rm_ID_new, 9
879
- , pixels_per_em, ascent, descent, width
880
- , height, max_advance, bounds
881
- , underline_position, underline_thickness);
856
+ return rb_funcall(Class_TypeMetric, rm_ID_new, 9,
857
+ pixels_per_em, ascent, descent, width,
858
+ height, max_advance, bounds,
859
+ underline_position, underline_thickness);
882
860
  }
883
861
 
884
862
 
@@ -932,13 +910,9 @@ Export_TypeMetric(TypeMetric *tm, VALUE st)
932
910
 
933
911
 
934
912
  /**
935
- * Create a string representation of a Magick::TypeMetric.
936
- *
937
- * Ruby usage:
938
- * - @verbatim Magick::TypeMetric#to_s @endverbatim
913
+ * Return a string representation of a {Magick::TypeMetric} object.
939
914
  *
940
- * @param self this object
941
- * @return the string
915
+ * @return [String] the string
942
916
  */
943
917
  VALUE
944
918
  TypeMetric_to_s(VALUE self)
@@ -950,17 +924,17 @@ TypeMetric_to_s(VALUE self)
950
924
 
951
925
  Export_TypeMetric(&tm, self);
952
926
 
953
- len = sprintf(temp, "pixels_per_em=(x=%g,y=%g) ", tm.pixels_per_em.x, tm.pixels_per_em.y);
927
+ len = snprintf(temp, sizeof(temp), "pixels_per_em=(x=%g,y=%g) ", tm.pixels_per_em.x, tm.pixels_per_em.y);
954
928
  str = rb_str_new(temp, len);
955
- len = sprintf(temp, "ascent=%g descent=%g ",tm.ascent, tm.descent);
929
+ len = snprintf(temp, sizeof(temp), "ascent=%g descent=%g ",tm.ascent, tm.descent);
956
930
  rb_str_cat(str, temp, len);
957
- len = sprintf(temp, "width=%g height=%g max_advance=%g ", tm.width, tm.height, tm.max_advance);
931
+ len = snprintf(temp, sizeof(temp), "width=%g height=%g max_advance=%g ", tm.width, tm.height, tm.max_advance);
958
932
  rb_str_cat(str, temp, len);
959
- len = sprintf(temp, "bounds.x1=%g bounds.y1=%g ", tm.bounds.x1, tm.bounds.y1);
933
+ len = snprintf(temp, sizeof(temp), "bounds.x1=%g bounds.y1=%g ", tm.bounds.x1, tm.bounds.y1);
960
934
  rb_str_cat(str, temp, len);
961
- len = sprintf(temp, "bounds.x2=%g bounds.y2=%g ", tm.bounds.x2, tm.bounds.y2);
935
+ len = snprintf(temp, sizeof(temp), "bounds.x2=%g bounds.y2=%g ", tm.bounds.x2, tm.bounds.y2);
962
936
  rb_str_cat(str, temp, len);
963
- len = sprintf(temp, "underline_position=%g underline_thickness=%g", tm.underline_position, tm.underline_thickness);
937
+ len = snprintf(temp, sizeof(temp), "underline_position=%g underline_thickness=%g", tm.underline_position, tm.underline_thickness);
964
938
  rb_str_cat(str, temp, len);
965
939
 
966
940
  RB_GC_GUARD(str);
data/ext/RMagick/rmutil.c CHANGED
@@ -13,6 +13,7 @@
13
13
  #include "rmagick.h"
14
14
  #include <errno.h>
15
15
 
16
+ static VALUE rescue_not_str(VALUE, VALUE ATTRIBUTE_UNUSED) ATTRIBUTE_NORETURN;
16
17
  static void handle_exception(ExceptionInfo *, Image *, ErrorRetention);
17
18
 
18
19
 
@@ -78,7 +79,7 @@ magick_malloc(const size_t size)
78
79
  void
79
80
  magick_free(void *ptr)
80
81
  {
81
- (void) RelinquishMagickMemory(ptr);
82
+ RelinquishMagickMemory(ptr);
82
83
  }
83
84
 
84
85
 
@@ -112,28 +113,6 @@ magick_safe_realloc(void *memory, const size_t count, const size_t quantum)
112
113
  }
113
114
 
114
115
 
115
- /**
116
- * ImageMagick version of realloc.
117
- *
118
- * No Ruby usage (internal function)
119
- *
120
- * @param ptr pointer to the existing block of memory
121
- * @param size the new size of memory to allocate
122
- * @return pointer to a block of memory
123
- */
124
- void *
125
- magick_realloc(void *ptr, const size_t size)
126
- {
127
- void *v;
128
- v = ResizeMagickMemory(ptr, size);
129
- if (!v)
130
- {
131
- rb_raise(rb_eNoMemError, "not enough memory to continue");
132
- }
133
- return v;
134
- }
135
-
136
-
137
116
  /**
138
117
  * Make a copy of a string in malloc'd memory.
139
118
  *
@@ -149,7 +128,7 @@ magick_realloc(void *ptr, const size_t size)
149
128
  void
150
129
  magick_clone_string(char **new_str, const char *str)
151
130
  {
152
- (void) CloneString(new_str, str);
131
+ CloneString(new_str, str);
153
132
  }
154
133
 
155
134
 
@@ -208,6 +187,28 @@ rm_strncasecmp(const char *s1, const char *s2, size_t n)
208
187
  }
209
188
 
210
189
 
190
+ /**
191
+ * Get string length.
192
+ *
193
+ * No Ruby usage (internal function)
194
+ *
195
+ * @param str the string
196
+ * @param strsz the maximum number of characters
197
+ * @return same as strnlen_s()
198
+ */
199
+ size_t
200
+ rm_strnlen_s(const char *str, size_t strsz)
201
+ {
202
+ size_t length = 0;
203
+ while(*str && length < strsz)
204
+ {
205
+ str++;
206
+ length++;
207
+ }
208
+ return length;
209
+ }
210
+
211
+
211
212
  /**
212
213
  * Raise exception if array too short.
213
214
  *
@@ -243,7 +244,7 @@ rm_check_ary_type(VALUE ary)
243
244
  VALUE checked = rb_check_array_type(ary);
244
245
  if (NIL_P(checked))
245
246
  {
246
- rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" was given. (must respond to :to_ary)", rb_obj_class(ary));
247
+ rb_raise(rb_eTypeError, "wrong argument type %"RMIsVALUE" was given. (must respond to :to_ary)", rb_obj_class(ary));
247
248
  }
248
249
  return checked;
249
250
  }
@@ -295,35 +296,12 @@ rm_check_frozen(VALUE obj)
295
296
  *
296
297
  * No Ruby usage (internal function)
297
298
  *
298
- * @param obj the object of the class to override
299
- * @return 0
300
- * @throw TypeError
299
+ * @raise [TypeError]
301
300
  */
302
301
  VALUE
303
302
  rm_no_freeze(VALUE obj)
304
303
  {
305
304
  rb_raise(rb_eTypeError, "can't freeze %s", rb_class2name(CLASS_OF(obj)));
306
- return (VALUE)0;
307
- }
308
-
309
-
310
- /**
311
- * Return obj.to_s, or obj if obj is already a string.
312
- *
313
- * No Ruby usage (internal function)
314
- *
315
- * @param obj a Ruby object
316
- * @return a String representation of obj
317
- */
318
- VALUE
319
- rm_to_s(VALUE obj)
320
- {
321
-
322
- if (TYPE(obj) != T_STRING)
323
- {
324
- return rb_funcall(obj, rm_ID_to_s, 0);
325
- }
326
- return obj;
327
305
  }
328
306
 
329
307
 
@@ -348,21 +326,6 @@ rm_str2cstr(VALUE str, long *len)
348
326
  }
349
327
 
350
328
 
351
- /**
352
- * Try to convert the argument to a double, raise an exception if fail.
353
- *
354
- * No Ruby usage (internal function)
355
- *
356
- * @param arg the argument
357
- * @return arg
358
- */
359
- static VALUE
360
- arg_is_number(VALUE arg)
361
- {
362
- return DBL2NUM(NUM2DBL(arg));
363
- }
364
-
365
-
366
329
  /**
367
330
  * Called when `rb_str_to_str' raises an exception.
368
331
  *
@@ -373,11 +336,10 @@ arg_is_number(VALUE arg)
373
336
  * @throw TypeError
374
337
  */
375
338
  static VALUE
376
- rescue_not_str(VALUE arg)
339
+ rescue_not_str(VALUE arg, VALUE raised_exc ATTRIBUTE_UNUSED)
377
340
  {
378
341
  rb_raise(rb_eTypeError, "argument must be a number or a string in the form 'NN%%' (%s given)",
379
342
  rb_class2name(CLASS_OF(arg)));
380
- return (VALUE)0;
381
343
  }
382
344
 
383
345
 
@@ -396,17 +358,15 @@ double
396
358
  rm_percentage(VALUE arg, double max)
397
359
  {
398
360
  double pct;
399
- long pct_long;
400
- char *pct_str, *end;
401
- int not_num;
402
-
403
- // Try to convert the argument to a number. If failure, sets not_num to non-zero.
404
- (void) rb_protect(arg_is_number, arg, &not_num);
361
+ char *end;
405
362
 
406
- if (not_num)
363
+ if (!rm_check_num2dbl(arg))
407
364
  {
365
+ char *pct_str;
366
+ long pct_long;
367
+
408
368
  arg = rb_rescue(rb_str_to_str, arg, rescue_not_str, arg);
409
- pct_str = StringValuePtr(arg);
369
+ pct_str = StringValueCStr(arg);
410
370
  errno = 0;
411
371
  pct_long = strtol(pct_str, &end, 10);
412
372
  if (errno == ERANGE)
@@ -455,7 +415,7 @@ rm_percentage(VALUE arg, double max)
455
415
  static VALUE
456
416
  check_num2dbl(VALUE obj)
457
417
  {
458
- (void) rb_num2dbl(obj);
418
+ rb_num2dbl(obj);
459
419
  return INT2FIX(1);
460
420
  }
461
421
 
@@ -469,7 +429,7 @@ check_num2dbl(VALUE obj)
469
429
  * @return 0
470
430
  */
471
431
  static VALUE
472
- rescue_not_dbl(VALUE ignored ATTRIBUTE_UNUSED)
432
+ rescue_not_dbl(VALUE ignored ATTRIBUTE_UNUSED, VALUE raised_exc ATTRIBUTE_UNUSED)
473
433
  {
474
434
  return INT2FIX(0);
475
435
  }
@@ -505,7 +465,7 @@ rm_str_to_pct(VALUE str)
505
465
  char *pct_str, *end;
506
466
 
507
467
  str = rb_rescue(rb_str_to_str, str, rescue_not_str, str);
508
- pct_str = StringValuePtr(str);
468
+ pct_str = StringValueCStr(str);
509
469
  errno = 0;
510
470
  pct = strtol(pct_str, &end, 10);
511
471
 
@@ -541,17 +501,15 @@ double
541
501
  rm_fuzz_to_dbl(VALUE fuzz_arg)
542
502
  {
543
503
  double fuzz;
544
- char *fuzz_str, *end;
545
- int not_num;
504
+ char *end;
546
505
 
547
- // Try to convert the argument to a number. If failure, sets not_num to non-zero.
548
- (void) rb_protect(arg_is_number, fuzz_arg, &not_num);
549
-
550
- if (not_num)
506
+ if (!rm_check_num2dbl(fuzz_arg))
551
507
  {
508
+ char *fuzz_str;
509
+
552
510
  // Convert to string, issue error message if failure.
553
511
  fuzz_arg = rb_rescue(rb_str_to_str, fuzz_arg, rescue_not_str, fuzz_arg);
554
- fuzz_str = StringValuePtr(fuzz_arg);
512
+ fuzz_str = StringValueCStr(fuzz_arg);
555
513
  errno = 0;
556
514
  fuzz = strtod(fuzz_str, &end);
557
515
  if (errno == ERANGE)
@@ -606,11 +564,9 @@ rm_app2quantum(VALUE obj)
606
564
 
607
565
  if (TYPE(obj) == T_FLOAT)
608
566
  {
609
- v = rb_funcall(obj, rm_ID_to_i, 0);
567
+ v = rb_Integer(obj);
610
568
  }
611
569
 
612
- RB_GC_GUARD(v);
613
-
614
570
  return NUM2QUANTUM(v);
615
571
  }
616
572
 
@@ -632,8 +588,8 @@ rm_acquire_image(ImageInfo *info)
632
588
 
633
589
  exception = AcquireExceptionInfo();
634
590
  new_image = AcquireImage(info, exception);
635
- CHECK_EXCEPTION()
636
- (void) DestroyExceptionInfo(exception);
591
+ CHECK_EXCEPTION();
592
+ DestroyExceptionInfo(exception);
637
593
  return new_image;
638
594
  #else
639
595
  return AcquireImage(info);
@@ -683,9 +639,9 @@ rm_pixelcolor_to_color_name(Image *image, PixelColor *color)
683
639
  pp.colorspace = image->colorspace;
684
640
  #endif
685
641
 
686
- (void) QueryColorname(image, &pp, X11Compliance, name, exception);
687
- CHECK_EXCEPTION()
688
- (void) DestroyExceptionInfo(exception);
642
+ QueryColorname(image, &pp, X11Compliance, name, exception);
643
+ CHECK_EXCEPTION();
644
+ DestroyExceptionInfo(exception);
689
645
 
690
646
  return rb_str_new2(name);
691
647
  }
@@ -726,7 +682,7 @@ rm_pixelcolor_to_color_name_info(Info *info, PixelColor *color)
726
682
  #endif
727
683
 
728
684
  color_name = rm_pixelcolor_to_color_name(image, color);
729
- (void) DestroyImage(image);
685
+ DestroyImage(image);
730
686
 
731
687
  return color_name;
732
688
  }
@@ -765,13 +721,13 @@ rm_set_magickpixel(MagickPixel *pp, const char *color)
765
721
  exception = AcquireExceptionInfo();
766
722
 
767
723
  #if defined(IMAGEMAGICK_7)
768
- (void) QueryColorCompliance(color, AllCompliance, pp, exception);
724
+ QueryColorCompliance(color, AllCompliance, pp, exception);
769
725
  #else
770
- (void) QueryMagickColor(color, pp, exception);
726
+ QueryMagickColor(color, pp, exception);
771
727
  #endif
772
728
  // This exception is ignored because the color comes from places where we control
773
729
  // the value and it is very unlikely that an exception will be thrown.
774
- (void) DestroyExceptionInfo(exception);
730
+ DestroyExceptionInfo(exception);
775
731
  }
776
732
 
777
733
  /**
@@ -785,10 +741,11 @@ rm_set_magickpixel(MagickPixel *pp, const char *color)
785
741
  *
786
742
  * @param image the image
787
743
  * @param temp_name the temporary name to use
744
+ * @param temp_name_l the length of temp_name
788
745
  * @return the "filename" of the registered image
789
746
  */
790
747
  void
791
- rm_write_temp_image(Image *image, char *temp_name)
748
+ rm_write_temp_image(Image *image, char *temp_name, size_t temp_name_l)
792
749
  {
793
750
 
794
751
  #define TMPNAM_CLASS_VAR "@@_tmpnam_"
@@ -815,11 +772,11 @@ rm_write_temp_image(Image *image, char *temp_name)
815
772
 
816
773
  id += 1;
817
774
  rb_cv_set(Module_Magick, TMPNAM_CLASS_VAR, INT2FIX(id));
818
- sprintf(temp_name, "mpri:%d", id);
775
+ snprintf(temp_name, temp_name_l, "mpri:%d", id);
819
776
 
820
777
  // Omit "mpri:" from filename to form the key
821
778
  okay = SetImageRegistry(ImageRegistryType, temp_name+5, image, exception);
822
- CHECK_EXCEPTION()
779
+ CHECK_EXCEPTION();
823
780
  DestroyExceptionInfo(exception);
824
781
  if (!okay)
825
782
  {
@@ -890,7 +847,7 @@ rm_magick_error(const char *msg)
890
847
  mesg = rb_str_new2(msg);
891
848
 
892
849
  exc = rb_funcall(Class_ImageMagickError, rm_ID_new, 2, mesg, Qnil);
893
- (void) rb_funcall(rb_cObject, rb_intern("raise"), 1, exc);
850
+ rb_funcall(rb_cObject, rb_intern("raise"), 1, exc);
894
851
 
895
852
  RB_GC_GUARD(exc);
896
853
  RB_GC_GUARD(mesg);
@@ -899,19 +856,12 @@ rm_magick_error(const char *msg)
899
856
 
900
857
  /**
901
858
  * Initialize a new ImageMagickError object - store the "loc" string in the
902
- * \@magick_location instance variable.
903
- *
904
- * Ruby usage:
905
- * - @verbatim ImageMagickError#initialize(msg) @endverbatim
906
- * - @verbatim ImageMagickError#initialize(msg, loc) @endverbatim
859
+ * magick_location instance variable.
907
860
  *
908
- * Notes:
909
- * - Default loc is nil
910
- *
911
- * @param argc number of input arguments
912
- * @param argv array of input arguments
913
- * @param self this object
914
- * @return self
861
+ * @overload initialize(msg, loc = nil)
862
+ * @param msg [String] the exception message
863
+ * @param loc [String] the location stored in the magick_location instance variable
864
+ * @return [Magick::ImageMagickError] self
915
865
  */
916
866
  VALUE
917
867
  ImageMagickError_initialize(int argc, VALUE *argv, VALUE self)
@@ -933,8 +883,8 @@ ImageMagickError_initialize(int argc, VALUE *argv, VALUE self)
933
883
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 2)", argc);
934
884
  }
935
885
 
936
- (void) rb_call_super(super_argc, (const VALUE *)super_argv);
937
- (void) rb_iv_set(self, "@"MAGICK_LOC, extra);
886
+ rb_call_super(super_argc, (const VALUE *)super_argv);
887
+ rb_iv_set(self, "@"MAGICK_LOC, extra);
938
888
 
939
889
  RB_GC_GUARD(extra);
940
890
 
@@ -960,8 +910,8 @@ rm_get_property(const Image *img, const char *property)
960
910
 
961
911
  exception = AcquireExceptionInfo();
962
912
  result = GetImageProperty(img, property, exception);
963
- CHECK_EXCEPTION()
964
- (void) DestroyExceptionInfo(exception);
913
+ CHECK_EXCEPTION();
914
+ DestroyExceptionInfo(exception);
965
915
  return result;
966
916
  #else
967
917
  return GetImageProperty(img, property);
@@ -975,7 +925,7 @@ rm_get_property(const Image *img, const char *property)
975
925
  * No Ruby usage (internal function)
976
926
  *
977
927
  * @param image the image
978
- * @param property the property name
928
+ * @param property the property name
979
929
  * @param value the property value
980
930
  * @return true if successful, otherwise false
981
931
  */
@@ -988,8 +938,8 @@ rm_set_property(Image *image, const char *property, const char *value)
988
938
 
989
939
  exception = AcquireExceptionInfo();
990
940
  okay = SetImageProperty(image, property, value, exception);
991
- CHECK_EXCEPTION()
992
- (void) DestroyExceptionInfo(exception);
941
+ CHECK_EXCEPTION();
942
+ DestroyExceptionInfo(exception);
993
943
  return okay;
994
944
  #else
995
945
  return SetImageProperty(image, property, value);
@@ -1008,16 +958,17 @@ rm_set_property(Image *image, const char *property, const char *value)
1008
958
  */
1009
959
  void rm_set_user_artifact(Image *images, Info *info)
1010
960
  {
1011
- Image *image;
1012
961
  const char *value;
1013
962
 
1014
963
  value = GetImageOption(info, "user");
1015
964
  if (value)
1016
965
  {
966
+ Image *image;
967
+
1017
968
  image = GetFirstImageInList(images);
1018
969
  while (image)
1019
970
  {
1020
- (void) SetImageArtifact(image, "user", value);
971
+ SetImageArtifact(image, "user", value);
1021
972
  image = GetNextImageInList(image);
1022
973
  }
1023
974
  }
@@ -1049,7 +1000,16 @@ rm_get_optional_arguments(VALUE img)
1049
1000
  optional_method_arguments = rb_const_get_from(Module_Magick, rb_intern("OptionalMethodArguments"));
1050
1001
  argv[0] = img;
1051
1002
  opt_args = rb_class_new_instance(1, argv, optional_method_arguments);
1052
- (void) rb_obj_instance_eval(0, NULL, opt_args);
1003
+
1004
+ if (rb_proc_arity(rb_block_proc()) == 0)
1005
+ {
1006
+ rb_warn("passing a block without an image argument is deprecated");
1007
+ rb_obj_instance_eval(0, NULL, opt_args);
1008
+ }
1009
+ else
1010
+ {
1011
+ rb_yield(opt_args);
1012
+ }
1053
1013
  }
1054
1014
 
1055
1015
  RB_GC_GUARD(optional_method_arguments);
@@ -1070,17 +1030,18 @@ rm_get_optional_arguments(VALUE img)
1070
1030
  static void copy_options(Image *image, Info *info)
1071
1031
  {
1072
1032
  char property[MaxTextExtent];
1073
- const char *value, *option;
1033
+ const char *option;
1074
1034
 
1075
1035
  ResetImageOptionIterator(info);
1076
1036
  for (option = GetNextImageOption(info); option; option = GetNextImageOption(info))
1077
1037
  {
1078
- value = GetImageOption(info,option);
1038
+ const char *value;
1039
+
1040
+ value = GetImageOption(info, option);
1079
1041
  if (value)
1080
1042
  {
1081
- strncpy(property, value, MaxTextExtent);
1082
- property[MaxTextExtent-1] = '\0';
1083
- (void) SetImageArtifact(image, property, value);
1043
+ strlcpy(property, value, sizeof(property));
1044
+ SetImageArtifact(image, property, value);
1084
1045
  }
1085
1046
  }
1086
1047
  }
@@ -1106,13 +1067,13 @@ void rm_sync_image_options(Image *image, Info *info)
1106
1067
 
1107
1068
  // The option strings will be set only when their attribute values were
1108
1069
  // set in the optional argument block.
1109
- option = GetImageOption(info,"background");
1070
+ option = GetImageOption(info, "background");
1110
1071
  if (option)
1111
1072
  {
1112
1073
  image->background_color = info->background_color;
1113
1074
  }
1114
1075
 
1115
- option = GetImageOption(info,"bordercolor");
1076
+ option = GetImageOption(info, "bordercolor");
1116
1077
  if (option)
1117
1078
  {
1118
1079
  image->border_color = info->border_color;
@@ -1126,7 +1087,7 @@ void rm_sync_image_options(Image *image, Info *info)
1126
1087
  // We should not throw an exception in this method because we will
1127
1088
  // leak memory in the place where this method is called. And that is
1128
1089
  // why the exception is being ignored here.
1129
- (void) DestroyExceptionInfo(exception);
1090
+ DestroyExceptionInfo(exception);
1130
1091
  #else
1131
1092
  SetImageColorspace(image, info->colorspace);
1132
1093
  #endif
@@ -1195,7 +1156,7 @@ void rm_sync_image_options(Image *image, Info *info)
1195
1156
  image->interlace = info->interlace;
1196
1157
  }
1197
1158
 
1198
- option = GetImageOption(info,"mattecolor");
1159
+ option = GetImageOption(info, "mattecolor");
1199
1160
  if (option)
1200
1161
  {
1201
1162
  image->matte_color = info->matte_color;
@@ -1208,7 +1169,7 @@ void rm_sync_image_options(Image *image, Info *info)
1208
1169
 
1209
1170
  if (info->page)
1210
1171
  {
1211
- (void)ParseAbsoluteGeometry(info->page, &image->page);
1172
+ ParseAbsoluteGeometry(info->page, &image->page);
1212
1173
  }
1213
1174
 
1214
1175
  if (info->quality != 0UL)
@@ -1225,7 +1186,7 @@ void rm_sync_image_options(Image *image, Info *info)
1225
1186
  option = GetImageOption(info, "tile-offset");
1226
1187
  if (option)
1227
1188
  {
1228
- (void)ParseAbsoluteGeometry(option, &image->tile_offset);
1189
+ ParseAbsoluteGeometry(option, &image->tile_offset);
1229
1190
  }
1230
1191
 
1231
1192
  option = GetImageOption(info, "transparent");
@@ -1308,10 +1269,10 @@ rm_exif_by_entry(Image *image)
1308
1269
  ExceptionInfo *exception;
1309
1270
 
1310
1271
  exception = AcquireExceptionInfo();
1311
- (void) GetImageProperty(image, "exif:*", exception);
1312
- CHECK_EXCEPTION()
1272
+ GetImageProperty(image, "exif:*", exception);
1273
+ CHECK_EXCEPTION();
1313
1274
  #else
1314
- (void) GetImageProperty(image, "exif:*");
1275
+ GetImageProperty(image, "exif:*");
1315
1276
  #endif
1316
1277
 
1317
1278
  ResetImagePropertyIterator(image);
@@ -1321,7 +1282,7 @@ rm_exif_by_entry(Image *image)
1321
1282
  while (property)
1322
1283
  {
1323
1284
  // ignore properties that don't start with "exif:"
1324
- property_l = strlen(property);
1285
+ property_l = rm_strnlen_s(property, MaxTextExtent);
1325
1286
  if (property_l > 5 && rm_strncasecmp(property, "exif:", 5) == 0)
1326
1287
  {
1327
1288
  if (len > 0)
@@ -1331,14 +1292,14 @@ rm_exif_by_entry(Image *image)
1331
1292
  len += property_l - 5;
1332
1293
  #if defined(IMAGEMAGICK_7)
1333
1294
  value = GetImageProperty(image, property, exception);
1334
- CHECK_EXCEPTION()
1295
+ CHECK_EXCEPTION();
1335
1296
  #else
1336
1297
  value = GetImageProperty(image, property);
1337
1298
  #endif
1338
1299
  if (value)
1339
1300
  {
1340
1301
  // add 1 for the = between property and value
1341
- len += 1 + strlen(value);
1302
+ len += 1 + rm_strnlen_s(value, MaxTextExtent);
1342
1303
  }
1343
1304
  }
1344
1305
  property = GetNextImageProperty(image);
@@ -1347,7 +1308,7 @@ rm_exif_by_entry(Image *image)
1347
1308
  if (len == 0)
1348
1309
  {
1349
1310
  #if defined(IMAGEMAGICK_7)
1350
- (void) DestroyExceptionInfo(exception);
1311
+ DestroyExceptionInfo(exception);
1351
1312
  #endif
1352
1313
  return Qnil;
1353
1314
  }
@@ -1361,7 +1322,7 @@ rm_exif_by_entry(Image *image)
1361
1322
 
1362
1323
  while (property)
1363
1324
  {
1364
- property_l = strlen(property);
1325
+ property_l = rm_strnlen_s(property, MaxTextExtent);
1365
1326
  if (property_l > 5 && rm_strncasecmp(property, "exif:", 5) == 0)
1366
1327
  {
1367
1328
  if (len > 0)
@@ -1382,7 +1343,7 @@ rm_exif_by_entry(Image *image)
1382
1343
  #endif
1383
1344
  if (value)
1384
1345
  {
1385
- value_l = strlen(value);
1346
+ value_l = rm_strnlen_s(value, MaxTextExtent);
1386
1347
  str[len++] = '=';
1387
1348
  memcpy(str+len, value, value_l);
1388
1349
  len += value_l;
@@ -1392,7 +1353,7 @@ rm_exif_by_entry(Image *image)
1392
1353
  }
1393
1354
 
1394
1355
  #if defined(IMAGEMAGICK_7)
1395
- (void) DestroyExceptionInfo(exception);
1356
+ DestroyExceptionInfo(exception);
1396
1357
  #endif
1397
1358
 
1398
1359
  v = rb_str_new(str, len);
@@ -1427,10 +1388,10 @@ rm_exif_by_number(Image *image)
1427
1388
  ExceptionInfo *exception;
1428
1389
 
1429
1390
  exception = AcquireExceptionInfo();
1430
- (void) GetImageProperty(image, "exif:!", exception);
1431
- CHECK_EXCEPTION()
1391
+ GetImageProperty(image, "exif:!", exception);
1392
+ CHECK_EXCEPTION();
1432
1393
  #else
1433
- (void) GetImageProperty(image, "exif:!");
1394
+ GetImageProperty(image, "exif:!");
1434
1395
  #endif
1435
1396
  ResetImagePropertyIterator(image);
1436
1397
  property = GetNextImageProperty(image);
@@ -1439,7 +1400,7 @@ rm_exif_by_number(Image *image)
1439
1400
  while (property)
1440
1401
  {
1441
1402
  // ignore properties that don't start with "#"
1442
- property_l = strlen(property);
1403
+ property_l = rm_strnlen_s(property, MaxTextExtent);
1443
1404
  if (property_l > 1 && property[0] == '#')
1444
1405
  {
1445
1406
  if (len > 0)
@@ -1449,14 +1410,14 @@ rm_exif_by_number(Image *image)
1449
1410
  len += property_l;
1450
1411
  #if defined(IMAGEMAGICK_7)
1451
1412
  value = GetImageProperty(image, property, exception);
1452
- CHECK_EXCEPTION()
1413
+ CHECK_EXCEPTION();
1453
1414
  #else
1454
1415
  value = GetImageProperty(image, property);
1455
1416
  #endif
1456
1417
  if (value)
1457
1418
  {
1458
1419
  // add 1 for the = between property and value
1459
- len += 1 + strlen(value);
1420
+ len += 1 + rm_strnlen_s(value, MaxTextExtent);
1460
1421
  }
1461
1422
  }
1462
1423
  property = GetNextImageProperty(image);
@@ -1465,7 +1426,7 @@ rm_exif_by_number(Image *image)
1465
1426
  if (len == 0)
1466
1427
  {
1467
1428
  #if defined(IMAGEMAGICK_7)
1468
- (void) DestroyExceptionInfo(exception);
1429
+ DestroyExceptionInfo(exception);
1469
1430
  #endif
1470
1431
  return Qnil;
1471
1432
  }
@@ -1479,7 +1440,7 @@ rm_exif_by_number(Image *image)
1479
1440
 
1480
1441
  while (property)
1481
1442
  {
1482
- property_l = strlen(property);
1443
+ property_l = rm_strnlen_s(property, MaxTextExtent);
1483
1444
  if (property_l > 1 && property[0] == '#')
1484
1445
  {
1485
1446
  if (len > 0)
@@ -1500,7 +1461,7 @@ rm_exif_by_number(Image *image)
1500
1461
  #endif
1501
1462
  if (value)
1502
1463
  {
1503
- value_l = strlen(value);
1464
+ value_l = rm_strnlen_s(value, MaxTextExtent);
1504
1465
  str[len++] = '=';
1505
1466
  memcpy(str+len, value, value_l);
1506
1467
  len += value_l;
@@ -1510,7 +1471,7 @@ rm_exif_by_number(Image *image)
1510
1471
  }
1511
1472
 
1512
1473
  #if defined(IMAGEMAGICK_7)
1513
- (void) DestroyExceptionInfo(exception);
1474
+ DestroyExceptionInfo(exception);
1514
1475
  #endif
1515
1476
 
1516
1477
  v = rb_str_new(str, len);
@@ -1522,66 +1483,6 @@ rm_exif_by_number(Image *image)
1522
1483
  }
1523
1484
 
1524
1485
 
1525
- /**
1526
- * Get the values from a Geometry object and return them in C variables.
1527
- *
1528
- * No Ruby usage (internal function)
1529
- *
1530
- * Notes:
1531
- * - No return value: modifies x, y, width, height, and flag
1532
- *
1533
- * @param geom the Geometry object
1534
- * @param x pointer to the x position of the start of the rectangle
1535
- * @param y pointer to the y position of the start of the rectangle
1536
- * @param width pointer to the width of the rectangle
1537
- * @param height pointer to the height of the rectangle
1538
- * @param flag pointer to the Geometry's flag
1539
- */
1540
- void
1541
- rm_get_geometry(
1542
- VALUE geom,
1543
- long *x,
1544
- long *y,
1545
- unsigned long *width,
1546
- unsigned long *height,
1547
- int *flag)
1548
- {
1549
- VALUE v;
1550
-
1551
- v = rb_funcall(geom, rm_ID_x, 0);
1552
- *x = NUM2LONG(v);
1553
- v = rb_funcall(geom, rm_ID_y, 0);
1554
- *y = NUM2LONG(v);
1555
- v = rb_funcall(geom, rm_ID_width, 0);
1556
- *width = NUM2ULONG(v);
1557
- v = rb_funcall(geom, rm_ID_height, 0);
1558
- *height = NUM2ULONG(v);
1559
-
1560
- // Getting the flag field is a bit more difficult since it's
1561
- // supposed to be an instance of the GeometryValue Enum class. We
1562
- // may not know the VALUE for the GeometryValue class, and we
1563
- // need to check that the flag field is an instance of that class.
1564
- if (flag)
1565
- {
1566
- MagickEnum *magick_enum;
1567
-
1568
- v = rb_funcall(geom, rm_ID_flag, 0);
1569
- if (!Class_GeometryValue)
1570
- {
1571
- Class_GeometryValue = rb_const_get(Module_Magick, rm_ID_GeometryValue);
1572
- }
1573
- if (CLASS_OF(v) != Class_GeometryValue)
1574
- {
1575
- rb_raise(rb_eTypeError, "wrong enumeration type - expected %s, got %s"
1576
- , rb_class2name(Class_GeometryValue),rb_class2name(CLASS_OF(v)));
1577
- }
1578
- Data_Get_Struct(v, MagickEnum, magick_enum);
1579
- *flag = magick_enum->val;
1580
- }
1581
-
1582
- }
1583
-
1584
-
1585
1486
  /**
1586
1487
  * Clone an image, handle errors.
1587
1488
  *
@@ -1607,7 +1508,7 @@ rm_clone_image(Image *image)
1607
1508
  rb_raise(rb_eNoMemError, "not enough memory to continue");
1608
1509
  }
1609
1510
  rm_check_exception(exception, clone, DestroyOnError);
1610
- (void) DestroyExceptionInfo(exception);
1511
+ DestroyExceptionInfo(exception);
1611
1512
 
1612
1513
  return clone;
1613
1514
  }
@@ -1638,14 +1539,15 @@ rm_progress_monitor(
1638
1539
  VALUE rval;
1639
1540
  VALUE method, offset, span;
1640
1541
 
1641
- // Default Ruby minimum stack size
1642
- #define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
1643
-
1644
- // Check stack length manually instead of ruby_stack_check() for old Ruby.
1645
- if (ruby_stack_length(NULL) > RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN)
1542
+ // Check running thread.
1543
+ if (rm_current_thread_id() != rm_main_thread_id)
1646
1544
  {
1647
- // If there is not enough stack or the using stack size shows an abnormal value in Ruby,
1648
- // skip the callback and continue ImageMagick process.
1545
+ // ImageMagick might call back in a different thread than Ruby is running in.
1546
+ // If it is a different thread, it would not have a Ruby GVL and
1547
+ // it could not retrieve properly Ruby stack.
1548
+
1549
+ // Unfortunately, there is no API available to check if the current thread has a GVL,
1550
+ // so the thread id was checked in here.
1649
1551
  return MagickTrue;
1650
1552
  }
1651
1553
 
@@ -1690,7 +1592,7 @@ rm_split(Image *image)
1690
1592
  }
1691
1593
  while (image)
1692
1594
  {
1693
- (void) RemoveFirstImageFromList(&image);
1595
+ RemoveFirstImageFromList(&image);
1694
1596
  }
1695
1597
  }
1696
1598
 
@@ -1743,7 +1645,7 @@ rm_check_image_exception(Image *imglist, ErrorRetention retention)
1743
1645
  rm_check_exception(exception, imglist, retention);
1744
1646
  }
1745
1647
 
1746
- (void) DestroyExceptionInfo(exception);
1648
+ DestroyExceptionInfo(exception);
1747
1649
  }
1748
1650
  #endif
1749
1651
 
@@ -1763,7 +1665,7 @@ static void
1763
1665
  format_exception(const ExceptionType severity, const char *reason, const char *description, char *msg)
1764
1666
  {
1765
1667
  int len;
1766
- memset(msg, 0, sizeof(ERROR_MSG_SIZE));
1668
+ memset(msg, 0, ERROR_MSG_SIZE);
1767
1669
 
1768
1670
  len = snprintf(msg, ERROR_MSG_SIZE, "%s%s%s",
1769
1671
  GetLocaleExceptionMessage(severity, reason),
@@ -1892,7 +1794,7 @@ handle_exception(ExceptionInfo *exception, Image *imglist, ErrorRetention retent
1892
1794
  {
1893
1795
  if (retention == DestroyOnError)
1894
1796
  {
1895
- (void) DestroyImageList(imglist);
1797
+ DestroyImageList(imglist);
1896
1798
  imglist = NULL;
1897
1799
  }
1898
1800
  else
@@ -1903,7 +1805,7 @@ handle_exception(ExceptionInfo *exception, Image *imglist, ErrorRetention retent
1903
1805
 
1904
1806
  format_exception(exception->severity, exception->reason, exception->description, msg);
1905
1807
 
1906
- (void) DestroyExceptionInfo(exception);
1808
+ DestroyExceptionInfo(exception);
1907
1809
 
1908
1810
  rm_magick_error(msg);
1909
1811
  }
@@ -1947,7 +1849,7 @@ rm_should_raise_exception(ExceptionInfo *exception, const ExceptionRetention ret
1947
1849
 
1948
1850
  if (retention == DestroyExceptionRetention)
1949
1851
  {
1950
- (void) DestroyExceptionInfo(exception);
1852
+ DestroyExceptionInfo(exception);
1951
1853
  }
1952
1854
 
1953
1855
  return MagickFalse;
@@ -1971,8 +1873,26 @@ rm_raise_exception(ExceptionInfo *exception)
1971
1873
 
1972
1874
  format_exception(exception->severity, exception->reason, exception->description, msg);
1973
1875
 
1974
- (void) DestroyExceptionInfo(exception);
1876
+ DestroyExceptionInfo(exception);
1975
1877
 
1976
1878
  rm_magick_error(msg);
1977
1879
  }
1978
1880
 
1881
+ /**
1882
+ * Get current thread id.
1883
+ *
1884
+ * No Ruby usage (internal function)
1885
+ *
1886
+ * @return thread id
1887
+ */
1888
+ unsigned long long
1889
+ rm_current_thread_id()
1890
+ {
1891
+ #if defined(_WIN32)
1892
+ #include <Windows.h>
1893
+ return (unsigned long long)GetCurrentThreadId();
1894
+ #else
1895
+ #include <pthread.h>
1896
+ return (unsigned long long)pthread_self();
1897
+ #endif
1898
+ }