34 #if PY_VERSION_HEX >= 0x03030000
35 typedef struct PyDictKeyEntry {
42 typedef struct _dictkeysobject {
45 dict_lookup_func dk_lookup;
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)
61 static PyObject* nullptr_repr( PyObject* )
63 return PyBytes_FromString(
"nullptr" );
66 static void nullptr_dealloc( PyObject* )
68 Py_FatalError(
"deallocating nullptr" );
71 static int nullptr_nonzero( PyObject* )
76 static PyNumberMethods nullptr_as_number = {
78 #if PY_VERSION_HEX < 0x03000000
82 (inquiry)nullptr_nonzero,
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 static PyTypeObject PyNullPtr_t_Type = {
116 PyVarObject_HEAD_INIT( &PyType_Type, 0 )
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
139 PyObject _PyROOT_NullPtrStruct = {
145 PyObject* gRootModule = 0;
146 PyObject* gNullPtrObject = 0;
147 std::vector<std::pair<Cppyy::TCppType_t, Cppyy::TCppType_t> > gPinnedTypes;
148 std::vector<Cppyy::TCppType_t> gIgnorePinnings;
155 using namespace PyROOT;
159 PyObject* RootModuleResetCallback( PyObject*, PyObject* )
162 Py_INCREF( Py_None );
169 PyObject* LookupCppEntity( PyObject* pyname, PyObject* args )
171 const char* cname = 0;
long macro_ok = 0;
172 if ( pyname && PyROOT_PyUnicode_CheckExact( pyname ) )
173 cname = PyROOT_PyUnicode_AsString( pyname );
174 else if ( ! ( args && PyArg_ParseTuple( args, const_cast< char* >(
"s|l" ), &cname, ¯o_ok ) ) )
178 if ( !gRootModule ) {
179 PyErr_Format( PyExc_AttributeError,
"%s", cname );
183 std::string name = cname;
186 if ( name.size() <= 2 || name.substr( 0, 2 ) !=
"__" ) {
188 PyObject* attr = PyObject_GetAttrString( gRootModule, const_cast< char* >( cname ) );
194 attr = CreateScopeProxy( name, 0 );
200 attr = GetCppGlobal( name );
206 TObject*
object = gROOT->FindObject( name.c_str() );
208 return BindCppObject(
object, object->IsA()->GetName() );
211 if (Cppyy::IsEnum(name)) {
213 Cppyy::TCppEnum_t enumtype = Cppyy::GetEnum(Cppyy::gGlobalScope, name);
216 Cppyy::TCppIndex_t ndata = Cppyy::GetNumEnumData(enumtype);
217 PyObject* dct = PyDict_New();
218 for (Cppyy::TCppIndex_t idata = 0; idata < ndata; ++idata) {
219 PyObject* val = PyLong_FromLongLong(Cppyy::GetEnumDataValue(enumtype, idata));
220 PyDict_SetItemString(dct, Cppyy::GetEnumDataName(enumtype, idata).c_str(), val);
225 PyObject* cppnamepy = PyROOT_PyUnicode_FromString(cname);
226 PyDict_SetItem(dct, PyStrings::gCppName, cppnamepy);
228 PyDict_SetItem(dct, PyStrings::gCppNameNew, cppnamepy);
229 Py_DECREF(cppnamepy);
232 PyObject* pybases = PyTuple_New(1);
233 Py_INCREF(&PyInt_Type);
234 PyTuple_SET_ITEM(pybases, 0, (PyObject*)&PyInt_Type);
235 PyObject* argsnt = Py_BuildValue((
char*)
"sOO", name.c_str(), pybases, dct);
236 attr = Py_TYPE(&PyInt_Type)->tp_new(Py_TYPE(&PyInt_Type), argsnt,
nullptr);
242 Py_INCREF(&PyInt_Type);
243 attr = (PyObject*)&PyInt_Type;
251 std::ostringstream ismacro;
252 ismacro <<
"#ifdef " << name <<
"\n_pyroot_" << name <<
"=" << name
253 <<
";true;\n#else\nfalse;\n#endif";
254 if ( gROOT->ProcessLine( ismacro.str().c_str() ) ) {
256 attr = GetCppGlobal(
"_pyroot_"+name );
264 PyErr_Format( PyExc_AttributeError,
"%s", name.c_str() );
270 #if PY_VERSION_HEX >= 0x03030000
271 inline PyDictKeyEntry* OrgDictLookup(
272 PyDictObject* mp, PyObject* key, Py_hash_t hash, PyObject*** value_addr )
274 return (*gDictLookupOrg)( mp, key, hash, value_addr );
277 #define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\
278 OrgDictLookup( mp, key, hash, value_addr )
280 PyDictKeyEntry* RootLookDictString(
281 PyDictObject* mp, PyObject* key, Py_hash_t hash, PyObject*** value_addr )
283 inline PyDictEntry* OrgDictLookup( PyDictObject* mp, PyObject* key, Long_t hash )
285 return (*gDictLookupOrg)( mp, key, hash );
288 #define PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr )\
289 OrgDictLookup( mp, key, hash )
291 PyDictEntry* RootLookDictString( PyDictObject* mp, PyObject* key, Long_t hash )
295 PyDictEntry* ep = PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr );
296 if ( ! ep || (ep->me_key && ep->me_value) || gDictLookupActive )
300 if ( PyDict_GetItem( PyEval_GetBuiltins(), key ) != 0 ) {
305 gDictLookupActive = kTRUE;
308 PyObject* gval = PyDict_GetItem( PyModule_GetDict( gRootModule ), key );
314 #if PY_VERSION_HEX >= 0x03030000
317 gDictLookupActive = kFALSE;
322 PyObject* val = LookupCppEntity( key, 0 );
327 if ( PropertyProxy_CheckExact( val ) ) {
332 PyObject* actual_val = Py_TYPE(val)->tp_descr_get( val, NULL, NULL );
338 PYROOT_GET_DICT_LOOKUP( mp ) = gDictLookupOrg;
339 if ( PyDict_SetItem( (PyObject*)mp, key, val ) == 0 ) {
340 ep = PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr );
345 PYROOT_GET_DICT_LOOKUP( mp ) = RootLookDictString;
352 #if PY_VERSION_HEX >= 0x03030000
353 if ( mp->ma_keys->dk_usable <= 0 ) {
357 PYROOT_GET_DICT_LOOKUP( mp ) = gDictLookupOrg;
358 const int maxinsert = 5;
359 PyObject* buf[maxinsert];
360 for (
int varmax = 1; varmax <= maxinsert; ++varmax ) {
361 for (
int ivar = 0; ivar < varmax; ++ivar ) {
362 buf[ivar] = PyROOT_PyUnicode_FromFormat(
"__ROOT_FORCE_RESIZE_%d", ivar );
363 PyDict_SetItem( (PyObject*)mp, buf[ivar], Py_None);
365 for (
int ivar = 0; ivar < varmax; ++ivar ) {
366 PyDict_DelItem( (PyObject*)mp, buf[ivar] );
367 Py_DECREF( buf[ivar] );
369 if ( 0 < mp->ma_keys->dk_usable )
374 ep = PYROOT_ORGDICT_LOOKUP( mp, key, hash, value_addr );
377 gDictLookupOrg = PYROOT_GET_DICT_LOOKUP( mp );
378 PYROOT_GET_DICT_LOOKUP( mp ) = RootLookDictString;
383 gDictLookupActive = kFALSE;
393 PyObject* SetRootLazyLookup( PyObject*, PyObject* args )
395 PyDictObject* dict = 0;
396 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!" ), &PyDict_Type, &dict ) )
405 PYROOT_GET_DICT_LOOKUP( dict ) = RootLookDictString;
407 Py_INCREF( Py_None );
414 PyObject* MakeRootTemplateClass( PyObject*, PyObject* args )
417 Py_ssize_t nArgs = PyTuple_GET_SIZE( args );
419 PyErr_Format( PyExc_TypeError,
"too few arguments for template instantiation" );
424 PyObject* pyname = Utility::BuildTemplateName( PyTuple_GET_ITEM( args, 0 ), args, 1 );
428 std::string name = PyROOT_PyUnicode_AsString( pyname );
431 return CreateScopeProxy( name );
437 void* GetObjectProxyAddress( PyObject*, PyObject* args )
439 ObjectProxy* pyobj = 0;
440 PyObject* pyname = 0;
441 if ( PyArg_ParseTuple( args, const_cast< char* >(
"O|O!" ), &pyobj,
442 &PyROOT_PyUnicode_Type, &pyname ) &&
443 ObjectProxy_Check( pyobj ) && pyobj->fObject ) {
447 PropertyProxy* pyprop = 0;
449 PyObject* pyclass = PyObject_GetAttr( (PyObject*)pyobj, PyStrings::gClass );
452 PyObject* dict = PyObject_GetAttr( pyclass, PyStrings::gDict );
453 pyprop = (PropertyProxy*)PyObject_GetItem( dict, pyname );
456 Py_XDECREF( pyclass );
458 if ( PropertyProxy_Check( pyprop ) ) {
460 void* addr = (
void*)pyprop->GetAddress( pyobj );
465 Py_XDECREF( pyprop );
467 PyErr_Format( PyExc_TypeError,
468 "%s is not a valid data member", PyROOT_PyUnicode_AsString( pyname ) );
473 return (
void*)&pyobj->fObject;
476 PyErr_SetString( PyExc_ValueError,
"invalid argument for AddressOf()" );
480 PyObject* _addressof_common( PyObject* dummy ) {
481 if ( dummy == Py_None || dummy == gNullPtrObject ) {
482 Py_INCREF( gNullPtrObject );
483 return gNullPtrObject;
485 if ( !PyErr_Occurred() ) {
486 PyObject* str = PyObject_Str( dummy );
487 if ( str && PyROOT_PyUnicode_Check( str ) )
488 PyErr_Format( PyExc_ValueError,
"unknown object %s", PyBytes_AS_STRING( str ) );
490 PyErr_Format( PyExc_ValueError,
"unknown object at %p", (
void*)dummy );
496 PyObject* AddressOf( PyObject* dummy, PyObject* args )
499 void* addr = GetObjectProxyAddress( dummy, args );
501 return BufFac_t::Instance()->PyBuffer_FromMemory( (Long_t*)addr,
sizeof(Long_t) );
502 if ( ! addr && PyTuple_Size( args ) ) {
503 Utility::GetBuffer( PyTuple_GetItem( args, 0 ),
'*', 1, addr, kFALSE );
505 return BufFac_t::Instance()->PyBuffer_FromMemory( (Long_t*)&addr,
sizeof(Long_t) );
510 PyObject* addressof( PyObject* dummy, PyObject* args )
513 void* addr = GetObjectProxyAddress( dummy, args );
515 return PyLong_FromLong( *(Long_t*)addr );
516 else if ( PyTuple_Size( args ) ) {
518 Utility::GetBuffer( PyTuple_GetItem( args, 0 ),
'*', 1, addr, kFALSE );
519 if ( addr )
return PyLong_FromLong( (Long_t)addr );
521 return _addressof_common( dummy );
524 PyObject* AsCObject( PyObject* dummy, PyObject* args )
527 void* addr = GetObjectProxyAddress( dummy, args );
529 return PyROOT_PyCapsule_New( (
void*)(*(Long_t*)addr), NULL, NULL );
537 PyObject* BindObject_(
void* addr, PyObject* pyname )
539 if ( ! PyROOT_PyUnicode_Check( pyname ) ) {
540 PyObject* nattr = PyObject_GetAttr( pyname, PyStrings::gCppName );
541 if ( ! nattr ) nattr = PyObject_GetAttr( pyname, PyStrings::gName );
544 pyname = PyObject_Str( pyname );
550 Cppyy::TCppType_t klass = (Cppyy::TCppType_t)Cppyy::GetScope( PyROOT_PyUnicode_AsString( pyname ) );
554 PyErr_SetString( PyExc_TypeError,
555 "BindObject expects a valid class or class name as an argument" );
559 return BindCppObjectNoCast( addr, klass, kFALSE );
565 PyObject* BindObject( PyObject*, PyObject* args )
567 Py_ssize_t argc = PyTuple_GET_SIZE( args );
569 PyErr_Format( PyExc_TypeError,
570 "BindObject takes exactly 2 argumenst (" PY_SSIZE_T_FORMAT
" given)", argc );
575 PyObject* pyaddr = PyTuple_GET_ITEM( args, 0 );
576 void* addr = PyROOT_PyCapsule_GetPointer( pyaddr, NULL );
577 if ( PyErr_Occurred() ) {
580 addr = PyLong_AsVoidPtr( pyaddr );
581 if ( PyErr_Occurred() ) {
585 int buflen = Utility::GetBuffer( PyTuple_GetItem( args, 0 ),
'*', 1, addr, kFALSE );
586 if ( ! addr || ! buflen ) {
587 PyErr_SetString( PyExc_TypeError,
588 "BindObject requires a CObject or long integer as first argument" );
594 return BindObject_( addr, PyTuple_GET_ITEM( args, 1 ) );
601 PyObject* MakeNullPointer( PyObject*, PyObject* args )
603 Py_ssize_t argc = PyTuple_GET_SIZE( args );
604 if ( argc != 0 && argc != 1 ) {
605 PyErr_Format( PyExc_TypeError,
606 "MakeNullPointer takes at most 1 argument (" PY_SSIZE_T_FORMAT
" given)", argc );
612 Py_INCREF( Py_None );
616 return BindObject_( 0, PyTuple_GET_ITEM( args, 0 ) );
622 PyObject* ObjectProxyExpand( PyObject*, PyObject* args )
624 PyObject* pybuf = 0, *pyname = 0;
625 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!O!:__expand__" ),
626 &PyBytes_Type, &pybuf, &PyBytes_Type, &pyname ) )
629 const char* clname = PyBytes_AS_STRING(pyname);
632 PyObject* mod = PyImport_ImportModule( (
char*)
"ROOT" );
634 PyObject* dummy = PyObject_GetAttrString( mod, (
char*)
"kRed" );
642 if ( strcmp( clname,
"TBufferFile" ) == 0 ) {
643 TBufferFile* buf =
new TBufferFile( TBuffer::kWrite );
644 buf->WriteFastArray( PyBytes_AS_STRING(pybuf), PyBytes_GET_SIZE( pybuf ) );
649 TBufferFile buf( TBuffer::kRead,
650 PyBytes_GET_SIZE( pybuf ), PyBytes_AS_STRING( pybuf ), kFALSE );
651 newObj = buf.ReadObjectAny( 0 );
654 PyObject* result = BindCppObject( newObj, clname );
658 ((ObjectProxy*)result)->HoldOn();
668 PyObject* SetMemoryPolicy( PyObject*, PyObject* args )
670 PyObject* policy = 0;
671 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!" ), &PyInt_Type, &policy ) )
674 Long_t l = PyInt_AS_LONG( policy );
675 if ( TCallContext::SetMemoryPolicy( (TCallContext::ECallFlags)l ) ) {
676 Py_INCREF( Py_None );
680 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld", l );
688 PyObject* SetSignalPolicy( PyObject*, PyObject* args )
690 PyObject* policy = 0;
691 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!" ), &PyInt_Type, &policy ) )
694 Long_t l = PyInt_AS_LONG( policy );
695 if ( TCallContext::SetSignalPolicy( (TCallContext::ECallFlags)l ) ) {
696 Py_INCREF( Py_None );
700 PyErr_Format( PyExc_ValueError,
"Unknown policy %ld", l );
707 PyObject* SetOwnership( PyObject*, PyObject* args )
709 ObjectProxy* pyobj = 0; PyObject* pykeep = 0;
710 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!O!" ),
711 &ObjectProxy_Type, (
void*)&pyobj, &PyInt_Type, &pykeep ) )
714 (Bool_t)PyLong_AsLong( pykeep ) ? pyobj->HoldOn() : pyobj->Release();
716 Py_INCREF( Py_None );
723 PyObject* AddSmartPtrType( PyObject*, PyObject* args )
725 const char* type_name;
726 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"s" ), &type_name ) )
729 Cppyy::AddSmartPtrType( type_name );
739 PyObject* SetTypePinning( PyObject*, PyObject* args )
741 PyRootClass* derived =
nullptr, *base =
nullptr;
742 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!O!" ),
743 &PyRootType_Type, &derived,
744 &PyRootType_Type, &base ) )
746 gPinnedTypes.push_back( std::make_pair( derived->fCppType, base->fCppType ) );
754 PyObject* IgnoreTypePinning( PyObject*, PyObject* args )
756 PyRootClass* derived =
nullptr;
757 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!" ),
758 &PyRootType_Type, &derived ) )
760 gIgnorePinnings.push_back( derived->fCppType );
768 PyObject* Cast( PyObject*, PyObject* args )
770 ObjectProxy* obj =
nullptr;
771 PyRootClass* type =
nullptr;
772 if ( ! PyArg_ParseTuple( args, const_cast< char* >(
"O!O!" ),
773 &ObjectProxy_Type, &obj,
774 &PyRootType_Type, &type ) )
778 return BindCppObjectNoCast( obj->GetObject(), type->fCppType,
779 obj->fFlags & ObjectProxy::kIsReference );
786 static PyMethodDef gPyROOTMethods[] = {
787 { (
char*)
"CreateScopeProxy", (PyCFunction)PyROOT::CreateScopeProxy,
788 METH_VARARGS, (
char*)
"PyROOT internal function" },
789 { (
char*)
"GetCppGlobal", (PyCFunction)PyROOT::GetCppGlobal,
790 METH_VARARGS, (
char*)
"PyROOT internal function" },
791 { (
char*)
"LookupCppEntity", (PyCFunction)LookupCppEntity,
792 METH_VARARGS, (
char*)
"PyROOT internal function" },
793 { (
char*)
"SetRootLazyLookup", (PyCFunction)SetRootLazyLookup,
794 METH_VARARGS, (
char*)
"PyROOT internal function" },
795 { (
char*)
"MakeRootTemplateClass", (PyCFunction)MakeRootTemplateClass,
796 METH_VARARGS, (
char*)
"PyROOT internal function" },
797 { (
char*)
"_DestroyPyStrings", (PyCFunction)PyROOT::DestroyPyStrings,
798 METH_NOARGS, (
char*)
"PyROOT internal function" },
799 { (
char*)
"_ResetRootModule", (PyCFunction)RootModuleResetCallback,
800 METH_NOARGS, (
char*)
"PyROOT internal function" },
801 { (
char*)
"ClearProxiedObjects", (PyCFunction)ClearProxiedObjects,
802 METH_NOARGS, (
char*)
"PyROOT internal function" },
803 { (
char*)
"AddressOf", (PyCFunction)AddressOf,
804 METH_VARARGS, (
char*)
"Retrieve address of held object in a buffer" },
805 { (
char*)
"addressof", (PyCFunction)addressof,
806 METH_VARARGS, (
char*)
"Retrieve address of held object as a value" },
807 { (
char*)
"AsCObject", (PyCFunction)AsCObject,
808 METH_VARARGS, (
char*)
"Retrieve held object in a CObject" },
809 { (
char*)
"as_cobject", (PyCFunction)AsCObject,
810 METH_VARARGS, (
char*)
"Retrieve held object in a CObject" },
811 { (
char*)
"BindObject", (PyCFunction)BindObject,
812 METH_VARARGS, (
char*)
"Create an object of given type, from given address" },
813 { (
char*)
"bind_object", (PyCFunction)BindObject,
814 METH_VARARGS, (
char*)
"Create an object of given type, from given address" },
815 { (
char*)
"MakeNullPointer", (PyCFunction)MakeNullPointer,
816 METH_VARARGS, (
char*)
"Create a NULL pointer of the given type" },
817 { (
char*)
"_ObjectProxy__expand__", (PyCFunction)ObjectProxyExpand,
818 METH_VARARGS, (
char*)
"Helper method for pickling" },
819 { (
char*)
"SetMemoryPolicy", (PyCFunction)SetMemoryPolicy,
820 METH_VARARGS, (
char*)
"Determines object ownership model" },
821 { (
char*)
"SetSignalPolicy", (PyCFunction)SetSignalPolicy,
822 METH_VARARGS, (
char*)
"Trap signals in safe mode to prevent interpreter abort" },
823 { (
char*)
"SetOwnership", (PyCFunction)SetOwnership,
824 METH_VARARGS, (
char*)
"Modify held C++ object ownership" },
825 { (
char*)
"AddSmartPtrType", (PyCFunction)AddSmartPtrType,
826 METH_VARARGS, (
char*)
"Add a smart pointer to the list of known smart pointer types" },
827 { (
char*)
"InstallGUIEventInputHook", (PyCFunction)PyROOT::Utility::InstallGUIEventInputHook,
828 METH_NOARGS, (
char*)
"Install input hook to sent GUI events" },
829 { (
char*)
"RemoveGUIEventInputHook", (PyCFunction)PyROOT::Utility::RemoveGUIEventInputHook,
830 METH_NOARGS, (
char*)
"Remove input hook to sent GUI events" },
831 { (
char*)
"SetTypePinning", (PyCFunction)SetTypePinning,
832 METH_VARARGS, (
char*)
"Install a type pinning" },
833 { (
char*)
"IgnoreTypePinning", (PyCFunction)IgnoreTypePinning,
834 METH_VARARGS, (
char*)
"Don't pin the given type" },
835 { (
char*)
"Cast", (PyCFunction)Cast,
836 METH_VARARGS, (
char*)
"Cast the given object to the given type" },
837 { NULL, NULL, 0, NULL }
841 #if PY_VERSION_HEX >= 0x03000000
842 struct module_state {
846 #define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
848 static int rootmodule_traverse( PyObject* m, visitproc visit,
void* arg )
850 Py_VISIT( GETSTATE( m )->error );
854 static int rootmodule_clear( PyObject* m )
856 Py_CLEAR( GETSTATE( m )->error );
861 static struct PyModuleDef moduledef = {
862 PyModuleDef_HEAD_INIT,
865 sizeof(
struct module_state),
876 #define PYROOT_INIT_ERROR return NULL
877 extern "C" PyObject* PyInit_libPyROOT()
879 #define PYROOT_INIT_ERROR return
880 extern "C" void initlibPyROOT()
883 using namespace PyROOT;
886 if ( ! PyROOT::CreatePyStrings() )
890 PyObject* dict = PyDict_New();
891 #if PY_VERSION_HEX >= 0x03030000
892 gDictLookupOrg = (dict_lookup_func)((PyDictObject*)dict)->ma_keys->dk_lookup;
894 gDictLookupOrg = (dict_lookup_func)((PyDictObject*)dict)->ma_lookup;
899 #if PY_VERSION_HEX >= 0x03000000
900 gRootModule = PyModule_Create( &moduledef );
902 gRootModule = Py_InitModule( const_cast< char* >(
"libPyROOT" ), gPyROOTMethods );
911 PyObject* userPythonizations = PyDict_New();
912 PyObject* gblList = PyList_New( 0 );
913 PyDict_SetItemString( userPythonizations,
"__global__", gblList );
914 Py_DECREF( gblList );
915 PyModule_AddObject( gRootModule,
"UserPythonizations", userPythonizations );
916 PyModule_AddObject( gRootModule,
"UserExceptions", PyDict_New() );
917 PyModule_AddObject( gRootModule,
"PythonizationScope", PyROOT_PyUnicode_FromString(
"__global__" ) );
920 if ( ! Utility::InitProxy( gRootModule, &PyRootType_Type,
"PyRootType" ) )
924 if ( ! Utility::InitProxy( gRootModule, &ObjectProxy_Type,
"ObjectProxy" ) )
928 if ( ! Utility::InitProxy( gRootModule, &MethodProxy_Type,
"MethodProxy" ) )
932 if ( ! Utility::InitProxy( gRootModule, &TemplateProxy_Type,
"TemplateProxy" ) )
936 if ( ! Utility::InitProxy( gRootModule, &PropertyProxy_Type,
"PropertyProxy" ) )
940 if ( ! Utility::InitProxy( gRootModule, &TCustomFloat_Type,
"Double" ) )
943 if ( ! Utility::InitProxy( gRootModule, &TCustomInt_Type,
"Long" ) )
946 if ( ! Utility::InitProxy( gRootModule, &TCustomFloat_Type,
"double" ) )
949 if ( ! Utility::InitProxy( gRootModule, &TCustomInt_Type,
"long" ) )
952 if ( ! Utility::InitProxy( gRootModule, &TCustomInstanceMethod_Type,
"InstanceMethod" ) )
955 if ( ! Utility::InitProxy( gRootModule, &TTupleOfInstances_Type,
"InstancesArray" ) )
958 if ( ! Utility::InitProxy( gRootModule, &PyNullPtr_t_Type,
"nullptr_t" ) )
962 gNullPtrObject = (PyObject*)&_PyROOT_NullPtrStruct;
963 Py_INCREF( gNullPtrObject );
964 PyModule_AddObject( gRootModule, (
char*)
"nullptr", gNullPtrObject );
967 PyModule_AddObject( gRootModule, (
char*)
"kMemoryHeuristics",
968 PyInt_FromLong( (
int)TCallContext::kUseHeuristics ) );
969 PyModule_AddObject( gRootModule, (
char*)
"kMemoryStrict",
970 PyInt_FromLong( (
int)TCallContext::kUseStrict ) );
971 PyModule_AddObject( gRootModule, (
char*)
"kSignalFast",
972 PyInt_FromLong( (
int)TCallContext::kFast ) );
973 PyModule_AddObject( gRootModule, (
char*)
"kSignalSafe",
974 PyInt_FromLong( (
int)TCallContext::kSafe ) );
980 TCallContext::SetSignalPolicy( gROOT->IsBatch() ? TCallContext::kFast : TCallContext::kSafe );
983 PyModule_AddObject( gRootModule, (
char*)
"ROOT", CreateScopeProxy(
"ROOT" ) );
985 #if PY_VERSION_HEX >= 0x03000000
986 Py_INCREF( gRootModule );