Skip to content

Commit

Permalink
one more regression wrt. pointers through void*
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Sep 2, 2019
1 parent 2675ee9 commit 80a0205
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/Converters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ static bool IsPyCArgObject(PyObject* pyobject)
return Py_TYPE(pyobject) == pycarg_type;
}

static bool IsCTypesArrayOrPointer(PyObject* pyobject)
{
static PyTypeObject* cstgdict_type = nullptr;
if (!cstgdict_type) {
// get any pointer type to initialize the extended dictionary type
PyTypeObject* ct_int = GetCTypesType(ct_c_int);
if (ct_int && ct_int->tp_dict) {
cstgdict_type = Py_TYPE(ct_int->tp_dict);
}
}

PyTypeObject* pytype = Py_TYPE(pyobject);
if (pytype->tp_dict && Py_TYPE(pytype->tp_dict) == cstgdict_type)
return true;
return false;
}


//- custom helpers to check ranges -------------------------------------------
static inline bool CPyCppyy_PyLong_AsBool(PyObject* pyobject)
Expand Down Expand Up @@ -1131,6 +1148,16 @@ bool CPyCppyy::VoidArrayConverter::SetArg(
return true;
}

// allow any other ctypes pointer type
if (IsCTypesArrayOrPointer(pyobject)) {
void** payload = (void**)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;
if (payload) {
para.fValue.fVoidp = *payload;
para.fTypeCode = 'p';
return true;
}
}

// final try: attempt to get buffer
Py_ssize_t buflen = Utility::GetBuffer(pyobject, '*', 1, para.fValue.fVoidp, false);

Expand Down Expand Up @@ -1257,14 +1284,18 @@ bool CPyCppyy::name##ArrayPtrConverter::SetArg( \
para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
para.fTypeCode = 'p'; \
return true; \
} else if (Py_TYPE(pyobject) == GetCTypesType(ct_c_void_p)) { \
/* special case: pass address of c_void_p buffer to return the address */\
para.fValue.fVoidp = (void*)&((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
para.fTypeCode = 'p'; \
return true; \
} \
bool res = name##ArrayConverter::SetArg(pyobject, para, ctxt); \
if (res && para.fTypeCode == 'p') { \
para.fRef = para.fValue.fVoidp; \
para.fValue.fVoidp = &para.fRef; \
return true; \
} \
\
return false; \
}

Expand Down

0 comments on commit 80a0205

Please sign in to comment.