41 if ( fRelease ) fSave = PyEval_SaveThread();
46 if ( fRelease ) PyEval_RestoreThread( fSave );
56#define PYROOT_IMPL_GILCALL( rtype, tcode ) \
57static inline rtype GILCall##tcode( \
58 Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, PyROOT::TCallContext* ctxt ) {\
59 GILControl gc( ctxt ); \
60 return Cppyy::Call##tcode( method, self, &ctxt->fArgs ); \
78 GILControl gc( ctxt );
79 return Cppyy::CallO( method, self, &ctxt->fArgs, klass );
84 GILControl gc( ctxt );
102PyObject* PyROOT::TBoolExecutor::Execute(
106 Bool_t retval = GILCallB( method, self, ctxt );
107 PyObject* result = retval ? Py_True : Py_False;
115PyObject* PyROOT::TBoolConstRefExecutor::Execute(
125PyObject* PyROOT::TCharExecutor::Execute(
135PyObject* PyROOT::TCharConstRefExecutor::Execute(
145PyObject* PyROOT::TUCharExecutor::Execute(
155PyObject* PyROOT::TUCharConstRefExecutor::Execute(
164PyObject* PyROOT::TIntExecutor::Execute(
167 return PyInt_FromLong( (
Int_t)GILCallI( method, self, ctxt ) );
173PyObject* PyROOT::TShortExecutor::Execute(
176 return PyInt_FromLong( (
Short_t)GILCallH( method, self, ctxt ) );
182PyObject* PyROOT::TLongExecutor::Execute(
185 return PyLong_FromLong( (
Long_t)GILCallL( method, self, ctxt ) );
191PyObject* PyROOT::TULongExecutor::Execute(
194 return PyLong_FromUnsignedLong( (
ULong_t)GILCallLL( method, self, ctxt ) );
200PyObject* PyROOT::TLongLongExecutor::Execute(
203 Long64_t result = GILCallLL( method, self, ctxt );
204 return PyLong_FromLongLong( result );
210PyObject* PyROOT::TULongLongExecutor::Execute(
220PyObject* PyROOT::TFloatExecutor::Execute(
223 return PyFloat_FromDouble( (
Double_t)GILCallF( method, self, ctxt ) );
229PyObject* PyROOT::TDoubleExecutor::Execute(
232 return PyFloat_FromDouble( (
Double_t)GILCallD( method, self, ctxt ) );
238PyObject* PyROOT::TLongDoubleExecutor::Execute(
241 return PyFloat_FromDouble( (
Double_t)GILCallLD( method, self, ctxt ) );
249 if ( pyobject != 0 ) {
250 Py_INCREF( pyobject );
261#define PYROOT_IMPLEMENT_BASIC_REFEXECUTOR( name, type, stype, F1, F2 ) \
262PyObject* PyROOT::T##name##RefExecutor::Execute( \
263 Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, TCallContext* ctxt )\
265 type* ref = (type*)GILCallR( method, self, ctxt ); \
266 if ( ! fAssignable ) \
267 return F1( (stype)*ref ); \
269 *ref = (type)F2( fAssignable ); \
270 Py_DECREF( fAssignable ); \
272 Py_INCREF( Py_None ); \
301 if ( ! fAssignable ) {
302 std::string* result = (std::string*)GILCallR( method, self, ctxt );
305 std::string* result = (std::string*)GILCallR( method, self, ctxt );
306 *result = std::string(
309 Py_DECREF( fAssignable );
312 Py_INCREF( Py_None );
320PyObject* PyROOT::TVoidExecutor::Execute(
323 GILCallV( method, self, ctxt );
324 Py_INCREF( Py_None );
331PyObject* PyROOT::TCStringExecutor::Execute(
334 char* result = (
char*)GILCallS( method, self, ctxt );
345PyObject* PyROOT::TVoidArrayExecutor::Execute(
349 Long_t* result = (
Long_t*)GILCallR( method, self, ctxt );
359#define PYROOT_IMPLEMENT_ARRAY_EXECUTOR( name, type ) \
360PyObject* PyROOT::T##name##ArrayExecutor::Execute( \
361 Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, TCallContext* ctxt )\
363 return BufFac_t::Instance()->PyBuffer_FromMemory( (type*)GILCallR( method, self, ctxt ) );\
380PyObject* PyROOT::TSTLStringExecutor::Execute(
386 std::string* result = (std::string*)
GILCallO( method, self, ctxt, sSTLStringScope );
402PyObject* PyROOT::TTGlobalExecutor::Execute(
414 return BindCppObject( (
void*)GILCallR( method, self, ctxt ), fClass );
426 if ( ! PyErr_Occurred() )
427 PyErr_SetString( PyExc_ValueError,
"NULL result where temporary expected" );
449 if ( ! result || ! fAssignable )
453 PyObject* assign = PyObject_GetAttrString( result,
const_cast< char*
>(
"__assign__" ) );
456 PyObject* descr = PyObject_Str( result );
458 PyErr_Format( PyExc_TypeError,
"can not assign to return object (%s)",
461 PyErr_SetString( PyExc_TypeError,
"can not assign to result" );
465 Py_DECREF( fAssignable ); fAssignable = 0;
469 PyObject* res2 = PyObject_CallFunction( assign,
const_cast< char*
>(
"O" ), fAssignable );
473 Py_DECREF( fAssignable ); fAssignable = 0;
477 Py_INCREF( Py_None );
513 if ( ! PyErr_Occurred() )
514 PyErr_SetString( PyExc_ValueError,
"NULL result where temporary expected" );
613 return BindCppObjectArray( (
void*)GILCallR( method, self, ctxt ), fClass, fArraySize );
620PyObject* PyROOT::TConstructorExecutor::Execute(
629PyObject* PyROOT::TPyObjectExecutor::Execute(
632 return (
PyObject*)GILCallR( method, self, ctxt );
651 return (
h->second)();
659 return (
h->second)();
668 return (
h->second)();
679 return (
h->second)();
687 if ( ! methods.empty() ) {
693 }
else if ( cpd ==
"*" ) {
695 }
else if ( cpd ==
"&" ) {
709 else if ( cpd ==
"&" )
711 else if ( cpd ==
"**" )
713 else if ( cpd ==
"*&" || cpd ==
"&*" )
715 else if ( cpd ==
"[]" ) {
731 s <<
"creating executor for unknown type \"" << fullType <<
"\"" << std::ends;
732 PyErr_Warn( PyExc_RuntimeWarning, (
char*)
s.str().c_str() );
739 result = (
h->second)();
746#define PYROOT_EXECUTOR_FACTORY( name ) \
747TExecutor* Create##name##Executor() \
749 return new T##name##Executor; \
807 typedef std::pair< const char*, ExecutorFactory_t > NFp_t;
809 NFp_t factories_[] = {
811 NFp_t(
"bool", &CreateBoolExecutor ),
812 NFp_t(
"bool&", &CreateBoolRefExecutor ),
813 NFp_t(
"const bool&", &CreateBoolConstRefExecutor ),
814 NFp_t(
"char", &CreateCharExecutor ),
815 NFp_t(
"signed char", &CreateCharExecutor ),
816 NFp_t(
"unsigned char", &CreateUCharExecutor ),
817 NFp_t(
"char&", &CreateCharRefExecutor ),
818 NFp_t(
"signed char&", &CreateCharRefExecutor ),
819 NFp_t(
"unsigned char&", &CreateUCharRefExecutor ),
820 NFp_t(
"const char&", &CreateCharConstRefExecutor ),
821 NFp_t(
"const signed char&", &CreateCharConstRefExecutor ),
822 NFp_t(
"const unsigned char&", &CreateUCharConstRefExecutor ),
823 NFp_t(
"short", &CreateShortExecutor ),
824 NFp_t(
"short&", &CreateShortRefExecutor ),
825 NFp_t(
"unsigned short", &CreateIntExecutor ),
826 NFp_t(
"unsigned short&", &CreateUShortRefExecutor ),
827 NFp_t(
"int", &CreateIntExecutor ),
828 NFp_t(
"int&", &CreateIntRefExecutor ),
829 NFp_t(
"unsigned int", &CreateULongExecutor ),
830 NFp_t(
"unsigned int&", &CreateUIntRefExecutor ),
831 NFp_t(
"UInt_t", &CreateULongExecutor ),
832 NFp_t(
"UInt_t&", &CreateUIntRefExecutor ),
833 NFp_t(
"long", &CreateLongExecutor ),
834 NFp_t(
"long&", &CreateLongRefExecutor ),
835 NFp_t(
"unsigned long", &CreateULongExecutor ),
836 NFp_t(
"unsigned long&", &CreateULongRefExecutor ),
837 NFp_t(
"long long", &CreateLongLongExecutor ),
838 NFp_t(
"Long64_t", &CreateLongLongExecutor ),
839 NFp_t(
"long long&", &CreateLongLongRefExecutor ),
840 NFp_t(
"Long64_t&", &CreateLongLongRefExecutor ),
841 NFp_t(
"unsigned long long", &CreateULongLongExecutor ),
842 NFp_t(
"ULong64_t", &CreateULongLongExecutor ),
843 NFp_t(
"unsigned long long&", &CreateULongLongRefExecutor ),
844 NFp_t(
"ULong64_t&", &CreateULongLongRefExecutor ),
846 NFp_t(
"float", &CreateFloatExecutor ),
847 NFp_t(
"float&", &CreateFloatRefExecutor ),
848 NFp_t(
"Float16_t", &CreateFloatExecutor ),
849 NFp_t(
"Float16_t&", &CreateFloatRefExecutor ),
850 NFp_t(
"double", &CreateDoubleExecutor ),
851 NFp_t(
"double&", &CreateDoubleRefExecutor ),
852 NFp_t(
"Double32_t", &CreateDoubleExecutor ),
853 NFp_t(
"Double32_t&", &CreateDoubleRefExecutor ),
854 NFp_t(
"long double", &CreateLongDoubleExecutor ),
855 NFp_t(
"long double&", &CreateLongDoubleRefExecutor ),
856 NFp_t(
"void", &CreateVoidExecutor ),
859 NFp_t(
"void*", &CreateVoidArrayExecutor ),
860 NFp_t(
"bool*", &CreateBoolArrayExecutor ),
861 NFp_t(
"signed char*", &CreateCharArrayExecutor ),
862 NFp_t(
"unsigned char*", &CreateUCharArrayExecutor ),
863 NFp_t(
"short*", &CreateShortArrayExecutor ),
864 NFp_t(
"unsigned short*", &CreateUShortArrayExecutor ),
865 NFp_t(
"int*", &CreateIntArrayExecutor ),
866 NFp_t(
"unsigned int*", &CreateUIntArrayExecutor ),
867 NFp_t(
"UInt_t*", &CreateUIntArrayExecutor ),
868 NFp_t(
"long*", &CreateLongArrayExecutor ),
869 NFp_t(
"unsigned long*", &CreateULongArrayExecutor ),
870 NFp_t(
"Long64_t*", &CreateLongArrayExecutor ),
871 NFp_t(
"ULong64_t*", &CreateULongArrayExecutor ),
872 NFp_t(
"float*", &CreateFloatArrayExecutor ),
873 NFp_t(
"double*", &CreateDoubleArrayExecutor ),
876 NFp_t(
"const char*", &CreateCStringExecutor ),
877 NFp_t(
"char*", &CreateCStringExecutor ),
878 NFp_t(
"std::string", &CreateSTLStringExecutor ),
879 NFp_t(
"string", &CreateSTLStringExecutor ),
880 NFp_t(
"std::string&", &CreateSTLStringRefExecutor ),
881 NFp_t(
"string&", &CreateSTLStringRefExecutor ),
882 NFp_t(
"TGlobal*", &CreateTGlobalExecutor ),
883 NFp_t(
"__init__", &CreateConstructorExecutor ),
884 NFp_t(
"PyObject*", &CreatePyObjectExecutor ),
885 NFp_t(
"_object*", &CreatePyObjectExecutor ),
886 NFp_t(
"FILE*", &CreateVoidArrayExecutor )
889 struct InitExecFactories_t {
891 InitExecFactories_t()
894 int nf =
sizeof( factories_ ) /
sizeof( factories_[ 0 ] );
895 for (
int i = 0; i < nf; ++i ) {
899 } initExecvFactories_;
static PyObject * PyROOT_PyUnicode_FromInt(Int_t c)
#define PYROOT_IMPLEMENT_ARRAY_EXECUTOR(name, type)
static Cppyy::TCppObject_t GILCallO(Cppyy::TCppMethod_t method, Cppyy::TCppObject_t self, PyROOT::TCallContext *ctxt, Cppyy::TCppType_t klass)
PyLong_FromUnsignedLongLong
#define PYROOT_IMPLEMENT_BASIC_REFEXECUTOR(name, type, stype, F1, F2)
static Cppyy::TCppObject_t GILCallConstructor(Cppyy::TCppMethod_t method, Cppyy::TCppType_t klass, PyROOT::TCallContext *ctxt)
#define PYROOT_IMPL_GILCALL(rtype, tcode)
#define PYROOT_EXECUTOR_FACTORY(name)
static PyObject * PyROOT_PyBool_FromInt(Int_t b)
#define PyBytes_AS_STRING
#define PyROOT_PyUnicode_AsString
#define PyROOT_PyUnicode_GET_SIZE
#define PyROOT_PyUnicode_FromString
#define PyBytes_CheckExact
#define PyROOT_PyUnicode_FromStringAndSize
#define PyROOT_PyUnicode_FromFormat
#define R(a, b, c, d, e, f, g, h, i)
unsigned long long ULong64_t
void SetSmartPtr(void *address, Cppyy::TCppType_t ptrType)
virtual PyObject * Execute(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext *)
execute <method> with argument <self, ctxt>, construct TTupleOfInstances from return value
virtual PyObject * Execute(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext *)
smart pointer excutor
virtual PyObject * Execute(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext *)
smart pointer excutor
virtual PyObject * Execute(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext *)
virtual PyObject * Execute(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext *)
execution will bring a temporary in existence
virtual PyObject * Execute(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext *)
execute <method> with argument <self, ctxt>, construct python proxy object return value
virtual PyObject * Execute(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext *)
execute <method> with argument <self, ctxt>, construct python ROOT object return ptr value
virtual PyObject * Execute(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext *)
execute <method> with argument <self, ctxt>, construct python ROOT object (ignoring ref) return ptr v...
virtual PyObject * Execute(Cppyy::TCppMethod_t, Cppyy::TCppObject_t, TCallContext *)
executor binds the result to the left-hand side, overwriting if an old object
PyObject * PyBuffer_FromMemory(Bool_t *buf, Py_ssize_t size=-1)
static TPyBufferFactory * Instance()
virtual Bool_t SetAssignable(PyObject *)
prepare "buffer" for by-ref returns, used with setitem
Global variables class (global variables are obtained from CINT).
TCppObject_t CallConstructor(TCppMethod_t method, TCppType_t type, void *args)
TCppObject_t CallO(TCppMethod_t method, TCppObject_t self, void *args, TCppType_t result_type)
std::string ResolveName(const std::string &cppitem_name)
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)
Bool_t IsSmartPtr(const std::string &)
std::string ResolveEnum(const TEnum *en)
R__EXTERN PyObject * gEmptyString
const std::string Compound(const std::string &name)
Break down the compound of a fully qualified type name.
Py_ssize_t ArraySize(const std::string &name)
Extract size from an array type, if available.
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 ReleasesGIL(UInt_t flags)
TExecutor * CreateExecutor(const std::string &fullType, Bool_t manage_smart_ptr=kTRUE)
PyObject * BindCppGlobal(TGlobal *)
gbl == 0 means global does not exist (rather than gbl is NULL pointer)
ExecFactories_t gExecFactories
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.
std::map< std::string, ExecutorFactory_t > ExecFactories_t
ULong64_t PyLongOrInt_AsULong64(PyObject *pyobject)
Convert <pyobject> to C++ unsigned long long, with bounds checking.
ULong_t PyLongOrInt_AsULong(PyObject *pyobject)
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)
RooArgSet S(const RooAbsArg &v1)
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
std::vector< TParameter > fArgs