Skip to content

Commit c0bf4f1

Browse files
committed
Fix compile error on MSVC 2019. MSVC does not support initializing the rb_data_type_t structure from a pointer. Error is:
ruby_wrapper.c(359): error C2099: initializer is not a constant ruby_wrapper.c(359): error C4047: 'initializing': 'void *' differs in levels of indirection from 'int' Fixed by moving code to pycall_init_ruby_wrapper.
1 parent 7848e94 commit c0bf4f1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ext/pycall/ruby_wrapper.c

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

357357
VALUE cPyRubyPtr;
358358

359-
const rb_data_type_t pycall_pyrubyptr_data_type = {
359+
rb_data_type_t pycall_pyrubyptr_data_type = {
360360
"PyCall::PyRubyPtr",
361-
{ 0, pycall_pyptr_free, pycall_pyptr_memsize, },
362-
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
363-
&pycall_pyptr_data_type, 0, RUBY_TYPED_FREE_IMMEDIATELY
364-
#endif
361+
{ 0, pycall_pyptr_free, pycall_pyptr_memsize, }
365362
};
366363

367364
static inline int
@@ -462,11 +459,19 @@ pycall_init_ruby_wrapper(void)
462459

463460
/* PyCall::PyRubyPtr */
464461

462+
// 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
468+
465469
cPyRubyPtr = rb_define_class_under(mPyCall, "PyRubyPtr", cPyPtr);
466470
rb_define_alloc_func(cPyRubyPtr, pycall_pyruby_allocate);
467471
rb_define_method(cPyRubyPtr, "__ruby_object_id__", pycall_pyruby_get_ruby_object_id, 0);
468472

469473
rb_define_module_function(mPyCall, "wrap_ruby_object", pycall_m_wrap_ruby_object, 1);
474+
470475
}
471476

472477
/* --- File internal utilities --- */

0 commit comments

Comments
 (0)