21#include "TPyClassGenerator.h"
112 if (!Py_IsInitialized()) {
114#if PY_VERSION_HEX < 0x03020000
115 PyEval_InitThreads();
118#if PY_VERSION_HEX >= 0x03020000
119 PyEval_InitThreads();
123 if (!Py_IsInitialized()) {
125 std::cerr <<
"Error: python has not been intialized; returning." << std::endl;
130#if PY_VERSION_HEX < 0x03000000
131 char *argv[] = {
const_cast<char *
>(
"root")};
133 wchar_t *argv[] = {
const_cast<wchar_t *
>(
L"root")};
135 PySys_SetArgv(
sizeof(argv) /
sizeof(argv[0]), argv);
138 PyRun_SimpleString(
const_cast<char *
>(
"import ROOT"));
143 gMainDict = PyModule_GetDict(PyImport_AddModule(
const_cast<char *
>(
"__main__")));
151 isInitialized =
kTRUE;
165 PyObject *mod = PyImport_ImportModule(mod_name);
178 PyObject *dct = PyModule_GetDict(mod);
181 PyObject *values = PyDict_Values(dct);
182 for (
int i = 0; i < PyList_GET_SIZE(values); ++i) {
183 PyObject *value = PyList_GET_ITEM(values, i);
194 if (PyErr_Occurred())
198 std::string fullname = mod_name;
205 Py_XDECREF(pyClName);
214 if (PyErr_Occurred())
234#if PY_VERSION_HEX < 0x03000000
235 Exec((std::string(
"execfile(\"") +
name +
"\")").c_str());
237 Exec((std::string(
"__pyroot_f = open(\"") +
name +
"\"); "
238 "exec(__pyroot_f.read()); "
239 "__pyroot_f.close(); del __pyroot_f")
247 for (
int i = 0; i < PyList_GET_SIZE(current); ++i) {
248 PyObject *value = PyList_GET_ITEM(current, i);
251 if (!PySequence_Contains(old, value)) {
258 if (PyErr_Occurred())
263 if ((pyModName && pyClName) &&
275 Py_XDECREF(pyClName);
276 Py_XDECREF(pyModName);
295#
if PY_VERSION_HEX < 0x03000000
307 std::cerr <<
"Error: no file name specified." << std::endl;
311 FILE *fp = fopen(
name,
"r");
313 std::cerr <<
"Error: could not open file \"" <<
name <<
"\"." << std::endl;
318 PyObject *oldargv = PySys_GetObject(
const_cast<char *
>(
"argv"));
322 PyObject *
l = PyList_New(PyList_GET_SIZE(oldargv));
323 for (
int i = 0; i < PyList_GET_SIZE(oldargv); ++i) {
324 PyObject *item = PyList_GET_ITEM(oldargv, i);
326 PyList_SET_ITEM(
l, i, item);
333#if PY_VERSION_HEX < 0x03000000
334 const char **argv2 =
new const char *[argc];
335 for (
int i = 1; i < argc; ++i)
336 argv2[i] = argv[i - 1];
337 argv2[0] = Py_GetProgramName();
338 PySys_SetArgv(argc,
const_cast<char **
>(argv2));
347 PyRun_FileEx(fp,
const_cast<char *
>(
name), Py_file_input, gbl, gbl, 1);
355 PySys_SetObject(
const_cast<char *
>(
"argv"), oldargv);
406 PyLong_Check(result) || PyInt_Check(result))
410 PyObject *pyclass = PyObject_GetAttrString(result,
const_cast<char*
>(
"__class__"));
446 TClass *klass =
object->IsA();
451 Bool_t bOk = PyDict_SetItemString(
gMainDict,
const_cast<char *
>(label), bound) == 0;
473 PyRun_InteractiveLoop(stdin,
const_cast<char *
>(
"\0"));
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_CheckExact
#define CPyCppyy_PyText_Check
static PyObject * gMainDict
TClass instances represent classes, structs and namespaces in the ROOT type system.
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.
virtual const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
Accessing the Python interpreter from C++.
static void Prompt()
Enter an interactive python session (exit with ^D).
static Bool_t CPPOverload_Check(PyObject *pyobject)
Test whether the type of the given pyobject is of CPPOverload type or any derived type.
static void * CPPInstance_AsVoidPtr(PyObject *pyobject)
Extract the object pointer held by the CPPInstance pyobject.
static Bool_t Import(const char *name)
Import the named python module and create Cling equivalents for its classes and methods.
static Bool_t CPPInstance_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPinstance type.
static Bool_t Bind(TObject *object, const char *label)
Bind a ROOT object with, at the python side, the name "label".
static void LoadMacro(const char *name)
Execute the give python script as if it were a macro (effectively an execfile in main),...
static Bool_t CPPOverload_CheckExact(PyObject *pyobject)
Test whether the type of the given pyobject is CPPOverload type.
static Bool_t Initialize()
Initialization method: setup the python interpreter and load the ROOT module.
static Bool_t Exec(const char *cmd)
Execute a python statement (e.g. "import ROOT").
static void ExecScript(const char *name, int argc=0, const char **argv=0)
Execute a python stand-alone script, with argv CLI arguments.
static Bool_t CPPInstance_Check(PyObject *pyobject)
Test whether the type of the given pyobject is of CPPInstance type or any derived type.
static const TPyReturn Eval(const char *expr)
Evaluate a python expression (e.g.
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.
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
bool CPPOverload_Check(T *object)
bool CPPInstance_Check(T *object)
bool CPPInstance_CheckExact(T *object)
PyObject * BindCppObject(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
bool CPPOverload_CheckExact(T *object)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
static constexpr double L