3#define CPYCPPYY_INTERNAL 1
5#undef CPYCPPYY_INTERNAL
43 static bool isInitialized =
false;
47 if (!Py_IsInitialized()) {
49#if PY_VERSION_HEX < 0x03020000
53#if PY_VERSION_HEX >= 0x03020000
54#if PY_VERSION_HEX < 0x03090000
60 if (!Py_IsInitialized()) {
62 std::cerr <<
"Error: python has not been intialized; returning." << std::endl;
67#if PY_VERSION_HEX < 0x03000000
68 char* argv[] = {
const_cast<char*
>(
"cppyy")};
70 wchar_t* argv[] = {
const_cast<wchar_t*
>(
L"cppyy")};
72 PySys_SetArgv(
sizeof(argv)/
sizeof(argv[0]), argv);
75 PyRun_SimpleString(
const_cast<char*
>(
"import cppyy"));
81 PyImport_AddModule(
const_cast<char*
>(
"__main__")));
110 void* addr,
const std::string& classname,
bool python_owns)
178 if (pyobject->ob_refcnt <= 1 && (((
CPPInstance*)pyobject)->fFlags & CPPInstance::kIsOwner))
214 PyObject* mod = PyImport_ImportModule(mod_name.c_str());
222 PyModule_AddObject(
gThisModule, mod_name.c_str(), mod);
228 PyObject* dct = PyModule_GetDict(mod);
231 PyObject* values = PyDict_Values(dct);
232 for (
int i = 0; i < PyList_GET_SIZE(values); ++i) {
233 PyObject* value = PyList_GET_ITEM(values, i);
237 if (PyClass_Check(value) || PyObject_HasAttr(value, PyStrings::gBases)) {
239 PyObject* pyClName = PyObject_GetAttr(value, PyStrings::gName);
240 if (PyErr_Occurred())
244 std::string fullname = mod_name;
252 Py_XDECREF(pyClName);
261 if (PyErr_Occurred())
279 std::cerr <<
"Error: no file name specified." << std::endl;
283 FILE* fp = fopen(
name.c_str(),
"r");
285 std::cerr <<
"Error: could not open file \"" <<
name <<
"\"." << std::endl;
290 PyObject* oldargv = PySys_GetObject(
const_cast<char*
>(
"argv"));
294 PyObject*
l = PyList_New(PyList_GET_SIZE(oldargv));
295 for (
int i = 0; i < PyList_GET_SIZE(oldargv); ++i) {
296 PyObject* item = PyList_GET_ITEM(oldargv, i);
298 PyList_SET_ITEM(
l, i, item);
304#if PY_VERSION_HEX < 0x03000000
305 int argc = args.size() + 1;
306 const char** argv =
new const char*[argc];
307 for (
int i = 1; i < argc; ++i) argv[i] = args[i-1].c_str();
308 argv[0] = Py_GetProgramName();
309 PySys_SetArgv(argc,
const_cast<char**
>(argv));
319 PyRun_FileEx(fp,
const_cast<char*
>(
name.c_str()), Py_file_input, gbl, gbl, 1);
327 PySys_SetObject(
const_cast<char*
>(
"argv"), oldargv);
377 PyFloat_Check(result) || PyLong_Check(result) || PyInt_Check(result))
384 PyObject*
name = PyObject_GetAttr(pyclass, PyStrings::gName);
385 PyObject* module = PyObject_GetAttr(pyclass, PyStrings::gModule);
397 void* klass =
nullptr;
416 PyRun_InteractiveLoop(stdin,
const_cast<char*
>(
"\0"));
static PyObject * gMainDict
#define CPyCppyy_PyText_AsString
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
Set of helper functions that are invoked from the pythonizors, on the Python side.
CPYCPPYY_EXTERN bool Instance_CheckExact(PyObject *pyobject)
CPYCPPYY_EXTERN void Prompt()
CPYCPPYY_EXTERN bool Overload_Check(PyObject *pyobject)
CPYCPPYY_EXTERN bool Overload_CheckExact(PyObject *pyobject)
CPYCPPYY_EXTERN bool Import(const std::string &name)
CPYCPPYY_EXTERN void ExecScript(const std::string &name, const std::vector< std::string > &args)
CPYCPPYY_EXTERN bool Instance_IsLively(PyObject *pyobject)
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
bool CPPOverload_Check(T *object)
bool CPPScope_Check(T *object)
CPYCPPYY_EXTERN bool Instance_Check(PyObject *pyobject)
CPYCPPYY_EXTERN PyObject * Instance_FromVoidPtr(void *addr, const std::string &classname, bool python_owns=false)
CPYCPPYY_EXTERN bool Scope_CheckExact(PyObject *pyobject)
bool CPPInstance_Check(T *object)
bool CPPInstance_CheckExact(T *object)
R__EXTERN PyObject * gThisModule
bool CPPScope_CheckExact(T *object)
CPYCPPYY_EXTERN void * Instance_AsVoidPtr(PyObject *pyobject)
CPYCPPYY_EXTERN bool Scope_Check(PyObject *pyobject)
CPYCPPYY_EXTERN bool Exec(const std::string &cmd)
bool CPPOverload_CheckExact(T *object)
CPYCPPYY_EXTERN const PyResult Eval(const std::string &expr)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RooArgList L(Args_t &&... args)
void Initialize(Bool_t useTMVAStyle=kTRUE)