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);
224#if PY_VERSION_HEX < 0x03090000
245 long l = PyLong_AsLong(pyobject);
247 if (!(
l == 0||
l == 1) || PyFloat_Check(pyobject)) {
248 PyErr_SetString(PyExc_ValueError,
"boolean value should be bool, or integer 1 or 0");
263 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
264 PyErr_SetString(PyExc_TypeError,
"short int conversion expects an integer object");
267 long l = PyLong_AsLong(pyobject);
268 if (
l < 0 || UCHAR_MAX <
l) {
269 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for uint8_t",
l);
280 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
281 PyErr_SetString(PyExc_TypeError,
"short int conversion expects an integer object");
284 long l = PyLong_AsLong(pyobject);
285 if (
l < SCHAR_MIN || SCHAR_MAX <
l) {
286 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for int8_t",
l);
298 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
299 PyErr_SetString(PyExc_TypeError,
"unsigned short conversion expects an integer object");
300 return (
unsigned short)-1;
302 long l = PyLong_AsLong(pyobject);
303 if (
l < 0 || USHRT_MAX <
l) {
304 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for unsigned short",
l);
305 return (
unsigned short)-1;
308 return (
unsigned short)
l;
315 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
316 PyErr_SetString(PyExc_TypeError,
"short int conversion expects an integer object");
319 long l = PyLong_AsLong(pyobject);
320 if (
l < SHRT_MIN || SHRT_MAX <
l) {
321 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for short int",
l);
335 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
336 PyErr_SetString(PyExc_TypeError,
"int/long conversion expects an integer object");
339 long l = PyLong_AsLong(pyobject);
340 if (
l < INT_MIN || INT_MAX <
l) {
341 PyErr_Format(PyExc_ValueError,
"integer %ld out of range for int",
l);
353 if (!(PyLong_Check(pyobject) || PyInt_Check(pyobject))) {
354 PyErr_SetString(PyExc_TypeError,
"int/long conversion expects an integer object");
357 return (
long)PyLong_AsLong(pyobject);
374 PyErr_Format(PyExc_TypeError,
375 "could not convert argument to buffer or nullptr");
399 PyTypeObject* pytype = (PyTypeObject*)
Py_TYPE(pyobject);
400 if (!(pytype == &PyList_Type || pytype == &PyTuple_Type)) {
417 Py_INCREF(pyobject); PyTuple_SET_ITEM(args, 0, pyobject);
421 if (!pytmp && PyTuple_CheckExact(pyobject)) {
425 pytmp = (
CPPInstance*)PyObject_Call(pyscope, pyobject, kwds);
455 PyErr_SetString(PyExc_TypeError,
"C++ type cannot be converted from memory");
463 PyErr_SetString(PyExc_TypeError,
"C++ type cannot be converted to memory");
469#define CPPYY_IMPL_BASIC_CONVERTER(name, type, stype, ctype, F1, F2, tc) \
470bool CPyCppyy::name##Converter::SetArg( \
471 PyObject* pyobject, Parameter& para, CallContext* ) \
474 type val = (type)F2(pyobject); \
475 if (val == (type)-1 && PyErr_Occurred()) { \
476 static PyTypeObject* ctypes_type = nullptr; \
477 if (!ctypes_type) { \
478 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0; \
479 PyErr_Fetch(&pytype, &pyvalue, &pytrace); \
480 ctypes_type = GetCTypesType(ct_##ctype); \
481 PyErr_Restore(pytype, pyvalue, pytrace); \
483 if (Py_TYPE(pyobject) == ctypes_type) { \
485 val = *((type*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr); \
489 para.fValue.f##name = val; \
490 para.fTypeCode = tc; \
494PyObject* CPyCppyy::name##Converter::FromMemory(void* address) \
496 return F1((stype)*((type*)address)); \
499bool CPyCppyy::name##Converter::ToMemory(PyObject* value, void* address, \
502 type s = (type)F2(value); \
503 if (s == (type)-1 && PyErr_Occurred()) \
505 *((type*)address) = (type)s; \
517 PyErr_Format(PyExc_ValueError,
"%s expected, got string of size " PY_SSIZE_T_FORMAT,
519 }
else if (!PyFloat_Check(pyobject)) {
520 lchar = (
int)PyLong_AsLong(pyobject);
521 if (lchar == -1 && PyErr_Occurred())
523 else if (!(low <= lchar && lchar <= high)) {
524 PyErr_Format(PyExc_ValueError,
525 "integer to character: value %d not in range [%d,%d]", lchar, low, high);
529 PyErr_SetString(PyExc_TypeError,
"char or small int type expected");
535#define CPPYY_IMPL_REFCONVERTER_FROM_MEMORY(name, ctype) \
536PyObject* CPyCppyy::name##RefConverter::FromMemory(void* ptr) \
539 PyTypeObject* ctypes_type = GetCTypesType(ct_##ctype); \
540 if (!ctypes_type) { \
541 PyErr_SetString(PyExc_RuntimeError, "no ctypes available"); \
544 PyObject* ref = ctypes_type->tp_new(ctypes_type, nullptr, nullptr); \
545 ((CPyCppyy_tagCDataObject*)ref)->b_ptr = (char*)ptr; \
546 ((CPyCppyy_tagCDataObject*)ref)->b_needsfree = 0; \
551#define CPPYY_IMPL_BASIC_CONST_REFCONVERTER(name, type, ctype, F1) \
552bool CPyCppyy::Const##name##RefConverter::SetArg( \
553 PyObject* pyobject, Parameter& para, CallContext* ) \
555 type val = (type)F1(pyobject); \
556 if (val == (type)-1 && PyErr_Occurred()) \
558 para.fValue.f##name = val; \
559 para.fRef = ¶.fValue.f##name; \
560 para.fTypeCode = 'r'; \
563CPPYY_IMPL_REFCONVERTER_FROM_MEMORY(Const##name, ctype)
566#define CPPYY_IMPL_BASIC_CONST_CHAR_REFCONVERTER(name, type, ctype, low, high)\
567bool CPyCppyy::Const##name##RefConverter::SetArg( \
568 PyObject* pyobject, Parameter& para, CallContext* ) \
571 type val = (type)ExtractChar(pyobject, #type, low, high); \
572 if (val == (type)-1 && PyErr_Occurred()) \
574 para.fValue.fLong = val; \
575 para.fTypeCode = 'l'; \
578CPPYY_IMPL_REFCONVERTER_FROM_MEMORY(Const##name, ctype)
582#define CPPYY_IMPL_BASIC_CHAR_CONVERTER(name, type, low, high) \
583bool CPyCppyy::name##Converter::SetArg( \
584 PyObject* pyobject, Parameter& para, CallContext* ) \
587 long val = ExtractChar(pyobject, #type, low, high); \
588 if (val == -1 && PyErr_Occurred()) \
590 para.fValue.fLong = val; \
591 para.fTypeCode = 'l'; \
595PyObject* CPyCppyy::name##Converter::FromMemory(void* address) \
597 return CPyCppyy_PyText_FromFormat("%c", *((type*)address)); \
600bool CPyCppyy::name##Converter::ToMemory(PyObject* value, void* address, \
604 const char* cstr = CPyCppyy_PyText_AsStringAndSize(value, &len); \
607 PyErr_Format(PyExc_TypeError, #type" expected, got string of size %zd", len);\
610 *((type*)address) = (type)cstr[0]; \
613 long l = PyLong_AsLong(value); \
614 if (l == -1 && PyErr_Occurred()) \
616 if (!(low <= l && l <= high)) { \
617 PyErr_Format(PyExc_ValueError, \
618 "integer to character: value %ld not in range [%d,%d]", l, low, high);\
621 *((type*)address) = (type)l; \
635#if PY_VERSION_HEX < 0x03000000
637 para.fValue.fVoidp = (
void*)&((PyIntObject*)pyobject)->ob_ival;
638 para.fTypeCode =
'V';
645 para.fTypeCode =
'V';
650 para.fTypeCode =
'V';
654 PyErr_SetString(PyExc_TypeError,
"use ctypes.c_long for pass-by-ref of longs");
675bool CPyCppyy::IntRefConverter::SetArg(
679#if PY_VERSION_HEX < 0x03000000
681 para.
fValue.
fVoidp = (
void*)&((PyIntObject*)pyobject)->ob_ival;
687#if PY_VERSION_HEX >= 0x02050000
702#if PY_VERSION_HEX < 0x02050000
703 PyErr_SetString(PyExc_TypeError,
"use cppyy.Long for pass-by-ref of ints");
705 PyErr_SetString(PyExc_TypeError,
"use ctypes.c_int for pass-by-ref of ints");
711#define CPPYY_IMPL_REFCONVERTER(name, ctype, type, code) \
712bool CPyCppyy::name##RefConverter::SetArg( \
713 PyObject* pyobject, Parameter& para, CallContext* ) \
716 if (Py_TYPE(pyobject) == GetCTypesType(ct_##ctype)) { \
717 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
718 para.fTypeCode = 'V'; \
721 bool res = CArraySetArg(pyobject, para, code, sizeof(type)); \
723 PyErr_SetString(PyExc_TypeError, "use ctypes."#ctype" for pass-by-ref of "#type);\
726 para.fTypeCode = 'V'; \
729CPPYY_IMPL_REFCONVERTER_FROM_MEMORY(name, ctype)
766 return PyInt_FromLong((
long)*((
unsigned char*)address));
770bool CPyCppyy::WCharConverter::SetArg(
775 PyErr_SetString(PyExc_ValueError,
"single wchar_t character expected");
787PyObject* CPyCppyy::WCharConverter::FromMemory(
void* address)
789 return PyUnicode_FromWideChar((
const wchar_t*)address, 1);
795 PyErr_SetString(PyExc_ValueError,
"single wchar_t character expected");
802 *((
wchar_t*)address) = val;
807bool CPyCppyy::Char16Converter::SetArg(
812 PyErr_SetString(PyExc_ValueError,
"single char16_t character expected");
816 PyObject* bstr = PyUnicode_AsUTF16String(pyobject);
817 if (!bstr)
return false;
826PyObject* CPyCppyy::Char16Converter::FromMemory(
void* address)
828 return PyUnicode_DecodeUTF16((
const char*)address,
sizeof(
char16_t),
nullptr,
nullptr);
834 PyErr_SetString(PyExc_ValueError,
"single char16_t character expected");
839 if (!bstr)
return false;
841 *((
char16_t*)address) = *(
char16_t*)(
PyBytes_AS_STRING(bstr) +
sizeof(char16_t) );
847bool CPyCppyy::Char32Converter::SetArg(
852 PyErr_SetString(PyExc_ValueError,
"single char32_t character expected");
856 PyObject* bstr = PyUnicode_AsUTF32String(pyobject);
857 if (!bstr)
return false;
866PyObject* CPyCppyy::Char32Converter::FromMemory(
void* address)
868 return PyUnicode_DecodeUTF32((
const char*)address,
sizeof(
char32_t),
nullptr,
nullptr);
874 PyErr_SetString(PyExc_ValueError,
"single char32_t character expected");
879 if (!bstr)
return false;
881 *((
char32_t*)address) = *(
char32_t*)(
PyBytes_AS_STRING(bstr) +
sizeof(char32_t) );
899bool CPyCppyy::ULongConverter::SetArg(
904 if (para.fValue.fULong == (
unsigned long)-1 && PyErr_Occurred())
906 para.fTypeCode =
'L';
910PyObject* CPyCppyy::ULongConverter::FromMemory(
void* address)
913 return PyLong_FromUnsignedLong(*((
unsigned long*)address));
920 if (u == (
unsigned long)-1 && PyErr_Occurred())
922 *((
unsigned long*)address) = u;
927PyObject* CPyCppyy::UIntConverter::FromMemory(
void* address)
930 return PyLong_FromUnsignedLong(*((
UInt_t*)address));
937 if (u == (
unsigned long)-1 && PyErr_Occurred())
941 PyErr_SetString(PyExc_OverflowError,
"value too large for unsigned int");
951 Float,
float,
double, c_float, PyFloat_FromDouble, PyFloat_AsDouble,
'f')
953 Double,
double,
double, c_double, PyFloat_FromDouble, PyFloat_AsDouble, '
d')
958CPyCppyy::ComplexDConverter::ComplexDConverter(
bool keepControl) :
959 InstanceConverter(
Cppyy::GetScope("std::complex<
double>"), keepControl) {}
962bool CPyCppyy::ComplexDConverter::SetArg(
965 const Py_complex& pc = PyComplex_AsCComplex(pyobject);
966 if (pc.real != -1.0 || !PyErr_Occurred()) {
974 return this->InstanceConverter::SetArg(pyobject, para, ctxt);
977PyObject* CPyCppyy::ComplexDConverter::FromMemory(
void* address)
979 std::complex<double>* dc = (std::complex<double>*)address;
980 return PyComplex_FromDoubles(dc->real(), dc->imag());
985 const Py_complex& pc = PyComplex_AsCComplex(
value);
986 if (pc.real != -1.0 || !PyErr_Occurred()) {
987 std::complex<double>* dc = (std::complex<double>*)address;
992 return this->InstanceConverter::ToMemory(
value, address, ctxt);
996bool CPyCppyy::DoubleRefConverter::SetArg(
1001 para.
fValue.
fVoidp = (
void*)&((PyFloatObject*)pyobject)->ob_fval;
1013#if PY_VERSION_HEX < 0x02050000
1014 PyErr_SetString(PyExc_TypeError,
"use cppyy.Double for pass-by-ref of doubles");
1016 PyErr_SetString(PyExc_TypeError,
"use ctypes.c_double for pass-by-ref of doubles");
1030 PyErr_SetString(PyExc_SystemError,
"void/unknown arguments can\'t be set");
1035bool CPyCppyy::LLongConverter::SetArg(
1039 if (PyFloat_Check(pyobject)) {
1042 PyErr_SetString(PyExc_ValueError,
"cannot convert float to long long");
1047 if (PyErr_Occurred())
1053PyObject* CPyCppyy::LLongConverter::FromMemory(
void* address)
1056 return PyLong_FromLongLong(*(
Long64_t*)address);
1063 if (ll == -1 && PyErr_Occurred())
1070bool CPyCppyy::ULLongConverter::SetArg(
1075 if (PyErr_Occurred())
1081PyObject* CPyCppyy::ULLongConverter::FromMemory(
void* address)
1084 return PyLong_FromUnsignedLongLong(*(
ULong64_t*)address);
1091 if (PyErr_Occurred())
1098bool CPyCppyy::CStringConverter::SetArg(
1106 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0;
1107 PyErr_Fetch(&pytype, &pyvalue, &pytrace);
1111 Py_XDECREF(pytype); Py_XDECREF(pyvalue); Py_XDECREF(pytrace);
1114 PyErr_Restore(pytype, pyvalue, pytrace);
1122 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for char array (truncated)");
1132PyObject* CPyCppyy::CStringConverter::FromMemory(
void* address)
1135 if (address && *(
char**)address) {
1137 std::string buf(*(
char**)address,
fMaxSize);
1154 if (!cstr)
return false;
1158 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for char array (truncated)");
1161 strncpy(*(
char**)address, cstr,
fMaxSize);
1164 strcpy(*(
char**)address, cstr);
1170bool CPyCppyy::WCStringConverter::SetArg(
1190PyObject* CPyCppyy::WCStringConverter::FromMemory(
void* address)
1193 if (address && *(
wchar_t**)address) {
1195 return PyUnicode_FromWideChar(*(
wchar_t**)address,
fMaxSize);
1197 return PyUnicode_FromWideChar(*(
wchar_t**)address, wcslen(*(
wchar_t**)address));
1202 return PyUnicode_FromWideChar(&
w, 0);
1214 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for wchar_t array (truncated)");
1223 if (res == -1)
return false;
1228bool CPyCppyy::CString16Converter::SetArg(
1236 PyObject* bstr = PyUnicode_AsUTF16String(pyobject);
1237 if (!bstr)
return false;
1250PyObject* CPyCppyy::CString16Converter::FromMemory(
void* address)
1253 if (address && *(
char16_t**)address) {
1255 return PyUnicode_DecodeUTF16(*(
const char**)address,
fMaxSize,
nullptr,
nullptr);
1257 return PyUnicode_DecodeUTF16(*(
const char**)address,
1258 std::char_traits<char16_t>::length(*(
char16_t**)address)*
sizeof(
char16_t),
nullptr,
nullptr);
1263 return PyUnicode_DecodeUTF16((
const char*)&
w, 0,
nullptr,
nullptr);
1275 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for char16_t array (truncated)");
1280 if (!bstr)
return false;
1284 *((
char16_t**)address)[
len] = u
'\0';
1289bool CPyCppyy::CString32Converter::SetArg(
1297 PyObject* bstr = PyUnicode_AsUTF32String(pyobject);
1298 if (!bstr)
return false;
1311PyObject* CPyCppyy::CString32Converter::FromMemory(
void* address)
1314 if (address && *(
char32_t**)address) {
1316 return PyUnicode_DecodeUTF32(*(
const char**)address,
fMaxSize,
nullptr,
nullptr);
1318 return PyUnicode_DecodeUTF32(*(
const char**)address,
1319 std::char_traits<char32_t>::length(*(
char32_t**)address)*
sizeof(
char32_t),
nullptr,
nullptr);
1324 return PyUnicode_DecodeUTF32((
const char*)&
w, 0,
nullptr,
nullptr);
1336 PyErr_Warn(PyExc_RuntimeWarning, (
char*)
"string too long for char32_t array (truncated)");
1341 if (!bstr)
return false;
1345 *((
char32_t**)address)[
len] = U
'\0';
1351bool CPyCppyy::NonConstCStringConverter::SetArg(
1355 if (this->CStringConverter::SetArg(pyobject, para, ctxt))
1360 return CArraySetArg(pyobject, para,
'c',
sizeof(
char));
1364PyObject* CPyCppyy::NonConstCStringConverter::FromMemory(
void* address)
1369 return this->CStringConverter::FromMemory(address);
1382 if (PyInt_CheckExact(pyobject) || PyLong_CheckExact(pyobject)) {
1383 intptr_t val = (intptr_t)PyLong_AsLongLong(pyobject);
1385 address = (
void*)val;
1419 if (GetAddressSpecialCase(pyobject, para.
fValue.
fVoidp)) {
1428 para.
fValue.
fVoidp = (
void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;
1435 void** payload = (
void**)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;
1460 if (!address || *(ptrdiff_t*)address == 0) {
1483 void* ptr =
nullptr;
1484 if (GetAddressSpecialCase(
value, ptr)) {
1485 *(
void**)address = ptr;
1490 void* buf =
nullptr;
1492 if (!buf || buflen == 0)
1495 *(
void**)address = buf;
1503 int nalloc = (dims && 0 < dims[0]) ? (
int)dims[0]+1: defdim+1;
1506 for (
int i = 0; i < nalloc; ++i)
1510 for (
int i = 1; i < nalloc; ++i) shape[i] =
UNKNOWN_SIZE;
1515#define CPPYY_IMPL_ARRAY_CONVERTER(name, ctype, type, code) \
1516CPyCppyy::name##ArrayConverter::name##ArrayConverter(dims_t dims, bool init) {\
1518 init_shape(1, dims, fShape); \
1519 fIsFixed = fShape[1] != UNKNOWN_SIZE; \
1520 } else fIsFixed = false; \
1523bool CPyCppyy::name##ArrayConverter::SetArg( \
1524 PyObject* pyobject, Parameter& para, CallContext* ctxt) \
1528 PyTypeObject* ctypes_type = GetCTypesType(ct_##ctype); \
1529 if (Py_TYPE(pyobject) == ctypes_type) { \
1530 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
1531 para.fTypeCode = 'p'; \
1533 } else if (Py_TYPE(pyobject) == GetCTypesPtrType(ct_##ctype)) { \
1534 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
1535 para.fTypeCode = 'V'; \
1537 } else if (IsPyCArgObject(pyobject)) { \
1538 CPyCppyy_tagPyCArgObject* carg = (CPyCppyy_tagPyCArgObject*)pyobject;\
1539 if (carg->obj && Py_TYPE(carg->obj) == ctypes_type) { \
1540 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)carg->obj)->b_ptr;\
1541 para.fTypeCode = 'p'; \
1545 if (!res) res = CArraySetArg(pyobject, para, code, sizeof(type)); \
1546 if (res) SetLifeLine(ctxt->fPyContext, pyobject, (intptr_t)this); \
1550PyObject* CPyCppyy::name##ArrayConverter::FromMemory(void* address) \
1553 return CreateLowLevelView((type**)address, fShape); \
1554 return CreateLowLevelView(*(type**)address, fShape); \
1557bool CPyCppyy::name##ArrayConverter::ToMemory( \
1558 PyObject* value, void* address, PyObject* ctxt) \
1560 if (fShape[0] != 1) { \
1561 PyErr_SetString(PyExc_ValueError, "only 1-dim arrays supported"); \
1564 void* buf = nullptr; \
1565 Py_ssize_t buflen = Utility::GetBuffer(value, code, sizeof(type), buf); \
1569 if (fShape[1] < buflen) { \
1570 PyErr_SetString(PyExc_ValueError, "buffer too large for value"); \
1573 memcpy(*(type**)address, buf, (0 < buflen ? buflen : 1)*sizeof(type));\
1575 *(type**)address = (type*)buf; \
1576 fShape[1] = buflen; \
1578 SetLifeLine(ctxt, value, (intptr_t)address); \
1582bool CPyCppyy::name##ArrayPtrConverter::SetArg( \
1583 PyObject* pyobject, Parameter& para, CallContext* ctxt ) \
1585 if (Py_TYPE(pyobject) == GetCTypesPtrType(ct_##ctype)) { \
1586 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
1587 para.fTypeCode = 'p'; \
1589 } else if (Py_TYPE(pyobject) == GetCTypesType(ct_c_void_p)) { \
1591 para.fValue.fVoidp = (void*)((CPyCppyy_tagCDataObject*)pyobject)->b_ptr;\
1592 para.fTypeCode = 'p'; \
1595 bool res = name##ArrayConverter::SetArg(pyobject, para, ctxt); \
1596 if (res && para.fTypeCode == 'p') { \
1597 para.fRef = para.fValue.fVoidp; \
1598 para.fValue.fVoidp = ¶.fRef; \
1609#if __cplusplus > 201402L
1649#define CPPYY_IMPL_STRING_AS_PRIMITIVE_CONVERTER(name, type, F1, F2) \
1650CPyCppyy::name##Converter::name##Converter(bool keepControl) : \
1651 InstanceConverter(Cppyy::GetScope(#type), keepControl) {} \
1653bool CPyCppyy::name##Converter::SetArg( \
1654 PyObject* pyobject, Parameter& para, CallContext* ctxt) \
1657 const char* cstr = CPyCppyy_PyText_AsStringAndSize(pyobject, &len); \
1659 fBuffer = type(cstr, len); \
1660 para.fValue.fVoidp = &fBuffer; \
1661 para.fTypeCode = 'V'; \
1666 if (!(PyInt_Check(pyobject) || PyLong_Check(pyobject))) { \
1667 bool result = InstanceConverter::SetArg(pyobject, para, ctxt); \
1668 para.fTypeCode = 'V'; \
1674PyObject* CPyCppyy::name##Converter::FromMemory(void* address) \
1677 return CPyCppyy_PyText_FromStringAndSize(((type*)address)->F1(), ((type*)address)->F2()); \
1678 Py_INCREF(PyStrings::gEmptyString); \
1679 return PyStrings::gEmptyString; \
1682bool CPyCppyy::name##Converter::ToMemory(PyObject* value, void* address, \
1685 if (CPyCppyy_PyText_Check(value)) { \
1686 *((type*)address) = CPyCppyy_PyText_AsString(value); \
1690 return InstanceConverter::ToMemory(value, address, ctxt); \
1696bool CPyCppyy::STLStringViewConverter::SetArg(
1699 if (this->STLStringViewBaseConverter::SetArg(pyobject, para, ctxt))
1712 fBuffer = *((std::string*)ptr);
1721CPyCppyy::STLWStringConverter::STLWStringConverter(
bool keepControl) :
1722 InstanceConverter(
Cppyy::
GetScope(
"std::wstring"), keepControl) {}
1724bool CPyCppyy::STLWStringConverter::SetArg(
1727 if (PyUnicode_Check(pyobject)) {
1736 if (!(PyInt_Check(pyobject) || PyLong_Check(pyobject))) {
1745PyObject* CPyCppyy::STLWStringConverter::FromMemory(
void* address)
1748 return PyUnicode_FromWideChar(((std::wstring*)address)->c_str(), ((std::wstring*)address)->
size());
1750 return PyUnicode_FromWideChar(&
w, 0);
1755 if (PyUnicode_Check(
value)) {
1757 wchar_t* buf =
new wchar_t[
len+1];
1759 *((std::wstring*)address) = std::wstring(buf,
len);
1763 return InstanceConverter::ToMemory(
value, address, ctxt);
1767bool CPyCppyy::STLStringMoveConverter::SetArg(
1771 int moveit_reason = 3;
1783 if (moveit_reason) {
1784 bool result = this->STLStringConverter::SetArg(pyobject, para, ctxt);
1785 if (!
result && moveit_reason == 2)
1790 PyErr_SetString(PyExc_ValueError,
"object is not an rvalue");
1850 void* ptr =
nullptr;
1851 if (GetAddressSpecialCase(
value, ptr)) {
1852 *(
void**)address = ptr;
1875bool CPyCppyy::InstanceConverter::SetArg(
1901PyObject* CPyCppyy::InstanceConverter::FromMemory(
void* address)
1923bool CPyCppyy::InstanceRefConverter::SetArg(
1954PyObject* CPyCppyy::InstanceRefConverter::FromMemory(
void* address)
1960bool CPyCppyy::InstanceMoveConverter::SetArg(
1971 int moveit_reason = 0;
1979 if (moveit_reason) {
1980 bool result = this->InstanceRefConverter::SetArg(pyobject, para, ctxt);
1981 if (!
result && moveit_reason == 2)
1986 PyErr_SetString(PyExc_ValueError,
"object is not an rvalue");
1991template <
bool ISREFERENCE>
1992bool CPyCppyy::InstancePtrPtrConverter<ISREFERENCE>::SetArg(
2010 para.
fTypeCode = ISREFERENCE ?
'V' :
'p';
2018template <
bool ISREFERENCE>
2019PyObject* CPyCppyy::InstancePtrPtrConverter<ISREFERENCE>::FromMemory(
void* address)
2026template <
bool ISREFERENCE>
2027bool CPyCppyy::InstancePtrPtrConverter<ISREFERENCE>::ToMemory(
PyObject*
value,
void* address,
PyObject* )
2053 template class CPyCppyy::InstancePtrPtrConverter<true>;
2054 template class CPyCppyy::InstancePtrPtrConverter<false>;
2058bool CPyCppyy::InstanceArrayConverter::SetArg(
2067 if (PyTuple_Size(pyobject) < 1)
2085PyObject* CPyCppyy::InstanceArrayConverter::FromMemory(
void* address)
2092bool CPyCppyy::InstanceArrayConverter::ToMemory(
PyObject* ,
void* ,
PyObject* )
2097 PyErr_SetString(PyExc_NotImplementedError,
2098 "access to C-arrays of objects not yet implemented!");
2105bool CPyCppyy::STLIteratorConverter::SetArg(
2120bool CPyCppyy::VoidPtrRefConverter::SetArg(
2135bool CPyCppyy::VoidPtrPtrConverter::SetArg(
2168PyObject* CPyCppyy::VoidPtrPtrConverter::FromMemory(
void* address)
2171 if (!address || *(ptrdiff_t*)address == 0) {
2179bool CPyCppyy::PyObjectConverter::SetArg(
2188PyObject* CPyCppyy::PyObjectConverter::FromMemory(
void* address)
2197 Py_INCREF(pyobject);
2205 Py_XDECREF(*((
PyObject**)address));
2225 void* wpraddress = ipos->second.first;
2227 sWrapperFree[ipos->second.second].push_back(wpraddress);
2233 const_cast<char*
>(
"interal_WrapperCacheEraser"),
2239 const std::string& rettype,
const std::string& signature)
2258 void* fptr = (
void*)
m->GetFunctionAddress();
2259 if (fptr)
return fptr;
2275 if (fptr)
return fptr;
2280 if (PyCallable_Check(pyobject)) {
2282 void* wpraddress =
nullptr;
2285 auto key = std::make_pair(rettype, signature);
2288 const auto& existing = lookup->second.find(pyobject);
2289 if (existing != lookup->second.end() && *
sWrapperReference[existing->second] == pyobject)
2290 wpraddress = existing->second;
2296 if (freewrap !=
sWrapperFree.end() && !freewrap->second.empty()) {
2297 wpraddress = freewrap->second.back();
2298 freewrap->second.pop_back();
2300 PyObject* wref = PyWeakref_NewRef(pyobject, sWrapperCacheEraser);
2313 int nArgs = (
int)argtypes.size();
2316 std::ostringstream wname;
2320 std::ostringstream code;
2321 code <<
"namespace __cppyy_internal {\n "
2322 << rettype <<
" " << wname.str() <<
"(";
2323 for (
int i = 0; i < nArgs; ++i) {
2324 code << argtypes[i] <<
" arg" << i;
2325 if (i != nArgs-1) code <<
", ";
2336 code <<
" PyObject** ref = (PyObject**)" << (intptr_t)ref <<
";\n"
2337 " PyObject* pyresult = nullptr;\n"
2338 " if (*ref) pyresult = PyObject_CallFunctionObjArgs(*ref";
2339 for (
int i = 0; i < nArgs; ++i)
2340 code <<
", pyargs[" << i <<
"]";
2341 code <<
", NULL);\n"
2342 " else PyErr_SetString(PyExc_TypeError, \"callable was deleted\");\n";
2362 PyObject* wref = PyWeakref_NewRef(pyobject, sWrapperCacheEraser);
2374bool CPyCppyy::FunctionPointerConverter::SetArg(
2395PyObject* CPyCppyy::FunctionPointerConverter::FromMemory(
void* address)
2402 PyErr_SetString(PyExc_TypeError,
"can not convert null function pointer");
2406bool CPyCppyy::FunctionPointerConverter::ToMemory(
PyObject* pyobject,
void* address,
PyObject* )
2410 *((
void**)address) =
nullptr;
2417 *((
void**)address) = fptr;
2426bool CPyCppyy::StdFunctionConverter::SetArg(
2440 if (this->FunctionPointerConverter::SetArg(pyobject, para, ctxt)) {
2456PyObject* CPyCppyy::StdFunctionConverter::FromMemory(
void* address)
2468bool CPyCppyy::SmartPtrConverter::SetArg(
2471 char typeCode =
fIsRef ?
'p' :
'V';
2530PyObject* CPyCppyy::SmartPtrConverter::FromMemory(
void* address)
2543#if defined (_LIBCPP_INITIALIZER_LIST) || defined(__GNUC__)
2546 typedef size_t size_type;
2547 typedef void* iterator;
2551#elif defined (_MSC_VER)
2554 typedef char* iterator;
2559#define NO_KNOWN_INITIALIZER_LIST 1
2564CPyCppyy::InitializerListConverter::~InitializerListConverter()
2569bool CPyCppyy::InitializerListConverter::SetArg(
2572#ifdef NO_KNOWN_INITIALIZER_LIST
2579#
if PY_VERSION_HEX >= 0x03000000
2587 faux_initlist* fake =
nullptr;
2588 if (buf && buflen) {
2590 fake = (faux_initlist*)
malloc(
sizeof(faux_initlist));
2591 fake->_M_array = (faux_initlist::iterator)buf;
2592#if defined (_LIBCPP_INITIALIZER_LIST) || defined(__GNUC__)
2593 fake->_M_len = (faux_initlist::size_type)buflen;
2594#elif defined (_MSC_VER)
2595 fake->_Last = fake->_M_array+buflen*
fValueSize;
2599 size_t len = (size_t)PySequence_Size(pyobject);
2601 fake->_M_array = (faux_initlist::iterator)((
char*)fake+
sizeof(faux_initlist));
2602#if defined (_LIBCPP_INITIALIZER_LIST) || defined(__GNUC__)
2603 fake->_M_len = (faux_initlist::size_type)
len;
2604 for (faux_initlist::size_type i = 0; i < fake->_M_len; ++i) {
2605#elif defined (_MSC_VER)
2607 for (
size_t i = 0; (fake->_M_array+i*
fValueSize) != fake->_Last; ++i) {
2609 PyObject* item = PySequence_GetItem(pyobject, i);
2610 bool convert_ok =
false;
2624 PyErr_Format(PyExc_TypeError,
"failed to get item %d from sequence", (
int)i);
2643 PyErr_SetString(PyExc_NotImplementedError,
"this method cannot (yet) be called");
2655 if (cpd ==
"**" || cpd ==
"*[]" || cpd ==
"&*")
2656 result =
new InstancePtrPtrConverter<false>(klass, control);
2657 else if (cpd ==
"*&")
2658 result =
new InstancePtrPtrConverter<true>(klass, control);
2659 else if (cpd ==
"*" &&
size <= 0)
2661 else if (cpd ==
"&")
2662 result =
new InstanceRefConverter(klass, isConst);
2663 else if (cpd ==
"&&")
2664 result =
new InstanceMoveConverter(klass);
2665 else if (cpd ==
"[]" ||
size > 0)
2666 result =
new InstanceArrayConverter(klass, dims,
false);
2668 result =
new InstanceConverter(klass,
true);
2686 dim_t size = (dims && dims[0] != -1) ? dims[1] : -1;
2691 return (
h->second)(dims);
2697 if (resolvedType != fullType) {
2700 return (
h->second)(dims);
2704 bool isConst = strncmp(resolvedType.c_str(),
"const", 5) == 0;
2711 return (
h->second)(dims);
2719 return (
h->second)(dims);
2728 return (
h->second)(dims);
2730 }
else if (cpd ==
"*[]") {
2736 dim_t newdim = (dims && 0 < dims[0]) ? dims[0]+1 : 2;
2738 newdims[0] = newdim;
2741 if (dims && 2 < newdim) {
2742 for (
int i = 2; i < (newdim-1); ++i)
2743 newdims[i+1] = dims[i];
2752 if (realType.compare(0, 16,
"initializer_list") == 0) {
2754 auto pos = realType.find(
'<');
2755 std::string value_type = realType.substr(pos+1, realType.size()-pos-2);
2756 Converter* cnv =
nullptr;
bool use_byte_cnv =
false;
2762 use_byte_cnv =
true;
2765 if (cnv || use_byte_cnv)
2766 return new InitializerListConverter(cnv,
Cppyy::SizeOf(value_type));
2770 bool control = cpd ==
"&" || isConst;
2773 auto pos = resolvedType.find(
"function<");
2774 if (pos == 0 || pos == 5 ||
2775 pos == 6 || pos == 11 ) {
2783 auto pos1 = resolvedType.find(
"(", pos+9);
2784 auto pos2 = resolvedType.rfind(
")");
2785 if (pos1 != std::string::npos && pos2 != std::string::npos) {
2786 auto sz1 = pos1-pos-9;
2787 if (resolvedType[pos+9+sz1-1] ==
' ') sz1 -= 1;
2789 return new StdFunctionConverter(cnv,
2790 resolvedType.substr(pos+9, sz1), resolvedType.substr(pos1, pos2-pos1+1));
2802 result =
new SmartPtrConverter(klass, raw, control);
2803 }
else if (cpd ==
"&") {
2804 result =
new SmartPtrConverter(klass, raw);
2805 }
else if (cpd ==
"*" &&
size <= 0) {
2806 result =
new SmartPtrConverter(klass, raw, control,
true);
2812 if (realType.rfind(
"__gnu_cxx::__normal_iterator", 0) == 0
2814 || realType.rfind(
"__wrap_iter", 0) == 0
2818 static STLIteratorConverter
c;
2824 }
else if (resolvedType.find(
"(*)") != std::string::npos ||
2825 (resolvedType.find(
"::*)") != std::string::npos)) {
2828 auto pos1 = resolvedType.find(
'(');
2829 auto pos2 = resolvedType.find(
"*)");
2830 auto pos3 = resolvedType.rfind(
')');
2831 result =
new FunctionPointerConverter(
2832 resolvedType.substr(0, pos1), resolvedType.substr(pos2+2, pos3-pos2-1));
2835 if (!
result && cpd ==
"&&") {
2839 return (
h->second)(dims);
2841 result =
new NotImplementedConverter();
2849 if (cpd.size() == 2 && cpd !=
"&&")
2851 else if (!cpd.empty())
2854 result =
new NotImplementedConverter();
2864 if (
p &&
p->HasState())
2900#define STRINGVIEW "basic_string_view<char,char_traits<char> >"
2901#define WSTRING "basic_string<wchar_t,char_traits<wchar_t>,allocator<wchar_t> >"
2903static struct InitConvFactories_t {
2905 InitConvFactories_t() {
2910 gf[
"bool"] = (
cf_t)+[](
dims_t) {
static BoolConverter
c{};
return &
c; };
2911 gf[
"const bool&"] = (
cf_t)+[](
dims_t) {
static ConstBoolRefConverter
c{};
return &
c; };
2912 gf[
"bool&"] = (
cf_t)+[](
dims_t) {
static BoolRefConverter
c{};
return &
c; };
2913 gf[
"char"] = (
cf_t)+[](
dims_t) {
static CharConverter
c{};
return &
c; };
2914 gf[
"const char&"] = (
cf_t)+[](
dims_t) {
static ConstCharRefConverter
c{};
return &
c; };
2915 gf[
"char&"] = (
cf_t)+[](
dims_t) {
static CharRefConverter
c{};
return &
c; };
2916 gf[
"signed char&"] = (
cf_t)+[](
dims_t) {
static SCharRefConverter
c{};
return &
c; };
2917 gf[
"unsigned char"] = (
cf_t)+[](
dims_t) {
static UCharConverter
c{};
return &
c; };
2918 gf[
"const unsigned char&"] = (
cf_t)+[](
dims_t) {
static ConstUCharRefConverter
c{};
return &
c; };
2919 gf[
"unsigned char&"] = (
cf_t)+[](
dims_t) {
static UCharRefConverter
c{};
return &
c; };
2920 gf[
"UCharAsInt"] = (
cf_t)+[](
dims_t) {
static UCharAsIntConverter
c{};
return &
c; };
2921 gf[
"wchar_t"] = (
cf_t)+[](
dims_t) {
static WCharConverter
c{};
return &
c; };
2922 gf[
"char16_t"] = (
cf_t)+[](
dims_t) {
static Char16Converter
c{};
return &
c; };
2923 gf[
"char32_t"] = (
cf_t)+[](
dims_t) {
static Char32Converter
c{};
return &
c; };
2924 gf[
"wchar_t&"] = (
cf_t)+[](
dims_t) {
static WCharRefConverter
c{};
return &
c; };
2925 gf[
"char16_t&"] = (
cf_t)+[](
dims_t) {
static Char16RefConverter
c{};
return &
c; };
2926 gf[
"char32_t&"] = (
cf_t)+[](
dims_t) {
static Char32RefConverter
c{};
return &
c; };
2927 gf[
"int8_t"] = (
cf_t)+[](
dims_t) {
static Int8Converter
c{};
return &
c; };
2928 gf[
"int8_t&"] = (
cf_t)+[](
dims_t) {
static Int8RefConverter
c{};
return &
c; };
2929 gf[
"const int8_t&"] = (
cf_t)+[](
dims_t) {
static ConstInt8RefConverter
c{};
return &
c; };
2930 gf[
"uint8_t"] = (
cf_t)+[](
dims_t) {
static UInt8Converter
c{};
return &
c; };
2931 gf[
"const uint8_t&"] = (
cf_t)+[](
dims_t) {
static ConstUInt8RefConverter
c{};
return &
c; };
2932 gf[
"uint8_t&"] = (
cf_t)+[](
dims_t) {
static UInt8RefConverter
c{};
return &
c; };
2933 gf[
"short"] = (
cf_t)+[](
dims_t) {
static ShortConverter
c{};
return &
c; };
2934 gf[
"const short&"] = (
cf_t)+[](
dims_t) {
static ConstShortRefConverter
c{};
return &
c; };
2935 gf[
"short&"] = (
cf_t)+[](
dims_t) {
static ShortRefConverter
c{};
return &
c; };
2936 gf[
"unsigned short"] = (
cf_t)+[](
dims_t) {
static UShortConverter
c{};
return &
c; };
2937 gf[
"const unsigned short&"] = (
cf_t)+[](
dims_t) {
static ConstUShortRefConverter
c{};
return &
c; };
2938 gf[
"unsigned short&"] = (
cf_t)+[](
dims_t) {
static UShortRefConverter
c{};
return &
c; };
2939 gf[
"int"] = (
cf_t)+[](
dims_t) {
static IntConverter
c{};
return &
c; };
2940 gf[
"int&"] = (
cf_t)+[](
dims_t) {
static IntRefConverter
c{};
return &
c; };
2941 gf[
"const int&"] = (
cf_t)+[](
dims_t) {
static ConstIntRefConverter
c{};
return &
c; };
2942 gf[
"unsigned int"] = (
cf_t)+[](
dims_t) {
static UIntConverter
c{};
return &
c; };
2943 gf[
"const unsigned int&"] = (
cf_t)+[](
dims_t) {
static ConstUIntRefConverter
c{};
return &
c; };
2944 gf[
"unsigned int&"] = (
cf_t)+[](
dims_t) {
static UIntRefConverter
c{};
return &
c; };
2945 gf[
"long"] = (
cf_t)+[](
dims_t) {
static LongConverter
c{};
return &
c; };
2946 gf[
"long&"] = (
cf_t)+[](
dims_t) {
static LongRefConverter
c{};
return &
c; };
2947 gf[
"const long&"] = (
cf_t)+[](
dims_t) {
static ConstLongRefConverter
c{};
return &
c; };
2948 gf[
"unsigned long"] = (
cf_t)+[](
dims_t) {
static ULongConverter
c{};
return &
c; };
2949 gf[
"const unsigned long&"] = (
cf_t)+[](
dims_t) {
static ConstULongRefConverter
c{};
return &
c; };
2950 gf[
"unsigned long&"] = (
cf_t)+[](
dims_t) {
static ULongRefConverter
c{};
return &
c; };
2951 gf[
"long long"] = (
cf_t)+[](
dims_t) {
static LLongConverter
c{};
return &
c; };
2952 gf[
"const long long&"] = (
cf_t)+[](
dims_t) {
static ConstLLongRefConverter
c{};
return &
c; };
2953 gf[
"long long&"] = (
cf_t)+[](
dims_t) {
static LLongRefConverter
c{};
return &
c; };
2954 gf[
"unsigned long long"] = (
cf_t)+[](
dims_t) {
static ULLongConverter
c{};
return &
c; };
2955 gf[
"const unsigned long long&"] = (
cf_t)+[](
dims_t) {
static ConstULLongRefConverter
c{};
return &
c; };
2956 gf[
"unsigned long long&"] = (
cf_t)+[](
dims_t) {
static ULLongRefConverter
c{};
return &
c; };
2958 gf[
"float"] = (
cf_t)+[](
dims_t) {
static FloatConverter
c{};
return &
c; };
2959 gf[
"const float&"] = (
cf_t)+[](
dims_t) {
static ConstFloatRefConverter
c{};
return &
c; };
2960 gf[
"float&"] = (
cf_t)+[](
dims_t) {
static FloatRefConverter
c{};
return &
c; };
2961 gf[
"double"] = (
cf_t)+[](
dims_t) {
static DoubleConverter
c{};
return &
c; };
2962 gf[
"double&"] = (
cf_t)+[](
dims_t) {
static DoubleRefConverter
c{};
return &
c; };
2963 gf[
"const double&"] = (
cf_t)+[](
dims_t) {
static ConstDoubleRefConverter
c{};
return &
c; };
2964 gf[
"long double"] = (
cf_t)+[](
dims_t) {
static LDoubleConverter
c{};
return &
c; };
2965 gf[
"const long double&"] = (
cf_t)+[](
dims_t) {
static ConstLDoubleRefConverter
c{};
return &
c; };
2966 gf[
"long double&"] = (
cf_t)+[](
dims_t) {
static LDoubleRefConverter
c{};
return &
c; };
2967 gf[
"std::complex<double>"] = (
cf_t)+[](
dims_t) {
return new ComplexDConverter{}; };
2968 gf[
"complex<double>"] = (
cf_t)+[](
dims_t) {
return new ComplexDConverter{}; };
2969 gf[
"const std::complex<double>&"] = (
cf_t)+[](
dims_t) {
return new ComplexDConverter{}; };
2970 gf[
"const complex<double>&"] = (
cf_t)+[](
dims_t) {
return new ComplexDConverter{}; };
2971 gf[
"void"] = (
cf_t)+[](
dims_t) {
static VoidConverter
c{};
return &
c; };
2974 gf[
"bool*"] = (
cf_t)+[](
dims_t d) {
return new BoolArrayConverter{
d}; };
2975 gf[
"bool**"] = (
cf_t)+[](
dims_t d) {
return new BoolArrayPtrConverter{
d}; };
2976 gf[
"const signed char[]"] = (
cf_t)+[](
dims_t d) {
return new SCharArrayConverter{
d}; };
2977 gf[
"signed char[]"] = (
cf_t)+[](
dims_t d) {
return new SCharArrayConverter{
d}; };
2978 gf[
"signed char**"] = (
cf_t)+[](
dims_t d) {
return new SCharArrayPtrConverter{
d}; };
2979 gf[
"const unsigned char*"] = (
cf_t)+[](
dims_t d) {
return new UCharArrayConverter{
d}; };
2980 gf[
"unsigned char*"] = (
cf_t)+[](
dims_t d) {
return new UCharArrayConverter{
d}; };
2981 gf[
"UCharAsInt*"] = (
cf_t)+[](
dims_t d) {
return new UCharArrayConverter{
d}; };
2982 gf[
"unsigned char**"] = (
cf_t)+[](
dims_t d) {
return new UCharArrayPtrConverter{
d}; };
2983#if __cplusplus > 201402L
2984 gf[
"byte*"] = (
cf_t)+[](
dims_t d) {
return new ByteArrayConverter{
d}; };
2985 gf[
"byte**"] = (
cf_t)+[](
dims_t d) {
return new ByteArrayPtrConverter{
d}; };
2987 gf[
"short*"] = (
cf_t)+[](
dims_t d) {
return new ShortArrayConverter{
d}; };
2988 gf[
"short**"] = (
cf_t)+[](
dims_t d) {
return new ShortArrayPtrConverter{
d}; };
2989 gf[
"unsigned short*"] = (
cf_t)+[](
dims_t d) {
return new UShortArrayConverter{
d}; };
2990 gf[
"unsigned short**"] = (
cf_t)+[](
dims_t d) {
return new UShortArrayPtrConverter{
d}; };
2991 gf[
"int*"] = (
cf_t)+[](
dims_t d) {
return new IntArrayConverter{
d}; };
2992 gf[
"int**"] = (
cf_t)+[](
dims_t d) {
return new IntArrayPtrConverter{
d}; };
2993 gf[
"unsigned int*"] = (
cf_t)+[](
dims_t d) {
return new UIntArrayConverter{
d}; };
2994 gf[
"unsigned int**"] = (
cf_t)+[](
dims_t d) {
return new UIntArrayPtrConverter{
d}; };
2995 gf[
"long*"] = (
cf_t)+[](
dims_t d) {
return new LongArrayConverter{
d}; };
2996 gf[
"long**"] = (
cf_t)+[](
dims_t d) {
return new LongArrayPtrConverter{
d}; };
2997 gf[
"unsigned long*"] = (
cf_t)+[](
dims_t d) {
return new ULongArrayConverter{
d}; };
2998 gf[
"unsigned long**"] = (
cf_t)+[](
dims_t d) {
return new ULongArrayPtrConverter{
d}; };
2999 gf[
"long long*"] = (
cf_t)+[](
dims_t d) {
return new LLongArrayConverter{
d}; };
3000 gf[
"long long**"] = (
cf_t)+[](
dims_t d) {
return new LLongArrayPtrConverter{
d}; };
3001 gf[
"unsigned long long*"] = (
cf_t)+[](
dims_t d) {
return new ULLongArrayConverter{
d}; };
3002 gf[
"unsigned long long**"] = (
cf_t)+[](
dims_t d) {
return new ULLongArrayPtrConverter{
d}; };
3003 gf[
"float*"] = (
cf_t)+[](
dims_t d) {
return new FloatArrayConverter{
d}; };
3004 gf[
"float**"] = (
cf_t)+[](
dims_t d) {
return new FloatArrayPtrConverter{
d}; };
3005 gf[
"double*"] = (
cf_t)+[](
dims_t d) {
return new DoubleArrayConverter{
d}; };
3006 gf[
"double**"] = (
cf_t)+[](
dims_t d) {
return new DoubleArrayPtrConverter{
d}; };
3007 gf[
"long double*"] = (
cf_t)+[](
dims_t d) {
return new LDoubleArrayConverter{
d}; };
3008 gf[
"long double**"] = (
cf_t)+[](
dims_t d) {
return new LDoubleArrayPtrConverter{
d}; };
3009 gf[
"std::complex<double>*"] = (
cf_t)+[](
dims_t d) {
return new ComplexDArrayConverter{
d}; };
3010 gf[
"complex<double>*"] = (
cf_t)+[](
dims_t d) {
return new ComplexDArrayConverter{
d}; };
3011 gf[
"std::complex<double>**"] = (
cf_t)+[](
dims_t d) {
return new ComplexDArrayPtrConverter{
d}; };
3015 gf[
"signed char"] = gf[
"char"];
3016 gf[
"const signed char&"] = gf[
"const char&"];
3017#if __cplusplus > 201402L
3018 gf[
"byte"] = gf[
"uint8_t"];
3019 gf[
"const byte&"] = gf[
"const uint8_t&"];
3020 gf[
"byte&"] = gf[
"uint8&"];
3022 gf[
"internal_enum_type_t"] = gf[
"int"];
3023 gf[
"internal_enum_type_t&"] = gf[
"int&"];
3024 gf[
"const internal_enum_type_t&"] = gf[
"const int&"];
3025 gf[
"Long64_t"] = gf[
"long long"];
3026 gf[
"Long64_t*"] = gf[
"long long*"];
3027 gf[
"Long64_t&"] = gf[
"long long&"];
3028 gf[
"const Long64_t&"] = gf[
"const long long&"];
3029 gf[
"ULong64_t"] = gf[
"unsigned long long"];
3030 gf[
"ULong64_t*"] = gf[
"unsigned long long*"];
3031 gf[
"ULong64_t&"] = gf[
"unsigned long long&"];
3032 gf[
"const ULong64_t&"] = gf[
"const unsigned long long&"];
3033 gf[
"Float16_t"] = gf[
"float"];
3034 gf[
"const Float16_t&"] = gf[
"const float&"];
3035 gf[
"Double32_t"] = gf[
"double"];
3036 gf[
"Double32_t&"] = gf[
"double&"];
3037 gf[
"const Double32_t&"] = gf[
"const double&"];
3040 gf[
"TString"] = (
cf_t)+[](
dims_t) {
return new TStringConverter{}; };
3041 gf[
"TString&"] = gf[
"TString"];
3042 gf[
"const TString&"] = gf[
"TString"];
3043 gf[
"nullptr_t"] = (
cf_t)+[](
dims_t) {
static NullptrConverter
c{};
return &
c;};
3044 gf[
"const char*"] = (
cf_t)+[](
dims_t) {
return new CStringConverter{}; };
3045 gf[
"const signed char*"] = gf[
"const char*"];
3046 gf[
"const char[]"] = (
cf_t)+[](
dims_t) {
return new CStringConverter{}; };
3047 gf[
"char*"] = (
cf_t)+[](
dims_t) {
return new NonConstCStringConverter{}; };
3048 gf[
"signed char*"] = gf[
"char*"];
3049 gf[
"wchar_t*"] = (
cf_t)+[](
dims_t) {
return new WCStringConverter{}; };
3050 gf[
"char16_t*"] = (
cf_t)+[](
dims_t) {
return new CString16Converter{}; };
3051 gf[
"char32_t*"] = (
cf_t)+[](
dims_t) {
return new CString32Converter{}; };
3053 gf[
"char16_t**"] = gf[
"char16_t*"];
3054 gf[
"char32_t**"] = gf[
"char32_t*"];
3055 gf[
"const char**"] = (
cf_t)+[](
dims_t d) {
return new CStringArrayConverter{
d}; };
3056 gf[
"char**"] = gf[
"const char**"];
3057 gf[
"const char*[]"] = gf[
"const char**"];
3058 gf[
"char*[]"] = gf[
"const char*[]"];
3059 gf[
"std::string"] = (
cf_t)+[](
dims_t) {
return new STLStringConverter{}; };
3060 gf[
"string"] = gf[
"std::string"];
3061 gf[
"const std::string&"] = gf[
"std::string"];
3062 gf[
"const string&"] = gf[
"std::string"];
3063 gf[
"string&&"] = (
cf_t)+[](
dims_t) {
return new STLStringMoveConverter{}; };
3064 gf[
"std::string&&"] = gf[
"string&&"];
3065 gf[
"std::string_view"] = (
cf_t)+[](
dims_t) {
return new STLStringViewConverter{}; };
3066 gf[
"string_view"] = gf[
"std::string_view"];
3068 gf[
"experimental::" STRINGVIEW] = gf[
"std::string_view"];
3069 gf[
"std::string_view&"] = gf[
"std::string_view"];
3070 gf[
"const string_view&"] = gf[
"std::string_view"];
3071 gf[
"const " STRINGVIEW "&"] = gf[
"std::string_view"];
3072 gf[
"std::wstring"] = (
cf_t)+[](
dims_t) {
return new STLWStringConverter{}; };
3073 gf[
WSTRING] = gf[
"std::wstring"];
3074 gf[
"std::" WSTRING] = gf[
"std::wstring"];
3075 gf[
"const std::wstring&"] = gf[
"std::wstring"];
3076 gf[
"const std::" WSTRING "&"] = gf[
"std::wstring"];
3077 gf[
"const " WSTRING "&"] = gf[
"std::wstring"];
3078 gf[
"void*&"] = (
cf_t)+[](
dims_t) {
static VoidPtrRefConverter
c{};
return &
c; };
3079 gf[
"void**"] = (
cf_t)+[](
dims_t d) {
return new VoidPtrPtrConverter{size_t((
d &&
d[0] != -1) ?
d[1] : -1)}; };
3080 gf[
"void*[]"] = (
cf_t)+[](
dims_t d) {
return new VoidPtrPtrConverter{size_t((
d &&
d[0] != -1) ?
d[1] : -1)}; };
3081 gf[
"PyObject*"] = (
cf_t)+[](
dims_t) {
static PyObjectConverter
c{};
return &
c; };
3082 gf[
"_object*"] = gf[
"PyObject*"];
3085} 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)
static PyObject * PyObject_CallMethodNoArgs(PyObject *obj, PyObject *name)
#define CPyCppyy_PyText_FromString
#define CPyCppyy_PyText_Check
static unsigned short CPyCppyy_PyLong_AsUShort(PyObject *pyobject)
#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 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)
PyObject * FuncPtr2StdFunction(const std::string &retType, const std::string &signature, void *address)
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 bool IsSmartPtr(TCppType_t type)
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::@206 value
PyObject_HEAD void * pffi_type
unsigned long long fULLong