Skip to content

Commit 2891c85

Browse files
committed
Use RTYPEDDATA_GET_DATA if exist
1 parent 74cc160 commit 2891c85

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ext/pycall/extconf.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
require 'mkmf'
22

3+
have_func("RTYPEDDATA_GET_DATA")
4+
35
create_makefile('pycall')

ext/pycall/range.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ struct enumerator_head {
66
VALUE args;
77
};
88

9+
#ifdef HAVE_RTYPEDDATA_GET_DATA
10+
# define GET_ENUMERATOR_DATA(obj) ((struct enumerator_head *)RTYPEDDATA_GET_DATA(obj))
11+
#else
12+
# define GET_ENUMERATOR_DATA(obj) ((struct enumerator_head *)DATA_PTR(obj))
13+
#endif
14+
915
int
1016
pycall_obj_is_step_range(VALUE obj)
1117
{
@@ -19,7 +25,7 @@ pycall_obj_is_step_range(VALUE obj)
1925
return 0;
2026
}
2127

22-
eh = (struct enumerator_head *)DATA_PTR(obj);
28+
eh = GET_ENUMERATOR_DATA(obj);
2329

2430
if (!rb_obj_is_kind_of(eh->obj, rb_cRange)) {
2531
return 0;
@@ -50,7 +56,7 @@ pycall_extract_range(VALUE obj, VALUE *pbegin, VALUE *pend, int *pexclude_end, V
5056
exclude_end = rb_funcallv(obj, id_exclude_end, 0, 0);
5157
}
5258
else if (pycall_obj_is_step_range(obj)) {
53-
struct enumerator_head *eh = (struct enumerator_head *)DATA_PTR(obj);
59+
struct enumerator_head *eh = GET_ENUMERATOR_DATA(obj);
5460
begin = rb_funcallv(eh->obj, id_begin, 0, 0);
5561
end = rb_funcallv(eh->obj, id_end, 0, 0);
5662
exclude_end = rb_funcallv(eh->obj, id_exclude_end, 0, 0);

0 commit comments

Comments
 (0)