From 4b33b468ac2f20d7b13e691ecc2c7e857b53d356 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Thu, 1 May 2025 18:36:24 +0900 Subject: [PATCH] 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. --- namespace.c | 12 ++++++------ 1 file 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);