summaryrefslogtreecommitdiff
path: root/src/runtime/python
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/python')
-rw-r--r--src/runtime/python/pypgf.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c
index c38a483f7..4725695ff 100644
--- a/src/runtime/python/pypgf.c
+++ b/src/runtime/python/pypgf.c
@@ -1212,16 +1212,21 @@ pypgf_literal_callback_match(PgfLiteralCallback* self,
PyObject* result =
PyObject_CallFunction(callback->pycallback, "isi",
lin_idx, sentence, *poffset);
- if (result == NULL || result == Py_None)
+ if (result == NULL)
return NULL;
+ if (result == Py_None) {
+ Py_DECREF(result);
+ return NULL;
+ }
+
PgfExprProb* ep = gu_new(PgfExprProb, out_pool);
ExprObject* pyexpr;
if (!PyArg_ParseTuple(result, "Ofi", &pyexpr, &ep->prob, poffset))
return NULL;
ep->expr = pyexpr->expr;
-
+
{
// This is an uggly hack. We first show the expression ep->expr
// and then we read it back but in out_pool. The whole purpose
@@ -1251,7 +1256,7 @@ pypgf_literal_callback_match(PgfLiteralCallback* self,
gu_pool_free(tmp_pool);
}
- Py_DECREF(pyexpr);
+ Py_DECREF(result);
return ep;
}
@@ -1300,6 +1305,8 @@ pypgf_new_callbacks_map(PgfConcr* concr, PyObject *py_callbacks,
callback->pycallback = pycallback;
callback->fin.fn = pypgf_literal_callback_fin;
+ Py_XINCREF(callback->pycallback);
+
gu_pool_finally(pool, &callback->fin);
pgf_callbacks_map_add_literal(concr, callbacks,