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
108#
if PY_VERSION_HEX >= 0x03050000
115#if !defined(_MSC_VER)
116#pragma GCC diagnostic push
117#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
130 (hashfunc)_Py_HashPointer,
131 0, 0, 0, 0, 0, Py_TPFLAGS_DEFAULT, 0, 0, 0, 0, 0, 0, 0,
132 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
133#if PY_VERSION_HEX >= 0x02030000
136#if PY_VERSION_HEX >= 0x02060000
139#if PY_VERSION_HEX >= 0x03040000
142#if PY_VERSION_HEX >= 0x03080000
144#if PY_VERSION_HEX < 0x03090000
150#if !defined(_MSC_VER)
151#pragma GCC diagnostic pop
162 std::vector<std::pair<Cppyy::TCppType_t, Cppyy::TCppType_t> >
gPinnedTypes;
177 Py_INCREF( Py_None );
186 const char* cname = 0;
long macro_ok = 0;
189 else if ( ! ( args && PyArg_ParseTuple( args,
const_cast< char*
>(
"s|l" ), &cname, ¯o_ok ) ) )
194 PyErr_Format( PyExc_AttributeError,
"%s", cname );
198 std::string
name = cname;
201 if (
name.size() <= 2 ||
name.substr( 0, 2 ) !=
"__" ) {
244 Py_DECREF(cppnamepy);
248 Py_INCREF(&PyInt_Type);
249 PyTuple_SET_ITEM(pybases, 0, (
PyObject*)&PyInt_Type);
250 PyObject* argsnt = Py_BuildValue((
char*)
"sOO",
name.c_str(), pybases, dct);
251 attr =
Py_TYPE(&PyInt_Type)->tp_new(
Py_TYPE(&PyInt_Type), argsnt,
nullptr);
257 Py_INCREF(&PyInt_Type);
266 std::ostringstream ismacro;
267 ismacro <<
"#ifdef " <<
name <<
"\n_pyroot_" <<
name <<
"=" <<
name
268 <<
";true;\n#else\nfalse;\n#endif";
269 if (
gROOT->ProcessLine( ismacro.str().c_str() ) ) {
279 PyErr_Format( PyExc_AttributeError,
"%s",
name.c_str() );
285#if PY_VERSION_HEX >= 0x03030000
286 inline PyDictKeyEntry* OrgDictLookup(
292#define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\
293 OrgDictLookup( mp, key, hash, value_addr )
295 PyDictKeyEntry* RootLookDictString(
298 inline PyDictEntry* OrgDictLookup( PyDictObject* mp,
PyObject* key,
Long_t hash )
303#define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\
304 OrgDictLookup( mp, key, hash )
306 PyDictEntry* RootLookDictString( PyDictObject* mp,
PyObject* key,
Long_t hash )
315 if ( PyDict_GetItem( PyEval_GetBuiltins(), key ) != 0 ) {
329#if PY_VERSION_HEX >= 0x03030000
337 PyObject* val = LookupCppEntity( key, 0 );
354 if ( PyDict_SetItem( (
PyObject*)mp, key, val ) == 0 ) {
367#if PY_VERSION_HEX >= 0x03030000
368 if ( mp->ma_keys->dk_usable <= 0 ) {
373 const int maxinsert = 5;
375 for (
int varmax = 1; varmax <= maxinsert; ++varmax ) {
376 for (
int ivar = 0; ivar < varmax; ++ivar ) {
378 PyDict_SetItem( (
PyObject*)mp, buf[ivar], Py_None);
380 for (
int ivar = 0; ivar < varmax; ++ivar ) {
381 PyDict_DelItem( (
PyObject*)mp, buf[ivar] );
382 Py_DECREF( buf[ivar] );
384 if ( 0 < mp->ma_keys->dk_usable )
410 PyDictObject* dict = 0;
411 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ), &PyDict_Type, &dict ) )
422 Py_INCREF( Py_None );
434 PyErr_Format( PyExc_TypeError,
"too few arguments for template instantiation" );
456 if ( PyArg_ParseTuple( args,
const_cast< char*
>(
"O|O!" ), &pyobj,
471 Py_XDECREF( pyclass );
475 void* addr = (
void*)pyprop->
GetAddress( pyobj );
480 Py_XDECREF( pyprop );
482 PyErr_Format( PyExc_TypeError,
491 PyErr_SetString( PyExc_ValueError,
"invalid argument for AddressOf()" );
500 if ( !PyErr_Occurred() ) {
505 PyErr_Format( PyExc_ValueError,
"unknown object at %p", (
void*)
dummy );
514 void* addr = GetObjectProxyAddress(
dummy, args );
516 return BufFac_t::Instance()->PyBuffer_FromMemory( (
Long_t*)addr,
sizeof(
Long_t) );
517 if ( ! addr && PyTuple_Size( args ) ) {
520 return BufFac_t::Instance()->PyBuffer_FromMemory( (
Long_t*)&addr,
sizeof(
Long_t) );
528 void* addr = GetObjectProxyAddress(
dummy, args );
530 return PyLong_FromLong( *(
Long_t*)addr );
531 else if ( PyTuple_Size( args ) ) {
534 if ( addr )
return PyLong_FromLong( (
Long_t)addr );
536 return _addressof_common(
dummy );
542 void* addr = GetObjectProxyAddress(
dummy, args );
569 PyErr_SetString( PyExc_TypeError,
570 "BindObject expects a valid class or class name as an argument" );
584 PyErr_Format( PyExc_TypeError,
590 PyObject* pyaddr = PyTuple_GET_ITEM( args, 0 );
592 if ( PyErr_Occurred() ) {
595 addr = PyLong_AsVoidPtr( pyaddr );
596 if ( PyErr_Occurred() ) {
601 if ( ! addr || ! buflen ) {
602 PyErr_SetString( PyExc_TypeError,
603 "BindObject requires a CObject or long integer as first argument" );
609 return BindObject_( addr, PyTuple_GET_ITEM( args, 1 ) );
619 if ( argc != 0 && argc != 1 ) {
620 PyErr_Format( PyExc_TypeError,
621 "MakeNullPointer takes at most 1 argument (" PY_SSIZE_T_FORMAT " given)", argc );
627 Py_INCREF( Py_None );
631 return BindObject_( 0, PyTuple_GET_ITEM( args, 0 ) );
640 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!:__expand__" ),
647 PyObject* mod = PyImport_ImportModule( (
char*)
"ROOT" );
649 PyObject*
dummy = PyObject_GetAttrString( mod, (
char*)
"kRed" );
657 if ( strcmp( clname,
"TBufferFile" ) == 0 ) {
686 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ), &PyInt_Type, &policy ) )
689 Long_t l = PyInt_AS_LONG( policy );
691 Py_INCREF( Py_None );
695 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld",
l );
706 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ), &PyInt_Type, &policy ) )
709 Long_t l = PyInt_AS_LONG( policy );
711 Py_INCREF( Py_None );
715 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld",
l );
725 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!" ),
729 (
Bool_t)PyLong_AsLong( pykeep ) ? pyobj->
HoldOn() : pyobj->Release();
731 Py_INCREF( Py_None );
740 const char* type_name;
741 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"s" ), &type_name ) )
757 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!" ),
772 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ),
787 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!" ),
803 METH_VARARGS, (
char*)
"PyROOT internal function" },
805 METH_VARARGS, (
char*)
"PyROOT internal function" },
806 { (
char*)
"LookupCppEntity", (PyCFunction)LookupCppEntity,
807 METH_VARARGS, (
char*)
"PyROOT internal function" },
808 { (
char*)
"SetRootLazyLookup", (PyCFunction)SetRootLazyLookup,
809 METH_VARARGS, (
char*)
"PyROOT internal function" },
810 { (
char*)
"MakeRootTemplateClass", (PyCFunction)MakeRootTemplateClass,
811 METH_VARARGS, (
char*)
"PyROOT internal function" },
813 METH_NOARGS, (
char*)
"PyROOT internal function" },
814 { (
char*)
"_ResetRootModule", (PyCFunction)RootModuleResetCallback,
815 METH_NOARGS, (
char*)
"PyROOT internal function" },
817 METH_NOARGS, (
char*)
"PyROOT internal function" },
818 { (
char*)
"AddressOf", (PyCFunction)AddressOf,
819 METH_VARARGS, (
char*)
"Retrieve address of held object in a buffer" },
820 { (
char*)
"addressof", (PyCFunction)addressof,
821 METH_VARARGS, (
char*)
"Retrieve address of held object as a value" },
822 { (
char*)
"AsCObject", (PyCFunction)AsCObject,
823 METH_VARARGS, (
char*)
"Retrieve held object in a CObject" },
824 { (
char*)
"as_cobject", (PyCFunction)AsCObject,
825 METH_VARARGS, (
char*)
"Retrieve held object in a CObject" },
826 { (
char*)
"BindObject", (PyCFunction)BindObject,
827 METH_VARARGS, (
char*)
"Create an object of given type, from given address" },
828 { (
char*)
"bind_object", (PyCFunction)BindObject,
829 METH_VARARGS, (
char*)
"Create an object of given type, from given address" },
830 { (
char*)
"MakeNullPointer", (PyCFunction)MakeNullPointer,
831 METH_VARARGS, (
char*)
"Create a NULL pointer of the given type" },
832 { (
char*)
"_ObjectProxy__expand__", (PyCFunction)ObjectProxyExpand,
833 METH_VARARGS, (
char*)
"Helper method for pickling" },
834 { (
char*)
"SetMemoryPolicy", (PyCFunction)SetMemoryPolicy,
835 METH_VARARGS, (
char*)
"Determines object ownership model" },
836 { (
char*)
"SetSignalPolicy", (PyCFunction)SetSignalPolicy,
837 METH_VARARGS, (
char*)
"Trap signals in safe mode to prevent interpreter abort" },
838 { (
char*)
"SetOwnership", (PyCFunction)SetOwnership,
839 METH_VARARGS, (
char*)
"Modify held C++ object ownership" },
841 METH_VARARGS, (
char*)
"Add a smart pointer to the list of known smart pointer types" },
843 METH_NOARGS, (
char*)
"Install input hook to sent GUI events" },
845 METH_NOARGS, (
char*)
"Remove input hook to sent GUI events" },
846 { (
char*)
"SetTypePinning", (PyCFunction)SetTypePinning,
847 METH_VARARGS, (
char*)
"Install a type pinning" },
848 { (
char*)
"IgnoreTypePinning", (PyCFunction)IgnoreTypePinning,
849 METH_VARARGS, (
char*)
"Don't pin the given type" },
850 { (
char*)
"Cast", (PyCFunction)Cast,
851 METH_VARARGS, (
char*)
"Cast the given object to the given type" },
852 { NULL, NULL, 0, NULL }
856#if PY_VERSION_HEX >= 0x03000000
861#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
863static int rootmodule_traverse(
PyObject*
m, visitproc visit,
void* arg )
865 Py_VISIT( GETSTATE(
m )->error );
869static int rootmodule_clear(
PyObject*
m )
871 Py_CLEAR( GETSTATE(
m )->error );
876static struct PyModuleDef moduledef = {
877 PyModuleDef_HEAD_INIT,
880 sizeof(
struct module_state),
891#define PYROOT_INIT_ERROR return NULL
892extern "C" PyObject* PyInit_libPyROOT()
894#define PYROOT_INIT_ERROR return
906#if PY_VERSION_HEX >= 0x03030000
914#if PY_VERSION_HEX >= 0x03000000
926 PyObject* userPythonizations = PyDict_New();
927 PyObject* gblList = PyList_New( 0 );
928 PyDict_SetItemString( userPythonizations,
"__global__", gblList );
929 Py_DECREF( gblList );
930 PyModule_AddObject(
gRootModule,
"UserPythonizations", userPythonizations );
931 PyModule_AddObject(
gRootModule,
"UserExceptions", PyDict_New() );
982 PyModule_AddObject(
gRootModule, (
char*)
"kMemoryHeuristics",
983 PyInt_FromLong( (
int)TCallContext::kUseHeuristics ) );
984 PyModule_AddObject(
gRootModule, (
char*)
"kMemoryStrict",
985 PyInt_FromLong( (
int)TCallContext::kUseStrict ) );
986 PyModule_AddObject(
gRootModule, (
char*)
"kSignalFast",
987 PyInt_FromLong( (
int)TCallContext::kFast ) );
988 PyModule_AddObject(
gRootModule, (
char*)
"kSignalSafe",
989 PyInt_FromLong( (
int)TCallContext::kSafe ) );
995 TCallContext::SetSignalPolicy(
gROOT->IsBatch() ? TCallContext::kFast : TCallContext::kSafe );
1000#if PY_VERSION_HEX >= 0x03000000
#define PyBytes_AS_STRING
#define PyBytes_FromString
#define PY_SSIZE_T_FORMAT
#define PyROOT_PyUnicode_Check
#define PyROOT_PyUnicode_AsString
static void * PyROOT_PyCapsule_GetPointer(PyObject *capsule, const char *)
PyDictEntry *(* dict_lookup_func)(PyDictObject *, PyObject *, Long_t)
static PyObject * PyROOT_PyCapsule_New(void *cobj, const char *, void(*destr)(void *))
#define PyROOT_PyUnicode_FromString
#define PyROOT_PyUnicode_FromFormat
#define PyROOT_PyUnicode_Type
#define PyROOT_PyUnicode_CheckExact
#define PyVarObject_HEAD_INIT(type, size)
static RooMathCoreReg dummy
PyObject _PyROOT_NullPtrStruct
static PyObject * nullptr_repr(PyObject *)
#define PYROOT_INIT_ERROR
static PyNumberMethods nullptr_as_number
#define PYROOT_GET_DICT_LOOKUP(mp)
static void nullptr_dealloc(PyObject *)
static int nullptr_nonzero(PyObject *)
#define PYROOT_ORGDICT_LOOKUP(mp, key, hash, value_addr)
static PyTypeObject PyNullPtr_t_Type
static PyMethodDef gPyROOTMethods[]
PyObject_HEAD void * fObject
void * GetAddress(ObjectProxy *pyobj)
class attributes, global properties
Type object to hold TClassRef instance (this is only semantically a presentation of PyRootType instan...
Cppyy::TCppType_t fCppType
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
void * ReadObjectAny(const TClass *cast) override
Read object from I/O buffer.
void WriteFastArray(const Bool_t *b, Int_t n) override
Write array of n bools into the I/O buffer.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
void AddSmartPtrType(const std::string &)
long long GetEnumDataValue(TCppEnum_t, TCppIndex_t idata)
Bool_t IsEnum(const std::string &type_name)
std::string GetEnumDataName(TCppEnum_t, TCppIndex_t idata)
TCppScope_t GetScope(const std::string &scope_name)
TCppEnum_t GetEnum(TCppScope_t scope, const std::string &enum_name)
TCppIndex_t GetNumEnumData(TCppEnum_t)
R__EXTERN PyObject * gClass
R__EXTERN PyObject * gName
R__EXTERN PyObject * gDict
R__EXTERN PyObject * gCppNameNew
R__EXTERN PyObject * gCppName
PyObject * RemoveGUIEventInputHook()
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.
PyObject * InstallGUIEventInputHook()
int GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, Bool_t check=kTRUE)
Retrieve a linear buffer pointer from the given pyobject.
PyObject * BuildTemplateName(PyObject *pyname, PyObject *tpArgs, int argoff, PyObject *args=nullptr, ArgPreference=kNone, int *pcnt=nullptr, bool inferredTypes=false)
Helper to construct the "< type, type, ... >" part of a templated name (either for a class as in Make...
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)
PyTypeObject PyRootType_Type
R__EXTERN dict_lookup_func gDictLookupOrg
Bool_t ObjectProxy_Check(T *object)
PyObject * DestroyPyStrings()
Remove all cached python strings.
PyTypeObject ObjectProxy_Type
PyTypeObject TCustomInstanceMethod_Type
PyObject * CreateScopeProxy(Cppyy::TCppScope_t)
Convenience function with a lookup first through the known existing proxies.
R__EXTERN Bool_t gDictLookupActive
PyTypeObject TemplateProxy_Type
std::vector< Cppyy::TCppType_t > gIgnorePinnings
PyTypeObject TTupleOfInstances_Type
Representation of C-style array of instances.
Bool_t PropertyProxy_CheckExact(T *object)
std::vector< std::pair< Cppyy::TCppType_t, Cppyy::TCppType_t > > gPinnedTypes
PyTypeObject MethodProxy_Type
R__EXTERN PyObject * gNullPtrObject
PyTypeObject TCustomInt_Type
R__EXTERN PyObject * gRootModule
PyTypeObject TCustomFloat_Type
Custom builtins, detectable by type, for pass by ref.
PyObject * GetCppGlobal(const std::string &name)
try named global variable/enum (first ROOT, then Cling: sync is too slow)
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 PropertyProxy_Check(T *object)
PyTypeObject PropertyProxy_Type
PyObject * ClearProxiedObjects()
Delete all memory-regulated objects.