20#include "TPyClassGenerator.h"
101 namespace PyStrings {
118 if (!Py_IsInitialized()) {
120#if PY_VERSION_HEX < 0x03020000
121 PyEval_InitThreads();
124#if PY_VERSION_HEX >= 0x03020000
125#if PY_VERSION_HEX < 0x03090000
126 PyEval_InitThreads();
131 if (!Py_IsInitialized()) {
133 std::cerr <<
"Error: python has not been intialized; returning." << std::endl;
138#if PY_VERSION_HEX < 0x03000000
139 char *argv[] = {
const_cast<char *
>(
"root")};
141 wchar_t *argv[] = {
const_cast<wchar_t *
>(L
"root")};
143 PySys_SetArgv(
sizeof(argv) /
sizeof(argv[0]), argv);
146 PyRun_SimpleString(
const_cast<char *
>(
"import ROOT"));
151 gMainDict = PyModule_GetDict(PyImport_AddModule(
const_cast<char *
>(
"__main__")));
159 isInitialized =
kTRUE;
173 PyObject *mod = PyImport_ImportModule(mod_name);
186 PyObject *dct = PyModule_GetDict(mod);
189 PyObject *values = PyDict_Values(dct);
190 for (
int i = 0; i < PyList_GET_SIZE(values); ++i) {
191 PyObject *value = PyList_GET_ITEM(values, i);
202 if (PyErr_Occurred())
206 std::string fullname = mod_name;
213 Py_XDECREF(pyClName);
222 if (PyErr_Occurred())
242#if PY_VERSION_HEX < 0x03000000
243 Exec((std::string(
"execfile(\"") +
name +
"\")").c_str());
245 Exec((std::string(
"__pyroot_f = open(\"") +
name +
"\"); "
246 "exec(__pyroot_f.read()); "
247 "__pyroot_f.close(); del __pyroot_f")
255 for (
int i = 0; i < PyList_GET_SIZE(current); ++i) {
256 PyObject *value = PyList_GET_ITEM(current, i);
259 if (!PySequence_Contains(old, value)) {
266 if (PyErr_Occurred())
271 if ((pyModName && pyClName) &&
283 Py_XDECREF(pyClName);
284 Py_XDECREF(pyModName);
303#
if PY_VERSION_HEX < 0x03000000
315 std::cerr <<
"Error: no file name specified." << std::endl;
319 FILE *fp = fopen(
name,
"r");
321 std::cerr <<
"Error: could not open file \"" <<
name <<
"\"." << std::endl;
326 PyObject *oldargv = PySys_GetObject(
const_cast<char *
>(
"argv"));
330 PyObject *
l = PyList_New(PyList_GET_SIZE(oldargv));
331 for (
int i = 0; i < PyList_GET_SIZE(oldargv); ++i) {
332 PyObject *item = PyList_GET_ITEM(oldargv, i);
334 PyList_SET_ITEM(
l, i, item);
341#if PY_VERSION_HEX < 0x03000000
342 const char **argv2 =
new const char *[argc];
343 for (
int i = 1; i < argc; ++i)
344 argv2[i] = argv[i - 1];
345 argv2[0] = Py_GetProgramName();
346 PySys_SetArgv(argc,
const_cast<char **
>(argv2));
355 PyRun_FileEx(fp,
const_cast<char *
>(
name), Py_file_input, gbl, gbl, 1);
363 PySys_SetObject(
const_cast<char *
>(
"argv"), oldargv);
414 PyLong_Check(result) || PyInt_Check(result))
418 PyObject *pyclass = PyObject_GetAttrString(result,
const_cast<char*
>(
"__class__"));
454 TClass *klass =
object->IsA();
459 Bool_t bOk = PyDict_SetItemString(
gMainDict,
const_cast<char *
>(label), bound) == 0;
481 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.
R__EXTERN PyObject * gName
R__EXTERN PyObject * gCppName
R__EXTERN PyObject * gBases
R__EXTERN PyObject * gModule
Set of helper functions that are invoked from the pythonizors, on the Python side.
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)
R__EXTERN PyObject * gThisModule
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)