diff options
| author | Yusuke Endoh <mame@ruby-lang.org> | 2025-05-01 18:36:24 +0900 |
|---|---|---|
| committer | Satoshi Tagomori <tagomoris@gmail.com> | 2025-05-11 23:32:50 +0900 |
| commit | 4b33b468ac2f20d7b13e691ecc2c7e857b53d356 (patch) | |
| tree | 794837dfc94a267c66fc261807ced0e1eaa38732 | |
| parent | cf3e2bbad27b8e37fcad7b804b44b907eca45a86 (diff) | |
Fix function pointer type mismatch with `rb_define_private_method`
`rb_define_private_method` performs strict type checking on the function
pointer. As a result, we cannot pass the function a generic signature.
```
/github/workspace/src/namespace.c:1097:72: note: expected 'VALUE (*)(void)' {aka 'long unsigned int (*)(void)'} but argument is of type 'VALUE (*)(int, VALUE *, VALUE)' {aka 'long unsigned int (*)(int, long unsigned int *, long unsigned int)'}
1097 | namespace_define_loader_method(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc)
| ~~~~~~~~^~~~~~~~~~~~~~
```
This commit defines the method directly to avoid the mismatch error.
| -rw-r--r-- | namespace.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/namespace.c b/namespace.c index 25b960f0f6..f742a6f245 100644 --- a/namespace.c +++ b/namespace.c @@ -1094,10 +1094,10 @@ setup_pushing_loading_namespace(rb_namespace_t *ns) } static void -namespace_define_loader_method(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc) +namespace_define_loader_method(const char *name) { - rb_define_private_method(module, name, func, argc); - rb_define_singleton_method(module, name, func, argc); + rb_define_private_method(rb_mNamespaceLoader, name, rb_namespace_user_loading_func, -1); + rb_define_singleton_method(rb_mNamespaceLoader, name, rb_namespace_user_loading_func, -1); } void @@ -1118,9 +1118,9 @@ Init_Namespace(void) } rb_mNamespaceLoader = rb_define_module_under(rb_cNamespace, "Loader"); - namespace_define_loader_method(rb_mNamespaceLoader, "require", rb_namespace_user_loading_func, -1); - namespace_define_loader_method(rb_mNamespaceLoader, "require_relative", rb_namespace_user_loading_func, -1); - namespace_define_loader_method(rb_mNamespaceLoader, "load", rb_namespace_user_loading_func, -1); + namespace_define_loader_method("require"); + namespace_define_loader_method("require_relative"); + namespace_define_loader_method("load"); rb_define_singleton_method(rb_cNamespace, "enabled?", rb_namespace_s_getenabled, 0); rb_define_singleton_method(rb_cNamespace, "current", rb_namespace_current, 0); |
