summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2013-01-29 09:41:12 +0000
committerkr.angelov <kr.angelov@gmail.com>2013-01-29 09:41:12 +0000
commit84fa796de4e9b5443a2857eae0878bf26c605cc0 (patch)
tree65b0c89870dfc121e182fabd9ff71da61c37ade0
parent05cb74d14aef10c86038c516791ca2692ca6e801 (diff)
bugfix in the reference counting for Python
-rw-r--r--src/runtime/python/pypgf.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c
index 98ca25e3a..997f3d3f7 100644
--- a/src/runtime/python/pypgf.c
+++ b/src/runtime/python/pypgf.c
@@ -36,6 +36,12 @@ gu2py_string(GuString s) {
}
typedef struct {
+ PyObject_HEAD
+ GuPool* pool;
+ PgfPGF* pgf;
+} PGFObject;
+
+typedef struct {
PyObject_HEAD
PyObject* master;
GuPool* pool;
@@ -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);
}
@@ -527,12 +537,6 @@ static PyTypeObject pgf_ExprIterType = {
typedef struct {
PyObject_HEAD
- GuPool* pool;
- PgfPGF* pgf;
-} PGFObject;
-
-typedef struct {
- PyObject_HEAD
PGFObject* grammar;
PgfConcr* concr;
} ConcrObject;
@@ -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;