mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -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);
|
return PyString_FromStringAndSize(src, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
GuPool* pool;
|
||||||
|
PgfPGF* pgf;
|
||||||
|
} PGFObject;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
PyObject* master;
|
PyObject* master;
|
||||||
@@ -411,6 +417,7 @@ Expr_getattro(ExprObject *self, PyObject *attr_name) {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
PGFObject* grammar;
|
||||||
GuPool* pool;
|
GuPool* pool;
|
||||||
int max_count;
|
int max_count;
|
||||||
int counter;
|
int counter;
|
||||||
@@ -422,6 +429,7 @@ ExprIter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||||||
{
|
{
|
||||||
ExprIterObject* self = (ExprIterObject *)type->tp_alloc(type, 0);
|
ExprIterObject* self = (ExprIterObject *)type->tp_alloc(type, 0);
|
||||||
if (self != NULL) {
|
if (self != NULL) {
|
||||||
|
self->grammar = NULL;
|
||||||
self->pool = NULL;
|
self->pool = NULL;
|
||||||
self->max_count = -1;
|
self->max_count = -1;
|
||||||
self->counter = 0;
|
self->counter = 0;
|
||||||
@@ -437,6 +445,8 @@ ExprIter_dealloc(ExprIterObject* self)
|
|||||||
if (self->pool != NULL)
|
if (self->pool != NULL)
|
||||||
gu_pool_free(self->pool);
|
gu_pool_free(self->pool);
|
||||||
|
|
||||||
|
Py_XDECREF(self->grammar);
|
||||||
|
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
self->ob_type->tp_free((PyObject*)self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,12 +535,6 @@ static PyTypeObject pgf_ExprIterType = {
|
|||||||
(newfunc) ExprIter_new, /*tp_new */
|
(newfunc) ExprIter_new, /*tp_new */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
GuPool* pool;
|
|
||||||
PgfPGF* pgf;
|
|
||||||
} PGFObject;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
PGFObject* grammar;
|
PGFObject* grammar;
|
||||||
@@ -596,6 +600,9 @@ Concr_parse(ConcrObject* self, PyObject *args, PyObject *keywds)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pyres->grammar = self->grammar;
|
||||||
|
Py_XINCREF(pyres->grammar);
|
||||||
|
|
||||||
pyres->pool = gu_new_pool();
|
pyres->pool = gu_new_pool();
|
||||||
pyres->max_count = max_count;
|
pyres->max_count = max_count;
|
||||||
pyres->counter = 0;
|
pyres->counter = 0;
|
||||||
@@ -1040,6 +1047,9 @@ PGF_generate(PGFObject* self, PyObject *args, PyObject *keywds)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pyres->grammar = self;
|
||||||
|
Py_INCREF(self);
|
||||||
|
|
||||||
pyres->pool = gu_new_pool();
|
pyres->pool = gu_new_pool();
|
||||||
pyres->max_count = max_count;
|
pyres->max_count = max_count;
|
||||||
pyres->counter = 0;
|
pyres->counter = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user