1 #include <lib/base/eerror.h>
4 #define _POSIX_C_SOURCE 200112L
5 extern "C" void init_enigma();
6 extern void bsodFatal();
9 #include <lib/python/python.h>
12 #ifdef PYTHON_REFCOUNT_DEBUG
13 ePyObject &ePyObject::operator=(PyObject *ob)
23 ePyObject &ePyObject::operator=(const ePyObject &ob)
34 ePyObject::operator PyObject*()
38 if (!m_erased && m_ob->ob_refcnt > 0)
40 eDebug("invalid access PyObject %s with refcount <= 0 %d",
41 m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt);
43 eDebug("last modified in file %s line %d from %d to %d",
44 m_file, m_line, m_from, m_to);
50 void ePyObject::incref(const char *file, int line)
54 eDebug("invalid incref python object with null pointer %s %d!!!", file, line);
56 eDebug("last modified in file %s line %d from %d to %d",
57 m_file, m_line, m_from, m_to);
60 if (m_erased || m_ob->ob_refcnt <= 0)
62 eDebug("invalid incref %s python object with refcounting value %d in file %s line %d!!!",
63 m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt, file, line);
65 eDebug("last modified in file %s line %d from %d to %d",
66 m_file, m_line, m_from, m_to);
69 if (m_ob->ob_refcnt == 0x7FFFFFFF)
71 eDebug("invalid incref %s python object with refcounting value %d (MAX_INT!!!) in file %s line %d!!!",
72 m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt, file, line);
74 eDebug("last modified in file %s line %d from %d to %d",
75 m_file, m_line, m_from, m_to);
80 m_from = m_ob->ob_refcnt;
85 void ePyObject::decref(const char *file, int line)
89 eDebug("invalid decref python object with null pointer %s %d!!!", file, line);
91 eDebug("last modified in file %s line %d from %d to %d",
92 m_file, m_line, m_from, m_to);
95 if (m_erased || m_ob->ob_refcnt <= 0)
97 eDebug("invalid decref %s python object with refcounting value %d in file %s line %d!!!",
98 m_erased ? "deleted" : "undeleted", m_ob->ob_refcnt, file, line);
100 eDebug("last modified in file %s line %d from %d to %d",
101 m_file, m_line, m_from, m_to);
106 m_from = m_ob->ob_refcnt;
111 #endif // PYTHON_REFCOUNT_DEBUG
114 #include <lib/python/python.h>
121 eDebug("create %p", this);
126 eDebug("destroy %p", this);
131 // Py_VerboseFlag = 1;
133 // Py_OptimizeFlag = 1;
145 int ePython::execute(const std::string &pythonfile, const std::string &funcname)
147 ePyObject pName, pModule, pDict, pFunc, pArgs, pValue;
148 pName = PyString_FromString(pythonfile.c_str());
150 pModule = PyImport_Import(pName);
155 pDict = PyModule_GetDict(pModule);
157 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
159 if (pFunc && PyCallable_Check(pFunc))
161 pArgs = PyTuple_New(0);
162 // implement arguments..
163 pValue = PyObject_CallObject(pFunc, pArgs);
167 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
178 if (PyErr_Occurred())
185 int ePython::call(ePyObject pFunc, ePyObject pArgs)
189 if (pFunc && PyCallable_Check(pFunc))
191 pValue = PyObject_CallObject(pFunc, pArgs);
194 if (PyInt_Check(pValue))
195 res = PyInt_AsLong(pValue);
208 ePyObject ePython::resolve(const std::string &pythonfile, const std::string &funcname)
210 ePyObject pName, pModule, pDict, pFunc;
212 pName = PyString_FromString(pythonfile.c_str());
214 pModule = PyImport_Import(pName);
219 pDict = PyModule_GetDict(pModule);
220 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
223 } else if (PyErr_Occurred())