mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
bugfix in the reference counting for Python
This commit is contained in:
@@ -35,6 +35,12 @@ gu2py_string(GuString s) {
|
||||
return PyString_FromStringAndSize(src, len);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
GuPool* pool;
|
||||
PgfPGF* pgf;
|
||||
} PGFObject;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PyObject* master;
|
||||
@@ -411,6 +417,7 @@ Expr_getattro(ExprObject *self, PyObject *attr_name) {
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PGFObject* grammar;
|
||||
GuPool* pool;
|
||||
int max_count;
|
||||
int counter;
|
||||
@@ -422,6 +429,7 @@ ExprIter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
ExprIterObject* self = (ExprIterObject *)type->tp_alloc(type, 0);
|
||||
if (self != NULL) {
|
||||
self->grammar = NULL;
|
||||
self->pool = NULL;
|
||||
self->max_count = -1;
|
||||
self->counter = 0;
|
||||
@@ -437,6 +445,8 @@ ExprIter_dealloc(ExprIterObject* self)
|
||||
if (self->pool != NULL)
|
||||
gu_pool_free(self->pool);
|
||||
|
||||
Py_XDECREF(self->grammar);
|
||||
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
@@ -525,12 +535,6 @@ static PyTypeObject pgf_ExprIterType = {
|
||||
(newfunc) ExprIter_new, /*tp_new */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
GuPool* pool;
|
||||
PgfPGF* pgf;
|
||||
} PGFObject;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PGFObject* grammar;
|
||||
@@ -596,6 +600,9 @@ Concr_parse(ConcrObject* self, PyObject *args, PyObject *keywds)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pyres->grammar = self->grammar;
|
||||
Py_XINCREF(pyres->grammar);
|
||||
|
||||
pyres->pool = gu_new_pool();
|
||||
pyres->max_count = max_count;
|
||||
pyres->counter = 0;
|
||||
@@ -1040,6 +1047,9 @@ PGF_generate(PGFObject* self, PyObject *args, PyObject *keywds)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pyres->grammar = self;
|
||||
Py_INCREF(self);
|
||||
|
||||
pyres->pool = gu_new_pool();
|
||||
pyres->max_count = max_count;
|
||||
pyres->counter = 0;
|
||||
|
||||
Reference in New Issue
Block a user