25#if __cplusplus > 201402L
30#define UNKNOWN_SIZE -1
31#define UNKNOWN_ARRAY_SIZE -2
44#if PY_VERSION_HEX < 0x03000000
92#define ct_c_longlong 13
93#define ct_c_ulonglong 14
96#define ct_c_longdouble 17
98#define ct_c_wchar_p 19
100#define ct_c_complex 21
104 "c_bool",
"c_char",
"c_wchar",
"c_byte",
"c_ubyte",
"c_short",
"c_ushort",
"c_uint16",
105 "c_int",
"c_uint",
"c_uint32",
"c_long",
"c_ulong",
"c_longlong",
"c_ulonglong",
106 "c_float",
"c_double",
"c_longdouble",
107 "c_char_p",
"c_wchar_p",
"c_void_p",
"c_complex" };
117 static PyObject* ctmod = PyImport_ImportModule(
"ctypes");
124 ct_t = (PyTypeObject*)PyObject_GetAttrString(ctmod,
gCTypesNames[nidx]);
125 if (!ct_t) PyErr_Clear();
136 static PyObject* ctmod = PyImport_ImportModule(
"ctypes");
144 cpt_t = (PyTypeObject*)PyObject_GetAttrString(ctmod,
"c_char_p");
148 PyObject* ptrcreat = PyObject_GetAttrString(ctmod,
"POINTER");
149 cpt_t = (PyTypeObject*)PyObject_CallFunctionObjArgs(ptrcreat, ct_t, NULL);
163 static PyTypeObject* pycarg_type =
nullptr;
165 PyObject* ctmod = PyImport_ImportModule(
"ctypes");
166 if (!ctmod) PyErr_Clear();
168 PyTypeObject* ct_t = (PyTypeObject*)PyObject_GetAttrString(ctmod,
"c_int");
169 PyObject* cobj = ct_t->tp_new(ct_t,
nullptr,
nullptr);
170 PyObject* byref = PyObject_GetAttrString(ctmod,
"byref");
171 PyObject* pyptr = PyObject_CallFunctionObjArgs(byref, cobj, NULL);
172 Py_DECREF(byref); Py_DECREF(cobj); Py_DECREF(ct_t);
178 return Py_TYPE(pyobject) == pycarg_type;
183 static PyTypeObject* cstgdict_type =
nullptr;
184 if (!cstgdict_type) {
187 if (ct_int && ct_int->tp_dict) {
188 cstgdict_type =
Py_TYPE(ct_int->tp_dict);
192 PyTypeObject* pytype =
Py_TYPE(pyobject);
193 if (pytype->tp_dict &&
Py_TYPE(pytype->tp_dict) == cstgdict_type)
203 if (!holder)
return false;
208 std::ostringstream attr_name;
209 attr_name <<
"__" << ref;
210 auto attr_name_str = attr_name.str();
211 auto res = PyObject_SetAttrString(holder, attr_name_str.c_str(),
target);
231 long l = PyLong_AsLong(pyobject);
233 if (!(
l == 0||
l == 1) || PyFloat_Check(pyobject)) {
234 PyErr_SetString(PyExc_ValueError,
"boolean value should be bool, or integer 1 or 0");
249 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
250 PyErr_SetString(PyExc_TypeError,
"short int conversion expects an integer object");
253 long l = PyLong_AsLong(pyobject);
254 if (
l < 0 || UCHAR_MAX <
l) {
255 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for uint8_t",
l);
266 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
267 PyErr_SetString(PyExc_TypeError,
"short int conversion expects an integer object");
270 long l = PyLong_AsLong(pyobject);
271 if (
l < SCHAR_MIN || SCHAR_MAX <
l) {
272 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for int8_t",
l);
284 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
285 PyErr_SetString(PyExc_TypeError,
"unsigned short conversion expects an integer object");
286 return (
unsigned short)-1;
288 long l = PyLong_AsLong(pyobject);
289 if (
l < 0 || USHRT_MAX <
l) {
290 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for unsigned short",
l);
291 return (
unsigned short)-1;
294 return (
unsigned short)
l;
301 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
302 PyErr_SetString(PyExc_TypeError,
"short int conversion expects an integer object");
305 long l = PyLong_AsLong(pyobject);
306 if (
l < SHRT_MIN || SHRT_MAX <
l) {
307 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for short int",
l);
321 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
322 PyErr_SetString(PyExc_TypeError,
"int/long conversion expects an integer object");
325 long l = PyLong_AsLong(pyobject);
326 if (
l < INT_MIN || INT_MAX <
l) {
327 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for int",
l);
339 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
340 PyErr_SetString(PyExc_TypeError,
"int/long conversion expects an integer object");
343 return (
long)PyLong_AsLong(pyobject);
360 PyErr_Format(PyExc_TypeError,
361 "could not convert argument to buffer or nullptr");
385 PyTypeObject* pytype = (PyTypeObject*)
Py_TYPE(pyobject);
386 if (!(pytype == &PyList_Type || pytype == &PyTuple_Type)) {
403 Py_INCREF(pyobject); PyTuple_SET_ITEM(args, 0, pyobject);
407 if (!pytmp && PyTuple_CheckExact(pyobject)) {
411 pytmp = (
CPPInstance*)PyObject_Call(pyscope, pyobject, kwds);
441 PyErr_SetString(PyExc_TypeError,
"C++ type cannot be converted from memory");
449 PyErr_SetString(PyExc_TypeError,
"C++ type cannot be converted to memory");
455#define CPPYY_IMPL_BASIC_CONVERTER(name, type, stype, ctype, F1, F2, tc) \
456bool CPyCppyy::name##Converter::SetArg( \
457 PyObject* pyobject, Parameter& para, CallContext* ) \
460 type val = (type)F2(pyobject); \
461 if (val == (type)-1 && PyErr_Occurred()) { \
462 static PyTypeObject* ctypes_type = nullptr; \
463 if (!ctypes_type) { \
464 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0; \
465 PyErr_Fetch(&pytype, &pyvalue, &pytrace); \
466 ctypes_type = GetCTypesType(ct_##ctype); \
467 PyErr_Restore(pytype, pyvalue, pytrace); \
469 if (Py_TYPE(pyobject) == ctypes_type) { \
471 val = *((type*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr); \
475 para.fValue.f##name = val; \
476 para.fTypeCode = tc; \
480PyObject* CPyCppyy::name##Converter::FromMemory(void* address) \
482 return F1((stype)*((type*)address)); \
485bool CPyCppyy::name##Converter::ToMemory(PyObject* value, void* address, \
488 type s = (type)F2(value); \
489 if (s == (type)-1 && PyErr_Occurred()) \
491 *((type*)address) = (type)s; \
503 PyErr_Format(PyExc_ValueError,
"%s expected, got string of size " PY_SSIZE_T_FORMAT,
505 }
else if (!PyFloat_Check(pyobject)) {
506 lchar = (
int)PyLong_AsLong(pyobject);
507 if (lchar == -1 && PyErr_Occurred())
509 else if (!(low <= lchar && lchar <= high)) {
510 PyErr_Format(PyExc_ValueError,
511 "integer to character: value %d not in range [%d,%d]", lchar, low, high);
515 PyErr_SetString(PyExc_TypeError,
"char or small int type expected");
521#define CPPYY_IMPL_REFCONVERTER_FROM_MEMORY(name, ctype) \
522PyObject* CPyCppyy::name##RefConverter::FromMemory(void* ptr) \
525 PyTypeObject* ctypes_type = GetCTypesType(ct_##ctype); \
526 if (!ctypes_type) { \
527 PyErr_SetString(PyExc_RuntimeError, "no ctypes available"); \
530 PyObject* ref = ctypes_type->tp_new(ctypes_type, nullptr, nullptr); \
531 ((CPyCppyy_tagCDataObject*)ref)->b_ptr = (char*)ptr; \
532 ((CPyCppyy_tagCDataObject*)ref)->b_needsfree = 0; \
537#define CPPYY_IMPL_BASIC_CONST_REFCONVERTER(name, type, ctype, F1) \
538bool CPyCppyy::Const##name##RefConverter::SetArg( \
539 PyObject* pyobject, Parameter& para, CallContext* ) \
541 type val = (type)F1(pyobject); \
542 if (val == (type)-1 && PyErr_Occurred()) \
544 para.fValue.f##name = val; \
545 para.fRef = ¶.fValue.f##name; \
546 para.fTypeCode = 'r'; \
549CPPYY_IMPL_REFCONVERTER_FROM_MEMORY(Const##name, ctype)
552#define CPPYY_IMPL_BASIC_CONST_CHAR_REFCONVERTER(name, type, ctype, low, high)\
553bool CPyCppyy::Const##name##RefConverter::SetArg( \
554 PyObject* pyobject, Parameter& para, CallContext* ) \
557 type val = (type)ExtractChar(pyobject, #type, low, high); \
558 if (val == (type)-1 && PyErr_Occurred()) \
560 para.fValue.fLong = val; \
561 para.fTypeCode = 'l'; \
564CPPYY_IMPL_REFCONVERTER_FROM_MEMORY(Const##name, ctype)
568#define CPPYY_IMPL_BASIC_CHAR_CONVERTER(name, type, low, high) \
569bool CPyCppyy::name##Converter::SetArg( \
570 PyObject* pyobject, Parameter& para, CallContext* ) \
573 long val = ExtractChar(pyobject, #type, low, high); \
574 if (val == -1 && PyErr_Occurred()) \
576 para.fValue.fLong = val; \
577 para.fTypeCode = 'l'; \
581PyObject* CPyCppyy::name##Converter::FromMemory(void* address) \
583 return CPyCppyy_PyText_FromFormat("%c", *((type*)address)); \
586bool CPyCppyy::name##Converter::ToMemory(PyObject* value, void* address, \
590 const char* cstr = CPyCppyy_PyText_AsStringAndSize(value, &len); \
593 PyErr_Format(PyExc_TypeError, #type" expected, got string of size %zd", len);\
596 *((type*)address) = (type)cstr[0]; \
599 long l = PyLong_AsLong(value); \
600 if (l == -1 && PyErr_Occurred()) \
602 if (!(low <= l && l <= high)) { \
603 PyErr_Format(PyExc_ValueError, \
604 "integer to character: value %ld not in range [%d,%d]", l, low, high);\
607 *((type*)address) = (type)l; \
621#if PY_VERSION_HEX < 0x03000000
623 para.fValue.fVoidp = (
void*)&((PyIntObject*)pyobject)->ob_ival;
624 para.fTypeCode =
'V';
631 para.fTypeCode =
'V';
636 para.fTypeCode =
'V';
640 PyErr_SetString(PyExc_TypeError,
"use ctypes.c_long for pass-by-ref of longs");
661bool CPyCppyy::IntRefConverter::SetArg(
665#if PY_VERSION_HEX < 0x03000000
667 para.
fValue.
fVoidp = (
void*)&((PyIntObject*)pyobject)->ob_ival;
673#if PY_VERSION_HEX >= 0x02050000
688#if PY_VERSION_HEX < 0x02050000
689 PyErr_SetString(PyExc_TypeError,
"use cppyy.Long for pass-by-ref of ints");
691 PyErr_SetString(PyExc_TypeError,
"use ctypes.c_int for pass-by-ref of ints");
697#define CPPYY_IMPL_REFCONVERTER(name, ctype, type, code) \
698bool CPyCppyy::name##RefConverter::SetArg( \
699 PyObject* pyobject, Parameter& para, CallContext* ) \
702 if (Py_TYPE(pyobject) == GetCTypesType(ct_##ctype)) { \
703 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
704 para.fTypeCode = 'V'; \
707 bool res = CArraySetArg(pyobject, para, code, sizeof(type)); \
709 PyErr_SetString(PyExc_TypeError, "use ctypes."#ctype" for pass-by-ref of "#type);\
712 para.fTypeCode = 'V'; \
715CPPYY_IMPL_REFCONVERTER_FROM_MEMORY(name, ctype)
752 return PyInt_FromLong((
long)*((
unsigned char*)address));
756bool CPyCppyy::WCharConverter::SetArg(
761 PyErr_SetString(PyExc_ValueError,
"single wchar_t character expected");
773PyObject* CPyCppyy::WCharConverter::FromMemory(
void* address)
775 return PyUnicode_FromWideChar((
const wchar_t*)address, 1);
781 PyErr_SetString(PyExc_ValueError,
"single wchar_t character expected");
788 *((
wchar_t*)address) = val;
793bool CPyCppyy::Char16Converter::SetArg(
798 PyErr_SetString(PyExc_ValueError,
"single char16_t character expected");
802 PyObject* bstr = PyUnicode_AsUTF16String(pyobject);
803 if (!bstr)
return false;
812PyObject* CPyCppyy::Char16Converter::FromMemory(
void* address)
814 return PyUnicode_DecodeUTF16((
const char*)address,
sizeof(
char16_t),
nullptr,
nullptr);
820 PyErr_SetString(PyExc_ValueError,
"single char16_t character expected");
825 if (!bstr)
return false;
827 *((
char16_t*)address) = *(
char16_t*)(
PyBytes_AS_STRING(bstr) +
sizeof(char16_t) );
833bool CPyCppyy::Char32Converter::SetArg(
838 PyErr_SetString(PyExc_ValueError,
"single char32_t character expected");
842 PyObject* bstr = PyUnicode_AsUTF32String(pyobject);
843 if (!bstr)
return false;
852PyObject* CPyCppyy::Char32Converter::FromMemory(
void* address)
854 return PyUnicode_DecodeUTF32((
const char*)address,
sizeof(
char32_t),
nullptr,
nullptr);
860 PyErr_SetString(PyExc_ValueError,
"single char32_t character expected");
865 if (!bstr)
return false;
867 *((
char32_t*)address) = *(
char32_t*)(
PyBytes_AS_STRING(bstr) +
sizeof(char32_t) );
885bool CPyCppyy::ULongConverter::SetArg(
890 if (para.fValue.fULong == (
unsigned long)-1 && PyErr_Occurred())
892 para.fTypeCode =
'L';
896PyObject* CPyCppyy::ULongConverter::FromMemory(
void* address)
899 return PyLong_FromUnsignedLong(*((
unsigned long*)address));
906 if (u == (
unsigned long)-1 && PyErr_Occurred())
908 *((
unsigned long*)address) = u;
913PyObject* CPyCppyy::UIntConverter::FromMemory(
void* address)
916 return PyLong_FromUnsignedLong(*((
UInt_t*)address));
923 if (u == (
unsigned long)-1 && PyErr_Occurred())
927 PyErr_SetString(PyExc_OverflowError,
"value too large for unsigned int");
937 Float,
float,
double, c_float, PyFloat_FromDouble, PyFloat_AsDouble,
'f')
939 Double,
double,
double, c_double, PyFloat_FromDouble, PyFloat_AsDouble, '
d')
944CPyCppyy::ComplexDConverter::ComplexDConverter(
bool keepControl) :
945 InstanceConverter(
Cppyy::GetScope("std::complex<
double>"), keepControl) {}
948bool CPyCppyy::ComplexDConverter::SetArg(
951 const Py_complex& pc = PyComplex_AsCComplex(pyobject);
952 if (pc.real != -1.0 || !PyErr_Occurred()) {
960 return this->InstanceConverter::SetArg(pyobject, para, ctxt);
963PyObject* CPyCppyy::ComplexDConverter::FromMemory(
void* address)
965 std::complex<double>* dc = (std::complex<double>*)address;
966 return PyComplex_FromDoubles(dc->real(), dc->imag());
971 const Py_complex& pc = PyComplex_AsCComplex(
value);
972 if (pc.real != -1.0 || !PyErr_Occurred()) {
973 std::complex<double>* dc = (std::complex<double>*)address;
978 return this->InstanceConverter::ToMemory(
value, address, ctxt);
982bool CPyCppyy::DoubleRefConverter::SetArg(
987 para.
fValue.
fVoidp = (
void*)&((PyFloatObject*)pyobject)->ob_fval;
999#if PY_VERSION_HEX < 0x02050000
1000 PyErr_SetString(PyExc_TypeError,
"use cppyy.Double for pass-by-ref of doubles");
1002 PyErr_SetString(PyExc_TypeError,
"use ctypes.c_double for pass-by-ref of doubles");
1016 PyErr_SetString(PyExc_SystemError,
"void/unknown arguments can\'t be set");
1021bool CPyCppyy::LLongConverter::SetArg(
1025 if (PyFloat_Check(pyobject)) {
1028 PyErr_SetString(PyExc_ValueError,
"cannot convert float to long long");
1033 if (PyErr_Occurred())
1039PyObject* CPyCppyy::LLongConverter::FromMemory(
void* address)
1042 return PyLong_FromLongLong(*(
Long64_t*)address);
1049 if (ll == -1 && PyErr_Occurred())
1056bool CPyCppyy::ULLongConverter::SetArg(
1061 if (PyErr_Occurred())
1067PyObject* CPyCppyy::ULLongConverter::FromMemory(
void* address)
1070 return PyLong_FromUnsignedLongLong(*(
ULong64_t*)address);
1077 if (PyErr_Occurred())
1084bool CPyCppyy::CStringConverter::SetArg(
1092 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0;
1093 PyErr_Fetch(&pytype, &pyvalue, &pytrace);
1097 Py_XDECREF(pytype); Py_XDECREF(pyvalue); Py_XDECREF(pytrace);
1100 PyErr_Restore(pytype, pyvalue, pytrace);
1108 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for char array (truncated)");
1118PyObject* CPyCppyy::CStringConverter::FromMemory(
void* address)
1121 if (address && *(
char**)address) {
1123 std::string buf(*(
char**)address,
fMaxSize);
1140 if (!cstr)
return false;
1144 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for char array (truncated)");
1147 strncpy(*(
char**)address, cstr,
fMaxSize);
1150 strcpy(*(
char**)address, cstr);
1156bool CPyCppyy::WCStringConverter::SetArg(
1176PyObject* CPyCppyy::WCStringConverter::FromMemory(
void* address)
1179 if (address && *(
wchar_t**)address) {
1181 return PyUnicode_FromWideChar(*(
wchar_t**)address,
fMaxSize);
1183 return PyUnicode_FromWideChar(*(
wchar_t**)address, wcslen(*(
wchar_t**)address));
1188 return PyUnicode_FromWideChar(&
w, 0);
1200 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for wchar_t array (truncated)");
1209 if (res == -1)
return false;
1214bool CPyCppyy::CString16Converter::SetArg(
1222 PyObject* bstr = PyUnicode_AsUTF16String(pyobject);
1223 if (!bstr)
return false;
1236PyObject* CPyCppyy::CString16Converter::FromMemory(
void* address)
1239 if (address && *(
char16_t**)address) {
1241 return PyUnicode_DecodeUTF16(*(
const char**)address,
fMaxSize,
nullptr,
nullptr);
1243 return PyUnicode_DecodeUTF16(*(
const char**)address,
1244 std::char_traits<char16_t>::length(*(
char16_t**)address)*
sizeof(
char16_t),
nullptr,
nullptr);
1249 return PyUnicode_DecodeUTF16((
const char*)&
w, 0,
nullptr,
nullptr);
1261 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for char16_t array (truncated)");
1266 if (!bstr)
return false;
1270 *((
char16_t**)address)[
len] = u
'\0';
1275bool CPyCppyy::CString32Converter::SetArg(
1283 PyObject* bstr = PyUnicode_AsUTF32String(pyobject);
1284 if (!bstr)
return false;
1297PyObject* CPyCppyy::CString32Converter::FromMemory(
void* address)
1300 if (address && *(
char32_t**)address) {
1302 return PyUnicode_DecodeUTF32(*(
const char**)address,
fMaxSize,
nullptr,
nullptr);
1304 return PyUnicode_DecodeUTF32(*(
const char**)address,
1305 std::char_traits<char32_t>::length(*(
char32_t**)address)*
sizeof(
char32_t),
nullptr,
nullptr);
1310 return PyUnicode_DecodeUTF32((
const char*)&
w, 0,
nullptr,
nullptr);
1322 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for char32_t array (truncated)");
1327 if (!bstr)
return false;
1331 *((
char32_t**)address)[
len] = U
'\0';
1337bool CPyCppyy::NonConstCStringConverter::SetArg(
1341 if (this->CStringConverter::SetArg(pyobject, para, ctxt))
1346 return CArraySetArg(pyobject, para,
'c',
sizeof(
char));
1350PyObject* CPyCppyy::NonConstCStringConverter::FromMemory(
void* address)
1355 return this->CStringConverter::FromMemory(address);
1368 if (PyInt_CheckExact(pyobject) || PyLong_CheckExact(pyobject)) {
1369 intptr_t val = (intptr_t)PyLong_AsLongLong(pyobject);
1371 address = (
void*)val;
1405 if (GetAddressSpecialCase(pyobject, para.
fValue.
fVoidp)) {
1414 para.
fValue.
fVoidp = (
void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;
1421 void** payload = (
void**)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;
1446 if (!address || *(ptrdiff_t*)address == 0) {
1469 void* ptr =
nullptr;
1470 if (GetAddressSpecialCase(
value, ptr)) {
1471 *(
void**)address = ptr;
1476 void* buf =
nullptr;
1478 if (!buf || buflen == 0)
1481 *(
void**)address = buf;
1489 int nalloc = (dims && 0 < dims[0]) ? (
int)dims[0]+1: defdim+1;
1492 for (
int i = 0; i < nalloc; ++i)
1496 for (
int i = 1; i < nalloc; ++i) shape[i] =
UNKNOWN_SIZE;
1501#define CPPYY_IMPL_ARRAY_CONVERTER(name, ctype, type, code) \
1502CPyCppyy::name##ArrayConverter::name##ArrayConverter(dims_t dims, bool init) {\
1504 init_shape(1, dims, fShape); \
1505 fIsFixed = fShape[1] != UNKNOWN_SIZE; \
1506 } else fIsFixed = false; \
1509bool CPyCppyy::name##ArrayConverter::SetArg( \
1510 PyObject* pyobject, Parameter& para, CallContext* ctxt) \
1514 PyTypeObject* ctypes_type = GetCTypesType(ct_##ctype); \
1515 if (Py_TYPE(pyobject) == ctypes_type) { \
1516 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
1517 para.fTypeCode = 'p'; \
1519 } else if (Py_TYPE(pyobject) == GetCTypesPtrType(ct_##ctype)) { \
1520 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
1521 para.fTypeCode = 'V'; \
1523 } else if (IsPyCArgObject(pyobject)) { \
1524 CPyCppyy_tagPyCArgObject* carg = (CPyCppyy_tagPyCArgObject*)pyobject;\
1525 if (carg->obj && Py_TYPE(carg->obj) == ctypes_type) { \
1526 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)carg->obj)->b_ptr;\
1527 para.fTypeCode = 'p'; \
1531 if (!res) res = CArraySetArg(pyobject, para, code, sizeof(type)); \
1532 if (res) SetLifeLine(ctxt->fPyContext, pyobject, (intptr_t)this); \
1536PyObject* CPyCppyy::name##ArrayConverter::FromMemory(void* address) \
1539 return CreateLowLevelView((type**)address, fShape); \
1540 return CreateLowLevelView(*(type**)address, fShape); \
1543bool CPyCppyy::name##ArrayConverter::ToMemory( \
1544 PyObject* value, void* address, PyObject* ctxt) \
1546 if (fShape[0] != 1) { \
1547 PyErr_SetString(PyExc_ValueError, "only 1-dim arrays supported"); \
1550 void* buf = nullptr; \
1551 Py_ssize_t buflen = Utility::GetBuffer(value, code, sizeof(type), buf); \
1555 if (fShape[1] < buflen) { \
1556 PyErr_SetString(PyExc_ValueError, "buffer too large for value"); \
1559 memcpy(*(type**)address, buf, (0 < buflen ? buflen : 1)*sizeof(type));\
1561 *(type**)address = (type*)buf; \
1562 fShape[1] = buflen; \
1564 SetLifeLine(ctxt, value, (intptr_t)address); \
1568bool CPyCppyy::name##ArrayPtrConverter::SetArg( \
1569 PyObject* pyobject, Parameter& para, CallContext* ctxt ) \
1571 if (Py_TYPE(pyobject) == GetCTypesPtrType(ct_##ctype)) { \
1572 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
1573 para.fTypeCode = 'p'; \
1575 } else if (Py_TYPE(pyobject) == GetCTypesType(ct_c_void_p)) { \
1577 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
1578 para.fTypeCode = 'p'; \
1581 bool res = name##ArrayConverter::SetArg(pyobject, para, ctxt); \
1582 if (res && para.fTypeCode == 'p') { \
1583 para.fRef = para.fValue.fVoidp; \
1584 para.fValue.fVoidp = ¶.fRef; \
1595#if __cplusplus > 201402L
1635#define CPPYY_IMPL_STRING_AS_PRIMITIVE_CONVERTER(name, type, F1, F2) \
1636CPyCppyy::name##Converter::name##Converter(bool keepControl) : \
1637 InstanceConverter(Cppyy::GetScope(#type), keepControl) {} \
1639bool CPyCppyy::name##Converter::SetArg( \
1640 PyObject* pyobject, Parameter& para, CallContext* ctxt) \
1643 const char* cstr = CPyCppyy_PyText_AsStringAndSize(pyobject, &len); \
1645 fBuffer = type(cstr, len); \
1646 para.fValue.fVoidp = &fBuffer; \
1647 para.fTypeCode = 'V'; \
1652 if (!(PyInt_Check(pyobject) || PyLong_Check(pyobject))) { \
1653 bool result = InstanceConverter::SetArg(pyobject, para, ctxt); \
1654 para.fTypeCode = 'V'; \
1660PyObject* CPyCppyy::name##Converter::FromMemory(void* address) \
1663 return CPyCppyy_PyText_FromStringAndSize(((type*)address)->F1(), ((type*)address)->F2()); \
1664 Py_INCREF(PyStrings::gEmptyString); \
1665 return PyStrings::gEmptyString; \
1668bool CPyCppyy::name##Converter::ToMemory(PyObject* value, void* address, \
1671 if (CPyCppyy_PyText_Check(value)) { \
1672 *((type*)address) = CPyCppyy_PyText_AsString(value); \
1676 return InstanceConverter::ToMemory(value, address, ctxt); \
1682bool CPyCppyy::STLStringViewConverter::SetArg(
1685 if (this->STLStringViewBaseConverter::SetArg(pyobject, para, ctxt))
1698 fBuffer = *((std::string*)ptr);
1707CPyCppyy::STLWStringConverter::STLWStringConverter(
bool keepControl) :
1708 InstanceConverter(
Cppyy::
GetScope(
"std::wstring"), keepControl) {}
1710bool CPyCppyy::STLWStringConverter::SetArg(
1713 if (PyUnicode_Check(pyobject)) {
1722 if (!(PyInt_Check(pyobject) || PyLong_Check(pyobject))) {
1731PyObject* CPyCppyy::STLWStringConverter::FromMemory(
void* address)
1734 return PyUnicode_FromWideChar(((std::wstring*)address)->c_str(), ((std::wstring*)address)->
size());
1736 return PyUnicode_FromWideChar(&
w, 0);
1741 if (PyUnicode_Check(
value)) {
1743 wchar_t* buf =
new wchar_t[
len+1];
1745 *((std::wstring*)address) = std::wstring(buf,
len);
1749 return InstanceConverter::ToMemory(
value, address, ctxt);
1753bool CPyCppyy::STLStringMoveConverter::SetArg(
1757 int moveit_reason = 3;
1769 if (moveit_reason) {
1770 bool result = this->STLStringConverter::SetArg(pyobject, para, ctxt);
1771 if (!
result && moveit_reason == 2)
1776 PyErr_SetString(PyExc_ValueError,
"object is not an rvalue");
1830 void* ptr =
nullptr;
1831 if (GetAddressSpecialCase(
value, ptr)) {
1832 *(
void**)address = ptr;
1855bool CPyCppyy::InstanceConverter::SetArg(
1881PyObject* CPyCppyy::InstanceConverter::FromMemory(
void* address)
1903bool CPyCppyy::InstanceRefConverter::SetArg(
1934PyObject* CPyCppyy::InstanceRefConverter::FromMemory(
void* address)
1940bool CPyCppyy::InstanceMoveConverter::SetArg(
1951 int moveit_reason = 0;
1959 if (moveit_reason) {
1960 bool result = this->InstanceRefConverter::SetArg(pyobject, para, ctxt);
1961 if (!
result && moveit_reason == 2)
1966 PyErr_SetString(PyExc_ValueError,
"object is not an rvalue");
1971template <
bool ISREFERENCE>
1972bool CPyCppyy::InstancePtrPtrConverter<ISREFERENCE>::SetArg(
1990 para.
fTypeCode = ISREFERENCE ?
'V' :
'p';
1998template <
bool ISREFERENCE>
1999PyObject* CPyCppyy::InstancePtrPtrConverter<ISREFERENCE>::FromMemory(
void* address)
2006template <
bool ISREFERENCE>
2007bool CPyCppyy::InstancePtrPtrConverter<ISREFERENCE>::ToMemory(
PyObject*
value,
void* address,
PyObject* )
2033 template class CPyCppyy::InstancePtrPtrConverter<true>;
2034 template class CPyCppyy::InstancePtrPtrConverter<false>;
2038bool CPyCppyy::InstanceArrayConverter::SetArg(
2047 if (PyTuple_Size(pyobject) < 1)
2065PyObject* CPyCppyy::InstanceArrayConverter::FromMemory(
void* address)
2072bool CPyCppyy::InstanceArrayConverter::ToMemory(
PyObject* ,
void* ,
PyObject* )
2077 PyErr_SetString(PyExc_NotImplementedError,
2078 "access to C-arrays of objects not yet implemented!");
2085bool CPyCppyy::STLIteratorConverter::SetArg(
2100bool CPyCppyy::VoidPtrRefConverter::SetArg(
2115bool CPyCppyy::VoidPtrPtrConverter::SetArg(
2148PyObject* CPyCppyy::VoidPtrPtrConverter::FromMemory(
void* address)
2151 if (!address || *(ptrdiff_t*)address == 0) {
2159bool CPyCppyy::PyObjectConverter::SetArg(
2168PyObject* CPyCppyy::PyObjectConverter::FromMemory(
void* address)
2177 Py_INCREF(pyobject);
2185 Py_XDECREF(*((
PyObject**)address));
2205 void* wpraddress = ipos->second.first;
2207 sWrapperFree[ipos->second.second].push_back(wpraddress);
2213 const_cast<char*
>(
"interal_WrapperCacheEraser"),
2219 const std::string& rettype,
const std::string& signature)
2238 void* fptr = (
void*)
m->GetFunctionAddress();
2239 if (fptr)
return fptr;
2255 if (fptr)
return fptr;
2260 if (PyCallable_Check(pyobject)) {
2262 void* wpraddress =
nullptr;
2265 auto key = std::make_pair(rettype, signature);
2268 const auto& existing = lookup->second.find(pyobject);
2269 if (existing != lookup->second.end() && *
sWrapperReference[existing->second] == pyobject)
2270 wpraddress = existing->second;
2276 if (freewrap !=
sWrapperFree.end() && !freewrap->second.empty()) {
2277 wpraddress = freewrap->second.back();
2278 freewrap->second.pop_back();
2280 PyObject* wref = PyWeakref_NewRef(pyobject, sWrapperCacheEraser);
2293 int nArgs = (
int)argtypes.size();
2296 std::ostringstream wname;
2300 std::ostringstream code;
2301 code <<
"namespace __cppyy_internal {\n "
2302 << rettype <<
" " << wname.str() <<
"(";
2303 for (
int i = 0; i < nArgs; ++i) {
2304 code << argtypes[i] <<
" arg" << i;
2305 if (i != nArgs-1) code <<
", ";
2316 code <<
" PyObject** ref = (PyObject**)" << (intptr_t)ref <<
";\n"
2317 " PyObject* pyresult = nullptr;\n"
2318 " if (*ref) pyresult = PyObject_CallFunctionObjArgs(*ref";
2319 for (
int i = 0; i < nArgs; ++i)
2320 code <<
", pyargs[" << i <<
"]";
2321 code <<
", NULL);\n"
2322 " else PyErr_SetString(PyExc_TypeError, \"callable was deleted\");\n";
2342 PyObject* wref = PyWeakref_NewRef(pyobject, sWrapperCacheEraser);
2354bool CPyCppyy::FunctionPointerConverter::SetArg(
2377PyObject* CPyCppyy::FunctionPointerConverter::FromMemory(
void* address)
2382 static int func_count = 0;
2384 if (!(address && *(
void**)address)) {
2389 void* faddr = *(
void**)address;
2392 std::ostringstream fname;
2393 fname <<
"ptr2func" << ++func_count;
2395 std::ostringstream code;
2396 code <<
"namespace __cppyy_internal {\n std::function<"
2414 PyObject* func = PyObject_GetAttrString(pyscope, cached->second.c_str());
2420bool CPyCppyy::FunctionPointerConverter::ToMemory(
PyObject* pyobject,
void* address,
PyObject* )
2424 *((
void**)address) =
nullptr;
2431 *((
void**)address) = fptr;
2440bool CPyCppyy::StdFunctionConverter::SetArg(
2454 if (this->FunctionPointerConverter::SetArg(pyobject, para, ctxt)) {
2470PyObject* CPyCppyy::StdFunctionConverter::FromMemory(
void* address)
2482bool CPyCppyy::SmartPtrConverter::SetArg(
2485 char typeCode =
fIsRef ?
'p' :
'V';
2544PyObject* CPyCppyy::SmartPtrConverter::FromMemory(
void* address)
2557#if defined (_LIBCPP_INITIALIZER_LIST) || defined(__GNUC__)
2560 typedef size_t size_type;
2561 typedef void* iterator;
2565#elif defined (_MSC_VER)
2568 typedef char* iterator;
2573#define NO_KNOWN_INITIALIZER_LIST 1
2578CPyCppyy::InitializerListConverter::~InitializerListConverter()
2583bool CPyCppyy::InitializerListConverter::SetArg(
2586#ifdef NO_KNOWN_INITIALIZER_LIST
2593#
if PY_VERSION_HEX >= 0x03000000
2601 faux_initlist* fake =
nullptr;
2602 if (buf && buflen) {
2604 fake = (faux_initlist*)
malloc(
sizeof(faux_initlist));
2605 fake->_M_array = (faux_initlist::iterator)buf;
2606#if defined (_LIBCPP_INITIALIZER_LIST) || defined(__GNUC__)
2607 fake->_M_len = (faux_initlist::size_type)buflen;
2608#elif defined (_MSC_VER)
2609 fake->_Last = fake->_M_array+buflen*
fValueSize;
2613 size_t len = (size_t)PySequence_Size(pyobject);
2615 fake->_M_array = (faux_initlist::iterator)((
char*)fake+
sizeof(faux_initlist));
2616#if defined (_LIBCPP_INITIALIZER_LIST) || defined(__GNUC__)
2617 fake->_M_len = (faux_initlist::size_type)
len;
2618 for (faux_initlist::size_type i = 0; i < fake->_M_len; ++i) {
2619#elif defined (_MSC_VER)
2621 for (
size_t i = 0; (fake->_M_array+i*
fValueSize) != fake->_Last; ++i) {
2623 PyObject* item = PySequence_GetItem(pyobject, i);
2624 bool convert_ok =
false;
2638 PyErr_Format(PyExc_TypeError,
"failed to get item %d from sequence", (
int)i);
2657 PyErr_SetString(PyExc_NotImplementedError,
"this method cannot (yet) be called");
2669 if (cpd ==
"**" || cpd ==
"*[]" || cpd ==
"&*")
2670 result =
new InstancePtrPtrConverter<false>(klass, control);
2671 else if (cpd ==
"*&")
2672 result =
new InstancePtrPtrConverter<true>(klass, control);
2673 else if (cpd ==
"*" &&
size <= 0)
2675 else if (cpd ==
"&")
2676 result =
new InstanceRefConverter(klass, isConst);
2677 else if (cpd ==
"&&")
2678 result =
new InstanceMoveConverter(klass);
2679 else if (cpd ==
"[]" ||
size > 0)
2680 result =
new InstanceArrayConverter(klass, dims,
false);
2682 result =
new InstanceConverter(klass,
true);
2700 dim_t size = (dims && dims[0] != -1) ? dims[1] : -1;
2705 return (
h->second)(dims);
2711 if (resolvedType != fullType) {
2714 return (
h->second)(dims);
2718 bool isConst = strncmp(resolvedType.c_str(),
"const", 5) == 0;
2725 return (
h->second)(dims);
2733 return (
h->second)(dims);
2742 return (
h->second)(dims);
2744 }
else if (cpd ==
"*[]") {
2750 dim_t newdim = (dims && 0 < dims[0]) ? dims[0]+1 : 2;
2752 newdims[0] = newdim;
2755 if (dims && 2 < newdim) {
2756 for (
int i = 2; i < (newdim-1); ++i)
2757 newdims[i+1] = dims[i];
2766 if (realType.compare(0, 16,
"initializer_list") == 0) {
2768 auto pos = realType.find(
'<');
2769 std::string value_type = realType.substr(pos+1, realType.size()-pos-2);
2770 Converter* cnv =
nullptr;
bool use_byte_cnv =
false;
2776 use_byte_cnv =
true;
2779 if (cnv || use_byte_cnv)
2780 return new InitializerListConverter(cnv,
Cppyy::SizeOf(value_type));
2784 bool control = cpd ==
"&" || isConst;
2787 auto pos = resolvedType.find(
"function<");
2788 if (pos == 0 || pos == 5 ||
2789 pos == 6 || pos == 11 ) {
2797 auto pos1 = resolvedType.find(
"(", pos+9);
2798 auto pos2 = resolvedType.rfind(
")");
2799 if (pos1 != std::string::npos && pos2 != std::string::npos) {
2800 auto sz1 = pos1-pos-9;
2801 if (resolvedType[pos+9+sz1-1] ==
' ') sz1 -= 1;
2803 return new StdFunctionConverter(cnv,
2804 resolvedType.substr(pos+9, sz1), resolvedType.substr(pos1, pos2-pos1+1));
2816 result =
new SmartPtrConverter(klass, raw, control);
2817 }
else if (cpd ==
"&") {
2818 result =
new SmartPtrConverter(klass, raw);
2819 }
else if (cpd ==
"*" &&
size <= 0) {
2820 result =
new SmartPtrConverter(klass, raw, control,
true);
2826 if (realType.rfind(
"__gnu_cxx::__normal_iterator", 0) == 0
2828 || realType.rfind(
"__wrap_iter", 0) == 0
2832 static STLIteratorConverter
c;
2838 }
else if (resolvedType.find(
"(*)") != std::string::npos ||
2839 (resolvedType.find(
"::*)") != std::string::npos)) {
2842 auto pos1 = resolvedType.find(
'(');
2843 auto pos2 = resolvedType.find(
"*)");
2844 auto pos3 = resolvedType.rfind(
')');
2845 result =
new FunctionPointerConverter(
2846 resolvedType.substr(0, pos1), resolvedType.substr(pos2+2, pos3-pos2-1));
2849 if (!
result && cpd ==
"&&") {
2853 return (
h->second)(dims);
2855 result =
new NotImplementedConverter();
2863 if (cpd.size() == 2 && cpd !=
"&&")
2865 else if (!cpd.empty())
2868 result =
new NotImplementedConverter();
2878 if (
p &&
p->HasState())
2914#define STRINGVIEW "basic_string_view<char,char_traits<char> >"
2915#define WSTRING "basic_string<wchar_t,char_traits<wchar_t>,allocator<wchar_t> >"
2917static struct InitConvFactories_t {
2919 InitConvFactories_t() {
2924 gf[
"bool"] = (
cf_t)+[](
dims_t) {
static BoolConverter
c{};
return &
c; };
2925 gf[
"const bool&"] = (
cf_t)+[](
dims_t) {
static ConstBoolRefConverter
c{};
return &
c; };
2926 gf[
"bool&"] = (
cf_t)+[](
dims_t) {
static BoolRefConverter
c{};
return &
c; };
2927 gf[
"char"] = (
cf_t)+[](
dims_t) {
static CharConverter
c{};
return &
c; };
2928 gf[
"const char&"] = (
cf_t)+[](
dims_t) {
static ConstCharRefConverter
c{};
return &
c; };
2929 gf[
"char&"] = (
cf_t)+[](
dims_t) {
static CharRefConverter
c{};
return &
c; };
2930 gf[
"signed char&"] = (
cf_t)+[](
dims_t) {
static SCharRefConverter
c{};
return &
c; };
2931 gf[
"unsigned char"] = (
cf_t)+[](
dims_t) {
static UCharConverter
c{};
return &
c; };
2932 gf[
"const unsigned char&"] = (
cf_t)+[](
dims_t) {
static ConstUCharRefConverter
c{};
return &
c; };
2933 gf[
"unsigned char&"] = (
cf_t)+[](
dims_t) {
static UCharRefConverter
c{};
return &
c; };
2934 gf[
"UCharAsInt"] = (
cf_t)+[](
dims_t) {
static UCharAsIntConverter
c{};
return &
c; };
2935 gf[
"wchar_t"] = (
cf_t)+[](
dims_t) {
static WCharConverter
c{};
return &
c; };
2936 gf[
"char16_t"] = (
cf_t)+[](
dims_t) {
static Char16Converter
c{};
return &
c; };
2937 gf[
"char32_t"] = (
cf_t)+[](
dims_t) {
static Char32Converter
c{};
return &
c; };
2938 gf[
"wchar_t&"] = (
cf_t)+[](
dims_t) {
static WCharRefConverter
c{};
return &
c; };
2939 gf[
"char16_t&"] = (
cf_t)+[](
dims_t) {
static Char16RefConverter
c{};
return &
c; };
2940 gf[
"char32_t&"] = (
cf_t)+[](
dims_t) {
static Char32RefConverter
c{};
return &
c; };
2941 gf[
"int8_t"] = (
cf_t)+[](
dims_t) {
static Int8Converter
c{};
return &
c; };
2942 gf[
"int8_t&"] = (
cf_t)+[](
dims_t) {
static Int8RefConverter
c{};
return &
c; };
2943 gf[
"const int8_t&"] = (
cf_t)+[](
dims_t) {
static ConstInt8RefConverter
c{};
return &
c; };
2944 gf[
"uint8_t"] = (
cf_t)+[](
dims_t) {
static UInt8Converter
c{};
return &
c; };
2945 gf[
"const uint8_t&"] = (
cf_t)+[](
dims_t) {
static ConstUInt8RefConverter
c{};
return &
c; };
2946 gf[
"uint8_t&"] = (
cf_t)+[](
dims_t) {
static UInt8RefConverter
c{};
return &
c; };
2947 gf[
"short"] = (
cf_t)+[](
dims_t) {
static ShortConverter
c{};
return &
c; };
2948 gf[
"const short&"] = (
cf_t)+[](
dims_t) {
static ConstShortRefConverter
c{};
return &
c; };
2949 gf[
"short&"] = (
cf_t)+[](
dims_t) {
static ShortRefConverter
c{};
return &
c; };
2950 gf[
"unsigned short"] = (
cf_t)+[](
dims_t) {
static UShortConverter
c{};
return &
c; };
2951 gf[
"const unsigned short&"] = (
cf_t)+[](
dims_t) {
static ConstUShortRefConverter
c{};
return &
c; };
2952 gf[
"unsigned short&"] = (
cf_t)+[](
dims_t) {
static UShortRefConverter
c{};
return &
c; };
2953 gf[
"int"] = (
cf_t)+[](
dims_t) {
static IntConverter
c{};
return &
c; };
2954 gf[
"int&"] = (
cf_t)+[](
dims_t) {
static IntRefConverter
c{};
return &
c; };
2955 gf[
"const int&"] = (
cf_t)+[](
dims_t) {
static ConstIntRefConverter
c{};
return &
c; };
2956 gf[
"unsigned int"] = (
cf_t)+[](
dims_t) {
static UIntConverter
c{};
return &
c; };
2957 gf[
"const unsigned int&"] = (
cf_t)+[](
dims_t) {
static ConstUIntRefConverter
c{};
return &
c; };
2958 gf[
"unsigned int&"] = (
cf_t)+[](
dims_t) {
static UIntRefConverter
c{};
return &
c; };
2959 gf[
"long"] = (
cf_t)+[](
dims_t) {
static LongConverter
c{};
return &
c; };
2960 gf[
"long&"] = (
cf_t)+[](
dims_t) {
static LongRefConverter
c{};
return &
c; };
2961 gf[
"const long&"] = (
cf_t)+[](
dims_t) {
static ConstLongRefConverter
c{};
return &
c; };
2962 gf[
"unsigned long"] = (
cf_t)+[](
dims_t) {
static ULongConverter
c{};
return &
c; };
2963 gf[
"const unsigned long&"] = (
cf_t)+[](
dims_t) {
static ConstULongRefConverter
c{};
return &
c; };
2964 gf[
"unsigned long&"] = (
cf_t)+[](
dims_t) {
static ULongRefConverter
c{};
return &
c; };
2965 gf[
"long long"] = (
cf_t)+[](
dims_t) {
static LLongConverter
c{};
return &
c; };
2966 gf[
"const long long&"] = (
cf_t)+[](
dims_t) {
static ConstLLongRefConverter
c{};
return &
c; };
2967 gf[
"long long&"] = (
cf_t)+[](
dims_t) {
static LLongRefConverter
c{};
return &
c; };
2968 gf[
"unsigned long long"] = (
cf_t)+[](
dims_t) {
static ULLongConverter
c{};
return &
c; };
2969 gf[
"const unsigned long long&"] = (
cf_t)+[](
dims_t) {
static ConstULLongRefConverter
c{};
return &
c; };
2970 gf[
"unsigned long long&"] = (
cf_t)+[](
dims_t) {
static ULLongRefConverter
c{};
return &
c; };
2972 gf[
"float"] = (
cf_t)+[](
dims_t) {
static FloatConverter
c{};
return &
c; };
2973 gf[
"const float&"] = (
cf_t)+[](
dims_t) {
static ConstFloatRefConverter
c{};
return &
c; };
2974 gf[
"float&"] = (
cf_t)+[](
dims_t) {
static FloatRefConverter
c{};
return &
c; };
2975 gf[
"double"] = (
cf_t)+[](
dims_t) {
static DoubleConverter
c{};
return &
c; };
2976 gf[
"double&"] = (
cf_t)+[](
dims_t) {
static DoubleRefConverter
c{};
return &
c; };
2977 gf[
"const double&"] = (
cf_t)+[](
dims_t) {
static ConstDoubleRefConverter
c{};
return &
c; };
2978 gf[
"long double"] = (
cf_t)+[](
dims_t) {
static LDoubleConverter
c{};
return &
c; };
2979 gf[
"const long double&"] = (
cf_t)+[](
dims_t) {
static ConstLDoubleRefConverter
c{};
return &
c; };
2980 gf[
"long double&"] = (
cf_t)+[](
dims_t) {
static LDoubleRefConverter
c{};
return &
c; };
2981 gf[
"std::complex<double>"] = (
cf_t)+[](
dims_t) {
return new ComplexDConverter{}; };
2982 gf[
"complex<double>"] = (
cf_t)+[](
dims_t) {
return new ComplexDConverter{}; };
2983 gf[
"const std::complex<double>&"] = (
cf_t)+[](
dims_t) {
return new ComplexDConverter{}; };
2984 gf[
"const complex<double>&"] = (
cf_t)+[](
dims_t) {
return new ComplexDConverter{}; };
2985 gf[
"void"] = (
cf_t)+[](
dims_t) {
static VoidConverter
c{};
return &
c; };
2988 gf[
"bool*"] = (
cf_t)+[](
dims_t d) {
return new BoolArrayConverter{
d}; };
2989 gf[
"bool**"] = (
cf_t)+[](
dims_t d) {
return new BoolArrayPtrConverter{
d}; };
2990 gf[
"const signed char[]"] = (
cf_t)+[](
dims_t d) {
return new SCharArrayConverter{
d}; };
2991 gf[
"signed char[]"] = (
cf_t)+[](
dims_t d) {
return new SCharArrayConverter{
d}; };
2992 gf[
"signed char**"] = (
cf_t)+[](
dims_t d) {
return new SCharArrayPtrConverter{
d}; };
2993 gf[
"const unsigned char*"] = (
cf_t)+[](
dims_t d) {
return new UCharArrayConverter{
d}; };
2994 gf[
"unsigned char*"] = (
cf_t)+[](
dims_t d) {
return new UCharArrayConverter{
d}; };
2995 gf[
"UCharAsInt*"] = (
cf_t)+[](
dims_t d) {
return new UCharArrayConverter{
d}; };
2996 gf[
"unsigned char**"] = (
cf_t)+[](
dims_t d) {
return new UCharArrayPtrConverter{
d}; };
2997#if __cplusplus > 201402L
2998 gf[
"byte*"] = (
cf_t)+[](
dims_t d) {
return new ByteArrayConverter{
d}; };
2999 gf[
"byte**"] = (
cf_t)+[](
dims_t d) {
return new ByteArrayPtrConverter{
d}; };
3001 gf[
"short*"] = (
cf_t)+[](
dims_t d) {
return new ShortArrayConverter{
d}; };
3002 gf[
"short**"] = (
cf_t)+[](
dims_t d) {
return new ShortArrayPtrConverter{
d}; };
3003 gf[
"unsigned short*"] = (
cf_t)+[](
dims_t d) {
return new UShortArrayConverter{
d}; };
3004 gf[
"unsigned short**"] = (
cf_t)+[](
dims_t d) {
return new UShortArrayPtrConverter{
d}; };
3005 gf[
"int*"] = (
cf_t)+[](
dims_t d) {
return new IntArrayConverter{
d}; };
3006 gf[
"int**"] = (
cf_t)+[](
dims_t d) {
return new IntArrayPtrConverter{
d}; };
3007 gf[
"unsigned int*"] = (
cf_t)+[](
dims_t d) {
return new UIntArrayConverter{
d}; };
3008 gf[
"unsigned int**"] = (
cf_t)+[](
dims_t d) {
return new UIntArrayPtrConverter{
d}; };
3009 gf[
"long*"] = (
cf_t)+[](
dims_t d) {
return new LongArrayConverter{
d}; };
3010 gf[
"long**"] = (
cf_t)+[](
dims_t d) {
return new LongArrayPtrConverter{
d}; };
3011 gf[
"unsigned long*"] = (
cf_t)+[](
dims_t d) {
return new ULongArrayConverter{
d}; };
3012 gf[
"unsigned long**"] = (
cf_t)+[](
dims_t d) {
return new ULongArrayPtrConverter{
d}; };
3013 gf[
"long long*"] = (
cf_t)+[](
dims_t d) {
return new LLongArrayConverter{
d}; };
3014 gf[
"long long**"] = (
cf_t)+[](
dims_t d) {
return new LLongArrayPtrConverter{
d}; };
3015 gf[
"unsigned long long*"] = (
cf_t)+[](
dims_t d) {
return new ULLongArrayConverter{
d}; };
3016 gf[
"unsigned long long**"] = (
cf_t)+[](
dims_t d) {
return new ULLongArrayPtrConverter{
d}; };
3017 gf[
"float*"] = (
cf_t)+[](
dims_t d) {
return new FloatArrayConverter{
d}; };
3018 gf[
"float**"] = (
cf_t)+[](
dims_t d) {
return new FloatArrayPtrConverter{
d}; };
3019 gf[
"double*"] = (
cf_t)+[](
dims_t d) {
return new DoubleArrayConverter{
d}; };
3020 gf[
"double**"] = (
cf_t)+[](
dims_t d) {
return new DoubleArrayPtrConverter{
d}; };
3021 gf[
"long double*"] = (
cf_t)+[](
dims_t d) {
return new LDoubleArrayConverter{
d}; };
3022 gf[
"long double**"] = (
cf_t)+[](
dims_t d) {
return new LDoubleArrayPtrConverter{
d}; };
3023 gf[
"std::complex<double>*"] = (
cf_t)+[](
dims_t d) {
return new ComplexDArrayConverter{
d}; };
3024 gf[
"complex<double>*"] = (
cf_t)+[](
dims_t d) {
return new ComplexDArrayConverter{
d}; };
3025 gf[
"std::complex<double>**"] = (
cf_t)+[](
dims_t d) {
return new ComplexDArrayPtrConverter{
d}; };
3029 gf[
"signed char"] = gf[
"char"];
3030 gf[
"const signed char&"] = gf[
"const char&"];
3031#if __cplusplus > 201402L
3032 gf[
"byte"] = gf[
"uint8_t"];
3033 gf[
"const byte&"] = gf[
"const uint8_t&"];
3034 gf[
"byte&"] = gf[
"uint8&"];
3036 gf[
"internal_enum_type_t"] = gf[
"int"];
3037 gf[
"internal_enum_type_t&"] = gf[
"int&"];
3038 gf[
"const internal_enum_type_t&"] = gf[
"const int&"];
3039 gf[
"Long64_t"] = gf[
"long long"];
3040 gf[
"Long64_t*"] = gf[
"long long*"];
3041 gf[
"Long64_t&"] = gf[
"long long&"];
3042 gf[
"const Long64_t&"] = gf[
"const long long&"];
3043 gf[
"ULong64_t"] = gf[
"unsigned long long"];
3044 gf[
"ULong64_t*"] = gf[
"unsigned long long*"];
3045 gf[
"ULong64_t&"] = gf[
"unsigned long long&"];
3046 gf[
"const ULong64_t&"] = gf[
"const unsigned long long&"];
3047 gf[
"Float16_t"] = gf[
"float"];
3048 gf[
"const Float16_t&"] = gf[
"const float&"];
3049 gf[
"Double32_t"] = gf[
"double"];
3050 gf[
"Double32_t&"] = gf[
"double&"];
3051 gf[
"const Double32_t&"] = gf[
"const double&"];
3054 gf[
"TString"] = (
cf_t)+[](
dims_t) {
return new TStringConverter{}; };
3055 gf[
"TString&"] = gf[
"TString"];
3056 gf[
"const TString&"] = gf[
"TString"];
3057 gf[
"nullptr_t"] = (
cf_t)+[](
dims_t) {
static NullptrConverter
c{};
return &
c;};
3058 gf[
"const char*"] = (
cf_t)+[](
dims_t) {
return new CStringConverter{}; };
3059 gf[
"const signed char*"] = gf[
"const char*"];
3060 gf[
"const char[]"] = (
cf_t)+[](
dims_t) {
return new CStringConverter{}; };
3061 gf[
"char*"] = (
cf_t)+[](
dims_t) {
return new NonConstCStringConverter{}; };
3062 gf[
"signed char*"] = gf[
"char*"];
3063 gf[
"wchar_t*"] = (
cf_t)+[](
dims_t) {
return new WCStringConverter{}; };
3064 gf[
"char16_t*"] = (
cf_t)+[](
dims_t) {
return new CString16Converter{}; };
3065 gf[
"char32_t*"] = (
cf_t)+[](
dims_t) {
return new CString32Converter{}; };
3067 gf[
"char16_t**"] = gf[
"char16_t*"];
3068 gf[
"char32_t**"] = gf[
"char32_t*"];
3069 gf[
"const char**"] = (
cf_t)+[](
dims_t d) {
return new CStringArrayConverter{
d}; };
3070 gf[
"char**"] = gf[
"const char**"];
3071 gf[
"const char*[]"] = gf[
"const char**"];
3072 gf[
"char*[]"] = gf[
"const char*[]"];
3073 gf[
"std::string"] = (
cf_t)+[](
dims_t) {
return new STLStringConverter{}; };
3074 gf[
"string"] = gf[
"std::string"];
3075 gf[
"const std::string&"] = gf[
"std::string"];
3076 gf[
"const string&"] = gf[
"std::string"];
3077 gf[
"string&&"] = (
cf_t)+[](
dims_t) {
return new STLStringMoveConverter{}; };
3078 gf[
"std::string&&"] = gf[
"string&&"];
3079 gf[
"std::string_view"] = (
cf_t)+[](
dims_t) {
return new STLStringViewConverter{}; };
3080 gf[
"string_view"] = gf[
"std::string_view"];
3082 gf[
"experimental::" STRINGVIEW] = gf[
"std::string_view"];
3083 gf[
"std::string_view&"] = gf[
"std::string_view"];
3084 gf[
"const string_view&"] = gf[
"std::string_view"];
3085 gf[
"const " STRINGVIEW "&"] = gf[
"std::string_view"];
3086 gf[
"std::wstring"] = (
cf_t)+[](
dims_t) {
return new STLWStringConverter{}; };
3087 gf[
WSTRING] = gf[
"std::wstring"];
3088 gf[
"std::" WSTRING] = gf[
"std::wstring"];
3089 gf[
"const std::wstring&"] = gf[
"std::wstring"];
3090 gf[
"const std::" WSTRING "&"] = gf[
"std::wstring"];
3091 gf[
"const " WSTRING "&"] = gf[
"std::wstring"];
3092 gf[
"void*&"] = (
cf_t)+[](
dims_t) {
static VoidPtrRefConverter
c{};
return &
c; };
3093 gf[
"void**"] = (
cf_t)+[](
dims_t d) {
return new VoidPtrPtrConverter{size_t((
d &&
d[0] != -1) ?
d[1] : -1)}; };
3094 gf[
"void*[]"] = (
cf_t)+[](
dims_t d) {
return new VoidPtrPtrConverter{size_t((
d &&
d[0] != -1) ?
d[1] : -1)}; };
3095 gf[
"PyObject*"] = (
cf_t)+[](
dims_t) {
static PyObjectConverter
c{};
return &
c; };
3096 gf[
"_object*"] = gf[
"PyObject*"];
3099} initConvFactories_;
static Py_ssize_t CPyCppyy_PyUnicode_AsWideChar(PyObject *pyobj, wchar_t *w, Py_ssize_t size)
#define PyBytes_AS_STRING
#define CPyCppyy_PyText_FromStringAndSize
#define CPyCppyy_PyUnicode_GET_SIZE
#define PY_SSIZE_T_FORMAT
static void * CPyCppyy_PyCapsule_GetPointer(PyObject *capsule, const char *)
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_GET_SIZE
#define CPyCppyy_PyCapsule_CheckExact
static const char * CPyCppyy_PyText_AsStringAndSize(PyObject *pystr, Py_ssize_t *size)
#define CPyCppyy_PyText_FromString
#define CPyCppyy_PyText_Check
static unsigned short CPyCppyy_PyLong_AsUShort(PyObject *pyobject)
static const char * FPCFM_ERRMSG
#define CPPYY_IMPL_BASIC_CONVERTER(name, type, stype, ctype, F1, F2, tc)
#define CPPYY_IMPL_ARRAY_CONVERTER(name, ctype, type, code)
static bool ConvertImplicit(Cppyy::TCppType_t klass, PyObject *pyobject, CPyCppyy::Parameter ¶, CPyCppyy::CallContext *ctxt)
static std::map< void *, PyObject ** > sWrapperReference
static bool CPyCppyy_PyLong_AsBool(PyObject *pyobject)
static bool IsPyCArgObject(PyObject *pyobject)
static std::array< PyTypeObject *, 22 > gCTypesTypes
static PyObject * WrapperCacheEraser(PyObject *, PyObject *pyref)
#define CPPYY_IMPL_STRING_AS_PRIMITIVE_CONVERTER(name, type, F1, F2)
#define CPPYY_IMPL_BASIC_CHAR_CONVERTER(name, type, low, high)
const size_t MOVE_REFCOUNT_CUTOFF
static char CPyCppyy_PyText_AsChar(PyObject *pyobject)
#define CPPYY_IMPL_BASIC_CONST_CHAR_REFCONVERTER(name, type, ctype, low, high)
static bool SetLifeLine(PyObject *holder, PyObject *target, intptr_t ref)
static std::map< RetSigKey_t, std::map< PyObject *, void * > > sWrapperLookup
static std::array< PyTypeObject *, 22 > gCTypesPtrTypes
static int ExtractChar(PyObject *pyobject, const char *tname, int low, int high)
static std::array< const char *, 22 > gCTypesNames
static void init_shape(Py_ssize_t defdim, dims_t dims, Py_ssize_t *&shape)
static PyTypeObject * GetCTypesPtrType(int nidx)
static std::map< PyObject *, std::pair< void *, RetSigKey_t > > sWrapperWeakRefs
static int8_t CPyCppyy_PyLong_AsInt8(PyObject *pyobject)
std::pair< std::string, std::string > RetSigKey_t
static PyMethodDef gWrapperCacheEraserMethodDef
#define CPPYY_IMPL_BASIC_CONST_REFCONVERTER(name, type, ctype, F1)
static CPyCppyy::Converter * selectInstanceCnv(Cppyy::TCppScope_t klass, const std::string &cpd, long size, dims_t dims, bool isConst, bool control)
static uint8_t CPyCppyy_PyLong_AsUInt8(PyObject *pyobject)
static std::map< void *, std::string > sFuncWrapperLookup
static short CPyCppyy_PyLong_AsShort(PyObject *pyobject)
static long CPyCppyy_PyLong_AsStrictLong(PyObject *pyobject)
static CPyCppyy::CPPInstance * GetCppInstance(PyObject *pyobject)
#define UNKNOWN_ARRAY_SIZE
#define CPPYY_IMPL_REFCONVERTER(name, ctype, type, code)
static PyTypeObject * GetCTypesType(int nidx)
static bool CArraySetArg(PyObject *pyobject, CPyCppyy::Parameter ¶, char tc, int size)
static int CPyCppyy_PyLong_AsStrictInt(PyObject *pyobject)
static std::map< RetSigKey_t, std::vector< void * > > sWrapperFree
static bool IsCTypesArrayOrPointer(PyObject *pyobject)
static unsigned int sWrapperCounter
static void * PyFunction_AsCPointer(PyObject *pyobject, const std::string &rettype, const std::string &signature)
#define CPPYY_IMPL_REFCONVERTER_FROM_MEMORY(name, ctype)
Cppyy::TCppType_t fSmartPtrType
Cppyy::TCppType_t fUnderlyingType
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned long long ULong64_t
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Cppyy::TCppType_t GetSmartIsA() const
Cppyy::TCppType_t ObjectIsA(bool check_smart=true) const
MethodInfo_t * fMethodInfo
virtual bool SetArg(PyObject *, Parameter &, CallContext *=nullptr)=0
virtual bool ToMemory(PyObject *value, void *address, PyObject *ctxt=nullptr)
virtual PyObject * FromMemory(void *address)
virtual bool SetArg(PyObject *, Parameter &, CallContext *=nullptr)
virtual PyObject * FromMemory(void *address)
virtual bool ToMemory(PyObject *value, void *address, PyObject *ctxt=nullptr)
static bool RegisterPyObject(CPPInstance *pyobj, void *cppobj)
virtual bool GetAddressSpecialCase(PyObject *pyobject, void *&address)
virtual bool ToMemory(PyObject *value, void *address, PyObject *ctxt=nullptr)
virtual PyObject * FromMemory(void *address)
virtual bool SetArg(PyObject *, Parameter &, CallContext *=nullptr)
std::string remove_const(const std::string &cppname)
std::string clean_type(const std::string &cppname, bool template_strip=true, bool const_strip=true)
std::vector< std::string > extract_arg_types(const std::string &sig)
void ConstructCallbackPreamble(const std::string &retType, const std::vector< std::string > &argtypes, std::ostringstream &code)
void ConstructCallbackReturn(const std::string &retType, int nArgs, std::ostringstream &code)
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
const std::string Compound(const std::string &name)
Set of helper functions that are invoked from the pythonizors, on the Python side.
unsigned long PyLongOrInt_AsULong(PyObject *pyobject)
bool TupleOfInstances_CheckExact(T *object)
PyObject * CreatePointerView(void *ptr, size_t size=(size_t) -1)
bool RefFloat_CheckExact(T *object)
bool CPPExcInstance_Check(T *object)
bool NoImplicit(CallContext *ctxt)
static ConvFactories_t gConvFactories
PyObject * CreateLowLevelView(bool *, Py_ssize_t *shape=nullptr)
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
bool CPPOverload_Check(T *object)
bool RefInt_CheckExact(T *object)
bool CPPScope_Check(T *object)
CPYCPPYY_EXTERN bool RegisterConverter(const std::string &name, ConverterFactory_t)
bool AllowImplicit(CallContext *ctxt)
bool UseStrictOwnership(CallContext *ctxt)
bool CPPInstance_Check(T *object)
PyObject * CreateScopeProxy(Cppyy::TCppScope_t)
Converter *(* cf_t)(dims_t d)
PyObject * gNullPtrObject
bool IsConstructor(uint64_t flags)
PyObject * BindCppObject(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
ULong64_t PyLongOrInt_AsULong64(PyObject *pyobject)
CPYCPPYY_EXTERN void DestroyConverter(Converter *p)
bool TemplateProxy_Check(T *object)
std::map< std::string, cf_t > ConvFactories_t
PyObject * BindCppObjectArray(Cppyy::TCppObject_t address, Cppyy::TCppType_t klass, Py_ssize_t *dims)
CPYCPPYY_EXTERN bool UnregisterConverter(const std::string &name)
CPYCPPYY_EXTERN Converter * CreateConverter(const std::string &name, Py_ssize_t *dims=nullptr)
RPY_EXPORTED ptrdiff_t GetBaseOffset(TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror=false)
RPY_EXPORTED size_t SizeOf(TCppType_t klass)
RPY_EXPORTED std::vector< TCppIndex_t > GetMethodIndicesFromName(TCppScope_t scope, const std::string &name)
RPY_EXPORTED bool IsSubtype(TCppType_t derived, TCppType_t base)
RPY_EXPORTED TCppMethod_t GetMethodTemplate(TCppScope_t scope, const std::string &name, const std::string &proto)
RPY_EXPORTED bool GetSmartPtrInfo(const std::string &, TCppType_t *raw, TCppMethod_t *deref)
RPY_EXPORTED std::string ResolveName(const std::string &cppitem_name)
RPY_EXPORTED TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RPY_EXPORTED TCppFuncAddr_t GetFunctionAddress(TCppMethod_t method, bool check_enabled=true)
RPY_EXPORTED bool Compile(const std::string &code)
RooArgList L(Args_t &&... args)
CPPOverload::Methods_t fMethods
static ECallFlags sMemoryPolicy
Cppyy::TCppScope_t fCurScope
void AddTemporary(PyObject *pyobj)
union CPyCppyy::Parameter::Value fValue
PyObject_HEAD char * b_ptr
union CPyCppyy_tagPyCArgObject::@215 value
PyObject_HEAD void * pffi_type
unsigned long long fULLong