diff --git a/src/runtime/python/marshaller.c b/src/runtime/python/marshaller.c index 5be63221d..c7b707802 100644 --- a/src/runtime/python/marshaller.c +++ b/src/runtime/python/marshaller.c @@ -1,11 +1,9 @@ #define PY_SSIZE_T_CLEAN #include - #include #include #include - #include "./compat.h" #include "./expr.h" diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c index 28edcce76..c019d9d27 100644 --- a/src/runtime/python/pypgf.c +++ b/src/runtime/python/pypgf.c @@ -1,6 +1,6 @@ #define PY_SSIZE_T_CLEAN #include -#include "structmember.h" +#include #include #include "./compat.h" @@ -2047,6 +2047,28 @@ PGF_functionType(PGFObject *self, PyObject *args) return (TypeObject *)type; } +static PyObject * +PGF_functionIsConstructor(PGFObject *self, PyObject *args) +{ + const char *s; + Py_ssize_t size; + if (!PyArg_ParseTuple(args, "s#", &s, &size)) + return NULL; + + PgfText *funname = (PgfText *)PyMem_Malloc(sizeof(PgfText)+size+1); + memcpy(funname->text, s, size+1); + funname->size = size; + + PgfExn err; + int isCon = pgf_function_is_constructor(self->db, self->revision, funname, &err); + PyMem_Free(funname); + if (handleError(err) != PGF_EXN_NONE) { + return NULL; + } + + return PyBool_FromLong(isCon); +} + // static IterObject* // PGF_generateAll(PGFObject* self, PyObject *args, PyObject *keywds) // { @@ -2382,6 +2404,9 @@ static PyMethodDef PGF_methods[] = { {"functionType", (PyCFunction)PGF_functionType, METH_VARARGS, "Returns the type of a function" }, + {"functionIsConstructor", (PyCFunction)PGF_functionIsConstructor, METH_VARARGS, + "Checks whether a function is a constructor" + }, // {"generateAll", (PyCFunction)PGF_generateAll, METH_VARARGS | METH_KEYWORDS, // "Generates abstract syntax trees of given category in decreasing probability order" // }, diff --git a/src/runtime/python/test_suite.py b/src/runtime/python/test_suite.py index a76cc13f8..dbdb19472 100644 --- a/src/runtime/python/test_suite.py +++ b/src/runtime/python/test_suite.py @@ -100,6 +100,18 @@ def test_categoryContext_3(PGF): def test_categoryContext_4(PGF): assert PGF.categoryContext("X") == [] +def test_functionIsConstructor_1(PGF): + assert PGF.functionIsConstructor("s") == True + +def test_functionIsConstructor_2(PGF): + assert PGF.functionIsConstructor("z") == True + +def test_functionIsConstructor_3(PGF): + assert PGF.functionIsConstructor("c") == True + +def test_functionIsConstructor_4(PGF): + assert PGF.functionIsConstructor("ind") == False + # types def test_readType_invalid():