Run .so init functions in namespaces to be loaded
authorSatoshi Tagomori <[email protected]>
Fri, 31 Oct 2025 11:06:33 +0000 (31 20:06 +0900)
committerSatoshi Tagomori <[email protected]>
Fri, 31 Oct 2025 13:42:07 +0000 (31 22:42 +0900)
load.c

diff --git a/load.c b/load.c
index 9a1ff53..d1d6969 100644 (file)
--- a/load.c
+++ b/load.c
@@ -1212,17 +1212,19 @@ load_ext(VALUE path, VALUE fname)
     return (VALUE)dln_load_feature(RSTRING_PTR(loaded), RSTRING_PTR(fname));
 }
 
-static bool
-run_static_ext_init(rb_vm_t *vm, const char *feature)
+static VALUE
+run_static_ext_init(VALUE vm_ptr, VALUE feature_value)
 {
+    rb_vm_t *vm = (rb_vm_t *)vm_ptr;
+    const char *feature = RSTRING_PTR(feature_value);
     st_data_t key = (st_data_t)feature;
     st_data_t init_func;
 
     if (vm->static_ext_inits && st_delete(vm->static_ext_inits, &key, &init_func)) {
         ((void (*)(void))init_func)();
-        return true;
+        return Qtrue;
     }
-    return false;
+    return Qfalse;
 }
 
 static int
@@ -1331,7 +1333,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception, bool wa
             else if (!*ftptr) {
                 result = TAG_RETURN;
             }
-            else if (found == 's' && run_static_ext_init(th->vm, RSTRING_PTR(path))) {
+            else if (found == 's' && RTEST(rb_vm_call_cfunc_in_namespace(Qnil, run_static_ext_init, (VALUE)th->vm, path, path, ns))) {
                 result = TAG_RETURN;
             }
             else if (RTEST(rb_hash_aref(realpaths,