Include Python.h headers first in _isl.c
[linpy.git] / pypol / _isl.c
index 974b0c0..fe29ec5 100644 (file)
@@ -1,7 +1,48 @@
 #include <Python.h>
-#include <isl/space.h>
+#include <stdlib.h>
+
+#include <isl/constraint.h>
+#include <isl/set.h>
+
+struct _isl_constraint_list {
+    int cursor;
+    PyObject *constraints;
+};
+typedef struct _isl_constraint_list _isl_constraint_list;
+
+int _isl_isl_basic_set_add_constraint_list(__isl_take isl_constraint *c,
+        void *user) {
+    _isl_constraint_list *list;
+
+    list = (_isl_constraint_list *) user;
+    return PyList_SetItem(list->constraints, list->cursor++,
+        PyLong_FromVoidPtr(c));
+}
+
+static PyObject * _isl_isl_basic_set_constraints(PyObject *self,
+        PyObject* args) {
+    long ptr;
+    isl_basic_set *bset;
+    int n;
+    PyObject *constraints;
+    _isl_constraint_list *list;
+
+    if (!PyArg_ParseTuple(args, "l", &ptr))
+        return NULL;
+    bset = (isl_basic_set*) ptr;
+    n = isl_basic_set_n_constraint(bset);
+    constraints = PyList_New(n);
+    list = malloc(sizeof(_isl_constraint_list));
+    list->cursor = 0;
+    list->constraints = constraints;
+    isl_basic_set_foreach_constraint(bset,
+        _isl_isl_basic_set_add_constraint_list, list);
+    free(list);
+    return constraints;
+}
 
 static PyMethodDef _isl_methods[] = {
+    {"isl_basic_set_constraints", _isl_isl_basic_set_constraints, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
 };