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
125 (hashfunc)_Py_HashPointer,
126 0, 0, 0, 0, 0, Py_TPFLAGS_DEFAULT, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
128#if PY_VERSION_HEX >= 0x02030000
131#if PY_VERSION_HEX >= 0x02060000
134#if PY_VERSION_HEX >= 0x03040000
147 std::vector<std::pair<Cppyy::TCppType_t, Cppyy::TCppType_t> >
gPinnedTypes;
162 Py_INCREF( Py_None );
171 const char* cname = 0;
long macro_ok = 0;
174 else if ( ! ( args && PyArg_ParseTuple( args,
const_cast< char*
>(
"s|l" ), &cname, ¯o_ok ) ) )
179 PyErr_Format( PyExc_AttributeError,
"%s", cname );
183 std::string
name = cname;
186 if (
name.size() <= 2 ||
name.substr( 0, 2 ) !=
"__" ) {
227 Py_DECREF(cppnamepy);
231 Py_INCREF(&PyInt_Type);
232 PyTuple_SET_ITEM(pybases, 0, (
PyObject*)&PyInt_Type);
233 PyObject* argsnt = Py_BuildValue((
char*)
"sOO",
name.c_str(), pybases, dct);
234 attr =
Py_TYPE(&PyInt_Type)->tp_new(
Py_TYPE(&PyInt_Type), argsnt,
nullptr);
240 Py_INCREF(&PyInt_Type);
249 std::ostringstream ismacro;
250 ismacro <<
"#ifdef " <<
name <<
"\n_pyroot_" <<
name <<
"=" <<
name
251 <<
";true;\n#else\nfalse;\n#endif";
252 if (
gROOT->ProcessLine( ismacro.str().c_str() ) ) {
262 PyErr_Format( PyExc_AttributeError,
"%s",
name.c_str() );
268#if PY_VERSION_HEX >= 0x03030000
269 inline PyDictKeyEntry* OrgDictLookup(
275#define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\
276 OrgDictLookup( mp, key, hash, value_addr )
278 PyDictKeyEntry* RootLookDictString(
281 inline PyDictEntry* OrgDictLookup( PyDictObject* mp,
PyObject* key,
Long_t hash )
286#define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\
287 OrgDictLookup( mp, key, hash )
289 PyDictEntry* RootLookDictString( PyDictObject* mp,
PyObject* key,
Long_t hash )
298 if ( PyDict_GetItem( PyEval_GetBuiltins(), key ) != 0 ) {
312#if PY_VERSION_HEX >= 0x03030000
320 PyObject* val = LookupCppEntity( key, 0 );
337 if ( PyDict_SetItem( (
PyObject*)mp, key, val ) == 0 ) {
350#if PY_VERSION_HEX >= 0x03030000
351 if ( mp->ma_keys->dk_usable <= 0 ) {
356 const int maxinsert = 5;
358 for (
int varmax = 1; varmax <= maxinsert; ++varmax ) {
359 for (
int ivar = 0; ivar < varmax; ++ivar ) {
361 PyDict_SetItem( (
PyObject*)mp, buf[ivar], Py_None);
363 for (
int ivar = 0; ivar < varmax; ++ivar ) {
364 PyDict_DelItem( (
PyObject*)mp, buf[ivar] );
365 Py_DECREF( buf[ivar] );
367 if ( 0 < mp->ma_keys->dk_usable )
393 PyDictObject* dict = 0;
394 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ), &PyDict_Type, &dict ) )
405 Py_INCREF( Py_None );
417 PyErr_Format( PyExc_TypeError,
"too few arguments for template instantiation" );
439 if ( PyArg_ParseTuple( args,
const_cast< char*
>(
"O|O!" ), &pyobj,
454 Py_XDECREF( pyclass );
458 void* addr = (
void*)pyprop->
GetAddress( pyobj );
463 Py_XDECREF( pyprop );
465 PyErr_Format( PyExc_TypeError,
474 PyErr_SetString( PyExc_ValueError,
"invalid argument for AddressOf()" );
483 if ( !PyErr_Occurred() ) {
488 PyErr_Format( PyExc_ValueError,
"unknown object at %p", (
void*)
dummy );
497 void* addr = GetObjectProxyAddress(
dummy, args );
499 return BufFac_t::Instance()->PyBuffer_FromMemory( (
Long_t*)addr,
sizeof(
Long_t) );
500 if ( ! addr && PyTuple_Size( args ) ) {
503 return BufFac_t::Instance()->PyBuffer_FromMemory( (
Long_t*)&addr,
sizeof(
Long_t) );
511 void* addr = GetObjectProxyAddress(
dummy, args );
513 return PyLong_FromLong( *(
Long_t*)addr );
514 else if ( PyTuple_Size( args ) ) {
517 if ( addr )
return PyLong_FromLong( (
Long_t)addr );
519 return _addressof_common(
dummy );
525 void* addr = GetObjectProxyAddress(
dummy, args );
552 PyErr_SetString( PyExc_TypeError,
553 "BindObject expects a valid class or class name as an argument" );
567 PyErr_Format( PyExc_TypeError,
573 PyObject* pyaddr = PyTuple_GET_ITEM( args, 0 );
575 if ( PyErr_Occurred() ) {
578 addr = PyLong_AsVoidPtr( pyaddr );
579 if ( PyErr_Occurred() ) {
584 if ( ! addr || ! buflen ) {
585 PyErr_SetString( PyExc_TypeError,
586 "BindObject requires a CObject or long integer as first argument" );
592 return BindObject_( addr, PyTuple_GET_ITEM( args, 1 ) );
602 if ( argc != 0 && argc != 1 ) {
603 PyErr_Format( PyExc_TypeError,
604 "MakeNullPointer takes at most 1 argument (" PY_SSIZE_T_FORMAT " given)", argc );
610 Py_INCREF( Py_None );
614 return BindObject_( 0, PyTuple_GET_ITEM( args, 0 ) );
623 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!:__expand__" ),
630 PyObject* mod = PyImport_ImportModule( (
char*)
"ROOT" );
632 PyObject*
dummy = PyObject_GetAttrString( mod, (
char*)
"kRed" );
640 if ( strcmp( clname,
"TBufferFile" ) == 0 ) {
669 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ), &PyInt_Type, &policy ) )
672 Long_t l = PyInt_AS_LONG( policy );
674 Py_INCREF( Py_None );
678 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld",
l );
689 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ), &PyInt_Type, &policy ) )
692 Long_t l = PyInt_AS_LONG( policy );
694 Py_INCREF( Py_None );
698 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld",
l );
708 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!" ),
712 (
Bool_t)PyLong_AsLong( pykeep ) ? pyobj->
HoldOn() : pyobj->Release();
714 Py_INCREF( Py_None );
723 const char* type_name;
724 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"s" ), &type_name ) )
740 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!" ),
755 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ),
770 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!" ),
786 METH_VARARGS, (
char*)
"PyROOT internal function" },
788 METH_VARARGS, (
char*)
"PyROOT internal function" },
789 { (
char*)
"LookupCppEntity", (PyCFunction)LookupCppEntity,
790 METH_VARARGS, (
char*)
"PyROOT internal function" },
791 { (
char*)
"SetRootLazyLookup", (PyCFunction)SetRootLazyLookup,
792 METH_VARARGS, (
char*)
"PyROOT internal function" },
793 { (
char*)
"MakeRootTemplateClass", (PyCFunction)MakeRootTemplateClass,
794 METH_VARARGS, (
char*)
"PyROOT internal function" },
796 METH_NOARGS, (
char*)
"PyROOT internal function" },
797 { (
char*)
"_ResetRootModule", (PyCFunction)RootModuleResetCallback,
798 METH_NOARGS, (
char*)
"PyROOT internal function" },
799 { (
char*)
"AddressOf", (PyCFunction)AddressOf,
800 METH_VARARGS, (
char*)
"Retrieve address of held object in a buffer" },
801 { (
char*)
"addressof", (PyCFunction)addressof,
802 METH_VARARGS, (
char*)
"Retrieve address of held object as a value" },
803 { (
char*)
"AsCObject", (PyCFunction)AsCObject,
804 METH_VARARGS, (
char*)
"Retrieve held object in a CObject" },
805 { (
char*)
"BindObject", (PyCFunction)BindObject,
806 METH_VARARGS, (
char*)
"Create an object of given type, from given address" },
807 { (
char*)
"MakeNullPointer", (PyCFunction)MakeNullPointer,
808 METH_VARARGS, (
char*)
"Create a NULL pointer of the given type" },
809 { (
char*)
"_ObjectProxy__expand__", (PyCFunction)ObjectProxyExpand,
810 METH_VARARGS, (
char*)
"Helper method for pickling" },
811 { (
char*)
"SetMemoryPolicy", (PyCFunction)SetMemoryPolicy,
812 METH_VARARGS, (
char*)
"Determines object ownership model" },
813 { (
char*)
"SetSignalPolicy", (PyCFunction)SetSignalPolicy,
814 METH_VARARGS, (
char*)
"Trap signals in safe mode to prevent interpreter abort" },
815 { (
char*)
"SetOwnership", (PyCFunction)SetOwnership,
816 METH_VARARGS, (
char*)
"Modify held C++ object ownership" },
818 METH_VARARGS, (
char*)
"Add a smart pointer to the list of known smart pointer types" },
820 METH_NOARGS, (
char*)
"Install input hook to sent GUI events" },
822 METH_NOARGS, (
char*)
"Remove input hook to sent GUI events" },
823 { (
char*)
"SetTypePinning", (PyCFunction)SetTypePinning,
824 METH_VARARGS, (
char*)
"Install a type pinning" },
825 { (
char*)
"IgnoreTypePinning", (PyCFunction)IgnoreTypePinning,
826 METH_VARARGS, (
char*)
"Don't pin the given type" },
827 { (
char*)
"Cast", (PyCFunction)Cast,
828 METH_VARARGS, (
char*)
"Cast the given object to the given type" },
829 { NULL, NULL, 0, NULL }
833#if PY_VERSION_HEX >= 0x03000000
838#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
840static int rootmodule_traverse(
PyObject*
m, visitproc visit,
void* arg )
842 Py_VISIT( GETSTATE(
m )->error );
846static int rootmodule_clear(
PyObject*
m )
848 Py_CLEAR( GETSTATE(
m )->error );
853static struct PyModuleDef moduledef = {
854 PyModuleDef_HEAD_INIT,
857 sizeof(
struct module_state),
868#define PYROOT_INIT_ERROR return NULL
869extern "C" PyObject* PyInit_libPyROOT()
871#define PYROOT_INIT_ERROR return
883#if PY_VERSION_HEX >= 0x03030000
891#if PY_VERSION_HEX >= 0x03000000
903 PyObject* userPythonizations = PyDict_New();
904 PyObject* gblList = PyList_New( 0 );
905 PyDict_SetItemString( userPythonizations,
"__global__", gblList );
906 Py_DECREF( gblList );
907 PyModule_AddObject(
gRootModule,
"UserPythonizations", userPythonizations );
908 PyModule_AddObject(
gRootModule,
"UserExceptions", PyDict_New() );
959 PyModule_AddObject(
gRootModule, (
char*)
"kMemoryHeuristics",
960 PyInt_FromLong( (
int)TCallContext::kUseHeuristics ) );
961 PyModule_AddObject(
gRootModule, (
char*)
"kMemoryStrict",
962 PyInt_FromLong( (
int)TCallContext::kUseStrict ) );
963 PyModule_AddObject(
gRootModule, (
char*)
"kSignalFast",
964 PyInt_FromLong( (
int)TCallContext::kFast ) );
965 PyModule_AddObject(
gRootModule, (
char*)
"kSignalSafe",
966 PyInt_FromLong( (
int)TCallContext::kSafe ) );
972 TCallContext::SetSignalPolicy(
gROOT->IsBatch() ? TCallContext::kFast : TCallContext::kSafe );
977#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.
virtual void WriteFastArray(const Bool_t *b, Int_t n)
Write array of n bools into the I/O buffer.
virtual void * ReadObjectAny(const TClass *cast)
Read object from I/O buffer.
Mother of all ROOT objects.
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 * 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 *args, int argoff)
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
@ object
object (unordered set of name/value pairs)