6#define CPYRT_INTERNAL 1
41static bool Initialize() {
44 static bool isInitialized =
false;
48 if (!Py_IsInitialized()) {
51 PyConfig_InitPythonConfig(&config);
52 PyConfig_SetString(&config, &config.program_name, L
"cppjit");
53 Py_InitializeFromConfig(&config);
56 if (!Py_IsInitialized()) {
58 std::cerr <<
"Error: python has not been initialized; returning."
67 PyObject* cppjitmod = PyImport_ImportModule(
"cppjit");
77 PyModule_GetDict(PyImport_AddModule(
const_cast<char*
>(
"__main__")));
96 "Instance_GetScopedFinalName : object is not a C++ instance");
245 return (
bool)PySequence_Check(pyobject);
249 PyTypeObject* t = Py_TYPE(pyobject);
250 if (!t->tp_as_sequence || !t->tp_as_sequence->sq_item)
254 if (t->tp_as_sequence->sq_item ==
CPPInstance_Type.tp_as_sequence->sq_item) {
275 if (Py_REFCNT(pyobject) <= 1 &&
306 CPPInstance::ReduceMethod() = reduceMethod;
318 PyObject* mod = PyImport_ImportModule(mod_name.c_str());
326 PyModule_AddObject(
gThisModule, mod_name.c_str(), mod);
332 PyObject* dct = PyModule_GetDict(mod);
335 PyObject* values = PyDict_Values(dct);
336 for (
int i = 0; i < PyList_GET_SIZE(values); ++i) {
341 if (PyType_Check(
value) || PyObject_HasAttr(
value, PyStrings::gBases)) {
343 PyObject* pyClName = PyObject_GetAttr(
value, PyStrings::gName);
344 if (PyErr_Occurred())
348 std::string fullname = mod_name;
350 fullname += PyUnicode_AsUTF8(pyClName);
352 Py_XDECREF(pyClName);
361 if (PyErr_Occurred())
368 const std::vector<std::string>& args) {
381 std::cerr <<
"Error: no file name specified." << std::endl;
385 FILE* fp = fopen(
name.c_str(),
"r");
387 std::cerr <<
"Error: could not open file \"" <<
name <<
"\"." << std::endl;
392 PyObject* oldargv = PySys_GetObject(
"argv");
394 PyObject* copy = PyList_GetSlice(oldargv, 0, PyList_Size(oldargv));
401 const int argc = (
int)args.size() + 1;
402 std::vector<wchar_t*> wargv(argc);
403 wargv[0] = Py_DecodeLocale(
name.c_str(),
nullptr);
405 for (
int i = 1; i < argc; ++i) {
406 wargv[i] = Py_DecodeLocale(args[i - 1].c_str(),
nullptr);
410 PyObject* sysmod = PyImport_ImportModule(
"sys");
412 PyObject* argv_obj = PyList_New(argc);
413 for (
int i = 0; i < argc; ++i) {
414 PyList_SET_ITEM(argv_obj, i, PyUnicode_FromWideChar(wargv[i], -1));
416 PyObject_SetAttrString(sysmod,
"argv", argv_obj);
426 PyRun_FileEx(fp,
const_cast<char*
>(
name.c_str()), Py_file_input, gbl, gbl,
437 PySys_SetObject(
"argv", oldargv);
442 for (
auto ptr : wargv)
454 PyObject*
result = PyRun_String(
const_cast<char*
>(cmd.c_str()), Py_file_input,
476 PyRun_InteractiveLoop(stdin,
const_cast<char*
>(
"\0"));
static PyObject * gMainDict
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
bool CPPOverload_Check(T *object)
CPYRT_EXTERN std::string Instance_GetScopedFinalName(PyObject *pyobject)
CPYRT_EXTERN void Instance_SetReduceMethod(PyCFunction reduceMethod)
PyTypeObject CPPInstance_Type
bool CPPOverload_CheckExact(T *object)
CPYRT_EXTERN bool Scope_CheckExact(PyObject *pyobject)
CPYRT_EXTERN bool Sequence_Check(PyObject *pyobject)
CPYRT_EXTERN bool Exec(const std::string &cmd)
bool CPPInstance_CheckExact(T *object)
CPYRT_EXTERN bool Scope_Check(PyObject *pyobject)
CPYRT_EXTERN bool Overload_Check(PyObject *pyobject)
CPYRT_EXTERN bool Instance_Check(PyObject *pyobject)
bool CPPScope_CheckExact(T *object)
CPYRT_EXTERN void ExecScript(const std::string &name, const std::vector< std::string > &args)
PyObject * BindCppObjectNoCast(interop::TCppObject_t object, interop::TCppScope_t klass, const unsigned flags=0)
CPYRT_EXTERN void Prompt()
CPYRT_EXTERN void * Instance_AsVoidPtr(PyObject *pyobject)
CPYRT_EXTERN bool Instance_IsLively(PyObject *pyobject)
bool CPPScope_Check(T *object)
bool CPPInstance_Check(T *object)
CPYRT_EXTERN void Instance_SetCppOwns(PyObject *pyobject)
CPYRT_EXTERN bool Overload_CheckExact(PyObject *pyobject)
PyObject * Instance_FromVoidPtr(void *addr, const char *classname, int python_owns)
CPYRT_EXTERN void Instance_SetPythonOwns(PyObject *pyobject)
CPYRT_EXTERN bool Instance_CheckExact(PyObject *pyobject)
CPYRT_EXTERN bool Import(const std::string &name)
TCppScope_t GetScope(const std::string &scope_name, TCppScope_t parent_scope=TCppScope_t{})
std::string GetScopedFinalName(TCppScope_t type)