mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-27 13:32:51 -06:00
Add helper function for checking and converting list of hypos
This commit is contained in:
@@ -116,21 +116,16 @@ Transaction_createCategory(TransactionObject *self, PyObject *args)
|
||||
PyErr_SetString(PyExc_TypeError, "hypos must be a list");
|
||||
return NULL;
|
||||
}
|
||||
// Py_INCREF(hypos);
|
||||
|
||||
PgfText *catname = (PgfText *)PyMem_Malloc(sizeof(PgfText)+size+1);
|
||||
memcpy(catname->text, s, size+1);
|
||||
catname->size = size;
|
||||
|
||||
Py_ssize_t n_hypos = PyList_Size(hypos);
|
||||
PgfTypeHypo context[n_hypos];
|
||||
// PgfTypeHypo *context = alloca(sizeof(PgfTypeHypo)*n_hypos);
|
||||
for (Py_ssize_t i = 0; i < n_hypos; i++) {
|
||||
PyObject *hytup = PyList_GetItem(hypos, i);
|
||||
context[i].bind_type = PyLong_AsLong(PyTuple_GetItem(hytup, 0));
|
||||
context[i].cid = PyUnicode_AsPgfText(PyTuple_GetItem(hytup, 1));
|
||||
context[i].type = (PgfType) PyTuple_GetItem(hytup, 2);
|
||||
Py_INCREF(context[i].type);
|
||||
}
|
||||
Py_ssize_t n_hypos;
|
||||
PgfTypeHypo *context = PyList_AsHypos(hypos, &n_hypos);
|
||||
if (PyErr_Occurred())
|
||||
return NULL;
|
||||
|
||||
PgfExn err;
|
||||
pgf_create_category(self->pgf->db, self->revision, catname, n_hypos, context, prob, &marshaller, &err);
|
||||
|
||||
Reference in New Issue
Block a user