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 ) !=
"__" ) {
242 Py_DECREF(cppnamepy);
246 Py_INCREF(&PyInt_Type);
247 PyTuple_SET_ITEM(pybases, 0, (
PyObject*)&PyInt_Type);
248 PyObject* argsnt = Py_BuildValue((
char*)
"sOO",
name.c_str(), pybases, dct);
249 attr =
Py_TYPE(&PyInt_Type)->tp_new(
Py_TYPE(&PyInt_Type), argsnt,
nullptr);
255 Py_INCREF(&PyInt_Type);
264 std::ostringstream ismacro;
265 ismacro <<
"#ifdef " <<
name <<
"\n_pyroot_" <<
name <<
"=" <<
name
266 <<
";true;\n#else\nfalse;\n#endif";
267 if (
gROOT->ProcessLine( ismacro.str().c_str() ) ) {
277 PyErr_Format( PyExc_AttributeError,
"%s",
name.c_str() );
283#if PY_VERSION_HEX >= 0x03030000
284 inline PyDictKeyEntry* OrgDictLookup(
290#define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\
291 OrgDictLookup( mp, key, hash, value_addr )
293 PyDictKeyEntry* RootLookDictString(
296 inline PyDictEntry* OrgDictLookup( PyDictObject* mp,
PyObject* key,
Long_t hash )
301#define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\
302 OrgDictLookup( mp, key, hash )
304 PyDictEntry* RootLookDictString( PyDictObject* mp,
PyObject* key,
Long_t hash )
313 if ( PyDict_GetItem( PyEval_GetBuiltins(), key ) != 0 ) {
327#if PY_VERSION_HEX >= 0x03030000
335 PyObject* val = LookupCppEntity( key, 0 );
352 if ( PyDict_SetItem( (
PyObject*)mp, key, val ) == 0 ) {
365#if PY_VERSION_HEX >= 0x03030000
366 if ( mp->ma_keys->dk_usable <= 0 ) {
371 const int maxinsert = 5;
373 for (
int varmax = 1; varmax <= maxinsert; ++varmax ) {
374 for (
int ivar = 0; ivar < varmax; ++ivar ) {
376 PyDict_SetItem( (
PyObject*)mp, buf[ivar], Py_None);
378 for (
int ivar = 0; ivar < varmax; ++ivar ) {
379 PyDict_DelItem( (
PyObject*)mp, buf[ivar] );
380 Py_DECREF( buf[ivar] );
382 if ( 0 < mp->ma_keys->dk_usable )
408 PyDictObject* dict = 0;
409 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ), &PyDict_Type, &dict ) )
420 Py_INCREF( Py_None );
432 PyErr_Format( PyExc_TypeError,
"too few arguments for template instantiation" );
454 if ( PyArg_ParseTuple( args,
const_cast< char*
>(
"O|O!" ), &pyobj,
469 Py_XDECREF( pyclass );
473 void* addr = (
void*)pyprop->
GetAddress( pyobj );
478 Py_XDECREF( pyprop );
480 PyErr_Format( PyExc_TypeError,
489 PyErr_SetString( PyExc_ValueError,
"invalid argument for AddressOf()" );
498 if ( !PyErr_Occurred() ) {
503 PyErr_Format( PyExc_ValueError,
"unknown object at %p", (
void*)
dummy );
512 void* addr = GetObjectProxyAddress(
dummy, args );
514 return BufFac_t::Instance()->PyBuffer_FromMemory( (
Long_t*)addr,
sizeof(
Long_t) );
515 if ( ! addr && PyTuple_Size( args ) ) {
518 return BufFac_t::Instance()->PyBuffer_FromMemory( (
Long_t*)&addr,
sizeof(
Long_t) );
526 void* addr = GetObjectProxyAddress(
dummy, args );
528 return PyLong_FromLong( *(
Long_t*)addr );
529 else if ( PyTuple_Size( args ) ) {
532 if ( addr )
return PyLong_FromLong( (
Long_t)addr );
534 return _addressof_common(
dummy );
540 void* addr = GetObjectProxyAddress(
dummy, args );
567 PyErr_SetString( PyExc_TypeError,
568 "BindObject expects a valid class or class name as an argument" );
582 PyErr_Format( PyExc_TypeError,
588 PyObject* pyaddr = PyTuple_GET_ITEM( args, 0 );
590 if ( PyErr_Occurred() ) {
593 addr = PyLong_AsVoidPtr( pyaddr );
594 if ( PyErr_Occurred() ) {
599 if ( ! addr || ! buflen ) {
600 PyErr_SetString( PyExc_TypeError,
601 "BindObject requires a CObject or long integer as first argument" );
607 return BindObject_( addr, PyTuple_GET_ITEM( args, 1 ) );
617 if ( argc != 0 && argc != 1 ) {
618 PyErr_Format( PyExc_TypeError,
619 "MakeNullPointer takes at most 1 argument (" PY_SSIZE_T_FORMAT " given)", argc );
625 Py_INCREF( Py_None );
629 return BindObject_( 0, PyTuple_GET_ITEM( args, 0 ) );
638 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!:__expand__" ),
645 PyObject* mod = PyImport_ImportModule( (
char*)
"ROOT" );
647 PyObject*
dummy = PyObject_GetAttrString( mod, (
char*)
"kRed" );
655 if ( strcmp( clname,
"TBufferFile" ) == 0 ) {
684 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ), &PyInt_Type, &policy ) )
687 Long_t l = PyInt_AS_LONG( policy );
689 Py_INCREF( Py_None );
693 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld",
l );
704 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ), &PyInt_Type, &policy ) )
707 Long_t l = PyInt_AS_LONG( policy );
709 Py_INCREF( Py_None );
713 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld",
l );
723 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!" ),
727 (
Bool_t)PyLong_AsLong( pykeep ) ? pyobj->
HoldOn() : pyobj->Release();
729 Py_INCREF( Py_None );
738 const char* type_name;
739 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"s" ), &type_name ) )
755 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!" ),
770 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!" ),
785 if ( ! PyArg_ParseTuple( args,
const_cast< char*
>(
"O!O!" ),
801 METH_VARARGS, (
char*)
"PyROOT internal function" },
803 METH_VARARGS, (
char*)
"PyROOT internal function" },
804 { (
char*)
"LookupCppEntity", (PyCFunction)LookupCppEntity,
805 METH_VARARGS, (
char*)
"PyROOT internal function" },
806 { (
char*)
"SetRootLazyLookup", (PyCFunction)SetRootLazyLookup,
807 METH_VARARGS, (
char*)
"PyROOT internal function" },
808 { (
char*)
"MakeRootTemplateClass", (PyCFunction)MakeRootTemplateClass,
809 METH_VARARGS, (
char*)
"PyROOT internal function" },
811 METH_NOARGS, (
char*)
"PyROOT internal function" },
812 { (
char*)
"_ResetRootModule", (PyCFunction)RootModuleResetCallback,
813 METH_NOARGS, (
char*)
"PyROOT internal function" },
814 { (
char*)
"AddressOf", (PyCFunction)AddressOf,
815 METH_VARARGS, (
char*)
"Retrieve address of held object in a buffer" },
816 { (
char*)
"addressof", (PyCFunction)addressof,
817 METH_VARARGS, (
char*)
"Retrieve address of held object as a value" },
818 { (
char*)
"AsCObject", (PyCFunction)AsCObject,
819 METH_VARARGS, (
char*)
"Retrieve held object in a CObject" },
820 { (
char*)
"BindObject", (PyCFunction)BindObject,
821 METH_VARARGS, (
char*)
"Create an object of given type, from given address" },
822 { (
char*)
"MakeNullPointer", (PyCFunction)MakeNullPointer,
823 METH_VARARGS, (
char*)
"Create a NULL pointer of the given type" },
824 { (
char*)
"_ObjectProxy__expand__", (PyCFunction)ObjectProxyExpand,
825 METH_VARARGS, (
char*)
"Helper method for pickling" },
826 { (
char*)
"SetMemoryPolicy", (PyCFunction)SetMemoryPolicy,
827 METH_VARARGS, (
char*)
"Determines object ownership model" },
828 { (
char*)
"SetSignalPolicy", (PyCFunction)SetSignalPolicy,
829 METH_VARARGS, (
char*)
"Trap signals in safe mode to prevent interpreter abort" },
830 { (
char*)
"SetOwnership", (PyCFunction)SetOwnership,
831 METH_VARARGS, (
char*)
"Modify held C++ object ownership" },
833 METH_VARARGS, (
char*)
"Add a smart pointer to the list of known smart pointer types" },
835 METH_NOARGS, (
char*)
"Install input hook to sent GUI events" },
837 METH_NOARGS, (
char*)
"Remove input hook to sent GUI events" },
838 { (
char*)
"SetTypePinning", (PyCFunction)SetTypePinning,
839 METH_VARARGS, (
char*)
"Install a type pinning" },
840 { (
char*)
"IgnoreTypePinning", (PyCFunction)IgnoreTypePinning,
841 METH_VARARGS, (
char*)
"Don't pin the given type" },
842 { (
char*)
"Cast", (PyCFunction)Cast,
843 METH_VARARGS, (
char*)
"Cast the given object to the given type" },
844 { NULL, NULL, 0, NULL }
848#if PY_VERSION_HEX >= 0x03000000
853#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
855static int rootmodule_traverse(
PyObject*
m, visitproc visit,
void* arg )
857 Py_VISIT( GETSTATE(
m )->error );
861static int rootmodule_clear(
PyObject*
m )
863 Py_CLEAR( GETSTATE(
m )->error );
868static struct PyModuleDef moduledef = {
869 PyModuleDef_HEAD_INIT,
872 sizeof(
struct module_state),
883#define PYROOT_INIT_ERROR return NULL
884extern "C" PyObject* PyInit_libPyROOT()
886#define PYROOT_INIT_ERROR return
898#if PY_VERSION_HEX >= 0x03030000
906#if PY_VERSION_HEX >= 0x03000000
918 PyObject* userPythonizations = PyDict_New();
919 PyObject* gblList = PyList_New( 0 );
920 PyDict_SetItemString( userPythonizations,
"__global__", gblList );
921 Py_DECREF( gblList );
922 PyModule_AddObject(
gRootModule,
"UserPythonizations", userPythonizations );
923 PyModule_AddObject(
gRootModule,
"UserExceptions", PyDict_New() );
974 PyModule_AddObject(
gRootModule, (
char*)
"kMemoryHeuristics",
975 PyInt_FromLong( (
int)TCallContext::kUseHeuristics ) );
976 PyModule_AddObject(
gRootModule, (
char*)
"kMemoryStrict",
977 PyInt_FromLong( (
int)TCallContext::kUseStrict ) );
978 PyModule_AddObject(
gRootModule, (
char*)
"kSignalFast",
979 PyInt_FromLong( (
int)TCallContext::kFast ) );
980 PyModule_AddObject(
gRootModule, (
char*)
"kSignalSafe",
981 PyInt_FromLong( (
int)TCallContext::kSafe ) );
987 TCallContext::SetSignalPolicy(
gROOT->IsBatch() ? TCallContext::kFast : TCallContext::kSafe );
992#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.
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 * 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