From 227c7c3497e942ab0e9cbb28a87079d84aa02228 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 30 Nov 2008 13:22:34 +0000 Subject: [PATCH] Compatibility with Python 2.3 --- dtool/src/interrogatedb/py_panda.h | 19 +++++++++++++++++++ panda/src/event/pythonTask.cxx | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/dtool/src/interrogatedb/py_panda.h b/dtool/src/interrogatedb/py_panda.h index 1a5e472660..21cb39c5e2 100755 --- a/dtool/src/interrogatedb/py_panda.h +++ b/dtool/src/interrogatedb/py_panda.h @@ -64,6 +64,25 @@ typedef int Py_ssize_t; #endif // PY_VERSION_HEX +// 2.4 macros which aren't available in 2.3 +#ifndef Py_RETURN_NONE +inline PyObject* doPy_RETURN_NONE() +{ Py_INCREF(Py_None); return Py_None; } +#define Py_RETURN_NONE return doPy_RETURN_NONE() +#endif + +#ifndef Py_RETURN_TRUE +inline PyObject* doPy_RETURN_TRUE() +{Py_INCREF(Py_True); return Py_True;} +#define Py_RETURN_TRUE return doPy_RETURN_TRUE() +#endif + +#ifndef Py_RETURN_FALSE +inline PyObject* doPy_RETURN_FALSE() +{Py_INCREF(Py_False); return Py_False;} +#define Py_RETURN_FALSE return doPy_RETURN_FALSE() +#endif + using namespace std; #define PY_PANDA_SMALLER_FOOTPRINT 1 diff --git a/panda/src/event/pythonTask.cxx b/panda/src/event/pythonTask.cxx index a512e74b6e..9706f65295 100644 --- a/panda/src/event/pythonTask.cxx +++ b/panda/src/event/pythonTask.cxx @@ -378,6 +378,7 @@ do_python_task() { Thread::get_current_thread()->call_python_func(_function, args); Py_DECREF(args); +#ifdef PyGen_Check if (result != (PyObject *)NULL && PyGen_Check(result)) { // The function has yielded a generator. We will call into that // henceforth, instead of calling the function from the top @@ -392,6 +393,7 @@ do_python_task() { _generator = result; result = NULL; } +#endif } if (_generator != (PyObject *)NULL) { @@ -597,7 +599,7 @@ call_function(PyObject *function) { PyObject *self = DTool_CreatePyInstanceTyped(this, Dtool_TypedReferenceCount, true, false, get_type_index()); - PyObject *args = PyTuple_Pack(1, self); + PyObject *args = Py_BuildValue("(O)", self); Py_DECREF(self); PyObject *result = PyObject_CallObject(function, args);