Skip to content

Commit 4b25edf

Browse files
committed
Rewrite the initialization of pycall_pyrubyptr_data_type
1 parent c0bf4f1 commit 4b25edf

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

ext/pycall/pycall_internal.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,19 @@ Py_ssize_t pycall_python_hexversion(void);
663663

664664
void pycall_Py_DecRef(PyObject *);
665665

666+
#if defined(_MSC_VER) && defined(RUBY_TYPED_FREE_IMMEDIATELY)
667+
# define PYCALL_PYPTR_PARENT 0
668+
# define PYCALL_PYPTR_DATA_INIT_PARENT(pyptr_data) ((pyptr_data).parent = &pycall_pyptr_data_type)
669+
#endif
670+
671+
#ifndef PYCALL_PYPTR_PARENT
672+
# define PYCALL_PYPTR_PARENT &pycall_pyptr_data_type
673+
#endif
674+
675+
#ifndef PYCALL_PYPTR_DATA_INIT_PARENT
676+
# define PYCALL_PYPTR_DATA_INIT_PARENT(pyptr_data) ((void)0)
677+
#endif
678+
666679
RUBY_EXTERN const rb_data_type_t pycall_pyptr_data_type;
667680
size_t pycall_pyptr_memsize(void const *);
668681
void pycall_pyptr_free(void *);

ext/pycall/ruby_wrapper.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,18 @@ PyRuby_getattro_with_gvl(PyRubyObject *pyro, PyObject *pyobj_name)
356356

357357
VALUE cPyRubyPtr;
358358

359-
rb_data_type_t pycall_pyrubyptr_data_type = {
359+
static rb_data_type_t pycall_pyrubyptr_data_type = {
360360
"PyCall::PyRubyPtr",
361-
{ 0, pycall_pyptr_free, pycall_pyptr_memsize, }
361+
{
362+
0,
363+
pycall_pyptr_free,
364+
pycall_pyptr_memsize,
365+
},
366+
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
367+
PYCALL_PYPTR_PARENT,
368+
0,
369+
RUBY_TYPED_FREE_IMMEDIATELY
370+
#endif
362371
};
363372

364373
static inline int
@@ -460,18 +469,13 @@ pycall_init_ruby_wrapper(void)
460469
/* PyCall::PyRubyPtr */
461470

462471
// This cannot be defined above because MSVC 2019 results in error C2099: initializer is not a constant
463-
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
464-
pycall_pyrubyptr_data_type.parent = &pycall_pyptr_data_type;
465-
pycall_pyrubyptr_data_type.data = 0;
466-
pycall_pyrubyptr_data_type.flags = RUBY_TYPED_FREE_IMMEDIATELY;
467-
#endif
472+
PYCALL_PYPTR_DATA_INIT_PARENT(pycall_pyrubyptr_data_type);
468473

469474
cPyRubyPtr = rb_define_class_under(mPyCall, "PyRubyPtr", cPyPtr);
470475
rb_define_alloc_func(cPyRubyPtr, pycall_pyruby_allocate);
471476
rb_define_method(cPyRubyPtr, "__ruby_object_id__", pycall_pyruby_get_ruby_object_id, 0);
472477

473478
rb_define_module_function(mPyCall, "wrap_ruby_object", pycall_m_wrap_ruby_object, 1);
474-
475479
}
476480

477481
/* --- File internal utilities --- */

0 commit comments

Comments
 (0)