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>
119 // Py_VerboseFlag = 1;
121 // Py_OptimizeFlag = 1;
124 PyEval_InitThreads();
134 int ePython::execute(const std::string &pythonfile, const std::string &funcname)
136 ePyObject pName, pModule, pDict, pFunc, pArgs, pValue;
137 pName = PyString_FromString(pythonfile.c_str());
139 pModule = PyImport_Import(pName);
144 pDict = PyModule_GetDict(pModule);
146 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
148 if (pFunc && PyCallable_Check(pFunc))
150 pArgs = PyTuple_New(0);
151 // implement arguments..
152 pValue = PyObject_CallObject(pFunc, pArgs);
156 printf("Result of call: %ld\n", PyInt_AsLong(pValue));
167 if (PyErr_Occurred())
174 int ePython::call(ePyObject pFunc, ePyObject pArgs)
178 if (pFunc && PyCallable_Check(pFunc))
180 pValue = PyObject_CallObject(pFunc, pArgs);
183 if (PyInt_Check(pValue))
184 res = PyInt_AsLong(pValue);
197 ePyObject ePython::resolve(const std::string &pythonfile, const std::string &funcname)
199 ePyObject pName, pModule, pDict, pFunc;
201 pName = PyString_FromString(pythonfile.c_str());
203 pModule = PyImport_Import(pName);
208 pDict = PyModule_GetDict(pModule);
209 pFunc = PyDict_GetItemString(pDict, funcname.c_str());
212 } else if (PyErr_Occurred())