add PyObject refcount debugging code
[vuplus_dvbapp] / lib / python / python.h
1 #ifndef __lib_python_python_h
2 #define __lib_python_python_h
3
4 #include <string>
5 #include <lib/base/object.h>
6 #include <Python.h>
7
8 // useable for debugging python refcounting
9 #undef Py_DECREF
10 #undef Py_XDECREF
11 #undef Py_INCREF
12 #undef Py_XINCREF
13 #define Py_XDECREF(obj) Impl_Py_XDECREF(__FILE__, __LINE__, obj)
14 #define Py_DECREF(obj) Impl_Py_DECREF(__FILE__, __LINE__, obj)
15 #define Py_XINCREF(obj) Impl_Py_XINCREF(__FILE__, __LINE__, obj)
16 #define Py_INCREF(obj) Impl_Py_INCREF(__FILE__, __LINE__, obj)
17
18 void Impl_Py_DECREF(const char* file, int line, PyObject *obj);
19
20 inline void Impl_Py_XDECREF(const char* file, int line, PyObject *obj)
21 {
22         if (obj)
23                 Impl_Py_DECREF(file, line, obj);
24 }
25
26 void Impl_Py_INCREF(const char* file, int line, PyObject *obj);
27
28 inline void Impl_Py_XINCREF(const char* file, int line, PyObject *obj)
29 {
30         if (obj)
31                 Impl_Py_INCREF(file, line, obj);
32 }
33
34 extern PyObject *New_TestObj();
35
36 class TestObj
37 {
38 DECLARE_REF(TestObj);
39 public:
40         TestObj();
41         ~TestObj();
42 };
43 TEMPLATE_TYPEDEF(ePtr<TestObj>, TestObjPtr);
44
45 #ifndef SWIG
46 /* class ePyObject
47 {
48         void *m_object;
49 public:
50         ePyObject(void *ptr);
51         ePyObject(ePyObject &p);
52         ePyObject();
53         ePyObject &operator=(ePyObject &p);
54         ePyObject &operator=(void *p);
55         ~ePyObject();
56         void *get() { return m_object; }
57 }; */
58
59 class ePython
60 {
61 public:
62         ePython();
63         ~ePython();
64         int execute(const std::string &pythonfile, const std::string &funcname);
65         static int call(PyObject *pFunc, PyObject *args);
66         static PyObject *resolve(const std::string &pythonfile, const std::string &funcname);
67 private:
68 };
69 #endif // SWIG
70
71 #endif