30 #define TParameter PyROOT::TParameter
45#if PY_VERSION_HEX >= 0x02050000
47struct PyROOT_tagCDataObject {
52static inline PyTypeObject* GetCTypesType(
const char*
name ) {
53 PyObject* ct = PyImport_ImportModule(
"ctypes" );
54 if ( ! ct )
return nullptr;
55 PyTypeObject* ct_t = (PyTypeObject*)PyObject_GetAttrString( ct,
name );
68 Long_t l = PyLong_AsLong( pyobject );
70 if ( ! (
l == 0 ||
l == 1 ) || PyFloat_Check( pyobject ) ) {
71 PyErr_SetString( PyExc_ValueError,
"boolean value should be bool, or integer 1 or 0" );
88 if ( ! (PyLong_Check( pyobject ) || PyInt_Check( pyobject )) ) {
89 PyErr_SetString( PyExc_TypeError,
"unsigned short conversion expects an integer object" );
92 Long_t l = PyLong_AsLong( pyobject );
93 if (
l < 0 || USHRT_MAX <
l ) {
94 PyErr_Format( PyExc_ValueError,
"integer %ld out of range for unsigned short",
l );
106 if ( ! (PyLong_Check( pyobject ) || PyInt_Check( pyobject )) ) {
107 PyErr_SetString( PyExc_TypeError,
"short int conversion expects an integer object" );
110 Long_t l = PyLong_AsLong( pyobject );
111 if (
l < SHRT_MIN || SHRT_MAX <
l ) {
112 PyErr_Format( PyExc_ValueError,
"integer %ld out of range for short int",
l );
127 if ( ! (PyLong_Check( pyobject ) || PyInt_Check( pyobject )) ) {
128 PyErr_SetString( PyExc_TypeError,
"int/long conversion expects an integer object" );
131 return (
Long_t)PyLong_AsLong( pyobject );
139 PyErr_SetString( PyExc_TypeError,
"C++ type can not be converted from memory" );
148 PyErr_SetString( PyExc_TypeError,
"C++ type can not be converted to memory" );
154#define PYROOT_IMPLEMENT_BASIC_CONVERTER( name, type, stype, F1, F2, tc ) \
155Bool_t PyROOT::T##name##Converter::SetArg( \
156 PyObject* pyobject, TParameter& para, TCallContext* ) \
159 type val = (type)F2( pyobject ); \
160 if ( val == (type)-1 && PyErr_Occurred() ) \
162 para.fValue.f##name = val; \
163 para.fTypeCode = tc; \
167PyObject* PyROOT::T##name##Converter::FromMemory( void* address ) \
169 return F1( (stype)*((type*)address) ); \
172Bool_t PyROOT::T##name##Converter::ToMemory( PyObject* value, void* address ) \
174 type s = (type)F2( value ); \
175 if ( s == (type)-1 && PyErr_Occurred() ) \
177 *((type*)address) = (type)s; \
189 PyErr_Format( PyExc_TypeError,
"%s expected, got string of size " PY_SSIZE_T_FORMAT,
191 }
else if ( ! PyFloat_Check( pyobject ) ) {
192 lchar = PyLong_AsLong( pyobject );
193 if ( lchar == -1 && PyErr_Occurred() )
195 else if ( ! ( low <= lchar && lchar <= high ) ) {
196 PyErr_Format( PyExc_ValueError,
197 "integer to character: value %d not in range [%d,%d]", lchar, low, high );
201 PyErr_SetString( PyExc_TypeError,
"char or small int type expected" );
207#define PYROOT_IMPLEMENT_BASIC_CONST_REF_CONVERTER( name, type, F1 )\
208Bool_t PyROOT::TConst##name##RefConverter::SetArg( \
209 PyObject* pyobject, TParameter& para, TCallContext* ) \
211 type val = (type)F1( pyobject ); \
212 if ( val == (type)-1 && PyErr_Occurred() ) \
214 para.fValue.f##name = val; \
215 para.fRef = ¶.fValue.f##name; \
216 para.fTypeCode = 'r'; \
220#define PYROOT_IMPLEMENT_BASIC_CONST_CHAR_REF_CONVERTER( name, type, low, high )\
221Bool_t PyROOT::TConst##name##RefConverter::SetArg( \
222 PyObject* pyobject, TParameter& para, TCallContext* ) \
225 type val = (type)ExtractChar( pyobject, #type, low, high ); \
226 if ( val == (type)-1 && PyErr_Occurred() ) \
228 para.fValue.fLong = val; \
229 para.fTypeCode = 'l'; \
236#define PYROOT_IMPLEMENT_BASIC_CHAR_CONVERTER( name, type, low, high ) \
237Bool_t PyROOT::T##name##Converter::SetArg( \
238 PyObject* pyobject, TParameter& para, TCallContext* ) \
241 Long_t val = ExtractChar( pyobject, #type, low, high ); \
242 if ( val == -1 && PyErr_Occurred() ) \
244 para.fValue.fLong = val; \
245 para.fTypeCode = 'l'; \
249PyObject* PyROOT::T##name##Converter::FromMemory( void* address ) \
251 return PyROOT_PyUnicode_FromFormat( "%c", *((type*)address) ); \
254Bool_t PyROOT::T##name##Converter::ToMemory( PyObject* value, void* address ) \
256 if ( PyROOT_PyUnicode_Check( value ) ) { \
257 const char* buf = PyROOT_PyUnicode_AsString( value ); \
258 if ( PyErr_Occurred() ) \
260 int len = PyROOT_PyUnicode_GET_SIZE( value ); \
262 PyErr_Format( PyExc_TypeError, #type" expected, got string of size %d", len );\
265 *((type*)address) = (type)buf[0]; \
267 Long_t l = PyLong_AsLong( value ); \
268 if ( l == -1 && PyErr_Occurred() ) \
270 if ( ! ( low <= l && l <= high ) ) { \
271 PyErr_Format( PyExc_ValueError, \
272 "integer to character: value %ld not in range [%d,%d]", l, low, high );\
275 *((type*)address) = (type)l; \
290#if PY_VERSION_HEX < 0x03000000
292 para.fValue.fVoidp = (
void*)&((PyIntObject*)pyobject)->ob_ival;
293 para.fTypeCode =
'V';
294 if (PyErr_WarnEx(PyExc_FutureWarning,
295 "ROOT.Long is deprecated and will disappear in a future version of ROOT. "
296 "Instead, use ctypes.c_long for pass-by-ref of longs", 1) < 0) {
303#if PY_VERSION_HEX < 0x02050000
304 PyErr_SetString( PyExc_TypeError,
"use ROOT.Long for pass-by-ref of longs" );
309 static PyTypeObject* c_long_type = GetCTypesType(
"c_long" );
310 if (
Py_TYPE( pyobject ) == c_long_type ) {
311 para.fValue.fVoidp = (
void*)((PyROOT_tagCDataObject*)pyobject)->b_ptr;
312 para.fTypeCode =
'V';
316 PyErr_SetString( PyExc_TypeError,
"use ctypes.c_long for pass-by-ref of longs" );
338Bool_t PyROOT::TIntRefConverter::SetArg(
341#if PY_VERSION_HEX < 0x03000000
343 para.
fValue.
fVoidp = (
void*)&((PyIntObject*)pyobject)->ob_ival;
345 if (PyErr_WarnEx(PyExc_FutureWarning,
346 "ROOT.Long is deprecated and will disappear in a future version of ROOT. "
347 "Instead, use ctypes.c_int for pass-by-ref of ints", 1) < 0) {
354#if PY_VERSION_HEX >= 0x02050000
356 static PyTypeObject* c_int_type = GetCTypesType(
"c_int" );
357 if (
Py_TYPE( pyobject ) == c_int_type ) {
358 para.
fValue.
fVoidp = (
void*)((PyROOT_tagCDataObject*)pyobject)->b_ptr;
371#if PY_VERSION_HEX < 0x02050000
372 PyErr_SetString( PyExc_TypeError,
"use ROOT.Long for pass-by-ref of ints" );
374 PyErr_SetString( PyExc_TypeError,
"use ctypes.c_int for pass-by-ref of ints" );
402 if ( PyErr_Occurred() )
404 para.fTypeCode =
'U';
408PyObject* PyROOT::TULongConverter::FromMemory(
void* address )
411 return PyLong_FromUnsignedLong( *((
ULong_t*)address) );
414Bool_t PyROOT::TULongConverter::ToMemory(
PyObject* value,
void* address )
418 if ( PyErr_Occurred() )
427PyObject* PyROOT::TUIntConverter::FromMemory(
void* address )
429 return PyLong_FromUnsignedLong( *((
UInt_t*)address) );
432Bool_t PyROOT::TUIntConverter::ToMemory(
PyObject* value,
void* address )
436 if ( PyErr_Occurred() )
440 PyErr_SetString( PyExc_OverflowError,
"value too large for unsigned int" );
463 para.fValue.fVoidp = (
void*)&((PyFloatObject*)pyobject)->ob_fval;
464 para.fTypeCode =
'V';
465 if (PyErr_WarnEx(PyExc_FutureWarning,
466 "ROOT.Double is deprecated and will disappear in a future version of ROOT. "
467 "Instead, use ctypes.c_double for pass-by-ref of doubles", 1) < 0) {
475 if ( para.fValue.fVoidp && buflen ) {
476 para.fTypeCode =
'V';
480 PyErr_SetString( PyExc_TypeError,
"use ctypes.c_double for pass-by-ref of doubles" );
495 PyErr_SetString( PyExc_SystemError,
"void/unknown arguments can\'t be set" );
502Bool_t PyROOT::TLongLongConverter::SetArg(
505 if ( PyFloat_Check( pyobject ) ) {
508 PyErr_SetString( PyExc_ValueError,
"can not convert float to long long" );
513 if ( PyErr_Occurred() )
519PyObject* PyROOT::TLongLongConverter::FromMemory(
void* address )
522 return PyLong_FromLongLong( *(
Long64_t*)address );
525Bool_t PyROOT::TLongLongConverter::ToMemory(
PyObject* value,
void* address )
528 Long64_t ll = PyLong_AsLongLong( value );
529 if ( ll == -1 && PyErr_Occurred() )
538Bool_t PyROOT::TULongLongConverter::SetArg(
542 if ( PyErr_Occurred() )
548PyObject* PyROOT::TULongLongConverter::FromMemory(
void* address )
554Bool_t PyROOT::TULongLongConverter::ToMemory(
PyObject* value,
void* address )
558 if ( PyErr_Occurred() )
568#if PY_VERSION_HEX >= 0x03030000
571 auto charArr = PyROOT_PyUnicode_AsStringAndSize(pyobject, &size);
576 return std::tuple<const char*,Py_ssize_t>(charArr, size);
583#
if PY_VERSION_HEX < 0x03000000
584 || PyUnicode_Check(pyobject)
588 fBuffer = std::string(std::get<0>(strAndSize), std::get<1>(strAndSize));
592 fBuffer = std::string(
s, size);
598 if ( fMaxSize < (
UInt_t)fBuffer.size() )
599 PyErr_Warn( PyExc_RuntimeWarning, (
char*)
"string too long for char array (truncated)" );
600 else if ( fMaxSize != UINT_MAX )
601 fBuffer.resize( fMaxSize,
'\0' );
612 if ( address && *(
char**)address ) {
613 if ( fMaxSize != UINT_MAX ) {
614 std::string buf( *(
char**)address, fMaxSize );
630 if ( PyErr_Occurred() )
635 PyErr_Warn( PyExc_RuntimeWarning, (
char*)
"string too long for char array (truncated)" );
637 if ( fMaxSize != UINT_MAX )
638 strncpy( *(
char**)address,
s, fMaxSize );
641 strcpy( *(
char**)address,
s );
652 inline Bool_t CArraySetArg(
681 return CArraySetArg( pyobject, para,
'c',
sizeof(
char) );
689 if ( fMaxSize != UINT_MAX )
705 return CArraySetArg( pyobject, para,
'B',
sizeof(
unsigned char) );
715 if (pyobject == Py_None) {
716 if (PyErr_WarnEx(PyExc_FutureWarning,
717 "The conversion from None to null pointer is deprecated "
718 "and will not be allowed anymore in a future version of ROOT. "
719 "Instead, use ROOT.nullptr or 0", 1) < 0) {
729 if ( PyInt_CheckExact( pyobject ) || PyLong_CheckExact( pyobject ) ) {
732 address = (
void*)val;
766 if ( GetAddressSpecialCase( pyobject, para.
fValue.
fVoidp ) ) {
789 if ( ! address || *(ptrdiff_t*)address == 0 ) {
807 *(
void**)address = ((
ObjectProxy*)value)->GetObject();
813 if ( GetAddressSpecialCase( value, ptr ) ) {
814 *(
void**)address = ptr;
821 if ( ! buf || buflen == 0 )
824 *(
void**)address = buf;
830#define PYROOT_IMPLEMENT_ARRAY_CONVERTER( name, type, code ) \
831Bool_t PyROOT::T##name##ArrayConverter::SetArg( \
832 PyObject* pyobject, TParameter& para, TCallContext* ) \
834 return CArraySetArg( pyobject, para, code, sizeof(type) ); \
837Bool_t PyROOT::T##name##ArrayRefConverter::SetArg( \
838 PyObject* pyobject, TParameter& para, TCallContext* ctxt ) \
840 Bool_t result = T##name##ArrayConverter::SetArg( pyobject, para, ctxt ); \
841 para.fTypeCode = 'V'; \
845PyObject* PyROOT::T##name##ArrayConverter::FromMemory( void* address ) \
847 return BufFac_t::Instance()->PyBuffer_FromMemory( *(type**)address, fSize * sizeof(type) );\
850Bool_t PyROOT::T##name##ArrayConverter::ToMemory( PyObject* value, void* address )\
853 int buflen = Utility::GetBuffer( value, code, sizeof(type), buf ); \
854 if ( ! buf || buflen == 0 ) \
856 if ( 0 <= fSize ) { \
857 if ( fSize < buflen/(int)sizeof(type) ) { \
858 PyErr_SetString( PyExc_ValueError, "buffer too large for value" ); \
861 memcpy( *(type**)address, buf, 0 < buflen ? ((size_t) buflen) : sizeof(type) );\
863 *(type**)address = (type*)buf; \
898#if PY_VERSION_HEX >= 0x03030000
901 auto charArr = PyROOT_PyUnicode_AsStringAndSize(pyobject, &size);
906 return std::tuple<const char*,Py_ssize_t>(charArr, size);
909#define PYROOT_IMPLEMENT_STRING_AS_PRIMITIVE_CONVERTER( name, type, F1, F2 ) \
910PyROOT::T##name##Converter::T##name##Converter( Bool_t keepControl ) : \
911 TCppObjectConverter( Cppyy::GetScope( #type ), keepControl ) {} \
913Bool_t PyROOT::T##name##Converter::SetArg( \
914 PyObject* pyobject, TParameter& para, TCallContext* ctxt ) \
916 if ( PyROOT_PyUnicode_Check( pyobject ) ) { \
917 auto strAndSize = getStringAndSizeSTLString(pyobject); \
918 fBuffer = type(std::get<0>(strAndSize), std::get<1>(strAndSize)); \
919 para.fValue.fVoidp = &fBuffer; \
920 para.fTypeCode = 'V'; \
924 if (PyBytes_Check(pyobject)) { \
925 auto s = PyBytes_AsString(pyobject); \
926 auto size = PyBytes_GET_SIZE(pyobject); \
927 fBuffer = type(s, size); \
928 para.fValue.fVoidp = &fBuffer; \
929 para.fTypeCode = 'V'; \
933 if ( ! ( PyInt_Check( pyobject ) || PyLong_Check( pyobject ) ) ) { \
934 Bool_t result = TCppObjectConverter::SetArg( pyobject, para, ctxt ); \
935 para.fTypeCode = 'V'; \
941PyObject* PyROOT::T##name##Converter::FromMemory( void* address ) \
944 return PyROOT_PyUnicode_FromStringAndSize( ((type*)address)->F1(), ((type*)address)->F2() );\
945 Py_INCREF( PyStrings::gEmptyString ); \
946 return PyStrings::gEmptyString; \
949Bool_t PyROOT::T##name##Converter::ToMemory( PyObject* value, void* address ) \
951 if ( PyROOT_PyUnicode_Check( value ) ) { \
952 *((type*)address) = PyROOT_PyUnicode_AsString( value ); \
956 return TCppObjectConverter::ToMemory( value, address ); \
970 if ( GetAddressSpecialCase( pyobject, para.fValue.fVoidp ) ) {
971 para.fTypeCode =
'p';
989 pyobj->
ObjectIsA(), fClass, para.fValue.fVoidp, 1 );
993 para.fTypeCode =
'p';
999 para.fTypeCode =
'p';
1021 if ( GetAddressSpecialCase( value, ptr ) ) {
1022 *(
void**)address = ptr;
1038 PyObject* result = PyObject_CallMethod( pyobj, (
char*)
"__assign__", (
char*)
"O", value );
1041 Py_DECREF( result );
1074 else if ( PyTuple_Check( pyobject ) ){
1080 if ( ! pyclass )
return kFALSE;
1081 fObjProxy = (
ObjectProxy*)((PyTypeObject*)pyclass)->tp_new( (PyTypeObject*)pyclass, NULL, NULL );
1082 Py_DECREF( pyclass );
1085 if( fObjProxy->GetObject() ) {
1089 fObjProxy->Set(
nullptr);
1094 if( ! constructor )
return kFALSE;
1097 PyObject* obj = PyObject_CallObject( constructor, pyobject );
1098 Py_DECREF( constructor );
1099 if ( ! obj )
return kFALSE;
1135 else if ( PyTuple_Check( pyobject ) ){
1141 if ( ! pyclass )
return kFALSE;
1142 fObjProxy = (
ObjectProxy*)((PyTypeObject*)pyclass)->tp_new( (PyTypeObject*)pyclass, NULL, NULL );
1143 Py_DECREF( pyclass );
1146 if( fObjProxy->GetObject() ) {
1150 fObjProxy->Set(
nullptr);
1155 if( ! constructor )
return kFALSE;
1158 PyObject* obj = PyObject_CallObject( constructor, pyobject );
1159 Py_DECREF( constructor );
1160 if ( ! obj )
return kFALSE;
1174template <
bool ISREFERENCE>
1192 para.
fTypeCode = ISREFERENCE ?
'V' :
'p';
1202template <
bool ISREFERENCE>
1211template <
bool ISREFERENCE>
1223 *(
void**)address = ((
ObjectProxy*)value)->GetObject();
1250 if ( PyTuple_Size( pyobject ) < 1 )
1284 PyErr_SetString( PyExc_NotImplementedError,
1285 "access to C-arrays of objects not yet implemented!" );
1351 if ( ! address || *(ptrdiff_t*)address == 0 ) {
1361Bool_t PyROOT::TPyObjectConverter::SetArg(
1369PyObject* PyROOT::TPyObjectConverter::FromMemory(
void* address )
1375 Py_INCREF( Py_None );
1379 Py_INCREF( pyobject );
1383Bool_t PyROOT::TPyObjectConverter::ToMemory(
PyObject* value,
void* address )
1398 char typeCode = fHandlePtr ?
'p' :
'V';
1401 if ( fHandlePtr && GetAddressSpecialCase( pyobject, para.
fValue.
fVoidp ) ) {
1448 if ( !address || !fClass )
1452 std::vector<TParameter> args;
1467 PyErr_SetString( PyExc_NotImplementedError,
"this method can not (yet) be called" );
1487 return (
h->second)( size );
1495 return (
h->second)( size );
1504 return (
h->second)( size );
1514 if ( cpd ==
"[]" ) {
1517 return (
h->second)( size );
1521 Bool_t isConst = resolvedType.substr(0, 5) ==
"const";
1522 Bool_t control = cpd ==
"&" || isConst;
1529 if ( ! methods.empty() ) {
1535 }
else if ( cpd ==
"&" ) {
1537 }
else if ( cpd ==
"*" && size <= 0 ) {
1549 if ( realType.find(
"__gnu_cxx::__normal_iterator", 0 ) == 0 )
1553 if ( cpd ==
"**" || cpd ==
"&*" )
1555 else if ( cpd ==
"*&" )
1557 else if ( cpd ==
"*" && size <= 0 )
1559 else if ( cpd ==
"&" )
1561 else if ( cpd ==
"[]" || size > 0 )
1563 else if ( cpd ==
"" )
1570 auto reft = et +
"&";
1574 }
else if ( realType.find(
"(*)" ) != std::string::npos ||
1575 ( realType.find(
"::*)" ) != std::string::npos ) ) {
1582 if ( ! result && cpd ==
"&&" )
1587 result = (
h->second)( size );
1588 else if ( ! result ) {
1590 std::stringstream
s;
1591 s <<
"creating converter for unknown type \"" << fullType <<
"\"" << std::ends;
1592 PyErr_Warn( PyExc_RuntimeWarning, (
char*)
s.str().c_str() );
1603#define PYROOT_BASIC_CONVERTER_FACTORY( name ) \
1604TConverter* Create##name##Converter( Long_t ) \
1606 return new T##name##Converter(); \
1609#define PYROOT_ARRAY_CONVERTER_FACTORY( name ) \
1610TConverter* Create##name##Converter( Long_t size ) \
1612 return new T##name##Converter( size ); \
1681 typedef std::pair< const char*, ConverterFactory_t > NFp_t;
1684 NFp_t factories_[] = {
1686 NFp_t(
"bool", &CreateBoolConverter ),
1687 NFp_t(
"const bool&", &CreateConstBoolRefConverter ),
1688 NFp_t(
"char", &CreateCharConverter ),
1689 NFp_t(
"const char&", &CreateConstCharRefConverter ),
1690 NFp_t(
"signed char", &CreateCharConverter ),
1691 NFp_t(
"const signed char&", &CreateConstCharRefConverter ),
1692 NFp_t(
"unsigned char", &CreateUCharConverter ),
1693 NFp_t(
"const unsigned char&", &CreateConstUCharRefConverter ),
1694 NFp_t(
"short", &CreateShortConverter ),
1695 NFp_t(
"const short&", &CreateConstShortRefConverter ),
1696 NFp_t(
"unsigned short", &CreateUShortConverter ),
1697 NFp_t(
"const unsigned short&", &CreateConstUShortRefConverter ),
1698 NFp_t(
"int", &CreateIntConverter ),
1699 NFp_t(
"int&", &CreateIntRefConverter ),
1700 NFp_t(
"const int&", &CreateConstIntRefConverter ),
1701 NFp_t(
"unsigned int", &CreateUIntConverter ),
1702 NFp_t(
"const unsigned int&", &CreateConstUIntRefConverter ),
1703 NFp_t(
"long", &CreateLongConverter ),
1704 NFp_t(
"long&", &CreateLongRefConverter ),
1705 NFp_t(
"const long&", &CreateConstLongRefConverter ),
1706 NFp_t(
"unsigned long", &CreateULongConverter ),
1707 NFp_t(
"const unsigned long&", &CreateConstULongRefConverter ),
1708 NFp_t(
"long long", &CreateLongLongConverter ),
1709 NFp_t(
"const long long&", &CreateConstLongLongRefConverter ),
1710 NFp_t(
"Long64_t", &CreateLongLongConverter ),
1711 NFp_t(
"const Long64_t&", &CreateConstLongLongRefConverter ),
1712 NFp_t(
"unsigned long long", &CreateULongLongConverter ),
1713 NFp_t(
"const unsigned long long&", &CreateConstULongLongRefConverter ),
1714 NFp_t(
"ULong64_t", &CreateULongLongConverter ),
1715 NFp_t(
"const ULong64_t&", &CreateConstULongLongRefConverter ),
1717 NFp_t(
"float", &CreateFloatConverter ),
1718 NFp_t(
"const float&", &CreateConstFloatRefConverter ),
1719 NFp_t(
"double", &CreateDoubleConverter ),
1720 NFp_t(
"double&", &CreateDoubleRefConverter ),
1721 NFp_t(
"const double&", &CreateConstDoubleRefConverter ),
1722 NFp_t(
"long double", &CreateLongDoubleConverter ),
1723 NFp_t(
"const long double&", &CreateConstLongDoubleRefConverter ),
1724 NFp_t(
"void", &CreateVoidConverter ),
1727 NFp_t(
"bool*", &CreateBoolArrayConverter ),
1728 NFp_t(
"bool&", &CreateBoolArrayRefConverter ),
1729 NFp_t(
"const unsigned char*", &CreateCStringConverter ),
1730 NFp_t(
"unsigned char*", &CreateNonConstUCStringConverter ),
1731 NFp_t(
"short*", &CreateShortArrayConverter ),
1732 NFp_t(
"short&", &CreateShortArrayRefConverter ),
1733 NFp_t(
"unsigned short*", &CreateUShortArrayConverter ),
1734 NFp_t(
"unsigned short&", &CreateUShortArrayRefConverter ),
1735 NFp_t(
"int*", &CreateIntArrayConverter ),
1736 NFp_t(
"unsigned int*", &CreateUIntArrayConverter ),
1737 NFp_t(
"unsigned int&", &CreateUIntArrayRefConverter ),
1738 NFp_t(
"long*", &CreateLongArrayConverter ),
1739 NFp_t(
"unsigned long*", &CreateULongArrayConverter ),
1740 NFp_t(
"unsigned long&", &CreateULongArrayRefConverter ),
1741 NFp_t(
"float*", &CreateFloatArrayConverter ),
1742 NFp_t(
"float&", &CreateFloatArrayRefConverter ),
1743 NFp_t(
"double*", &CreateDoubleArrayConverter ),
1744 NFp_t(
"long long*", &CreateLongLongArrayConverter ),
1745 NFp_t(
"Long64_t*", &CreateLongLongArrayConverter ),
1746 NFp_t(
"unsigned long long*", &CreateLongLongArrayConverter ),
1747 NFp_t(
"ULong64_t*", &CreateLongLongArrayConverter ),
1748 NFp_t(
"void*", &CreateVoidArrayConverter ),
1751 NFp_t(
"const char*", &CreateCStringConverter ),
1752 NFp_t(
"char*", &CreateNonConstCStringConverter ),
1753 NFp_t(
"TString", &CreateTStringConverter ),
1754 NFp_t(
"const TString&", &CreateTStringConverter ),
1755 NFp_t(
"std::string", &CreateSTLStringConverter ),
1756 NFp_t(
"string", &CreateSTLStringConverter ),
1757 NFp_t(
"const std::string&", &CreateSTLStringConverter ),
1758 NFp_t(
"const string&", &CreateSTLStringConverter ),
1759 NFp_t(
"std::string_view", &CreateSTLStringViewConverter ),
1760 NFp_t(
"string_view", &CreateSTLStringViewConverter ),
1761 NFp_t(
"experimental::basic_string_view<char,char_traits<char> >",&CreateSTLStringViewConverter),
1762 NFp_t(
"basic_string_view<char,char_traits<char> >",&CreateSTLStringViewConverter),
1763 NFp_t(
"void*&", &CreateVoidPtrRefConverter ),
1764 NFp_t(
"void**", &CreateVoidPtrPtrConverter ),
1765 NFp_t(
"PyObject*", &CreatePyObjectConverter ),
1766 NFp_t(
"_object*", &CreatePyObjectConverter ),
1767 NFp_t(
"FILE*", &CreateVoidArrayConverter ),
1768 NFp_t(
"Float16_t", &CreateFloatConverter ),
1769 NFp_t(
"const Float16_t&", &CreateConstFloatRefConverter ),
1770 NFp_t(
"Double32_t", &CreateDoubleConverter ),
1771 NFp_t(
"Double32_t&", &CreateDoubleRefConverter ),
1772 NFp_t(
"const Double32_t&", &CreateConstDoubleRefConverter )
1776 struct InitConvFactories_t {
1778 InitConvFactories_t()
1781 int nf =
sizeof( factories_ ) /
sizeof( factories_[ 0 ] );
1782 for (
int i = 0; i < nf; ++i ) {
1783 gConvFactories[ factories_[ i ].first ] = factories_[ i ].second;
1786 } initConvFactories_;
#define PYROOT_IMPLEMENT_BASIC_CHAR_CONVERTER(name, type, low, high)
static Bool_t PyROOT_PyLong_AsBool(PyObject *pyobject)
range-checking python integer to C++ bool conversion
static UShort_t PyROOT_PyLong_AsUShort(PyObject *pyobject)
range-checking python integer to C++ unsigned short int conversion
#define PYROOT_ARRAY_CONVERTER_FACTORY(name)
static std::tuple< const char *, Py_ssize_t > getStringAndSizeSTLString(PyObject *pyobject)
#define PYROOT_IMPLEMENT_BASIC_CONST_REF_CONVERTER(name, type, F1)
static std::tuple< const char *, Py_ssize_t > getStringAndSizeCString(PyObject *pyobject)
construct a new string and copy it in new memory
static Char_t PyROOT_PyUnicode_AsChar(PyObject *pyobject)
python string to C++ char conversion
static Int_t ExtractChar(PyObject *pyobject, const char *tname, Int_t low, Int_t high)
#define PYROOT_IMPLEMENT_BASIC_CONST_CHAR_REF_CONVERTER(name, type, low, high)
#define PYROOT_IMPLEMENT_ARRAY_CONVERTER(name, type, code)
static Short_t PyROOT_PyLong_AsShort(PyObject *pyobject)
range-checking python integer to C++ short int conversion
#define PYROOT_IMPLEMENT_BASIC_CONVERTER(name, type, stype, F1, F2, tc)
#define PYROOT_BASIC_CONVERTER_FACTORY(name)
static Long_t PyROOT_PyLong_AsStrictLong(PyObject *pyobject)
strict python integer to C++ integer conversion
#define PYROOT_IMPLEMENT_STRING_AS_PRIMITIVE_CONVERTER(name, type, F1, F2)
PyLong_FromUnsignedLongLong
#define PY_SSIZE_T_FORMAT
#define PyROOT_PyUnicode_Check
#define PyROOT_PyUnicode_AsString
#define PyROOT_PyCapsule_CheckExact
static void * PyROOT_PyCapsule_GetPointer(PyObject *capsule, const char *)
#define PyROOT_PyUnicode_GET_SIZE
#define PyROOT_PyUnicode_FromString
#define PyROOT_PyUnicode_FromStringAndSize
#define PyROOT_PyUnicode_AsStringChecked
unsigned long long ULong64_t
Cppyy::TCppType_t ObjectIsA() const
void SetSmartPtr(void *address, Cppyy::TCppType_t ptrType)
Cppyy::TCppType_t fSmartPtrType
virtual Bool_t ToMemory(PyObject *value, void *address)
could happen if no derived class override
virtual PyObject * FromMemory(void *address)
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
virtual Bool_t ToMemory(PyObject *value, void *address)
could happen if no derived class override
virtual PyObject * FromMemory(void *address)
virtual PyObject * FromMemory(void *address)
construct python tuple of instances from C++ array read at <address>
virtual Bool_t ToMemory(PyObject *value, void *address)
convert to C++ array of instances, write it at <address>
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert pyobject to C++ instance**, set arg for call
virtual PyObject * FromMemory(void *address)
construct python object from C++ instance read at <address>
virtual Bool_t ToMemory(PyObject *value, void *address)
convert to C++ instance, write it at <address>
virtual Bool_t ToMemory(PyObject *value, void *address)
convert to C++ instance*, write it at <address>
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert pyobject to C++ instance**, set arg for call
virtual PyObject * FromMemory(void *address)
construct python object from C++ instance* read at <address>
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
attempt base class first (i.e. passing a string), but if that fails, try a buffer
virtual PyObject * FromMemory(void *address)
assume this is a buffer access if the size is known; otherwise assume string
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
attempt base class first (i.e. passing a string), but if that fails, try a buffer
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *=0)
raise a NotImplemented exception to take a method out of overload resolution
PyObject * PyBuffer_FromMemory(Bool_t *buf, Py_ssize_t size=-1)
static TPyBufferFactory * Instance()
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert pyobject to C++ instance&, set arg for call
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
smart pointer converter
virtual PyObject * FromMemory(void *address)
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert pyobject to C++ instance, set arg for call
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
just convert pointer if it is a ROOT object
virtual Bool_t GetAddressSpecialCase(PyObject *pyobject, void *&address)
(1): "null pointer" or C++11 style nullptr
virtual Bool_t ToMemory(PyObject *value, void *address)
just convert pointer if it is a ROOT object
virtual PyObject * FromMemory(void *address)
nothing sensible can be done, just return <address> as pylong
virtual PyObject * FromMemory(void *address)
read a void** from address; since this is unknown, long is used (user can cast)
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert pyobject to C++ void**, set arg for call
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert pyobject to C++ void*&, set arg for call
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
basic_string_view< char > string_view
ptrdiff_t GetBaseOffset(TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror=false)
void CallDestructor(TCppType_t type, TCppObject_t self)
void * CallR(TCppMethod_t method, TCppObject_t self, void *args)
std::string ResolveName(const std::string &cppitem_name)
void Deallocate(TCppType_t type, TCppObject_t instance)
Bool_t IsEnum(const std::string &type_name)
TCppScope_t GetScope(const std::string &scope_name)
std::vector< TCppMethod_t > GetMethodsFromName(TCppScope_t scope, const std::string &name, bool alsoInBases=false)
std::string GetMethodResultType(TCppMethod_t)
std::string GetFinalName(TCppType_t type)
Bool_t IsSmartPtr(const std::string &)
std::string ResolveEnum(const TEnum *en)
Bool_t IsSubtype(TCppType_t derived, TCppType_t base)
R__EXTERN PyObject * gEmptyString
R__EXTERN PyObject * gInit
R__EXTERN PyObject * gTypeCode
const std::string Compound(const std::string &name)
Break down the compound of a fully qualified type name.
int GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, Bool_t check=kTRUE)
Retrieve a linear buffer pointer from the given pyobject.
PyObject * BindCppObject(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, Bool_t isRef=kFALSE)
if the object is a null pointer, return a typed one (as needed for overloading)
Bool_t TTupleOfInstances_CheckExact(T *object)
std::map< std::string, ConverterFactory_t > ConvFactories_t
ConvFactories_t gConvFactories
Bool_t ObjectProxy_Check(T *object)
PyObject * BindCppObjectArray(Cppyy::TCppObject_t address, Cppyy::TCppType_t klass, Int_t size)
TODO: this function exists for symmetry; need to figure out if it's useful.
ULong64_t PyLongOrInt_AsULong64(PyObject *pyobject)
Convert <pyobject> to C++ unsigned long long, with bounds checking.
Bool_t UseStrictOwnership(TCallContext *ctxt)
PyObject * CreateScopeProxy(Cppyy::TCppScope_t)
Convenience function with a lookup first through the known existing proxies.
TConverter * CreateConverter(const std::string &fullType, Long_t size=-1)
ULong_t PyLongOrInt_AsULong(PyObject *pyobject)
Bool_t TCustomFloat_CheckExact(T *object)
R__EXTERN PyObject * gNullPtrObject
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, Bool_t isRef=kFALSE, Bool_t isValue=kFALSE)
only known or knowable objects will be bound (null object is ok)
Bool_t TCustomInt_CheckExact(T *object)
std::string ResolveTypedef(const char *tname, bool resolveAll=false)
std::string CleanType(const char *typeDesc, int mode=0, const char **tail=0)
Cleanup type description, redundant blanks removed and redundant tail ignored return *tail = pointer ...
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
static constexpr double s
static constexpr double L
static ECallFlags sMemoryPolicy
union PyROOT::TParameter::Value fValue