summaryrefslogtreecommitdiff
path: root/ext/ffi_c/Function.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ffi_c/Function.c')
-rw-r--r--ext/ffi_c/Function.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/ext/ffi_c/Function.c b/ext/ffi_c/Function.c
index 40d613e..9da6b37 100644
--- a/ext/ffi_c/Function.c
+++ b/ext/ffi_c/Function.c
@@ -492,6 +492,7 @@ static VALUE
function_attach(VALUE self, VALUE module, VALUE name)
{
Function* fn;
+ char var[1024];
StringValue(name);
TypedData_Get_Struct(self, Function, &function_data_type, fn);
@@ -511,14 +512,11 @@ function_attach(VALUE self, VALUE module, VALUE name)
}
/*
- * Stash the Function in a module variable so it does not get garbage collected
+ * Stash the Function in a module variable so it does not get garbage collected and can be inspected by attached_functions
*/
- VALUE funcs = rb_iv_get(module, "@ffi_functions");
- if (RB_NIL_P(funcs)) {
- funcs = rb_hash_new();
- rb_iv_set(module, "@ffi_functions", funcs);
- }
- rb_hash_aset(funcs, name, self);
+ snprintf(var, sizeof(var), "@ffi_function_%s", StringValueCStr(name));
+ rb_ractor_make_shareable(self);
+ rb_iv_set(module, var, self);
rb_define_singleton_method(module, StringValueCStr(name),
rbffi_MethodHandle_CodeAddress(fn->methodHandle), -1);