1 #include <lib/base/eerror.h>
4 #define _POSIX_C_SOURCE 200112L
5 extern "C" void init_enigma();
6 extern "C" void eBaseInit(void);
7 extern void bsodFatal();
10 #include <lib/python/python.h>
13 #ifdef PYTHON_REFCOUNT_DEBUG
14 ePyObject &ePyObject::operator=(PyObject *ob)
24 ePyObject &ePyObject::operator=(const ePyObject &ob)
35 ePyObject::operator PyObject*()
39 if (!m_erased && m_ob->ob_refcnt > 0)
41 eDebug("invalid access PyObject %s with refcount <= 0 %d",
42 m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt);
44 eDebug("last modified in file %s line %d from %d to %d",
45 m_file, m_line, m_from, m_to);
51 void ePyObject::incref(const char *file, int line)
55 eDebug("invalid incref python object with null pointer %s %d!!!", file, line);
57 eDebug("last modified in file %s line %d from %d to %d",
58 m_file, m_line, m_from, m_to);
61 if (m_erased || m_ob->ob_refcnt <= 0)
63 eDebug("invalid incref %s python object with refcounting value %d in file %s line %d!!!",
64 m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt, file, line);
66 eDebug("last modified in file %s line %d from %d to %d",
67 m_file, m_line, m_from, m_to);
70 if (m_ob->ob_refcnt == 0x7FFFFFFF)
72 eDebug("invalid incref %s python object with refcounting value %d (MAX_INT!!!) in file %s line %d!!!",
73 m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt, file, line);
75 eDebug("last modified in file %s line %d from %d to %d",
76 m_file, m_line, m_from, m_to);
81 m_from = m_ob->ob_refcnt;
86 void ePyObject::decref(const char *file, int line)
90 eDebug("invalid decref python object with null pointer %s %d!!!", file, line);
92 eDebug("last modified in file %s line %d from %d to %d",
93 m_file, m_line, m_from, m_to);
96 if (m_erased || m_ob->ob_refcnt <= 0)
98 eDebug("invalid decref %s python object with refcounting value %d in file %s line %d!!!",
99 m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt, file, line);
101 eDebug("last modified in file %s line %d from %d to %d",
102 m_file, m_line, m_from, m_to);
107 m_from = m_ob->ob_refcnt;
112 #endif // PYTHON_REFCOUNT_DEBUG
115 #include <lib/python/python.h>
120 // Py_VerboseFlag = 1;
122 // Py_OptimizeFlag = 1;
125 PyEval_InitThreads();
136 int ePython::execute(const std::string &pythonfile, const std::string &funcname)
138 ePyObject pName, pModule, pDict, pFunc, pArgs, pValue;
139 pName = PyString_FromString(pythonfile.c_str());
141 pModule = PyImport_Import(pName);
146 pDict = PyModule_GetDict(pModule);
148 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
150 if (pFunc && PyCallable_Check(pFunc))
152 pArgs = PyTuple_New(0);
153 // implement arguments..
154 pValue = PyObject_CallObject(pFunc, pArgs);
158 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
169 if (PyErr_Occurred())
176 int ePython::call(ePyObject pFunc, ePyObject pArgs)
180 if (pFunc && PyCallable_Check(pFunc))
182 pValue = PyObject_CallObject(pFunc, pArgs);
185 if (PyInt_Check(pValue))
186 res = PyInt_AsLong(pValue);
193 ePyObject FuncStr = PyObject_Str(pFunc);
194 ePyObject ArgStr = PyObject_Str(pArgs);
195 eDebug("(PyObject_CallObject(%s,%s) failed)", PyString_AS_STRING(FuncStr), PyString_AS_STRING(ArgStr));
204 ePyObject ePython::resolve(const std::string &pythonfile, const std::string &funcname)
206 ePyObject pName, pModule, pDict, pFunc;
208 pName = PyString_FromString(pythonfile.c_str());
210 pModule = PyImport_Import(pName);
215 pDict = PyModule_GetDict(pModule);
216 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
219 } else if (PyErr_Occurred())