34 #if PY_VERSION_HEX >= 0x03030000 35 typedef struct PyDictKeyEntry {
42 typedef struct _dictkeysobject {
47 PyDictKeyEntry dk_entries[1];
50 #define PYROOT_GET_DICT_LOOKUP( mp )\ 51 ((dict_lookup_func&)mp->ma_keys->dk_lookup) 55 #define PYROOT_GET_DICT_LOOKUP( mp )\ 56 ((dict_lookup_func&)mp->ma_lookup) 68 Py_FatalError(
"deallocating nullptr" );
78 #if PY_VERSION_HEX < 0x03000000 84 #
if PY_VERSION_HEX < 0x03000000
88 #
if PY_VERSION_HEX < 0x03000000
92 #
if PY_VERSION_HEX < 0x03000000
96 #
if PY_VERSION_HEX >= 0x02020000
98 #
if PY_VERSION_HEX < 0x03000000
105 #
if PY_VERSION_HEX >= 0x02050000
120 (hashfunc)_Py_HashPointer,
121 0, 0, 0, 0, 0, Py_TPFLAGS_DEFAULT, 0, 0, 0, 0, 0, 0, 0,
122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
123 #if PY_VERSION_HEX >= 0x02030000 126 #if PY_VERSION_HEX >= 0x02060000 129 #if PY_VERSION_HEX >= 0x03040000 142 std::vector<std::pair<Cppyy::TCppType_t, Cppyy::TCppType_t> >
gPinnedTypes;
157 Py_INCREF( Py_None );
166 const char* cname = 0;
long macro_ok = 0;
169 else if ( ! ( args && PyArg_ParseTuple( args, const_cast< char* >(
"s|l" ), &cname, ¯o_ok ) ) )
174 PyErr_Format( PyExc_AttributeError,
"%s", cname );
178 std::string
name = cname;
181 if ( name.size() <= 2 || name.substr( 0, 2 ) !=
"__" ) {
207 Py_INCREF( &PyInt_Type );
214 std::ostringstream ismacro;
215 ismacro <<
"#ifdef " << name <<
"\n_pyroot_" << name <<
"=" << name
216 <<
";true;\n#else\nfalse;\n#endif";
217 if (
gROOT->ProcessLine( ismacro.str().c_str() ) ) {
227 PyErr_Format( PyExc_AttributeError,
"%s", name.c_str() );
233 #if PY_VERSION_HEX >= 0x03030000 234 inline PyDictKeyEntry* OrgDictLookup(
240 #define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\ 241 OrgDictLookup( mp, key, hash, value_addr ) 243 PyDictKeyEntry* RootLookDictString(
246 inline PyDictEntry* OrgDictLookup( PyDictObject* mp,
PyObject* key,
Long_t hash )
251 #define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\ 252 OrgDictLookup( mp, key, hash ) 254 PyDictEntry* RootLookDictString( PyDictObject* mp,
PyObject* key,
Long_t hash )
263 if ( PyDict_GetItem( PyEval_GetBuiltins(), key ) != 0 ) {
277 #if PY_VERSION_HEX >= 0x03030000 285 PyObject* val = LookupCppEntity( key, 0 );
302 if ( PyDict_SetItem( (
PyObject*)mp, key, val ) == 0 ) {
315 #if PY_VERSION_HEX >= 0x03030000 316 if ( mp->ma_keys->dk_usable <= 0 ) {
321 const int maxinsert = 5;
323 for (
int varmax = 1; varmax <= maxinsert; ++varmax ) {
324 for (
int ivar = 0; ivar < varmax; ++ivar ) {
326 PyDict_SetItem( (
PyObject*)mp, buf[ivar], Py_None);
328 for (
int ivar = 0; ivar < varmax; ++ivar ) {
329 PyDict_DelItem( (
PyObject*)mp, buf[ivar] );
330 Py_DECREF( buf[ivar] );
332 if ( 0 < mp->ma_keys->dk_usable )
358 PyDictObject* dict = 0;
359 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!" ), &PyDict_Type, &dict ) )
370 Py_INCREF( Py_None );
382 PyErr_Format( PyExc_TypeError,
"too few arguments for template instantiation" );
404 if ( PyArg_ParseTuple( args, const_cast< char* >(
"O|O!" ), &pyobj,
419 Py_XDECREF( pyclass );
423 void* addr = (
void*)pyprop->
GetAddress( pyobj );
428 Py_XDECREF( pyprop );
430 PyErr_Format( PyExc_TypeError,
439 PyErr_SetString( PyExc_ValueError,
"invalid argument for AddressOf()" );
448 if ( !PyErr_Occurred() ) {
449 PyObject* str = PyObject_Str( dummy );
453 PyErr_Format( PyExc_ValueError,
"unknown object at %p", (
void*)dummy );
462 void* addr = GetObjectProxyAddress( dummy, args );
464 return BufFac_t::Instance()->PyBuffer_FromMemory( (
Long_t*)addr,
sizeof(
Long_t) );
465 if ( ! addr && PyTuple_Size( args ) ) {
468 return BufFac_t::Instance()->PyBuffer_FromMemory( (
Long_t*)&addr,
sizeof(
Long_t) );
476 void* addr = GetObjectProxyAddress( dummy, args );
478 return PyLong_FromLong( *(
Long_t*)addr );
479 else if ( PyTuple_Size( args ) ) {
482 if ( addr )
return PyLong_FromLong( (
Long_t)addr );
484 return _addressof_common( dummy );
490 void* addr = GetObjectProxyAddress( dummy, args );
507 pyname = PyObject_Str( pyname );
517 PyErr_SetString( PyExc_TypeError,
518 "BindObject expects a valid class or class name as an argument" );
532 PyErr_Format( PyExc_TypeError,
538 PyObject* pyaddr = PyTuple_GET_ITEM( args, 0 );
540 if ( PyErr_Occurred() ) {
543 addr = PyLong_AsVoidPtr( pyaddr );
544 if ( PyErr_Occurred() ) {
549 if ( ! addr || ! buflen ) {
550 PyErr_SetString( PyExc_TypeError,
551 "BindObject requires a CObject or long integer as first argument" );
557 return BindObject_( addr, PyTuple_GET_ITEM( args, 1 ) );
567 if ( argc != 0 && argc != 1 ) {
568 PyErr_Format( PyExc_TypeError,
569 "MakeNullPointer takes at most 1 argument (" PY_SSIZE_T_FORMAT " given)", argc );
575 Py_INCREF( Py_None );
579 return BindObject_( 0, PyTuple_GET_ITEM( args, 0 ) );
588 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!O!:__expand__" ),
595 PyObject* mod = PyImport_ImportModule( (
char*)
"ROOT" );
597 PyObject* dummy = PyObject_GetAttrString( mod, (
char*)
"kRed" );
605 if ( strcmp( clname,
"TBufferFile" ) == 0 ) {
634 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!" ), &PyInt_Type, &policy ) )
637 Long_t l = PyInt_AS_LONG( policy );
639 Py_INCREF( Py_None );
643 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld", l );
654 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!" ), &PyInt_Type, &policy ) )
657 Long_t l = PyInt_AS_LONG( policy );
659 Py_INCREF( Py_None );
663 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld", l );
673 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!O!" ),
677 (
Bool_t)PyLong_AsLong( pykeep ) ? pyobj->
HoldOn() : pyobj->Release();
679 Py_INCREF( Py_None );
688 const char* type_name;
689 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"s" ), &type_name ) )
705 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!O!" ),
720 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!" ),
735 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!O!" ),
751 METH_VARARGS, (
char*)
"PyROOT internal function" },
753 METH_VARARGS, (
char*)
"PyROOT internal function" },
754 { (
char*)
"LookupCppEntity", (PyCFunction)LookupCppEntity,
755 METH_VARARGS, (
char*)
"PyROOT internal function" },
756 { (
char*)
"SetRootLazyLookup", (PyCFunction)SetRootLazyLookup,
757 METH_VARARGS, (
char*)
"PyROOT internal function" },
758 { (
char*)
"MakeRootTemplateClass", (PyCFunction)MakeRootTemplateClass,
759 METH_VARARGS, (
char*)
"PyROOT internal function" },
761 METH_NOARGS, (
char*)
"PyROOT internal function" },
762 { (
char*)
"_ResetRootModule", (PyCFunction)RootModuleResetCallback,
763 METH_NOARGS, (
char*)
"PyROOT internal function" },
764 { (
char*)
"AddressOf", (PyCFunction)AddressOf,
765 METH_VARARGS, (
char*)
"Retrieve address of held object in a buffer" },
766 { (
char*)
"addressof", (PyCFunction)addressof,
767 METH_VARARGS, (
char*)
"Retrieve address of held object as a value" },
768 { (
char*)
"AsCObject", (PyCFunction)AsCObject,
769 METH_VARARGS, (
char*)
"Retrieve held object in a CObject" },
770 { (
char*)
"BindObject", (PyCFunction)BindObject,
771 METH_VARARGS, (
char*)
"Create an object of given type, from given address" },
772 { (
char*)
"MakeNullPointer", (PyCFunction)MakeNullPointer,
773 METH_VARARGS, (
char*)
"Create a NULL pointer of the given type" },
774 { (
char*)
"_ObjectProxy__expand__", (PyCFunction)ObjectProxyExpand,
775 METH_VARARGS, (
char*)
"Helper method for pickling" },
776 { (
char*)
"SetMemoryPolicy", (PyCFunction)SetMemoryPolicy,
777 METH_VARARGS, (
char*)
"Determines object ownership model" },
778 { (
char*)
"SetSignalPolicy", (PyCFunction)SetSignalPolicy,
779 METH_VARARGS, (
char*)
"Trap signals in safe mode to prevent interpreter abort" },
780 { (
char*)
"SetOwnership", (PyCFunction)SetOwnership,
781 METH_VARARGS, (
char*)
"Modify held C++ object ownership" },
783 METH_VARARGS, (
char*)
"Add a smart pointer to the list of known smart pointer types" },
785 METH_NOARGS, (
char*)
"Install input hook to sent GUI events" },
787 METH_NOARGS, (
char*)
"Remove input hook to sent GUI events" },
788 { (
char*)
"SetTypePinning", (PyCFunction)SetTypePinning,
789 METH_VARARGS, (
char*)
"Install a type pinning" },
790 { (
char*)
"IgnoreTypePinning", (PyCFunction)IgnoreTypePinning,
791 METH_VARARGS, (
char*)
"Don't pin the given type" },
792 { (
char*)
"Cast", (PyCFunction)Cast,
793 METH_VARARGS, (
char*)
"Cast the given object to the given type" },
798 #if PY_VERSION_HEX >= 0x03000000 799 struct module_state {
803 #define GETSTATE(m) ((struct module_state*)PyModule_GetState(m)) 805 static int rootmodule_traverse(
PyObject*
m, visitproc visit,
void* arg )
807 Py_VISIT( GETSTATE( m )->error );
811 static int rootmodule_clear(
PyObject* m )
813 Py_CLEAR( GETSTATE( m )->error );
818 static struct PyModuleDef moduledef = {
819 PyModuleDef_HEAD_INIT,
822 sizeof(
struct module_state),
833 #define PYROOT_INIT_ERROR return NULL 834 extern "C" PyObject* PyInit_libPyROOT()
836 #define PYROOT_INIT_ERROR return 848 #if PY_VERSION_HEX >= 0x03030000 856 #if PY_VERSION_HEX >= 0x03000000 859 gRootModule = Py_InitModule( const_cast< char* >(
"libPyROOT" ), gPyROOTMethods );
868 PyObject* userPythonizations = PyDict_New();
869 PyObject* gblList = PyList_New( 0 );
870 PyDict_SetItemString( userPythonizations,
"__global__", gblList );
871 Py_DECREF( gblList );
872 PyModule_AddObject(
gRootModule,
"UserPythonizations", userPythonizations );
873 PyModule_AddObject(
gRootModule,
"UserExceptions", PyDict_New() );
924 PyModule_AddObject(
gRootModule, (
char*)
"kMemoryHeuristics",
925 PyInt_FromLong( (
int)TCallContext::kUseHeuristics ) );
926 PyModule_AddObject(
gRootModule, (
char*)
"kMemoryStrict",
927 PyInt_FromLong( (
int)TCallContext::kUseStrict ) );
928 PyModule_AddObject(
gRootModule, (
char*)
"kSignalFast",
929 PyInt_FromLong( (
int)TCallContext::kFast ) );
930 PyModule_AddObject(
gRootModule, (
char*)
"kSignalSafe",
931 PyInt_FromLong( (
int)TCallContext::kSafe ) );
937 TCallContext::SetSignalPolicy(
gROOT->IsBatch() ? TCallContext::kFast : TCallContext::kSafe );
942 #if PY_VERSION_HEX >= 0x03000000
#define PyBytes_FromString
Bool_t InitProxy(PyObject *module, PyTypeObject *pytype, const char *name)
Initialize a proxy class for use by python, and add it to the ROOT module.
#define PyROOT_PyUnicode_FromString
PyDictEntry *(* dict_lookup_func)(PyDictObject *, PyObject *, Long_t)
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket...
R__EXTERN PyObject * gDict
PyObject * RemoveGUIEventInputHook()
static void nullptr_dealloc(PyObject *)
PyTypeObject TTupleOfInstances_Type
Representation of C-style array of instances.
static PyTypeObject PyNullPtr_t_Type
PyTypeObject PropertyProxy_Type
R__EXTERN dict_lookup_func gDictLookupOrg
static PyObject * nullptr_repr(PyObject *)
PyObject * BuildTemplateName(PyObject *pyname, PyObject *args, int argoff)
Helper to construct the "< type, type, ... >" part of a templated name (either for a class as in Make...
virtual void * ReadObjectAny(const TClass *cast)
Read object from I/O buffer.
#define PYROOT_INIT_ERROR
static PyMethodDef gPyROOTMethods[]
static int nullptr_nonzero(PyObject *)
R__EXTERN Bool_t gDictLookupActive
#define PyVarObject_HEAD_INIT(type, size)
#define PY_SSIZE_T_FORMAT
#define PyROOT_PyUnicode_FromFormat
void * GetAddress(ObjectProxy *pyobj)
class attributes, global properties
std::vector< Cppyy::TCppType_t > gIgnorePinnings
R__EXTERN PyObject * gRootModule
PyObject * GetCppGlobal(const std::string &name)
try named global variable/enum (first ROOT, then Cling: sync is too slow)
PyTypeObject TCustomInt_Type
#define PyROOT_PyUnicode_Type
#define PyROOT_PyUnicode_AsString
Bool_t PropertyProxy_Check(T *object)
static PyNumberMethods nullptr_as_number
R__EXTERN PyObject * gNullPtrObject
PyTypeObject PyRootType_Type
PyTypeObject ObjectProxy_Type
void AddSmartPtrType(const std::string &)
Bool_t ObjectProxy_Check(T *object)
R__EXTERN PyObject * gClass
std::vector< std::pair< Cppyy::TCppType_t, Cppyy::TCppType_t > > gPinnedTypes
#define PYROOT_GET_DICT_LOOKUP(mp)
PyObject * DestroyPyStrings()
Remove all cached python strings.
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)
PyTypeObject MethodProxy_Type
PyTypeObject TemplateProxy_Type
Type object to hold TClassRef instance (this is only semantically a presentation of PyRootType instan...
PyObject * CreateScopeProxy(Cppyy::TCppScope_t)
Convenience function with a lookup first through the known existing proxies.
PyObject * InstallGUIEventInputHook()
TCppScope_t GetScope(const std::string &scope_name)
R__EXTERN PyObject * gName
PyTypeObject TCustomInstanceMethod_Type
static RooMathCoreReg dummy
#define PyROOT_PyUnicode_Check
Cppyy::TCppType_t fCppType
static void * PyROOT_PyCapsule_GetPointer(PyObject *capsule, const char *)
R__EXTERN PyObject * gCppName
Mother of all ROOT objects.
#define PyROOT_PyUnicode_CheckExact
PyObject_HEAD void * fObject
PyObject _PyROOT_NullPtrStruct
int GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, Bool_t check=kTRUE)
Retrieve a linear buffer pointer from the given pyobject.
virtual void WriteFastArray(const Bool_t *b, Int_t n)
Write array of n bools into the I/O buffer.
Bool_t PropertyProxy_CheckExact(T *object)
PyTypeObject TCustomFloat_Type
Custom builtins, detectable by type, for pass by ref.
static PyObject * PyROOT_PyCapsule_New(void *cobj, const char *, void(*destr)(void *))
virtual const char * GetName() const
Returns name of object.
#define PyBytes_AS_STRING
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)
#define PYROOT_ORGDICT_LOOKUP(mp, key, hash, value_addr)