diff options
Diffstat (limited to 'ext/ffi_c')
-rw-r--r-- | ext/ffi_c/DynamicLibrary.c | 7 | ||||
-rw-r--r-- | ext/ffi_c/Function.c | 12 | ||||
-rw-r--r-- | ext/ffi_c/FunctionInfo.c | 2 | ||||
-rw-r--r-- | ext/ffi_c/MappedType.c | 2 | ||||
-rw-r--r-- | ext/ffi_c/StructLayout.c | 7 | ||||
-rw-r--r-- | ext/ffi_c/Type.c | 4 | ||||
-rw-r--r-- | ext/ffi_c/Variadic.c | 5 | ||||
-rw-r--r-- | ext/ffi_c/rbffi.h | 2 |
8 files changed, 31 insertions, 10 deletions
diff --git a/ext/ffi_c/DynamicLibrary.c b/ext/ffi_c/DynamicLibrary.c index 9abafc7..1d83940 100644 --- a/ext/ffi_c/DynamicLibrary.c +++ b/ext/ffi_c/DynamicLibrary.c @@ -161,7 +161,9 @@ library_initialize(VALUE self, VALUE libname, VALUE libflags) library->handle = RTLD_DEFAULT; } #endif - rb_iv_set(self, "@name", libname != Qnil ? libname : rb_str_new2("[current process]")); + rb_iv_set(self, "@name", libname != Qnil ? rb_str_new_frozen(libname) : rb_str_new2("[current process]")); + + rb_obj_freeze(self); return self; } @@ -266,8 +268,9 @@ symbol_new(VALUE library, void* address, VALUE name) sym->base.memory.typeSize = 1; sym->base.memory.flags = MEM_RD | MEM_WR; RB_OBJ_WRITE(obj, &sym->base.rbParent, library); - RB_OBJ_WRITE(obj, &sym->name, name); + RB_OBJ_WRITE(obj, &sym->name, rb_str_new_frozen(name)); + rb_obj_freeze(obj); return obj; } diff --git a/ext/ffi_c/Function.c b/ext/ffi_c/Function.c index 9da6b37..d0b65fb 100644 --- a/ext/ffi_c/Function.c +++ b/ext/ffi_c/Function.c @@ -492,7 +492,7 @@ static VALUE function_attach(VALUE self, VALUE module, VALUE name) { Function* fn; - char var[1024]; + VALUE funcs; StringValue(name); TypedData_Get_Struct(self, Function, &function_data_type, fn); @@ -514,9 +514,13 @@ function_attach(VALUE self, VALUE module, VALUE name) /* * Stash the Function in a module variable so it does not get garbage collected and can be inspected by attached_functions */ - snprintf(var, sizeof(var), "@ffi_function_%s", StringValueCStr(name)); - rb_ractor_make_shareable(self); - rb_iv_set(module, var, self); + + 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, rb_str_intern(name), self); rb_define_singleton_method(module, StringValueCStr(name), rbffi_MethodHandle_CodeAddress(fn->methodHandle), -1); diff --git a/ext/ffi_c/FunctionInfo.c b/ext/ffi_c/FunctionInfo.c index 7495215..b5150d8 100644 --- a/ext/ffi_c/FunctionInfo.c +++ b/ext/ffi_c/FunctionInfo.c @@ -251,6 +251,8 @@ fntype_initialize(int argc, VALUE* argv, VALUE self) fnInfo->invoke = rbffi_GetInvoker(fnInfo); + rb_obj_freeze(fnInfo->rbParameterTypes); + rb_obj_freeze(self); return self; } diff --git a/ext/ffi_c/MappedType.c b/ext/ffi_c/MappedType.c index 20b14e9..2e506f2 100644 --- a/ext/ffi_c/MappedType.c +++ b/ext/ffi_c/MappedType.c @@ -110,6 +110,8 @@ mapped_initialize(VALUE self, VALUE rbConverter) TypedData_Get_Struct(m->rbType, Type, &rbffi_type_data_type, m->type); m->base.ffiType = m->type->ffiType; + rb_obj_freeze(self); + return self; } diff --git a/ext/ffi_c/StructLayout.c b/ext/ffi_c/StructLayout.c index 613394a..a56d48f 100644 --- a/ext/ffi_c/StructLayout.c +++ b/ext/ffi_c/StructLayout.c @@ -181,6 +181,8 @@ struct_field_initialize(int argc, VALUE* argv, VALUE self) break; } + rb_obj_freeze(self); + return self; } @@ -538,6 +540,11 @@ struct_layout_initialize(VALUE self, VALUE fields, VALUE size, VALUE align) rb_raise(rb_eRuntimeError, "Struct size is zero"); } + rb_obj_freeze(layout->rbFieldMap); + rb_obj_freeze(layout->rbFields); + rb_obj_freeze(layout->rbFieldNames); + rb_obj_freeze(self); + return self; } diff --git a/ext/ffi_c/Type.c b/ext/ffi_c/Type.c index 9bf5681..a94c009 100644 --- a/ext/ffi_c/Type.c +++ b/ext/ffi_c/Type.c @@ -128,6 +128,8 @@ type_initialize(VALUE self, VALUE value) rb_raise(rb_eArgError, "wrong type"); } + rb_obj_freeze(self); + return self; } @@ -192,6 +194,8 @@ builtin_type_new(VALUE klass, int nativeType, ffi_type* ffiType, const char* nam type->type.nativeType = nativeType; type->type.ffiType = ffiType; + rb_obj_freeze(obj); + return obj; } diff --git a/ext/ffi_c/Variadic.c b/ext/ffi_c/Variadic.c index 0f321d9..09d7ce8 100644 --- a/ext/ffi_c/Variadic.c +++ b/ext/ffi_c/Variadic.c @@ -183,9 +183,8 @@ variadic_initialize(VALUE self, VALUE rbFunction, VALUE rbParameterTypes, VALUE /* * @fixed and @type_map are used by the parameter mangling ruby code */ - rb_iv_set(self, "@fixed", fixed); - rb_iv_set(self, "@type_map", rb_obj_dup(rb_hash_aref(options, ID2SYM(rb_intern("type_map"))))); - rb_ractor_make_shareable(self); + rb_iv_set(self, "@fixed", rb_obj_freeze(fixed)); + rb_iv_set(self, "@type_map", rb_hash_aref(options, ID2SYM(rb_intern("type_map")))); return retval; } diff --git a/ext/ffi_c/rbffi.h b/ext/ffi_c/rbffi.h index 89b3e32..0e4e91a 100644 --- a/ext/ffi_c/rbffi.h +++ b/ext/ffi_c/rbffi.h @@ -39,7 +39,7 @@ extern "C" { #define MAX_PARAMETERS (32) extern VALUE rbffi_FFIModule; - + extern void rbffi_Type_Init(VALUE ffiModule); extern void rbffi_Buffer_Init(VALUE ffiModule); extern void rbffi_Invoker_Init(VALUE ffiModule); |