29 #define TParameter PyROOT::TParameter 44 #if PY_VERSION_HEX >= 0x02050000 46 struct PyROOT_tagCDataObject {
51 static inline PyTypeObject* GetCTypesType(
const char*
name ) {
52 PyObject* ct = PyImport_ImportModule(
"ctypes" );
53 if ( ! ct )
return nullptr;
54 PyTypeObject* ct_t = (PyTypeObject*)PyObject_GetAttrString( ct, name );
67 Long_t l = PyLong_AsLong( pyobject );
69 if ( ! ( l == 0 || l == 1 ) || PyFloat_Check( pyobject ) ) {
70 PyErr_SetString( PyExc_ValueError,
"boolean value should be bool, or integer 1 or 0" );
87 if ( ! (PyLong_Check( pyobject ) || PyInt_Check( pyobject )) ) {
88 PyErr_SetString( PyExc_TypeError,
"unsigned short converion expects an integer object" );
91 Long_t l = PyLong_AsLong( pyobject );
92 if ( l < 0 || USHRT_MAX < l ) {
93 PyErr_Format( PyExc_ValueError,
"integer %ld out of range for unsigned short", l );
105 if ( ! (PyLong_Check( pyobject ) || PyInt_Check( pyobject )) ) {
106 PyErr_SetString( PyExc_TypeError,
"short int converion expects an integer object" );
109 Long_t l = PyLong_AsLong( pyobject );
110 if ( l < SHRT_MIN || SHRT_MAX < l ) {
111 PyErr_Format( PyExc_ValueError,
"integer %ld out of range for short int", l );
126 if ( ! (PyLong_Check( pyobject ) || PyInt_Check( pyobject )) ) {
127 PyErr_SetString( PyExc_TypeError,
"int/long converion expects an integer object" );
130 return (
Long_t)PyLong_AsLong( pyobject );
138 PyErr_SetString( PyExc_TypeError,
"C++ type can not be converted from memory" );
147 PyErr_SetString( PyExc_TypeError,
"C++ type can not be converted to memory" );
153 #define PYROOT_IMPLEMENT_BASIC_CONVERTER( name, type, stype, F1, F2, tc ) \ 154 Bool_t PyROOT::T##name##Converter::SetArg( \ 155 PyObject* pyobject, TParameter& para, TCallContext* ) \ 158 type val = (type)F2( pyobject ); \ 159 if ( val == (type)-1 && PyErr_Occurred() ) \ 161 para.fValue.f##name = val; \ 162 para.fTypeCode = tc; \ 166 PyObject* PyROOT::T##name##Converter::FromMemory( void* address ) \ 168 return F1( (stype)*((type*)address) ); \ 171 Bool_t PyROOT::T##name##Converter::ToMemory( PyObject* value, void* address ) \ 173 type s = (type)F2( value ); \ 174 if ( s == (type)-1 && PyErr_Occurred() ) \ 176 *((type*)address) = (type)s; \ 188 PyErr_Format( PyExc_TypeError,
"%s expected, got string of size " PY_SSIZE_T_FORMAT,
190 }
else if ( ! PyFloat_Check( pyobject ) ) {
191 lchar = PyLong_AsLong( pyobject );
192 if ( lchar == -1 && PyErr_Occurred() )
194 else if ( ! ( low <= lchar && lchar <= high ) ) {
195 PyErr_Format( PyExc_ValueError,
196 "integer to character: value %d not in range [%d,%d]", lchar, low, high );
200 PyErr_SetString( PyExc_TypeError,
"char or small int type expected" );
206 #define PYROOT_IMPLEMENT_BASIC_CONST_REF_CONVERTER( name, type, F1 )\ 207 Bool_t PyROOT::TConst##name##RefConverter::SetArg( \ 208 PyObject* pyobject, TParameter& para, TCallContext* ) \ 210 type val = (type)F1( pyobject ); \ 211 if ( val == (type)-1 && PyErr_Occurred() ) \ 213 para.fValue.f##name = val; \ 214 para.fRef = ¶.fValue.f##name; \ 215 para.fTypeCode = 'r'; \ 219 #define PYROOT_IMPLEMENT_BASIC_CONST_CHAR_REF_CONVERTER( name, type, low, high )\ 220 Bool_t PyROOT::TConst##name##RefConverter::SetArg( \ 221 PyObject* pyobject, TParameter& para, TCallContext* ) \ 224 type val = (type)ExtractChar( pyobject, #type, low, high ); \ 225 if ( val == (type)-1 && PyErr_Occurred() ) \ 227 para.fValue.fLong = val; \ 228 para.fTypeCode = 'l'; \ 235 #define PYROOT_IMPLEMENT_BASIC_CHAR_CONVERTER( name, type, low, high ) \ 236 Bool_t PyROOT::T##name##Converter::SetArg( \ 237 PyObject* pyobject, TParameter& para, TCallContext* ) \ 240 Long_t val = ExtractChar( pyobject, #type, low, high ); \ 241 if ( val == -1 && PyErr_Occurred() ) \ 243 para.fValue.fLong = val; \ 244 para.fTypeCode = 'l'; \ 248 PyObject* PyROOT::T##name##Converter::FromMemory( void* address ) \ 250 return PyROOT_PyUnicode_FromFormat( "%c", *((type*)address) ); \ 253 Bool_t PyROOT::T##name##Converter::ToMemory( PyObject* value, void* address ) \ 255 if ( PyROOT_PyUnicode_Check( value ) ) { \ 256 const char* buf = PyROOT_PyUnicode_AsString( value ); \ 257 if ( PyErr_Occurred() ) \ 259 int len = PyROOT_PyUnicode_GET_SIZE( value ); \ 261 PyErr_Format( PyExc_TypeError, #type" expected, got string of size %d", len );\ 264 *((type*)address) = (type)buf[0]; \ 266 Long_t l = PyLong_AsLong( value ); \ 267 if ( l == -1 && PyErr_Occurred() ) \ 269 if ( ! ( low <= l && l <= high ) ) { \ 270 PyErr_Format( PyExc_ValueError, \ 271 "integer to character: value %ld not in range [%d,%d]", l, low, high );\ 274 *((type*)address) = (type)l; \ 289 #if PY_VERSION_HEX < 0x03000000 291 para.fValue.fVoidp = (
void*)&((PyIntObject*)pyobject)->ob_ival;
292 para.fTypeCode =
'V';
297 #if PY_VERSION_HEX < 0x02050000 298 PyErr_SetString( PyExc_TypeError,
"use ROOT.Long for pass-by-ref of longs" );
303 static PyTypeObject* c_long_type = GetCTypesType(
"c_long" );
304 if (
Py_TYPE( pyobject ) == c_long_type ) {
305 para.fValue.fVoidp = (
void*)((PyROOT_tagCDataObject*)pyobject)->b_ptr;
306 para.fTypeCode =
'V';
310 PyErr_SetString( PyExc_TypeError,
"use ctypes.c_long for pass-by-ref of longs" );
332 Bool_t PyROOT::TIntRefConverter::SetArg(
335 #if PY_VERSION_HEX < 0x03000000 337 para.
fValue.
fVoidp = (
void*)&((PyIntObject*)pyobject)->ob_ival;
343 #if PY_VERSION_HEX >= 0x02050000 345 static PyTypeObject* c_int_type = GetCTypesType(
"c_int" );
346 if (
Py_TYPE( pyobject ) == c_int_type ) {
347 para.
fValue.
fVoidp = (
void*)((PyROOT_tagCDataObject*)pyobject)->b_ptr;
360 #if PY_VERSION_HEX < 0x02050000 361 PyErr_SetString( PyExc_TypeError,
"use ROOT.Long for pass-by-ref of ints" );
363 PyErr_SetString( PyExc_TypeError,
"use ctypes.c_int for pass-by-ref of ints" );
387 Bool_t PyROOT::TULongConverter::SetArg(
391 if ( PyErr_Occurred() )
397 PyObject* PyROOT::TULongConverter::FromMemory(
void* address )
400 return PyLong_FromUnsignedLong( *((
ULong_t*)address) );
403 Bool_t PyROOT::TULongConverter::ToMemory(
PyObject* value,
void* address )
407 if ( PyErr_Occurred() )
416 PyObject* PyROOT::TUIntConverter::FromMemory(
void* address )
418 return PyLong_FromUnsignedLong( *((
UInt_t*)address) );
421 Bool_t PyROOT::TUIntConverter::ToMemory(
PyObject* value,
void* address )
425 if ( PyErr_Occurred() )
429 PyErr_SetString( PyExc_OverflowError,
"value too large for unsigned int" );
448 Bool_t PyROOT::TDoubleRefConverter::SetArg(
452 para.
fValue.
fVoidp = (
void*)&((PyFloatObject*)pyobject)->ob_fval;
464 PyErr_SetString( PyExc_TypeError,
"use ROOT.Double for pass-by-ref of doubles" );
479 PyErr_SetString( PyExc_SystemError,
"void/unknown arguments can\'t be set" );
486 Bool_t PyROOT::TLongLongConverter::SetArg(
489 if ( PyFloat_Check( pyobject ) ) {
492 PyErr_SetString( PyExc_ValueError,
"can not convert float to long long" );
497 if ( PyErr_Occurred() )
503 PyObject* PyROOT::TLongLongConverter::FromMemory(
void* address )
506 return PyLong_FromLongLong( *(
Long64_t*)address );
509 Bool_t PyROOT::TLongLongConverter::ToMemory(
PyObject* value,
void* address )
512 Long64_t ll = PyLong_AsLongLong( value );
513 if ( ll == -1 && PyErr_Occurred() )
522 Bool_t PyROOT::TULongLongConverter::SetArg(
526 if ( PyErr_Occurred() )
532 PyObject* PyROOT::TULongLongConverter::FromMemory(
void* address )
538 Bool_t PyROOT::TULongLongConverter::ToMemory(
PyObject* value,
void* address )
542 if ( PyErr_Occurred() )
555 if ( PyErr_Occurred() )
561 if ( fMaxSize < (
UInt_t)fBuffer.size() )
562 PyErr_Warn( PyExc_RuntimeWarning, (
char*)
"string too long for char array (truncated)" );
563 else if ( fMaxSize != UINT_MAX )
564 fBuffer.resize( fMaxSize,
'\0' );
575 if ( address && *(
char**)address ) {
576 if ( fMaxSize != UINT_MAX ) {
577 std::string buf( *(
char**)address, fMaxSize );
593 if ( PyErr_Occurred() )
598 PyErr_Warn( PyExc_RuntimeWarning, (
char*)
"string too long for char array (truncated)" );
600 if ( fMaxSize != UINT_MAX )
601 strncpy( *(
char**)address, s, fMaxSize );
604 strcpy( *(
char**)address, s );
615 inline Bool_t CArraySetArg(
644 return CArraySetArg( pyobject, para,
'c',
sizeof(
char) );
652 if ( fMaxSize != UINT_MAX )
668 return CArraySetArg( pyobject, para,
'B',
sizeof(
unsigned char) );
682 if ( PyInt_CheckExact( pyobject ) || PyLong_CheckExact( pyobject ) ) {
685 address = (
void*)val;
719 if ( GetAddressSpecialCase( pyobject, para.
fValue.
fVoidp ) ) {
742 if ( ! address || *(ptrdiff_t*)address == 0 ) {
760 *(
void**)address = ((
ObjectProxy*)value)->GetObject();
766 if ( GetAddressSpecialCase( value, ptr ) ) {
767 *(
void**)address = ptr;
774 if ( ! buf || buflen == 0 )
777 *(
void**)address = buf;
783 #define PYROOT_IMPLEMENT_ARRAY_CONVERTER( name, type, code ) \ 784 Bool_t PyROOT::T##name##ArrayConverter::SetArg( \ 785 PyObject* pyobject, TParameter& para, TCallContext* ) \ 787 return CArraySetArg( pyobject, para, code, sizeof(type) ); \ 790 Bool_t PyROOT::T##name##ArrayRefConverter::SetArg( \ 791 PyObject* pyobject, TParameter& para, TCallContext* ctxt ) \ 793 Bool_t result = T##name##ArrayConverter::SetArg( pyobject, para, ctxt ); \ 794 para.fTypeCode = 'V'; \ 798 PyObject* PyROOT::T##name##ArrayConverter::FromMemory( void* address ) \ 800 return BufFac_t::Instance()->PyBuffer_FromMemory( *(type**)address, fSize * sizeof(type) );\ 803 Bool_t PyROOT::T##name##ArrayConverter::ToMemory( PyObject* value, void* address )\ 806 int buflen = Utility::GetBuffer( value, code, sizeof(type), buf ); \ 807 if ( ! buf || buflen == 0 ) \ 809 if ( 0 <= fSize ) { \ 810 if ( fSize < buflen/(int)sizeof(type) ) { \ 811 PyErr_SetString( PyExc_ValueError, "buffer too large for value" ); \ 814 memcpy( *(type**)address, buf, 0 < buflen ? ((size_t) buflen) : sizeof(type) );\ 816 *(type**)address = (type*)buf; \ 849 #define PYROOT_IMPLEMENT_STRING_AS_PRIMITIVE_CONVERTER( name, type, F1, F2 ) \ 850 PyROOT::T##name##Converter::T##name##Converter( Bool_t keepControl ) : \ 851 TCppObjectConverter( Cppyy::GetScope( #type ), keepControl ) {} \ 853 Bool_t PyROOT::T##name##Converter::SetArg( \ 854 PyObject* pyobject, TParameter& para, TCallContext* ctxt ) \ 856 if ( PyROOT_PyUnicode_Check( pyobject ) ) { \ 857 fBuffer = type( PyROOT_PyUnicode_AsString( pyobject ), \ 858 PyROOT_PyUnicode_GET_SIZE( pyobject ) ); \ 859 para.fValue.fVoidp = &fBuffer; \ 860 para.fTypeCode = 'V'; \ 864 if ( ! ( PyInt_Check( pyobject ) || PyLong_Check( pyobject ) ) ) { \ 865 Bool_t result = TCppObjectConverter::SetArg( pyobject, para, ctxt ); \ 866 para.fTypeCode = 'V'; \ 872 PyObject* PyROOT::T##name##Converter::FromMemory( void* address ) \ 875 return PyROOT_PyUnicode_FromStringAndSize( ((type*)address)->F1(), ((type*)address)->F2() );\ 876 Py_INCREF( PyStrings::gEmptyString ); \ 877 return PyStrings::gEmptyString; \ 880 Bool_t PyROOT::T##name##Converter::ToMemory( PyObject* value, void* address ) \ 882 if ( PyROOT_PyUnicode_Check( value ) ) { \ 883 *((type*)address) = PyROOT_PyUnicode_AsString( value ); \ 887 return TCppObjectConverter::ToMemory( value, address ); \ 901 if ( GetAddressSpecialCase( pyobject, para.fValue.fVoidp ) ) {
902 para.fTypeCode =
'p';
920 pyobj->
ObjectIsA(), fClass, para.fValue.fVoidp, 1 );
924 para.fTypeCode =
'p';
930 para.fTypeCode =
'p';
952 if ( GetAddressSpecialCase( value, ptr ) ) {
953 *(
void**)address = ptr;
969 PyObject* result = PyObject_CallMethod( pyobj, (
char*)
"__assign__", (
char*)
"O", value );
1005 else if ( PyTuple_Check( pyobject ) ){
1011 if ( ! pyclass )
return kFALSE;
1012 fObjProxy = (
ObjectProxy*)((PyTypeObject*)pyclass)->tp_new( (PyTypeObject*)pyclass, NULL, NULL );
1013 Py_DECREF( pyclass );
1016 if( fObjProxy->GetObject() ) {
1020 fObjProxy->Set(
nullptr);
1025 if( ! constructor )
return kFALSE;
1028 PyObject* obj = PyObject_CallObject( constructor, pyobject );
1029 Py_DECREF( constructor );
1030 if ( ! obj )
return kFALSE;
1066 else if ( PyTuple_Check( pyobject ) ){
1072 if ( ! pyclass )
return kFALSE;
1073 fObjProxy = (
ObjectProxy*)((PyTypeObject*)pyclass)->tp_new( (PyTypeObject*)pyclass, NULL, NULL );
1074 Py_DECREF( pyclass );
1077 if( fObjProxy->GetObject() ) {
1081 fObjProxy->Set(
nullptr);
1086 if( ! constructor )
return kFALSE;
1089 PyObject* obj = PyObject_CallObject( constructor, pyobject );
1090 Py_DECREF( constructor );
1091 if ( ! obj )
return kFALSE;
1105 template <
bool ISREFERENCE>
1123 para.
fTypeCode = ISREFERENCE ?
'V' :
'p';
1133 template <
bool ISREFERENCE>
1142 template <
bool ISREFERENCE>
1154 *(
void**)address = ((
ObjectProxy*)value)->GetObject();
1181 if ( PyTuple_Size( pyobject ) < 1 )
1215 PyErr_SetString( PyExc_NotImplementedError,
1216 "access to C-arrays of objects not yet implemented!" );
1282 if ( ! address || *(ptrdiff_t*)address == 0 ) {
1292 Bool_t PyROOT::TPyObjectConverter::SetArg(
1300 PyObject* PyROOT::TPyObjectConverter::FromMemory(
void* address )
1306 Py_INCREF( Py_None );
1310 Py_INCREF( pyobject );
1314 Bool_t PyROOT::TPyObjectConverter::ToMemory(
PyObject* value,
void* address )
1329 char typeCode = fHandlePtr ?
'p' :
'V';
1332 if ( fHandlePtr && GetAddressSpecialCase( pyobject, para.
fValue.
fVoidp ) ) {
1379 if ( !address || !fClass )
1383 std::vector<TParameter> args;
1398 PyErr_SetString( PyExc_NotImplementedError,
"this method can not (yet) be called" );
1418 return (h->second)( size );
1426 return (h->second)( size );
1435 return (h->second)( size );
1445 if ( cpd ==
"[]" ) {
1448 return (h->second)( size );
1452 Bool_t isConst = resolvedType.substr(0, 5) ==
"const";
1453 Bool_t control = cpd ==
"&" || isConst;
1460 if ( ! methods.empty() ) {
1466 }
else if ( cpd ==
"&" ) {
1468 }
else if ( cpd ==
"*" && size <= 0 ) {
1480 if ( realType.find(
"__gnu_cxx::__normal_iterator", 0 ) == 0 )
1484 if ( cpd ==
"**" || cpd ==
"&*" )
1486 else if ( cpd ==
"*&" )
1488 else if ( cpd ==
"*" && size <= 0 )
1490 else if ( cpd ==
"&" )
1492 else if ( cpd ==
"[]" || size > 0 )
1494 else if ( cpd ==
"" )
1503 }
else if ( realType.find(
"(*)" ) != std::string::npos ||
1504 ( realType.find(
"::*)" ) != std::string::npos ) ) {
1511 if ( ! result && cpd ==
"&&" )
1516 result = (h->second)( size );
1517 else if ( ! result ) {
1519 std::stringstream
s;
1520 s <<
"creating converter for unknown type \"" << fullType <<
"\"" << std::ends;
1521 PyErr_Warn( PyExc_RuntimeWarning, (
char*)s.str().c_str() );
1532 #define PYROOT_BASIC_CONVERTER_FACTORY( name ) \ 1533 TConverter* Create##name##Converter( Long_t ) \ 1535 return new T##name##Converter(); \ 1538 #define PYROOT_ARRAY_CONVERTER_FACTORY( name ) \ 1539 TConverter* Create##name##Converter( Long_t size ) \ 1541 return new T##name##Converter( size ); \ 1610 typedef std::pair< const char*, ConverterFactory_t > NFp_t;
1613 NFp_t factories_[] = {
1615 NFp_t(
"bool", &CreateBoolConverter ),
1616 NFp_t(
"const bool&", &CreateConstBoolRefConverter ),
1617 NFp_t(
"char", &CreateCharConverter ),
1618 NFp_t(
"const char&", &CreateConstCharRefConverter ),
1619 NFp_t(
"signed char", &CreateCharConverter ),
1620 NFp_t(
"const signed char&", &CreateConstCharRefConverter ),
1621 NFp_t(
"unsigned char", &CreateUCharConverter ),
1622 NFp_t(
"const unsigned char&", &CreateConstUCharRefConverter ),
1623 NFp_t(
"short", &CreateShortConverter ),
1624 NFp_t(
"const short&", &CreateConstShortRefConverter ),
1625 NFp_t(
"unsigned short", &CreateUShortConverter ),
1626 NFp_t(
"const unsigned short&", &CreateConstUShortRefConverter ),
1627 NFp_t(
"int", &CreateIntConverter ),
1628 NFp_t(
"int&", &CreateIntRefConverter ),
1629 NFp_t(
"const int&", &CreateConstIntRefConverter ),
1630 NFp_t(
"unsigned int", &CreateUIntConverter ),
1631 NFp_t(
"const unsigned int&", &CreateConstUIntRefConverter ),
1632 NFp_t(
"UInt_t", &CreateIntConverter ),
1633 NFp_t(
"long", &CreateLongConverter ),
1634 NFp_t(
"long&", &CreateLongRefConverter ),
1635 NFp_t(
"const long&", &CreateConstLongRefConverter ),
1636 NFp_t(
"unsigned long", &CreateULongConverter ),
1637 NFp_t(
"const unsigned long&", &CreateConstULongRefConverter ),
1638 NFp_t(
"long long", &CreateLongLongConverter ),
1639 NFp_t(
"const long long&", &CreateConstLongLongRefConverter ),
1640 NFp_t(
"Long64_t", &CreateLongLongConverter ),
1641 NFp_t(
"const Long64_t&", &CreateConstLongLongRefConverter ),
1642 NFp_t(
"unsigned long long", &CreateULongLongConverter ),
1643 NFp_t(
"const unsigned long long&", &CreateConstULongLongRefConverter ),
1644 NFp_t(
"ULong64_t", &CreateULongLongConverter ),
1645 NFp_t(
"const ULong64_t&", &CreateConstULongLongRefConverter ),
1647 NFp_t(
"float", &CreateFloatConverter ),
1648 NFp_t(
"const float&", &CreateConstFloatRefConverter ),
1649 NFp_t(
"double", &CreateDoubleConverter ),
1650 NFp_t(
"double&", &CreateDoubleRefConverter ),
1651 NFp_t(
"const double&", &CreateConstDoubleRefConverter ),
1652 NFp_t(
"long double", &CreateLongDoubleConverter ),
1653 NFp_t(
"const long double&", &CreateConstLongDoubleRefConverter ),
1654 NFp_t(
"void", &CreateVoidConverter ),
1657 NFp_t(
"bool*", &CreateBoolArrayConverter ),
1658 NFp_t(
"bool&", &CreateBoolArrayRefConverter ),
1659 NFp_t(
"const unsigned char*", &CreateCStringConverter ),
1660 NFp_t(
"unsigned char*", &CreateNonConstUCStringConverter ),
1661 NFp_t(
"short*", &CreateShortArrayConverter ),
1662 NFp_t(
"short&", &CreateShortArrayRefConverter ),
1663 NFp_t(
"unsigned short*", &CreateUShortArrayConverter ),
1664 NFp_t(
"unsigned short&", &CreateUShortArrayRefConverter ),
1665 NFp_t(
"int*", &CreateIntArrayConverter ),
1666 NFp_t(
"unsigned int*", &CreateUIntArrayConverter ),
1667 NFp_t(
"unsigned int&", &CreateUIntArrayRefConverter ),
1668 NFp_t(
"long*", &CreateLongArrayConverter ),
1669 NFp_t(
"unsigned long*", &CreateULongArrayConverter ),
1670 NFp_t(
"unsigned long&", &CreateULongArrayRefConverter ),
1671 NFp_t(
"float*", &CreateFloatArrayConverter ),
1672 NFp_t(
"float&", &CreateFloatArrayRefConverter ),
1673 NFp_t(
"double*", &CreateDoubleArrayConverter ),
1674 NFp_t(
"long long*", &CreateLongLongArrayConverter ),
1675 NFp_t(
"Long64_t*", &CreateLongLongArrayConverter ),
1676 NFp_t(
"unsigned long long*", &CreateLongLongArrayConverter ),
1677 NFp_t(
"ULong64_t*", &CreateLongLongArrayConverter ),
1678 NFp_t(
"void*", &CreateVoidArrayConverter ),
1681 NFp_t(
"const char*", &CreateCStringConverter ),
1682 NFp_t(
"char*", &CreateNonConstCStringConverter ),
1683 NFp_t(
"TString", &CreateTStringConverter ),
1684 NFp_t(
"const TString&", &CreateTStringConverter ),
1685 NFp_t(
"std::string", &CreateSTLStringConverter ),
1686 NFp_t(
"string", &CreateSTLStringConverter ),
1687 NFp_t(
"const std::string&", &CreateSTLStringConverter ),
1688 NFp_t(
"const string&", &CreateSTLStringConverter ),
1689 NFp_t(
"std::string_view", &CreateSTLStringViewConverter ),
1690 NFp_t(
"string_view", &CreateSTLStringViewConverter ),
1691 NFp_t(
"experimental::basic_string_view<char,char_traits<char> >",&CreateSTLStringViewConverter),
1692 NFp_t(
"basic_string_view<char,char_traits<char> >",&CreateSTLStringViewConverter),
1693 NFp_t(
"void*&", &CreateVoidPtrRefConverter ),
1694 NFp_t(
"void**", &CreateVoidPtrPtrConverter ),
1695 NFp_t(
"PyObject*", &CreatePyObjectConverter ),
1696 NFp_t(
"_object*", &CreatePyObjectConverter ),
1697 NFp_t(
"FILE*", &CreateVoidArrayConverter ),
1698 NFp_t(
"Float16_t", &CreateFloatConverter ),
1699 NFp_t(
"const Float16_t&", &CreateConstFloatRefConverter ),
1700 NFp_t(
"Double32_t", &CreateDoubleConverter ),
1701 NFp_t(
"Double32_t&", &CreateDoubleRefConverter ),
1702 NFp_t(
"const Double32_t&", &CreateConstDoubleRefConverter )
1706 struct InitConvFactories_t {
1708 InitConvFactories_t()
1711 int nf =
sizeof( factories_ ) /
sizeof( factories_[ 0 ] );
1712 for (
int i = 0; i < nf; ++i ) {
1713 gConvFactories[ factories_[ i ].first ] = factories_[ i ].second;
1716 } initConvFactories_;
virtual Bool_t ToMemory(PyObject *value, void *address)
could happen if no derived class override
R__EXTERN PyObject * gInit
#define PyROOT_PyUnicode_FromString
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
construct a new string and copy it in new memory
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
basic_string_view< char > string_view
#define PyROOT_PyUnicode_GET_SIZE
Cppyy::TCppType_t fSmartPtrType
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert <pyobject> to C++ instance**, set arg for call
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
ptrdiff_t GetBaseOffset(TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror=false)
static Long_t PyROOT_PyLong_AsStrictLong(PyObject *pyobject)
strict python integer to C++ integer conversion
std::vector< TCppMethod_t > GetMethodsFromName(TCppScope_t scope, const std::string &name)
#define PyROOT_PyCapsule_CheckExact
std::string GetFinalName(TCppType_t type)
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 ...
#define PYROOT_BASIC_CONVERTER_FACTORY(name)
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.
virtual Bool_t ToMemory(PyObject *value, void *address)
could happen if no derived class override
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
smart pointer converter
Bool_t UseStrictOwnership(TCallContext *ctxt)
#define PY_SSIZE_T_FORMAT
virtual PyObject * FromMemory(void *address)
#define PYROOT_IMPLEMENT_BASIC_CHAR_CONVERTER(name, type, low, high)
#define PYROOT_IMPLEMENT_BASIC_CONST_CHAR_REF_CONVERTER(name, type, low, high)
std::string ResolveName(const std::string &cppitem_name)
PyLong_FromUnsignedLongLong
union PyROOT::TParameter::Value fValue
static UShort_t PyROOT_PyLong_AsUShort(PyObject *pyobject)
range-checking python integer to C++ unsigend short int conversion
virtual PyObject * FromMemory(void *address)
void SetSmartPtr(void *address, Cppyy::TCppType_t ptrType)
static constexpr double L
ClassInfo_t * GetClassInfo() const
#define PyROOT_PyUnicode_AsStringChecked
virtual Bool_t ToMemory(PyObject *value, void *address)
convert to C++ array of instances, write it at <address>
#define PyROOT_PyUnicode_AsString
void CallDestructor(TCppType_t type, TCppObject_t self)
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *=0)
raise a NotImplemented exception to take a method out of overload resolution
virtual PyObject * FromMemory(void *address)
R__EXTERN PyObject * gNullPtrObject
ULong_t PyLongOrInt_AsULong(PyObject *pyobject)
#define PYROOT_ARRAY_CONVERTER_FACTORY(name)
TConverter * CreateConverter(const std::string &fullType, Long_t size=-1)
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
Bool_t ObjectProxy_Check(T *object)
virtual Bool_t GetAddressSpecialCase(PyObject *pyobject, void *&address)
(1): "null pointer" or C++11 style nullptr
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 ToMemory(PyObject *value, void *address)
convert to C++ instance, write it at <address>
Bool_t TTupleOfInstances_CheckExact(T *object)
#define PyROOT_PyUnicode_FromStringAndSize
virtual PyObject * FromMemory(void *address)
assume this is a buffer access if the size is known; otherwise assume string
#define PYROOT_IMPLEMENT_ARRAY_CONVERTER(name, type, code)
ULong64_t PyLongOrInt_AsULong64(PyObject *pyobject)
Convert <pyobject> to C++ unsigned long long, with bounds checking.
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)
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert <pyobject> to C++ void*&, set arg for call
virtual PyObject * FromMemory(void *address)
construct python object from C++ instance* read at <address>
PyObject * PyBuffer_FromMemory(Bool_t *buf, Py_ssize_t size=-1)
virtual PyObject * FromMemory(void *address)
construct python tuple of instances from C++ array read at <address>
Bool_t TCustomFloat_CheckExact(T *object)
void * CallR(TCppMethod_t method, TCppObject_t self, void *args)
Bool_t IsSubtype(TCppType_t derived, TCppType_t base)
PyObject * CreateScopeProxy(Cppyy::TCppScope_t)
Convenience function with a lookup first through the known existing proxies.
static Bool_t PyROOT_PyLong_AsBool(PyObject *pyobject)
range-checking python integer to C++ bool conversion
TCppScope_t GetScope(const std::string &scope_name)
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 ...
std::string GetMethodResultType(TCppMethod_t)
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
just convert pointer if it is a ROOT object
virtual PyObject * FromMemory(void *address)
construct python object from C++ instance read at <address>
R__EXTERN PyObject * gTypeCode
unsigned long long ULong64_t
#define PYROOT_IMPLEMENT_BASIC_CONST_REF_CONVERTER(name, type, F1)
static constexpr double s
#define PyROOT_PyUnicode_Check
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.
void Deallocate(TCppType_t type, TCppObject_t instance)
virtual PyObject * FromMemory(void *address)
read a void** from address; since this is unknown, long is used (user can cast)
static Int_t ExtractChar(PyObject *pyobject, const char *tname, Int_t low, Int_t high)
static void * PyROOT_PyCapsule_GetPointer(PyObject *capsule, const char *)
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert <pyobject> to C++ instance, set arg for call
static Short_t PyROOT_PyLong_AsShort(PyObject *pyobject)
range-checking python integer to C++ short int conversion
Bool_t IsSmartPtr(const std::string &)
static TPyBufferFactory * Instance()
static Char_t PyROOT_PyUnicode_AsChar(PyObject *pyobject)
python string to C++ char conversion
int GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, Bool_t check=kTRUE)
Retrieve a linear buffer pointer from the given pyobject.
std::map< std::string, ConverterFactory_t > ConvFactories_t
std::string ShortType(const char *typeDesc, int mode)
Return the absolute type of typeDesc.
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 IsEnum(const std::string &type_name)
Bool_t TCustomInt_CheckExact(T *object)
static ECallFlags sMemoryPolicy
ConvFactories_t gConvFactories
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert <pyobject> to C++ void**, set arg for call
#define PYROOT_IMPLEMENT_STRING_AS_PRIMITIVE_CONVERTER(name, type, F1, F2)
virtual Bool_t SetArg(PyObject *, TParameter &, TCallContext *ctxt=0)
convert <pyobject> to C++ instance&, set arg for call
R__EXTERN PyObject * gEmptyString
Cppyy::TCppType_t ObjectIsA() const
#define PYROOT_IMPLEMENT_BASIC_CONVERTER(name, type, stype, F1, F2, tc)
const std::string Compound(const std::string &name)
Break down the compound of a fully qualified type name.