mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
Add FreeHypos function. Remove old Python 2 preproc definition
This commit is contained in:
@@ -42,9 +42,6 @@ PyUnicode_AsPgfText(PyObject *pystr)
|
|||||||
PyErr_SetString(PyExc_TypeError, "input to PyUnicode_AsPgfText is not a string");
|
PyErr_SetString(PyExc_TypeError, "input to PyUnicode_AsPgfText is not a string");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (PyUnicode_READY(pystr) != 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
const char *enc = PyUnicode_AsUTF8AndSize(pystr, &size);
|
const char *enc = PyUnicode_AsUTF8AndSize(pystr, &size);
|
||||||
@@ -186,6 +183,16 @@ FreePgfText(PgfText *txt)
|
|||||||
PyMem_RawFree(txt);
|
PyMem_RawFree(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FreeHypos(PgfTypeHypo *hypos, Py_ssize_t n_hypos)
|
||||||
|
{
|
||||||
|
for (Py_ssize_t i = 0; i < n_hypos; i++) {
|
||||||
|
FreePgfText(hypos[i].cid);
|
||||||
|
Py_DECREF(hypos[i].type);
|
||||||
|
}
|
||||||
|
PyMem_RawFree(hypos);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FreePgfPrintContext(PgfPrintContext *ctxt)
|
FreePgfPrintContext(PgfPrintContext *ctxt)
|
||||||
{
|
{
|
||||||
@@ -508,11 +515,7 @@ match_type(PgfMarshaller *this, PgfUnmarshaller *u, PgfType ty)
|
|||||||
for (Py_ssize_t i = 0; i < n_exprs; i++) {
|
for (Py_ssize_t i = 0; i < n_exprs; i++) {
|
||||||
Py_DECREF(exprs[i]);
|
Py_DECREF(exprs[i]);
|
||||||
}
|
}
|
||||||
for (Py_ssize_t i = 0; i < n_hypos; i++) {
|
FreeHypos(hypos, n_hypos);
|
||||||
free(hypos[i].cid);
|
|
||||||
Py_DECREF(hypos[i].type);
|
|
||||||
}
|
|
||||||
PyMem_Free(hypos);
|
|
||||||
FreePgfText(cat);
|
FreePgfText(cat);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ PyObject *PyList_FromHypos(PgfTypeHypo *hypos, const size_t n_hypos);
|
|||||||
PgfPrintContext *PyList_AsPgfPrintContext(PyObject *pylist);
|
PgfPrintContext *PyList_AsPgfPrintContext(PyObject *pylist);
|
||||||
|
|
||||||
void FreePgfText(PgfText *txt);
|
void FreePgfText(PgfText *txt);
|
||||||
|
void FreeHypos(PgfTypeHypo *hypos, Py_ssize_t n_hypos);
|
||||||
void FreePgfPrintContext(PgfPrintContext *ctxt);
|
void FreePgfPrintContext(PgfPrintContext *ctxt);
|
||||||
|
|
||||||
PgfUnmarshaller unmarshaller;
|
PgfUnmarshaller unmarshaller;
|
||||||
|
|||||||
@@ -724,21 +724,13 @@ static PyMethodDef module_methods[] = {
|
|||||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#define MOD_ERROR_VAL NULL
|
||||||
#define MOD_ERROR_VAL NULL
|
#define MOD_SUCCESS_VAL(val) val
|
||||||
#define MOD_SUCCESS_VAL(val) val
|
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
|
||||||
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
|
#define MOD_DEF(ob, name, doc, methods) \
|
||||||
#define MOD_DEF(ob, name, doc, methods) \
|
static struct PyModuleDef moduledef = { \
|
||||||
static struct PyModuleDef moduledef = { \
|
PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
|
||||||
PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
|
ob = PyModule_Create(&moduledef);
|
||||||
ob = PyModule_Create(&moduledef);
|
|
||||||
#else
|
|
||||||
#define MOD_ERROR_VAL
|
|
||||||
#define MOD_SUCCESS_VAL(val)
|
|
||||||
#define MOD_INIT(name) void init##name(void)
|
|
||||||
#define MOD_DEF(ob, name, doc, methods) \
|
|
||||||
ob = Py_InitModule3(name, methods, doc);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TYPE_READY(type) \
|
#define TYPE_READY(type) \
|
||||||
if (PyType_Ready(&type) < 0) \
|
if (PyType_Ready(&type) < 0) \
|
||||||
|
|||||||
@@ -205,12 +205,9 @@ Transaction_createCategory(TransactionObject *self, PyObject *args)
|
|||||||
pgf_create_category(self->pgf->db, self->revision, catname, n_hypos, context, prob, &marshaller, &err);
|
pgf_create_category(self->pgf->db, self->revision, catname, n_hypos, context, prob, &marshaller, &err);
|
||||||
|
|
||||||
FreePgfText(catname);
|
FreePgfText(catname);
|
||||||
for (Py_ssize_t i = 0; i < n_hypos; i++) {
|
FreeHypos(context, n_hypos);
|
||||||
FreePgfText(context[i].cid);
|
|
||||||
}
|
|
||||||
PyMem_Free(context);
|
|
||||||
|
|
||||||
if (handleError(err) != PGF_EXN_NONE) {
|
if (handleError(err) != PGF_EXN_NONE) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user