+
+#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;
+ PyObject *value;
+
+ list = (_isl_constraint_list *) user;
+ value = PyLong_FromVoidPtr(c);
+ if (value == NULL) {
+ return -1;
+ }
+ return PyList_SetItem(list->constraints, list->cursor++, value);
+}
+
+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);
+ if (n == -1) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "an error occurred in isl_basic_set_n_constraint");
+ return NULL;
+ }
+ constraints = PyList_New(n);
+ if (constraints == NULL) {
+ return NULL;
+ }
+ list = malloc(sizeof(_isl_constraint_list));
+ if (list == NULL) {
+ Py_DECREF(constraints);
+ return PyErr_NoMemory();
+ }
+ list->cursor = 0;
+ list->constraints = constraints;
+ n = isl_basic_set_foreach_constraint(bset,
+ _isl_isl_basic_set_add_constraint_list, list);
+ free(list);
+ if (n == -1) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "an error occurred in isl_basic_set_foreach_constraint");
+ Py_DECREF(constraints);
+ return NULL;
+ }
+ return constraints;
+}