Type initialiser accepts sequences, stores internally as tuples. Add tests which try to break things.

This commit is contained in:
John J. Camilleri
2021-09-28 11:58:22 +02:00
parent 388829d63d
commit 16eb5f1a89
7 changed files with 162 additions and 112 deletions

View File

@@ -184,13 +184,17 @@ Transaction_createCategory(TransactionObject *self, PyObject *args)
Py_ssize_t size;
PyObject *hypos;
prob_t prob = 0.0;
if (!PyArg_ParseTuple(args, "s#O!f", &s, &size, &PyList_Type, &hypos, &prob))
if (!PyArg_ParseTuple(args, "s#Of", &s, &size, &hypos, &prob))
return NULL;
if (!PySequence_Check(hypos)) {
PyErr_SetString(PyExc_TypeError, "context must be a sequence");
return NULL;
}
PgfText *catname = CString_AsPgfText(s, size);
Py_ssize_t n_hypos;
PgfTypeHypo *context = PyList_AsHypos(hypos, &n_hypos);
PgfTypeHypo *context = PySequence_AsHypos(hypos, &n_hypos);
if (PyErr_Occurred()) {
FreePgfText(catname);
return NULL;