X-Git-Url: https://scm.cri.ensmp.fr/git/linpy.git/blobdiff_plain/3b1b3560c8880ef25995a18b6e365e0d730a2df2..34bcb159c06a4725f7a2baaf5ddcc6dffd5d74fe:/pypol/_isl.c?ds=inline diff --git a/pypol/_isl.c b/pypol/_isl.c index 974b0c0..1b086dc 100644 --- a/pypol/_isl.c +++ b/pypol/_isl.c @@ -1,7 +1,68 @@ #include -#include + +#include +#include + +struct pointer_list { + int cursor; + PyObject *pointers; +}; +typedef struct pointer_list pointer_list; + +static int pointer_list_append_constraint(isl_constraint *c, void *user) { + pointer_list *list; + PyObject *value; + + list = (pointer_list *) user; + value = PyLong_FromVoidPtr(c); + if (value == NULL) { + return -1; + } + PyList_SET_ITEM(list->pointers, list->cursor++, value); + return 0; +} + +static PyObject * basic_set_constraints(PyObject *self, PyObject* args) { + long ptr; + isl_basic_set *bset; + int n; + PyObject *pointers; + pointer_list *list; + + if (!PyArg_ParseTuple(args, "l", &ptr)) + return NULL; + bset = (isl_basic_set*) ptr; + n = isl_basic_set_n_constraint(bset); + if (n == -1) { + PyErr_SetString(PyExc_RuntimeError, + "an error occurred in isl_basic_set_n_constraint"); + return NULL; + } + pointers = PyList_New(n); + if (pointers == NULL) { + return NULL; + } + list = malloc(sizeof(pointer_list)); + if (list == NULL) { + Py_DECREF(pointers); + return PyErr_NoMemory(); + } + list->cursor = 0; + list->pointers = pointers; + n = isl_basic_set_foreach_constraint(bset, pointer_list_append_constraint, + list); + free(list); + if (n == -1) { + PyErr_SetString(PyExc_RuntimeError, + "an error occurred in isl_basic_set_foreach_constraint"); + Py_DECREF(pointers); + return NULL; + } + return pointers; +} static PyMethodDef _isl_methods[] = { + {"basic_set_constraints", basic_set_constraints, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; @@ -9,17 +70,20 @@ static struct PyModuleDef _islmodule = { PyModuleDef_HEAD_INIT, "_isl", NULL, - -1, + 0, _isl_methods }; PyMODINIT_FUNC PyInit__isl(void) { PyObject *m; m = PyModule_Create(&_islmodule); - if (m == NULL) + if (m == NULL) { return NULL; + } - PyModule_AddObject(m, "isl_dim_set", PyLong_FromLong(isl_dim_set)); + if (PyModule_AddObject(m, "dim_set", PyLong_FromLong(isl_dim_set)) == -1) { + return NULL; + } return m; }