From f8073ea1cd935154a50b0b9b8221db1254119100 Mon Sep 17 00:00:00 2001 From: "kr.angelov" Date: Wed, 19 Jun 2013 19:31:55 +0000 Subject: [PATCH] =?UTF-8?q?f=C3=ADx=20in=20the=20Python=20binding=20for=20?= =?UTF-8?q?compatibility=20with=20Python<2.7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/runtime/python/pypgf.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c index 756f7c7cb..dc2d18bfa 100644 --- a/src/runtime/python/pypgf.c +++ b/src/runtime/python/pypgf.c @@ -666,6 +666,15 @@ pypgf_new_python_lexer(PyObject* pylexer, GuPool* pool) return ((PgfLexer*) lexer); } +#if ( (PY_VERSION_HEX < 0x02070000) \ + || ((PY_VERSION_HEX >= 0x03000000) \ + && (PY_VERSION_HEX < 0x03010000)) ) + +#define PyPool_New(pool) \ + PyCObject_FromVoidPtr(pool, gu_pool_free) + +#else + #define PGF_CONTAINER_NAME "pgf.Container" void pypgf_container_descructor(PyObject *capsule) @@ -674,6 +683,12 @@ void pypgf_container_descructor(PyObject *capsule) gu_pool_free(pool); } +#define PyPool_New(pool) \ + PyCapsule_New(pool, PGF_CONTAINER_NAME, \ + pypgf_container_descructor) + +#endif + static IterObject* Concr_parse(ConcrObject* self, PyObject *args, PyObject *keywds) { @@ -712,10 +727,8 @@ Concr_parse(ConcrObject* self, PyObject *args, PyObject *keywds) Py_XINCREF(pyres->grammar); GuPool* out_pool = gu_new_pool(); - - PyObject* py_pool = - PyCapsule_New(out_pool, PGF_CONTAINER_NAME, - pypgf_container_descructor); + + PyObject* py_pool = PyPool_New(out_pool); pyres->container = PyTuple_Pack(2, pyres->grammar, py_pool); Py_DECREF(py_pool);