Skip to content

Commit

Permalink
Rewrite the initialization of pycall_pyrubyptr_data_type
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed May 25, 2020
1 parent c0bf4f1 commit 4b25edf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
13 changes: 13 additions & 0 deletions ext/pycall/pycall_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,19 @@ Py_ssize_t pycall_python_hexversion(void);

void pycall_Py_DecRef(PyObject *);

#if defined(_MSC_VER) && defined(RUBY_TYPED_FREE_IMMEDIATELY)
# define PYCALL_PYPTR_PARENT 0
# define PYCALL_PYPTR_DATA_INIT_PARENT(pyptr_data) ((pyptr_data).parent = &pycall_pyptr_data_type)
#endif

#ifndef PYCALL_PYPTR_PARENT
# define PYCALL_PYPTR_PARENT &pycall_pyptr_data_type
#endif

#ifndef PYCALL_PYPTR_DATA_INIT_PARENT
# define PYCALL_PYPTR_DATA_INIT_PARENT(pyptr_data) ((void)0)
#endif

RUBY_EXTERN const rb_data_type_t pycall_pyptr_data_type;
size_t pycall_pyptr_memsize(void const *);
void pycall_pyptr_free(void *);
Expand Down
20 changes: 12 additions & 8 deletions ext/pycall/ruby_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,18 @@ PyRuby_getattro_with_gvl(PyRubyObject *pyro, PyObject *pyobj_name)

VALUE cPyRubyPtr;

rb_data_type_t pycall_pyrubyptr_data_type = {
static rb_data_type_t pycall_pyrubyptr_data_type = {
"PyCall::PyRubyPtr",
{ 0, pycall_pyptr_free, pycall_pyptr_memsize, }
{
0,
pycall_pyptr_free,
pycall_pyptr_memsize,
},
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
PYCALL_PYPTR_PARENT,
0,
RUBY_TYPED_FREE_IMMEDIATELY
#endif
};

static inline int
Expand Down Expand Up @@ -460,18 +469,13 @@ pycall_init_ruby_wrapper(void)
/* PyCall::PyRubyPtr */

// This cannot be defined above because MSVC 2019 results in error C2099: initializer is not a constant
#ifdef RUBY_TYPED_FREE_IMMEDIATELY
pycall_pyrubyptr_data_type.parent = &pycall_pyptr_data_type;
pycall_pyrubyptr_data_type.data = 0;
pycall_pyrubyptr_data_type.flags = RUBY_TYPED_FREE_IMMEDIATELY;
#endif
PYCALL_PYPTR_DATA_INIT_PARENT(pycall_pyrubyptr_data_type);

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

rb_define_module_function(mPyCall, "wrap_ruby_object", pycall_m_wrap_ruby_object, 1);

}

/* --- File internal utilities --- */
Expand Down

0 comments on commit 4b25edf

Please sign in to comment.