mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
fíx in the Python binding for compatibility with Python<2.7
This commit is contained in:
@@ -666,6 +666,15 @@ pypgf_new_python_lexer(PyObject* pylexer, GuPool* pool)
|
|||||||
return ((PgfLexer*) lexer);
|
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"
|
#define PGF_CONTAINER_NAME "pgf.Container"
|
||||||
|
|
||||||
void pypgf_container_descructor(PyObject *capsule)
|
void pypgf_container_descructor(PyObject *capsule)
|
||||||
@@ -674,6 +683,12 @@ void pypgf_container_descructor(PyObject *capsule)
|
|||||||
gu_pool_free(pool);
|
gu_pool_free(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PyPool_New(pool) \
|
||||||
|
PyCapsule_New(pool, PGF_CONTAINER_NAME, \
|
||||||
|
pypgf_container_descructor)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static IterObject*
|
static IterObject*
|
||||||
Concr_parse(ConcrObject* self, PyObject *args, PyObject *keywds)
|
Concr_parse(ConcrObject* self, PyObject *args, PyObject *keywds)
|
||||||
{
|
{
|
||||||
@@ -712,10 +727,8 @@ Concr_parse(ConcrObject* self, PyObject *args, PyObject *keywds)
|
|||||||
Py_XINCREF(pyres->grammar);
|
Py_XINCREF(pyres->grammar);
|
||||||
|
|
||||||
GuPool* out_pool = gu_new_pool();
|
GuPool* out_pool = gu_new_pool();
|
||||||
|
|
||||||
PyObject* py_pool =
|
PyObject* py_pool = PyPool_New(out_pool);
|
||||||
PyCapsule_New(out_pool, PGF_CONTAINER_NAME,
|
|
||||||
pypgf_container_descructor);
|
|
||||||
pyres->container = PyTuple_Pack(2, pyres->grammar, py_pool);
|
pyres->container = PyTuple_Pack(2, pyres->grammar, py_pool);
|
||||||
Py_DECREF(py_pool);
|
Py_DECREF(py_pool);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user