swig-4.0.1-Add-support-for-Ruby-2.7.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. From 00e291b319bd6b58bf061feee3721a58c9c6be32 Mon Sep 17 00:00:00 2001
  2. From: Thomas Reitmayr <treitmayr@devbase.at>
  3. Date: Mon, 30 Dec 2019 20:11:03 +0100
  4. Subject: [PATCH 1/3] Add support for Ruby 2.7
  5. This commit fixes the signatures of various callback methods
  6. and cleans up the macro definitions used for casting callbacks.
  7. Note that the transparent version of the macro RUBY_METHOD_FUNC
  8. is currently masked behind RUBY_DEVEL, see commit
  9. https://github.com/ruby/ruby/commit/1d91feaf13e0ffe04b2dabc6e77e4101b6d0bb07
  10. In order to still support strict signature checking and prevent
  11. nasty deprecation warnings, the use of RUBY_METHOD_FUNC had to
  12. be replaced with VALUEFUNC.
  13. ---
  14. Lib/ruby/rubyclasses.swg | 14 +++++++-------
  15. Lib/ruby/rubyhead.swg | 26 +++++++++-----------------
  16. Lib/ruby/rubyprimtypes.swg | 15 ++++++++-------
  17. Lib/ruby/rubytracking.swg | 10 +++++-----
  18. Source/Modules/ruby.cxx | 22 +++++++++-------------
  19. 5 files changed, 38 insertions(+), 49 deletions(-)
  20. diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg
  21. index f7b51bdcc5..b345fcebeb 100644
  22. --- a/Lib/ruby/rubyclasses.swg
  23. +++ b/Lib/ruby/rubyclasses.swg
  24. @@ -174,7 +174,7 @@ namespace swig {
  25. return rb_inspect(_obj);
  26. }
  27. - static VALUE swig_rescue_swallow(VALUE)
  28. + static VALUE swig_rescue_swallow(VALUE, VALUE)
  29. {
  30. /*
  31. VALUE errstr = rb_obj_as_string(rb_errinfo());
  32. @@ -203,8 +203,8 @@ namespace swig {
  33. args.id = op_id;
  34. args.nargs = 1;
  35. args.target = VALUE(other);
  36. - ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args),
  37. - (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil);
  38. + ret = rb_rescue(VALUEFUNC(swig_rescue_funcall), VALUE(&args),
  39. + (VALUEFUNC(swig_rescue_swallow)), Qnil);
  40. }
  41. if (ret == Qnil) {
  42. VALUE a = rb_funcall( _obj, hash_id, 0 );
  43. @@ -243,8 +243,8 @@ namespace swig {
  44. args.id = op_id;
  45. args.nargs = 0;
  46. args.target = Qnil;
  47. - ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args),
  48. - (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil);
  49. + ret = rb_rescue(VALUEFUNC(swig_rescue_funcall), VALUE(&args),
  50. + (VALUEFUNC(swig_rescue_swallow)), Qnil);
  51. SWIG_RUBY_THREAD_END_BLOCK;
  52. return ret;
  53. }
  54. @@ -262,8 +262,8 @@ namespace swig {
  55. args.id = op_id;
  56. args.nargs = 1;
  57. args.target = VALUE(other);
  58. - ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args),
  59. - (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil);
  60. + ret = rb_rescue(VALUEFUNC(swig_rescue_funcall), VALUE(&args),
  61. + (VALUEFUNC(swig_rescue_swallow)), Qnil);
  62. SWIG_RUBY_THREAD_END_BLOCK;
  63. return GC_VALUE(ret);
  64. }
  65. diff --git a/Lib/ruby/rubyhead.swg b/Lib/ruby/rubyhead.swg
  66. index 90f07cf683..9a0400eea9 100644
  67. --- a/Lib/ruby/rubyhead.swg
  68. +++ b/Lib/ruby/rubyhead.swg
  69. @@ -110,26 +110,18 @@
  70. * can be passed as an argument to API functions like Data_Wrap_Struct()
  71. * and Data_Make_Struct().
  72. */
  73. -
  74. -#ifdef __cplusplus
  75. -# ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
  76. -# define PROTECTFUNC(f) ((VALUE (*)()) f)
  77. -# define VALUEFUNC(f) ((VALUE (*)()) f)
  78. -# define VOIDFUNC(f) ((void (*)()) f)
  79. -# else
  80. -# ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
  81. -# define PROTECTFUNC(f) ((VALUE (*)()) f)
  82. -# define VALUEFUNC(f) ((VALUE (*)()) f)
  83. -# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
  84. -# else /* These definitions should work for Ruby 1.7+ */
  85. -# define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
  86. -# define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
  87. -# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
  88. -# endif
  89. -# endif
  90. +#if defined(__cplusplus) && !defined(RB_METHOD_DEFINITION_DECL)
  91. +# define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
  92. +# define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
  93. +# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
  94. +# define VOID_ANYARGS_FUNC(f) ((void (*)(ANYARGS))(f))
  95. +# define INT_ANYARGS_FUNC(f) ((int (*)(ANYARGS))(f))
  96. #else
  97. +# define PROTECTFUNC(f) (f)
  98. # define VALUEFUNC(f) (f)
  99. # define VOIDFUNC(f) (f)
  100. +# define VOID_ANYARGS_FUNC(f) (f)
  101. +# define INT_ANYARGS_FUNC(f) (f)
  102. #endif
  103. /* Don't use for expressions have side effect */
  104. diff --git a/Lib/ruby/rubyprimtypes.swg b/Lib/ruby/rubyprimtypes.swg
  105. index 3a848191cd..4b078deea0 100644
  106. --- a/Lib/ruby/rubyprimtypes.swg
  107. +++ b/Lib/ruby/rubyprimtypes.swg
  108. @@ -10,15 +10,16 @@
  109. %fragment("SWIG_ruby_failed","header")
  110. {
  111. SWIGINTERN VALUE
  112. -SWIG_ruby_failed(void)
  113. +SWIG_ruby_failed(VALUE SWIGUNUSEDPARM(arg1), VALUE SWIGUNUSEDPARM(arg2))
  114. {
  115. return Qnil;
  116. }
  117. }
  118. %define %ruby_aux_method(Type, Method, Action)
  119. -SWIGINTERN VALUE SWIG_AUX_##Method##(VALUE *args)
  120. +SWIGINTERN VALUE SWIG_AUX_##Method##(VALUE arg)
  121. {
  122. + VALUE *args = (VALUE *)arg;
  123. VALUE obj = args[0];
  124. VALUE type = TYPE(obj);
  125. Type *res = (Type *)(args[1]);
  126. @@ -79,7 +80,7 @@ SWIG_AsVal_dec(long)(VALUE obj, long* val)
  127. VALUE a[2];
  128. a[0] = obj;
  129. a[1] = (VALUE)(&v);
  130. - if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2LONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
  131. + if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2LONG), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) {
  132. if (val) *val = v;
  133. return SWIG_OK;
  134. }
  135. @@ -111,7 +112,7 @@ SWIG_AsVal_dec(unsigned long)(VALUE obj, unsigned long *val)
  136. VALUE a[2];
  137. a[0] = obj;
  138. a[1] = (VALUE)(&v);
  139. - if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
  140. + if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2ULONG), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) {
  141. if (val) *val = v;
  142. return SWIG_OK;
  143. }
  144. @@ -149,7 +150,7 @@ SWIG_AsVal_dec(long long)(VALUE obj, long long *val)
  145. VALUE a[2];
  146. a[0] = obj;
  147. a[1] = (VALUE)(&v);
  148. - if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2LL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
  149. + if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2LL), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) {
  150. if (val) *val = v;
  151. return SWIG_OK;
  152. }
  153. @@ -187,7 +188,7 @@ SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val)
  154. VALUE a[2];
  155. a[0] = obj;
  156. a[1] = (VALUE)(&v);
  157. - if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
  158. + if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2ULL), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) {
  159. if (val) *val = v;
  160. return SWIG_OK;
  161. }
  162. @@ -215,7 +216,7 @@ SWIG_AsVal_dec(double)(VALUE obj, double *val)
  163. VALUE a[2];
  164. a[0] = obj;
  165. a[1] = (VALUE)(&v);
  166. - if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2DBL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
  167. + if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2DBL), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) {
  168. if (val) *val = v;
  169. return SWIG_OK;
  170. }
  171. diff --git a/Lib/ruby/rubytracking.swg b/Lib/ruby/rubytracking.swg
  172. index b9fb249d80..221a681939 100644
  173. --- a/Lib/ruby/rubytracking.swg
  174. +++ b/Lib/ruby/rubytracking.swg
  175. @@ -32,7 +32,7 @@ extern "C" {
  176. */
  177. static st_table* swig_ruby_trackings = NULL;
  178. -static VALUE swig_ruby_trackings_count(ANYARGS) {
  179. +static VALUE swig_ruby_trackings_count(ID id, VALUE *var) {
  180. return SWIG2NUM(swig_ruby_trackings->num_entries);
  181. }
  182. @@ -69,7 +69,7 @@ SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) {
  183. swig_ruby_trackings = (st_table*)NUM2SWIG(trackings_value);
  184. }
  185. - rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", swig_ruby_trackings_count, NULL);
  186. + rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", VALUEFUNC(swig_ruby_trackings_count), VOID_ANYARGS_FUNC((rb_gvar_setter_t*)NULL));
  187. }
  188. /* Add a Tracking from a C/C++ struct to a Ruby object */
  189. @@ -118,13 +118,13 @@ SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) {
  190. to the passed callback function. */
  191. /* Proxy method to abstract the internal trackings datatype */
  192. -static int swig_ruby_internal_iterate_callback(void* ptr, VALUE obj, void(*meth)(void* ptr, VALUE obj)) {
  193. - (*meth)(ptr, obj);
  194. +static int swig_ruby_internal_iterate_callback(st_data_t ptr, st_data_t obj, st_data_t meth) {
  195. + ((void (*) (void *, VALUE))meth)((void *)ptr, (VALUE)obj);
  196. return ST_CONTINUE;
  197. }
  198. SWIGRUNTIME void SWIG_RubyIterateTrackings( void(*meth)(void* ptr, VALUE obj) ) {
  199. - st_foreach(swig_ruby_trackings, (int (*)(ANYARGS))&swig_ruby_internal_iterate_callback, (st_data_t)meth);
  200. + st_foreach(swig_ruby_trackings, INT_ANYARGS_FUNC(swig_ruby_internal_iterate_callback), (st_data_t)meth);
  201. }
  202. #ifdef __cplusplus
  203. diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx
  204. index c8f582679b..01b75befa5 100644
  205. --- a/Source/Modules/ruby.cxx
  206. +++ b/Source/Modules/ruby.cxx
  207. @@ -2191,6 +2191,7 @@ class RUBY:public Language {
  208. String *tm;
  209. String *getfname, *setfname;
  210. Wrapper *getf, *setf;
  211. + const int assignable = is_assignable(n);
  212. // Determine whether virtual global variables shall be used
  213. // which have different getter and setter signatures,
  214. @@ -2206,7 +2207,7 @@ class RUBY:public Language {
  215. getfname = Swig_name_wrapper(getname);
  216. Setattr(n, "wrap:name", getfname);
  217. Printv(getf->def, "SWIGINTERN VALUE\n", getfname, "(", NIL);
  218. - Printf(getf->def, (use_virtual_var) ? "ID id" : "VALUE self");
  219. + Printf(getf->def, (use_virtual_var) ? "ID id, VALUE *data" : "VALUE self");
  220. Printf(getf->def, ") {");
  221. Wrapper_add_local(getf, "_val", "VALUE _val");
  222. @@ -2229,8 +2230,8 @@ class RUBY:public Language {
  223. Wrapper_print(getf, f_wrappers);
  224. - if (!is_assignable(n)) {
  225. - setfname = NewString("NULL");
  226. + if (!assignable) {
  227. + setfname = NewString("(rb_gvar_setter_t *)NULL");
  228. } else {
  229. /* create setter */
  230. String* docs = docstring(n, AUTODOC_SETTER);
  231. @@ -2242,7 +2243,7 @@ class RUBY:public Language {
  232. Setattr(n, "wrap:name", setfname);
  233. Printf(setf->def, "SWIGINTERN ");
  234. if (use_virtual_var) {
  235. - Printv(setf->def, "void\n", setfname, "(VALUE _val, ID id) {", NIL);
  236. + Printv(setf->def, "void\n", setfname, "(VALUE _val, ID id, VALUE *data) {", NIL);
  237. } else {
  238. Printv(setf->def, "VALUE\n", setfname, "(VALUE self, VALUE _val) {", NIL);
  239. }
  240. @@ -2273,7 +2274,7 @@ class RUBY:public Language {
  241. if (CPlusPlus) {
  242. Insert(getfname, 0, "VALUEFUNC(");
  243. Append(getfname, ")");
  244. - Insert(setfname, 0, (use_virtual_var) ? "(void (*)(ANYARGS))(" : "VALUEFUNC(");
  245. + Insert(setfname, 0, (use_virtual_var) ? "VOID_ANYARGS_FUNC(" : "VALUEFUNC(");
  246. Append(setfname, ")");
  247. }
  248. @@ -2282,7 +2283,7 @@ class RUBY:public Language {
  249. case STATIC_VAR:
  250. /* C++ class variable */
  251. Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"", klass->strip(iname), "\", ", getfname, ", 0);\n", NIL);
  252. - if (!GetFlag(n, "feature:immutable")) {
  253. + if (assignable) {
  254. Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"", klass->strip(iname), "=\", ", setfname, ", 1);\n", NIL);
  255. }
  256. Printv(klass->init, s, NIL);
  257. @@ -2293,16 +2294,11 @@ class RUBY:public Language {
  258. assert(current == NO_CPP);
  259. if (!useGlobalModule) {
  260. Printv(s, tab4, "rb_define_singleton_method(", modvar, ", \"", iname, "\", ", getfname, ", 0);\n", NIL);
  261. - if (!GetFlag(n, "feature:immutable")) {
  262. + if (assignable) {
  263. Printv(s, tab4, "rb_define_singleton_method(", modvar, ", \"", iname, "=\", ", setfname, ", 1);\n", NIL);
  264. }
  265. } else {
  266. - Printv(s, tab4, "rb_define_virtual_variable(\"$", iname, "\", ", getfname, ", ", NIL);
  267. - if (GetFlag(n, "feature:immutable")) {
  268. - Printv(s, tab4, "0);\n", NIL);
  269. - } else {
  270. - Printv(s, tab4, setfname, ");\n", NIL);
  271. - }
  272. + Printv(s, tab4, "rb_define_virtual_variable(\"$", iname, "\", ", getfname, ", ", setfname, ");\n", NIL);
  273. }
  274. Printv(f_init, s, NIL);
  275. Delete(s);
  276. From 5542cc228ad10bdc5c91107afb77c808c43bf2a4 Mon Sep 17 00:00:00 2001
  277. From: Thomas Reitmayr <treitmayr@devbase.at>
  278. Date: Fri, 3 Jan 2020 21:45:53 +0100
  279. Subject: [PATCH 2/3] Move new macros for Ruby to their dedicated namespace
  280. ---
  281. Lib/ruby/rubyhead.swg | 8 ++++----
  282. Lib/ruby/rubytracking.swg | 8 ++++++--
  283. Source/Modules/ruby.cxx | 2 +-
  284. 3 files changed, 11 insertions(+), 7 deletions(-)
  285. diff --git a/Lib/ruby/rubyhead.swg b/Lib/ruby/rubyhead.swg
  286. index 9a0400eea9..89d6f14662 100644
  287. --- a/Lib/ruby/rubyhead.swg
  288. +++ b/Lib/ruby/rubyhead.swg
  289. @@ -114,14 +114,14 @@
  290. # define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
  291. # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
  292. # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
  293. -# define VOID_ANYARGS_FUNC(f) ((void (*)(ANYARGS))(f))
  294. -# define INT_ANYARGS_FUNC(f) ((int (*)(ANYARGS))(f))
  295. +# define SWIG_RUBY_VOID_ANYARGS_FUNC(f) ((void (*)(ANYARGS))(f))
  296. +# define SWIG_RUBY_INT_ANYARGS_FUNC(f) ((int (*)(ANYARGS))(f))
  297. #else
  298. # define PROTECTFUNC(f) (f)
  299. # define VALUEFUNC(f) (f)
  300. # define VOIDFUNC(f) (f)
  301. -# define VOID_ANYARGS_FUNC(f) (f)
  302. -# define INT_ANYARGS_FUNC(f) (f)
  303. +# define SWIG_RUBY_VOID_ANYARGS_FUNC(f) (f)
  304. +# define SWIG_RUBY_INT_ANYARGS_FUNC(f) (f)
  305. #endif
  306. /* Don't use for expressions have side effect */
  307. diff --git a/Lib/ruby/rubytracking.swg b/Lib/ruby/rubytracking.swg
  308. index 221a681939..1edcc56819 100644
  309. --- a/Lib/ruby/rubytracking.swg
  310. +++ b/Lib/ruby/rubytracking.swg
  311. @@ -69,7 +69,9 @@ SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) {
  312. swig_ruby_trackings = (st_table*)NUM2SWIG(trackings_value);
  313. }
  314. - rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", VALUEFUNC(swig_ruby_trackings_count), VOID_ANYARGS_FUNC((rb_gvar_setter_t*)NULL));
  315. + rb_define_virtual_variable("SWIG_TRACKINGS_COUNT",
  316. + VALUEFUNC(swig_ruby_trackings_count),
  317. + SWIG_RUBY_VOID_ANYARGS_FUNC((rb_gvar_setter_t*)NULL));
  318. }
  319. /* Add a Tracking from a C/C++ struct to a Ruby object */
  320. @@ -124,7 +126,9 @@ static int swig_ruby_internal_iterate_callback(st_data_t ptr, st_data_t obj, st_
  321. }
  322. SWIGRUNTIME void SWIG_RubyIterateTrackings( void(*meth)(void* ptr, VALUE obj) ) {
  323. - st_foreach(swig_ruby_trackings, INT_ANYARGS_FUNC(swig_ruby_internal_iterate_callback), (st_data_t)meth);
  324. + st_foreach(swig_ruby_trackings,
  325. + SWIG_RUBY_INT_ANYARGS_FUNC(swig_ruby_internal_iterate_callback),
  326. + (st_data_t)meth);
  327. }
  328. #ifdef __cplusplus
  329. diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx
  330. index 01b75befa5..fcbcb7a5c1 100644
  331. --- a/Source/Modules/ruby.cxx
  332. +++ b/Source/Modules/ruby.cxx
  333. @@ -2274,7 +2274,7 @@ class RUBY:public Language {
  334. if (CPlusPlus) {
  335. Insert(getfname, 0, "VALUEFUNC(");
  336. Append(getfname, ")");
  337. - Insert(setfname, 0, (use_virtual_var) ? "VOID_ANYARGS_FUNC(" : "VALUEFUNC(");
  338. + Insert(setfname, 0, (use_virtual_var) ? "SWIG_RUBY_VOID_ANYARGS_FUNC(" : "VALUEFUNC(");
  339. Append(setfname, ")");
  340. }
  341. From f5908eca7638b786acda58306ba96ff70094e98b Mon Sep 17 00:00:00 2001
  342. From: Thomas Reitmayr <treitmayr@devbase.at>
  343. Date: Sat, 4 Jan 2020 18:21:10 +0100
  344. Subject: [PATCH 3/3] Improve description of cast macros for Ruby
  345. The macros for casting function pointers are now fully described and also
  346. clarify why the macros act transparently for C even before Ruby 2.7.
  347. In addition, an "if (CPlusPlus)" was removed in the code generator for
  348. global variables in order to keep the distinction between C and C++ in
  349. one place, which is at the definition of said macros.
  350. ---
  351. Lib/ruby/rubyhead.swg | 32 ++++++++++++++++++++++++--------
  352. Source/Modules/ruby.cxx | 12 +++++-------
  353. 2 files changed, 29 insertions(+), 15 deletions(-)
  354. diff --git a/Lib/ruby/rubyhead.swg b/Lib/ruby/rubyhead.swg
  355. index 89d6f14662..bf4e36248e 100644
  356. --- a/Lib/ruby/rubyhead.swg
  357. +++ b/Lib/ruby/rubyhead.swg
  358. @@ -98,17 +98,33 @@
  359. /*
  360. - * Need to be very careful about how these macros are defined, especially
  361. - * when compiling C++ code or C code with an ANSI C compiler.
  362. + * The following macros are used for providing the correct type of a
  363. + * function pointer to the Ruby C API.
  364. + * Starting with Ruby 2.7 (corresponding to RB_METHOD_DEFINITION_DECL being
  365. + * defined) these macros act transparently due to Ruby's moving away from
  366. + * ANYARGS and instead employing strict function signatures.
  367. *
  368. - * VALUEFUNC(f) is a macro used to typecast a C function that implements
  369. - * a Ruby method so that it can be passed as an argument to API functions
  370. - * like rb_define_method() and rb_define_singleton_method().
  371. + * Note: In case of C (not C++) the macros are transparent even before
  372. + * Ruby 2.7 due to the fact that the Ruby C API used function declarators
  373. + * with empty parentheses, which allows for an unspecified number of
  374. + * arguments.
  375. *
  376. - * VOIDFUNC(f) is a macro used to typecast a C function that implements
  377. - * either the "mark" or "free" stuff for a Ruby Data object, so that it
  378. - * can be passed as an argument to API functions like Data_Wrap_Struct()
  379. + * PROTECTFUNC(f) is used for the function pointer argument of the Ruby
  380. + * C API function rb_protect().
  381. + *
  382. + * VALUEFUNC(f) is used for the function pointer argument(s) of Ruby C API
  383. + * functions like rb_define_method() and rb_define_singleton_method().
  384. + *
  385. + * VOIDFUNC(f) is used to typecast a C function that implements either
  386. + * the "mark" or "free" stuff for a Ruby Data object, so that it can be
  387. + * passed as an argument to Ruby C API functions like Data_Wrap_Struct()
  388. * and Data_Make_Struct().
  389. + *
  390. + * SWIG_RUBY_VOID_ANYARGS_FUNC(f) is used for the function pointer
  391. + * argument(s) of Ruby C API functions like rb_define_virtual_variable().
  392. + *
  393. + * SWIG_RUBY_INT_ANYARGS_FUNC(f) is used for the function pointer
  394. + * argument(s) of Ruby C API functions like st_foreach().
  395. */
  396. #if defined(__cplusplus) && !defined(RB_METHOD_DEFINITION_DECL)
  397. # define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
  398. diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx
  399. index fcbcb7a5c1..48b0efab36 100644
  400. --- a/Source/Modules/ruby.cxx
  401. +++ b/Source/Modules/ruby.cxx
  402. @@ -2270,13 +2270,11 @@ class RUBY:public Language {
  403. Delete(setname);
  404. }
  405. - /* define accessor method */
  406. - if (CPlusPlus) {
  407. - Insert(getfname, 0, "VALUEFUNC(");
  408. - Append(getfname, ")");
  409. - Insert(setfname, 0, (use_virtual_var) ? "SWIG_RUBY_VOID_ANYARGS_FUNC(" : "VALUEFUNC(");
  410. - Append(setfname, ")");
  411. - }
  412. + /* define accessor methods */
  413. + Insert(getfname, 0, "VALUEFUNC(");
  414. + Append(getfname, ")");
  415. + Insert(setfname, 0, (use_virtual_var) ? "SWIG_RUBY_VOID_ANYARGS_FUNC(" : "VALUEFUNC(");
  416. + Append(setfname, ")");
  417. String *s = NewString("");
  418. switch (current) {