Skip to content

Commit 9bd4c9f

Browse files
committed
Fix failure with Ruby 3.3
The method of getting pointers from TypedData structure has changed since Ruby 3.3. Ruby 3.2 or below can get the pointer with DATA_PTR(). https://github.com/ruby/ruby/blob/52bb2ac0a6971d0391efa2275f7a66bff319087c/error.c#L1073 Ruby 3.3 or later uses RTYPEDDATA_GET_DATA() to get pointer. https://github.com/ruby/ruby/blob/5124f9ac7513eb590c37717337c430cb93caa151/error.c#L1326
1 parent 44777a6 commit 9bd4c9f

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

ext/numo/narray/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def d(file)
8888
end
8989
have_func("exp10")
9090
have_func("rb_arithmetic_sequence_extract")
91+
have_func("RTYPEDDATA_GET_DATA")
9192

9293
have_var("rb_cComplex")
9394

ext/numo/narray/index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ na_parse_enumerator_step(VALUE enum_obj, VALUE *pstep )
272272
if (!RB_TYPE_P(enum_obj, T_DATA)) {
273273
rb_raise(rb_eTypeError,"wrong argument type (not T_DATA)");
274274
}
275-
e = (struct enumerator *)DATA_PTR(enum_obj);
275+
e = RENUMERATOR_PTR(enum_obj);
276276

277277
if (!rb_obj_is_kind_of(e->obj, rb_cRange)) {
278278
rb_raise(rb_eTypeError,"not Range object");
@@ -306,7 +306,7 @@ na_parse_enumerator(VALUE enum_obj, int orig_dim, ssize_t size, na_index_arg_t *
306306
rb_raise(rb_eTypeError,"wrong argument type (not T_DATA)");
307307
}
308308
na_parse_enumerator_step(enum_obj, &step);
309-
e = (struct enumerator *)DATA_PTR(enum_obj);
309+
e = RENUMERATOR_PTR(enum_obj);
310310
na_parse_range(e->obj, NUM2SSIZET(step), orig_dim, size, q); // e->obj : Range Object
311311
}
312312

ext/numo/narray/numo/narray.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ _na_get_narray_t(VALUE obj, unsigned char na_type)
301301
#define RNARRAY_VIEW(val) ((narray_view_t*)DATA_PTR(val))
302302
#define RNARRAY_FILEMAP(val) ((narray_filemap_t*)DATA_PTR(val))
303303

304+
#ifdef HAVE_RTYPEDDATA_GET_DATA
305+
#define RENUMERATOR_PTR(ptr) ((struct enumerator *)RTYPEDDATA_GET_DATA(ptr))
306+
#else
307+
#define RENUMERATOR_PTR(ptr) ((struct enumerator *)DATA_PTR(ptr))
308+
#endif
309+
304310
#define RNARRAY_NDIM(val) (RNARRAY(val)->ndim)
305311
#define RNARRAY_TYPE(val) (RNARRAY(val)->type)
306312
#define RNARRAY_FLAG(val) (RNARRAY(val)->flag)

ext/numo/narray/step.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ nary_step_array_index(VALUE obj, size_t ary_size,
6060
vstep = rb_ivar_get(obj, id_step);
6161
} else { // Enumerator
6262
na_parse_enumerator_step(obj, &vstep);
63-
e = (struct enumerator *)DATA_PTR(obj);
63+
e = RENUMERATOR_PTR(obj);
6464
obj = e->obj; // Range
6565
}
6666

@@ -208,7 +208,7 @@ nary_step_sequence( VALUE obj, size_t *plen, double *pbeg, double *pstep )
208208
vstep = rb_ivar_get(obj, id_step);
209209
} else { // Enumerator
210210
na_parse_enumerator_step(obj, &vstep);
211-
e = (struct enumerator *)DATA_PTR(obj);
211+
e = RENUMERATOR_PTR(obj);
212212
obj = e->obj; // Range
213213
}
214214

0 commit comments

Comments
 (0)