-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
Problem
Ruby 3.2+ emits deprecation warnings when using the legacy Data_Wrap_Struct API:
warning: undefining the allocator of T_DATA class GSL::Vector
warning: undefining the allocator of T_DATA class GSL::Matrix
warning: undefining the allocator of T_DATA class GSL::Rng
...
These warnings appear on every require 'gsl' and when instantiating GSL objects.
Root Cause
The codebase uses the legacy Ruby C API:
Data_Wrap_Struct/Data_Make_StructData_Get_Structrb_undef_alloc_func
Ruby recommends migrating to the TypedData API which provides better GC integration, type safety, and memory profiling.
Scope
~3,300 occurrences across the codebase
Required Changes
For each class, the migration involves:
1. Define a rb_data_type_t struct
static const rb_data_type_t gsl_vector_type = {
.wrap_struct_name = "GSL::Vector",
.function = {
.dmark = NULL, // or mark function if needed
.dfree = gsl_vector_free,
.dsize = NULL, // optional: memory size function
},
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
};2. Replace Data_Wrap_Struct
// BEFORE
Data_Wrap_Struct(klass, mark_func, free_func, ptr);
// AFTER
TypedData_Wrap_Struct(klass, &gsl_vector_type, ptr);3. Replace Data_Get_Struct
// BEFORE
Data_Get_Struct(obj, gsl_vector, v);
// AFTER
TypedData_Get_Struct(obj, gsl_vector, &gsl_vector_type, v);4. Remove rb_undef_alloc_func calls
TypedData handles allocation differently; these calls become unnecessary.
Workaround
Users can suppress warnings until migration is complete:
Warning[:deprecated] = false
require 'gsl'
Warning[:deprecated] = trueOr via environment:
RUBYOPT='-W:no-deprecated' ruby script.rbReferences
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels