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::execFile(const char *file)
138 FILE *fp = fopen(file, "r");
141 int ret = PyRun_SimpleFile(fp, file);
146 int ePython::execute(const std::string &pythonfile, const std::string &funcname)
148 ePyObject pName, pModule, pDict, pFunc, pArgs, pValue;
149 pName = PyString_FromString(pythonfile.c_str());
151 pModule = PyImport_Import(pName);
156 pDict = PyModule_GetDict(pModule);
158 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
160 if (pFunc && PyCallable_Check(pFunc))
162 pArgs = PyTuple_New(0);
163 // implement arguments..
164 pValue = PyObject_CallObject(pFunc, pArgs);
168 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
179 if (PyErr_Occurred())
186 int ePython::call(ePyObject pFunc, ePyObject pArgs)
190 if (pFunc && PyCallable_Check(pFunc))
192 pValue = PyObject_CallObject(pFunc, pArgs);
195 if (PyInt_Check(pValue))
196 res = PyInt_AsLong(pValue);
203 ePyObject FuncStr = PyObject_Str(pFunc);
204 ePyObject ArgStr = PyObject_Str(pArgs);
205 eDebug("(PyObject_CallObject(%s,%s) failed)", PyString_AS_STRING(FuncStr), PyString_AS_STRING(ArgStr));
214 ePyObject ePython::resolve(const std::string &pythonfile, const std::string &funcname)
216 ePyObject pName, pModule, pDict, pFunc;
218 pName = PyString_FromString(pythonfile.c_str());
220 pModule = PyImport_Import(pName);
225 pDict = PyModule_GetDict(pModule);
226 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
229 } else if (PyErr_Occurred())