|
84 | 84 |
|
85 | 85 | #elif defined(_WIN32) || defined(__CYGWIN__) |
86 | 86 | # /* Skip due to [Bug #16134] */ |
| 87 | +# define RBIMPL_CAST_FN_PTR 1 |
87 | 88 |
|
88 | 89 | #elif ! RBIMPL_HAS_ATTRIBUTE(transparent_union) |
89 | 90 | # /* :TODO: improve here, please find a way to support. */ |
| 91 | +# define RBIMPL_CAST_FN_PTR 1 |
90 | 92 |
|
91 | 93 | #elif ! defined(HAVE_VA_ARGS_MACRO) |
92 | 94 | # /* :TODO: improve here, please find a way to support. */ |
| 95 | +# define RBIMPL_CAST_FN_PTR 1 |
93 | 96 |
|
94 | 97 | #else |
95 | 98 | # /** @cond INTERNAL_MACRO */ |
@@ -348,6 +351,25 @@ RBIMPL_ANYARGS_DECL(rb_define_method, VALUE, const char *) |
348 | 351 |
|
349 | 352 | #endif /* __cplusplus */ |
350 | 353 |
|
| 354 | +#if defined(RBIMPL_CAST_FN_PTR) && !defined(__cplusplus) |
| 355 | +/* In C23, K&R style prototypes are gone and so `void foo(ANYARGS)` became |
| 356 | + * equivalent to `void foo(void)` unlike in earlier versions. This is a problem |
| 357 | + * for rb_define_* functions since that makes all valid functions one can pass |
| 358 | + * trip -Wincompatible-pointer-types, which we treat as errors. This is mostly |
| 359 | + * not a problem for the __builtin_choose_expr path, but outside of that we |
| 360 | + * need to add a cast for compatibility. |
| 361 | + */ |
| 362 | +#define rb_define_method(klass, mid, func, arity) rb_define_method((klass), (mid), (VALUE (*)(ANYARGS))(func), (arity)) |
| 363 | +#define rb_define_method_id(klass, mid, func, arity) rb_define_method_id((klass), (mid), (VALUE (*)(ANYARGS))(func), (arity)) |
| 364 | +#define rb_define_singleton_method(obj, mid, func, arity) rb_define_singleton_method((obj), (mid), (VALUE (*)(ANYARGS))(func), (arity)) |
| 365 | +#define rb_define_protected_method(klass, mid, func, arity) rb_define_protected_method((klass), (mid), (VALUE (*)(ANYARGS))(func), (arity)) |
| 366 | +#define rb_define_private_method(klass, mid, func, arity) rb_define_private_method((klass), (mid), (VALUE (*)(ANYARGS))(func), (arity)) |
| 367 | +#define rb_define_module_function(mod, mid, func, arity) rb_define_module_function((mod), (mid), (VALUE (*)(ANYARGS))(func), (arity)) |
| 368 | +#define rb_define_global_function(mid, func, arity) rb_define_global_function((mid), (VALUE (*)(ANYARGS))(func), (arity)) |
| 369 | + |
| 370 | +#undef RBIMPL_CAST_FN_PTR |
| 371 | +#endif /* defined(RBIMPL_CAST_FN_PTR) && !defined(__cplusplus) */ |
| 372 | + |
351 | 373 | /** |
352 | 374 | * This macro is to properly cast a function parameter of *_define_method |
353 | 375 | * family. It has been around since 1.x era so you can maximise backwards |
|
0 commit comments