Logo ROOT  
Reference Guide
TPython.cxx
Go to the documentation of this file.
1 // Author: Enric Tejedor CERN 08/2019
2 // Original PyROOT code by Wim Lavrijsen, LBL
3 //
4 // /*************************************************************************
5 // * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 // * All rights reserved. *
7 // * *
8 // * For the licensing terms see $ROOTSYS/LICENSE. *
9 // * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 // *************************************************************************/
11 
12 // Bindings
13 // CPyCppyy.h must be go first, since it includes Python.h, which must be
14 // included before any standard header
15 #include "CPyCppyy.h"
16 #include "TPython.h"
17 #include "CPPInstance.h"
18 #include "CPPOverload.h"
19 #include "ProxyWrappers.h"
20 #include "TPyClassGenerator.h"
21 
22 // ROOT
23 #include "TROOT.h"
24 #include "TClassRef.h"
25 #include "TObject.h"
26 
27 // Standard
28 #include <stdio.h>
29 #include <Riostream.h>
30 #include <string>
31 
32 /// \class TPython
33 /// Accessing the Python interpreter from C++.
34 ///
35 /// The TPython class allows for access to python objects from Cling. The current
36 /// functionality is only basic: ROOT objects and builtin types can freely cross
37 /// the boundary between the two interpreters, python objects can be instantiated
38 /// and their methods can be called. All other cross-coding is based on strings
39 /// that are run on the python interpreter.
40 ///
41 /// Examples:
42 ///
43 /// ~~~{.cpp}
44 /// $ root -l
45 /// // Execute a string of python code.
46 /// root [0] TPython::Exec( "print(\'Hello World!\')" );
47 /// Hello World!
48 ///
49 /// // Create a TBrowser on the python side, and transfer it back and forth.
50 /// // Note the required explicit (void*) cast!
51 /// root [1] TBrowser* b = (void*)TPython::Eval( "ROOT.TBrowser()" );
52 /// root [2] TPython::Bind( b, "b" );
53 /// root [3] b == (void*) TPython::Eval( "b" )
54 /// (int)1
55 ///
56 /// // Builtin variables can cross-over by using implicit casts.
57 /// root [4] int i = TPython::Eval( "1 + 1" );
58 /// root [5] i
59 /// (int)2
60 /// ~~~
61 ///
62 /// And with a python file `MyPyClass.py` like this:
63 /// ~~~{.py}
64 /// print 'creating class MyPyClass ... '
65 ///
66 /// class MyPyClass:
67 /// def __init__( self ):
68 /// print 'in MyPyClass.__init__'
69 ///
70 /// def gime( self, what ):
71 /// return what
72 /// ~~~
73 /// one can load a python module, and use the class. Casts are
74 /// necessary as the type information can not be otherwise derived.
75 /// ~~~{.cpp}
76 /// root [6] TPython::LoadMacro( "MyPyClass.py" );
77 /// creating class MyPyClass ...
78 /// root [7] MyPyClass m;
79 /// in MyPyClass.__init__
80 /// root [8] std::string s = (char*)m.gime( "aap" );
81 /// root [9] s
82 /// (class TString)"aap"
83 /// ~~~
84 /// It is possible to switch between interpreters by calling `TPython::Prompt()`
85 /// on the Cling side, while returning with `^D` (EOF). State is preserved between
86 /// successive switches.
87 ///
88 /// The API part provides (direct) C++ access to the bindings functionality of
89 /// PyROOT. It allows verifying that you deal with a PyROOT python object in the
90 /// first place (CPPInstance_Check for CPPInstance and any derived types, as well
91 /// as CPPInstance_CheckExact for CPPInstance's only); and it allows conversions
92 /// of `void*` to an CPPInstance and vice versa.
93 
94 //- data ---------------------------------------------------------------------
96 static PyObject *gMainDict = 0;
97 
98 // needed to properly resolve (dllimport) symbols on Windows
99 namespace CPyCppyy {
101  namespace PyStrings {
106  }
107 }
108 
109 //- static public members ----------------------------------------------------
110 /// Initialization method: setup the python interpreter and load the
111 /// ROOT module.
113 {
114  static Bool_t isInitialized = kFALSE;
115  if (isInitialized)
116  return kTRUE;
117 
118  if (!Py_IsInitialized()) {
119 // this happens if Cling comes in first
120 #if PY_VERSION_HEX < 0x03020000
121  PyEval_InitThreads();
122 #endif
123  Py_Initialize();
124 #if PY_VERSION_HEX >= 0x03020000
125  PyEval_InitThreads();
126 #endif
127 
128  // try again to see if the interpreter is initialized
129  if (!Py_IsInitialized()) {
130  // give up ...
131  std::cerr << "Error: python has not been intialized; returning." << std::endl;
132  return kFALSE;
133  }
134 
135 // set the command line arguments on python's sys.argv
136 #if PY_VERSION_HEX < 0x03000000
137  char *argv[] = {const_cast<char *>("root")};
138 #else
139  wchar_t *argv[] = {const_cast<wchar_t *>(L"root")};
140 #endif
141  PySys_SetArgv(sizeof(argv) / sizeof(argv[0]), argv);
142 
143  // force loading of the ROOT module
144  PyRun_SimpleString(const_cast<char *>("import ROOT"));
145  }
146 
147  if (!gMainDict) {
148  // retrieve the main dictionary
149  gMainDict = PyModule_GetDict(PyImport_AddModule(const_cast<char *>("__main__")));
150  Py_INCREF(gMainDict);
151  }
152 
153  // python side class construction, managed by ROOT
154  gROOT->AddClassGenerator(new TPyClassGenerator);
155 
156  // declare success ...
157  isInitialized = kTRUE;
158  return kTRUE;
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Import the named python module and create Cling equivalents for its classes
163 /// and methods.
164 
165 Bool_t TPython::Import(const char *mod_name)
166 {
167  // setup
168  if (!Initialize())
169  return kFALSE;
170 
171  PyObject *mod = PyImport_ImportModule(mod_name);
172  if (!mod) {
173  PyErr_Print();
174  return kFALSE;
175  }
176 
177  // allow finding to prevent creation of a python proxy for the C++ proxy
178  Py_INCREF(mod);
179  PyModule_AddObject(CPyCppyy::gThisModule, mod_name, mod);
180 
181  // force creation of the module as a namespace
182  TClass::GetClass(mod_name, kTRUE);
183 
184  PyObject *dct = PyModule_GetDict(mod);
185 
186  // create Cling classes for all new python classes
187  PyObject *values = PyDict_Values(dct);
188  for (int i = 0; i < PyList_GET_SIZE(values); ++i) {
189  PyObject *value = PyList_GET_ITEM(values, i);
190  Py_INCREF(value);
191 
192  // collect classes
193  if (PyClass_Check(value) || PyObject_HasAttr(value, CPyCppyy::PyStrings::gBases)) {
194  // get full class name (including module)
195  PyObject *pyClName = PyObject_GetAttr(value, CPyCppyy::PyStrings::gCppName);
196  if (!pyClName) {
197  pyClName = PyObject_GetAttr(value, CPyCppyy::PyStrings::gName);
198  }
199 
200  if (PyErr_Occurred())
201  PyErr_Clear();
202 
203  // build full, qualified name
204  std::string fullname = mod_name;
205  fullname += ".";
206  fullname += CPyCppyy_PyText_AsString(pyClName);
207 
208  // force class creation (this will eventually call TPyClassGenerator)
209  TClass::GetClass(fullname.c_str(), kTRUE);
210 
211  Py_XDECREF(pyClName);
212  }
213 
214  Py_DECREF(value);
215  }
216 
217  Py_DECREF(values);
218 
219  // TODO: mod "leaks" here
220  if (PyErr_Occurred())
221  return kFALSE;
222  return kTRUE;
223 }
224 
225 ////////////////////////////////////////////////////////////////////////////////
226 /// Execute the give python script as if it were a macro (effectively an
227 /// execfile in __main__), and create Cling equivalents for any newly available
228 /// python classes.
229 
230 void TPython::LoadMacro(const char *name)
231 {
232  // setup
233  if (!Initialize())
234  return;
235 
236  // obtain a reference to look for new classes later
237  PyObject *old = PyDict_Values(gMainDict);
238 
239 // actual execution
240 #if PY_VERSION_HEX < 0x03000000
241  Exec((std::string("execfile(\"") + name + "\")").c_str());
242 #else
243  Exec((std::string("__pyroot_f = open(\"") + name + "\"); "
244  "exec(__pyroot_f.read()); "
245  "__pyroot_f.close(); del __pyroot_f")
246  .c_str());
247 #endif
248 
249  // obtain new __main__ contents
250  PyObject *current = PyDict_Values(gMainDict);
251 
252  // create Cling classes for all new python classes
253  for (int i = 0; i < PyList_GET_SIZE(current); ++i) {
254  PyObject *value = PyList_GET_ITEM(current, i);
255  Py_INCREF(value);
256 
257  if (!PySequence_Contains(old, value)) {
258  // collect classes
259  if (PyClass_Check(value) || PyObject_HasAttr(value, CPyCppyy::PyStrings::gBases)) {
260  // get full class name (including module)
261  PyObject *pyModName = PyObject_GetAttr(value, CPyCppyy::PyStrings::gModule);
262  PyObject *pyClName = PyObject_GetAttr(value, CPyCppyy::PyStrings::gName);
263 
264  if (PyErr_Occurred())
265  PyErr_Clear();
266 
267  // need to check for both exact and derived (differences exist between older and newer
268  // versions of python ... bug?)
269  if ((pyModName && pyClName) &&
270  ((CPyCppyy_PyText_CheckExact(pyModName) && CPyCppyy_PyText_CheckExact(pyClName)) ||
271  (CPyCppyy_PyText_Check(pyModName) && CPyCppyy_PyText_Check(pyClName)))) {
272  // build full, qualified name
273  std::string fullname = CPyCppyy_PyText_AsString(pyModName);
274  fullname += '.';
275  fullname += CPyCppyy_PyText_AsString(pyClName);
276 
277  // force class creation (this will eventually call TPyClassGenerator)
278  TClass::GetClass(fullname.c_str(), kTRUE);
279  }
280 
281  Py_XDECREF(pyClName);
282  Py_XDECREF(pyModName);
283  }
284  }
285 
286  Py_DECREF(value);
287  }
288 
289  Py_DECREF(current);
290  Py_DECREF(old);
291 }
292 
293 ////////////////////////////////////////////////////////////////////////////////
294 /// Execute a python stand-alone script, with argv CLI arguments.
295 ///
296 /// example of use:
297 /// const char* argv[] = { "1", "2", "3" };
298 /// TPython::ExecScript( "test.py", sizeof(argv)/sizeof(argv[0]), argv );
299 
300 void TPython::ExecScript(const char *name, int argc, const char **
301 #if PY_VERSION_HEX < 0x03000000
302  argv
303 #endif
304  )
305 {
306 
307  // setup
308  if (!Initialize())
309  return;
310 
311  // verify arguments
312  if (!name) {
313  std::cerr << "Error: no file name specified." << std::endl;
314  return;
315  }
316 
317  FILE *fp = fopen(name, "r");
318  if (!fp) {
319  std::cerr << "Error: could not open file \"" << name << "\"." << std::endl;
320  return;
321  }
322 
323  // store a copy of the old cli for restoration
324  PyObject *oldargv = PySys_GetObject(const_cast<char *>("argv")); // borrowed
325  if (!oldargv) // e.g. apache
326  PyErr_Clear();
327  else {
328  PyObject *l = PyList_New(PyList_GET_SIZE(oldargv));
329  for (int i = 0; i < PyList_GET_SIZE(oldargv); ++i) {
330  PyObject *item = PyList_GET_ITEM(oldargv, i);
331  Py_INCREF(item);
332  PyList_SET_ITEM(l, i, item); // steals ref
333  }
334  oldargv = l;
335  }
336 
337  // create and set (add progam name) the new command line
338  argc += 1;
339 #if PY_VERSION_HEX < 0x03000000
340  const char **argv2 = new const char *[argc];
341  for (int i = 1; i < argc; ++i)
342  argv2[i] = argv[i - 1];
343  argv2[0] = Py_GetProgramName();
344  PySys_SetArgv(argc, const_cast<char **>(argv2));
345  delete[] argv2;
346 #else
347 // TODO: fix this to work like above ...
348 #endif
349 
350  // actual script execution
351  PyObject *gbl = PyDict_Copy(gMainDict);
352  PyObject *result = // PyRun_FileEx closes fp (b/c of last argument "1")
353  PyRun_FileEx(fp, const_cast<char *>(name), Py_file_input, gbl, gbl, 1);
354  if (!result)
355  PyErr_Print();
356  Py_XDECREF(result);
357  Py_DECREF(gbl);
358 
359  // restore original command line
360  if (oldargv) {
361  PySys_SetObject(const_cast<char *>("argv"), oldargv);
362  Py_DECREF(oldargv);
363  }
364 }
365 
366 ////////////////////////////////////////////////////////////////////////////////
367 /// Execute a python statement (e.g. "import ROOT").
368 
369 Bool_t TPython::Exec(const char *cmd)
370 {
371  // setup
372  if (!Initialize())
373  return kFALSE;
374 
375  // execute the command
376  PyObject *result = PyRun_String(const_cast<char *>(cmd), Py_file_input, gMainDict, gMainDict);
377 
378  // test for error
379  if (result) {
380  Py_DECREF(result);
381  return kTRUE;
382  }
383 
384  PyErr_Print();
385  return kFALSE;
386 }
387 
388 ////////////////////////////////////////////////////////////////////////////////
389 /// Evaluate a python expression (e.g. "ROOT.TBrowser()").
390 ///
391 /// Caution: do not hold on to the return value: either store it in a builtin
392 /// type (implicit casting will work), or in a pointer to a ROOT object (explicit
393 /// casting to a void* is required).
394 
395 const TPyReturn TPython::Eval(const char *expr)
396 {
397  // setup
398  if (!Initialize())
399  return TPyReturn();
400 
401  // evaluate the expression
402  PyObject *result = PyRun_String(const_cast<char *>(expr), Py_eval_input, gMainDict, gMainDict);
403 
404  // report errors as appropriate; return void
405  if (!result) {
406  PyErr_Print();
407  return TPyReturn();
408  }
409 
410  // results that require no convserion
411  if (result == Py_None || CPyCppyy::CPPInstance_Check(result) || PyBytes_Check(result) || PyFloat_Check(result) ||
412  PyLong_Check(result) || PyInt_Check(result))
413  return TPyReturn(result);
414 
415  // explicit conversion for python type required
416  PyObject *pyclass = PyObject_GetAttrString(result, const_cast<char*>("__class__"));
417  if (pyclass != 0) {
418  // retrieve class name and the module in which it resides
419  PyObject *name = PyObject_GetAttr(pyclass, CPyCppyy::PyStrings::gName);
420  PyObject *module = PyObject_GetAttr(pyclass, CPyCppyy::PyStrings::gModule);
421 
422  // concat name
423  std::string qname = std::string(CPyCppyy_PyText_AsString(module)) + '.' + CPyCppyy_PyText_AsString(name);
424  Py_DECREF(module);
425  Py_DECREF(name);
426  Py_DECREF(pyclass);
427 
428  // locate ROOT style class with this name
429  TClass *klass = TClass::GetClass(qname.c_str());
430 
431  // construct general ROOT python object that pretends to be of class 'klass'
432  if (klass != 0)
433  return TPyReturn(result);
434  } else
435  PyErr_Clear();
436 
437  // no conversion, return null pointer object
438  Py_DECREF(result);
439  return TPyReturn();
440 }
441 
442 ////////////////////////////////////////////////////////////////////////////////
443 /// Bind a ROOT object with, at the python side, the name "label".
444 
445 Bool_t TPython::Bind(TObject *object, const char *label)
446 {
447  // check given address and setup
448  if (!(object && Initialize()))
449  return kFALSE;
450 
451  // bind object in the main namespace
452  TClass *klass = object->IsA();
453  if (klass != 0) {
454  PyObject *bound = CPyCppyy::BindCppObject((void *)object, Cppyy::GetScope(klass->GetName()));
455 
456  if (bound) {
457  Bool_t bOk = PyDict_SetItemString(gMainDict, const_cast<char *>(label), bound) == 0;
458  Py_DECREF(bound);
459 
460  return bOk;
461  }
462  }
463 
464  return kFALSE;
465 }
466 
467 ////////////////////////////////////////////////////////////////////////////////
468 /// Enter an interactive python session (exit with ^D). State is preserved
469 /// between successive calls.
470 
472 {
473  // setup
474  if (!Initialize()) {
475  return;
476  }
477 
478  // enter i/o interactive mode
479  PyRun_InteractiveLoop(stdin, const_cast<char *>("\0"));
480 }
481 
482 ////////////////////////////////////////////////////////////////////////////////
483 /// Test whether the type of the given pyobject is of CPPInstance type or any
484 /// derived type.
485 
487 {
488  // setup
489  if (!Initialize())
490  return kFALSE;
491 
492  // detailed walk through inheritance hierarchy
493  return CPyCppyy::CPPInstance_Check(pyobject);
494 }
495 
496 ////////////////////////////////////////////////////////////////////////////////
497 /// Test whether the type of the given pyobject is CPPinstance type.
498 
500 {
501  // setup
502  if (!Initialize())
503  return kFALSE;
504 
505  // direct pointer comparison of type member
506  return CPyCppyy::CPPInstance_CheckExact(pyobject);
507 }
508 
509 ////////////////////////////////////////////////////////////////////////////////
510 /// Test whether the type of the given pyobject is of CPPOverload type or any
511 /// derived type.
512 
514 {
515  // setup
516  if (!Initialize())
517  return kFALSE;
518 
519  // detailed walk through inheritance hierarchy
520  return CPyCppyy::CPPOverload_Check(pyobject);
521 }
522 
523 ////////////////////////////////////////////////////////////////////////////////
524 /// Test whether the type of the given pyobject is CPPOverload type.
525 
527 {
528  // setup
529  if (!Initialize())
530  return kFALSE;
531 
532  // direct pointer comparison of type member
533  return CPyCppyy::CPPOverload_CheckExact(pyobject);
534 }
535 
536 ////////////////////////////////////////////////////////////////////////////////
537 /// Extract the object pointer held by the CPPInstance pyobject.
538 
540 {
541  // setup
542  if (!Initialize())
543  return 0;
544 
545  // check validity of cast
546  if (!CPyCppyy::CPPInstance_Check(pyobject))
547  return 0;
548 
549  // get held object (may be null)
550  return ((CPyCppyy::CPPInstance *)pyobject)->GetObject();
551 }
552 
553 ////////////////////////////////////////////////////////////////////////////////
554 /// Bind the addr to a python object of class defined by classname.
555 
556 PyObject *TPython::CPPInstance_FromVoidPtr(void *addr, const char *classname, Bool_t python_owns)
557 {
558  // setup
559  if (!Initialize())
560  return 0;
561 
562  // perform cast (the call will check TClass and addr, and set python errors)
563  PyObject *pyobject = CPyCppyy::BindCppObjectNoCast(addr, Cppyy::GetScope(classname), false);
564 
565  // give ownership, for ref-counting, to the python side, if so requested
566  if (python_owns && CPyCppyy::CPPInstance_Check(pyobject))
567  ((CPyCppyy::CPPInstance *)pyobject)->PythonOwns();
568 
569  return pyobject;
570 }
CPyCppyy
Set of helper functions that are invoked from the pythonizors, on the Python side.
Definition: TPyClassGenerator.cxx:31
l
auto * l
Definition: textangle.C:4
CPPInstance.h
TPython::Bind
static Bool_t Bind(TObject *object, const char *label)
Bind a ROOT object with, at the python side, the name "label".
Definition: TPython.cxx:445
TPython::Prompt
static void Prompt()
Enter an interactive python session (exit with ^D).
Definition: TPython.cxx:471
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
CPyCppyy::PyStrings::gModule
R__EXTERN PyObject * gModule
Definition: TPython.cxx:104
TPython.h
PyObject
_object PyObject
Definition: PyMethodBase.h:42
TPython::Eval
static const TPyReturn Eval(const char *expr)
Evaluate a python expression (e.g.
Definition: TPython.cxx:395
gMainDict
static PyObject * gMainDict
Definition: TPython.cxx:96
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TPython
Accessing the Python interpreter from C++.
Definition: TPython.h:29
CPyCppyy::CPPInstance_CheckExact
bool CPPInstance_CheckExact(T *object)
Definition: CPPInstance.h:128
CPyCppyy::CPPInstance
Definition: CPPInstance.h:26
TPython::CPPInstance_CheckExact
static Bool_t CPPInstance_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPinstance type.
Definition: TPython.cxx:499
CPyCppyy_PyText_CheckExact
#define CPyCppyy_PyText_CheckExact
Definition: CPyCppyy.h:96
PyBytes_Check
#define PyBytes_Check
Definition: CPyCppyy.h:83
CPyCppyy_PyText_Check
#define CPyCppyy_PyText_Check
Definition: CPyCppyy.h:95
TPython::ExecScript
static void ExecScript(const char *name, int argc=0, const char **argv=0)
Execute a python stand-alone script, with argv CLI arguments.
Definition: TPython.cxx:300
TPython::LoadMacro
static void LoadMacro(const char *name)
Execute the give python script as if it were a macro (effectively an execfile in main),...
Definition: TPython.cxx:230
bool
TROOT.h
TGeant4Unit::L
static constexpr double L
Definition: TGeant4SystemOfUnits.h:117
CPyCppyy::CPPOverload_Check
bool CPPOverload_Check(T *object)
Definition: CPPOverload.h:79
Cppyy::GetScope
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
Definition: clingwrapper.cxx:497
TPython::CPPInstance_FromVoidPtr
static PyObject * CPPInstance_FromVoidPtr(void *addr, const char *classname, Bool_t python_owns=kFALSE)
Bind the addr to a python object of class defined by classname.
Definition: TPython.cxx:556
CPyCppyy::BindCppObject
PyObject * BindCppObject(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
Definition: ProxyWrappers.cxx:876
CPyCppyy::PyStrings::gCppName
R__EXTERN PyObject * gCppName
Definition: TPython.cxx:103
ProxyWrappers.h
CPyCppyy::CPPOverload_CheckExact
bool CPPOverload_CheckExact(T *object)
Definition: CPPOverload.h:85
CPyCppyy::PyStrings::gBases
R__EXTERN PyObject * gBases
Definition: TPyClassGenerator.cxx:34
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
extract_docstrings.module
module
Definition: extract_docstrings.py:39
CPyCppyy.h
TClass::GetClass
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2946
CPyCppyy::PyStrings::gName
R__EXTERN PyObject * gName
Definition: TPython.cxx:105
TPython::Import
static Bool_t Import(const char *name)
Import the named python module and create Cling equivalents for its classes and methods.
Definition: TPython.cxx:165
TPyReturn
Definition: TPyReturn.h:30
CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_AsString
Definition: CPyCppyy.h:97
TPyClassGenerator
Definition: TPyClassGenerator.h:18
TPython::Exec
static Bool_t Exec(const char *cmd)
Execute a python statement (e.g. "import ROOT").
Definition: TPython.cxx:369
TClassRef.h
TObject.h
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TPython::Initialize
static Bool_t Initialize()
Initialization method: setup the python interpreter and load the ROOT module.
Definition: TPython.cxx:112
CPPOverload.h
name
char name[80]
Definition: TGX11.cxx:110
R__EXTERN
#define R__EXTERN
Definition: DllImport.h:27
TPython::CPPOverload_CheckExact
static Bool_t CPPOverload_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPOverload type.
Definition: TPython.cxx:526
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Riostream.h
CPyCppyy::gThisModule
R__EXTERN PyObject * gThisModule
Definition: TPython.cxx:100
CPyCppyy::CPPInstance_Check
bool CPPInstance_Check(T *object)
Definition: CPPInstance.h:118
TPython::CPPInstance_AsVoidPtr
static void * CPPInstance_AsVoidPtr(PyObject *pyobject)
Extract the object pointer held by the CPPInstance pyobject.
Definition: TPython.cxx:539
TPython::CPPOverload_Check
static Bool_t CPPOverload_Check(PyObject *pyobject)
Test whether the type of the given pyobject is of CPPOverload type or any derived type.
Definition: TPython.cxx:513
CPyCppyy::BindCppObjectNoCast
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
Definition: ProxyWrappers.cxx:802
TPython::CPPInstance_Check
static Bool_t CPPInstance_Check(PyObject *pyobject)
Test whether the type of the given pyobject is of CPPInstance type or any derived type.
Definition: TPython.cxx:486
gROOT
#define gROOT
Definition: TROOT.h:406