#define __lib_python_python_class_h
#endif
+#include <Python.h>
#include <string>
#include <lib/base/object.h>
-#include <Python.h>
#if !defined(SKIP_PART1) && !defined(SWIG)
class ePyObject
#ifdef PYTHON_REFCOUNT_DEBUG
inline ePyObject(PyObject *ob, const char *file, int line);
#endif
+ inline ePyObject(PyVarObject *ob);
inline ePyObject(PyDictObject *ob);
inline ePyObject(PyTupleObject *ob);
inline ePyObject(PyListObject *ob);
operator bool() { return !!m_ob; }
ePyObject &operator=(const ePyObject &);
ePyObject &operator=(PyObject *);
+ ePyObject &operator=(PyVarObject *ob) { return operator=((PyObject*)ob); }
ePyObject &operator=(PyDictObject *ob) { return operator=((PyObject*)ob); }
ePyObject &operator=(PyTupleObject *ob) { return operator=((PyObject*)ob); }
ePyObject &operator=(PyListObject *ob) { return operator=((PyObject*)ob); }
ePyObject &operator=(PyStringObject *ob) { return operator=((PyObject*)ob); }
operator PyObject*();
+ operator PyVarObject*() { return (PyVarObject*)operator PyVarObject*(); }
operator PyTupleObject*() { return (PyTupleObject*)operator PyObject*(); }
operator PyListObject*() { return (PyListObject*)operator PyObject*(); }
operator PyStringObject*() { return (PyStringObject*)operator PyObject*(); }
}
#endif
+inline ePyObject::ePyObject(PyVarObject *ob)
+ :m_ob((PyObject*)ob)
+#ifdef PYTHON_REFCOUNT_DEBUG
+ ,m_file(0), m_line(0), m_from(0), m_to(0), m_erased(false)
+#endif
+{
+}
+
inline ePyObject::ePyObject(PyDictObject *ob)
:m_ob((PyObject*)ob)
#ifdef PYTHON_REFCOUNT_DEBUG
Py_DECREF(m_ob);
}
+class ePyObjectWrapper
+{
+ ePyObject m_obj;
+public:
+ ePyObjectWrapper(const ePyObjectWrapper &wrapper)
+ :m_obj(wrapper.m_obj)
+ {
+ Py_INCREF(m_obj);
+ }
+ ePyObjectWrapper(const ePyObject &obj)
+ :m_obj(obj)
+ {
+ Py_INCREF(m_obj);
+ }
+ ~ePyObjectWrapper()
+ {
+ Py_DECREF(m_obj);
+ }
+ ePyObjectWrapper &operator=(const ePyObjectWrapper &wrapper)
+ {
+ Py_DECREF(m_obj);
+ m_obj = wrapper.m_obj;
+ Py_INCREF(m_obj);
+ return *this;
+ }
+ operator PyObject*()
+ {
+ return m_obj;
+ }
+ operator ePyObject()
+ {
+ return m_obj;
+ }
+};
+
#endif // ! PYTHON_REFCOUNT_DEBUG
#endif // !SWIG && !SKIP_PART1
#ifndef SKIP_PART2
-
-class TestObj
-{
-DECLARE_REF(TestObj);
-public:
- TestObj();
- ~TestObj();
-};
-TEMPLATE_TYPEDEF(ePtr<TestObj>, TestObjPtr);
-
#ifndef SWIG
-extern PyObject *New_TestObj();
#ifdef PYTHON_REFCOUNT_DEBUG
inline void Impl_Py_DECREF(const char* file, int line, const ePyObject &obj)
{
return ePyObject(PyString_FromString(str), file, line);
}
+inline ePyObject Impl_PyString_FromFormat(const char* file, int line, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ PyObject *ob = PyString_FromFormatV(fmt, ap);
+ va_end(ap);
+ return ePyObject(ob, file, line);
+}
+
inline ePyObject Impl_PyInt_FromLong(const char* file, int line, long val)
{
return ePyObject(PyInt_FromLong(val), file, line);
return ePyObject(PyLong_FromLongLong(val), file, line);
}
-inline ePyObject Impl_New_TestObj(const char* file, int line)
-{
- return ePyObject(New_TestObj(), file, line);
-}
-
inline ePyObject Impl_PyList_GET_ITEM(const char *file, int line, ePyObject list, unsigned int pos)
{
return ePyObject(PyList_GET_ITEM(list, pos), file, line);
return PyString_FromString(str);
}
+inline ePyObject Impl_PyString_FromFormat(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ PyObject *ob = PyString_FromFormatV(fmt, ap);
+ va_end(ap);
+ return ePyObject(ob);
+}
+
inline ePyObject Impl_PyInt_FromLong(long val)
{
return PyInt_FromLong(val);
return PyLong_FromLongLong(val);
}
-inline ePyObject Impl_New_TestObj()
-{
- return New_TestObj();
-}
-
inline ePyObject Impl_PyList_GET_ITEM(ePyObject list, unsigned int pos)
{
return PyList_GET_ITEM(list, pos);
}
#endif
+inline void Impl_INCREF(PyObject *ob)
+{
+ Py_INCREF(ob);
+}
+
inline void Impl_DECREF(PyObject *ob)
{
Py_DECREF(ob);
}
+#define Org_Py_INCREF(obj) Impl_INCREF(obj)
#define Org_Py_DECREF(obj) Impl_DECREF(obj)
#undef Py_DECREF
#undef Py_XDECREF
#define PyTuple_New(args...) Impl_PyTuple_New(__FILE__, __LINE__, args)
#define PyDict_New(...) Impl_PyDict_New(__FILE__, __LINE__)
#define PyString_FromString(str) Impl_PyString_FromString(__FILE__, __LINE__, str)
+#define PyString_FromFormat(str, args...) Impl_PyString_FromFormat(__FILE__, __LINE__, str, args)
#define PyInt_FromLong(val) Impl_PyInt_FromLong(__FILE__, __LINE__, val)
#define PyLong_FromLong(val) Impl_PyLong_FromLong(__FILE__, __LINE__, val)
#define PyLong_FromUnsignedLong(val) Impl_PyLong_FromUnsignedLong(__FILE__, __LINE__, val)
#define PyLong_FromLongLong(val) Impl_PyLong_FromLongLong(__FILE__, __LINE__, val)
-#define NEW_TestObj(...) Impl_New_TestObj(__FILE__, __LINE__)
#define PyList_GET_ITEM(list, pos) Impl_PyList_GET_ITEM(__FILE__, __LINE__, list, pos)
#define PyTuple_GET_ITEM(list, pos) Impl_PyTuple_GET_ITEM(__FILE__, __LINE__, list, pos)
#else
#define PyTuple_New(args...) Impl_PyTuple_New(args)
#define PyDict_New(...) Impl_PyDict_New()
#define PyString_FromString(str) Impl_PyString_FromString(str)
+#define PyString_FromFormat(str, args...) Impl_PyString_FromFormat(str, args)
#define PyInt_FromLong(val) Impl_PyInt_FromLong(val)
#define PyLong_FromLong(val) Impl_PyLong_FromLong(val)
#define PyLong_FromUnsignedLong(val) Impl_PyLong_FromUnsignedLong(val)
#define PyLong_FromLongLong(val) Impl_PyLong_FromLongLong(val)
-#define NEW_TestObj(...) Impl_New_TestObj()
#define PyList_GET_ITEM(list, pos) Impl_PyList_GET_ITEM(list, pos)
#define PyTuple_GET_ITEM(list, pos) Impl_PyTuple_GET_ITEM(list, pos)
#endif
public:
ePython();
~ePython();
+ int execFile(const char *file);
int execute(const std::string &pythonfile, const std::string &funcname);
static int call(ePyObject pFunc, ePyObject args);
static ePyObject resolve(const std::string &pythonfile, const std::string &funcname);
#endif // SWIG
#endif // SKIP_PART2
-
#endif // __lib_python_python_class_h