828e10d92d02f4a55b1884bf8d52875744a2da44
[linpy.git] / pypol / _isl.c
1 #include <Python.h>
2
3 #include <isl/constraint.h>
4 #include <isl/set.h>
5
6 struct _isl_constraint_list {
7 int cursor;
8 PyObject *constraints;
9 };
10 typedef struct _isl_constraint_list _isl_constraint_list;
11
12 int _isl_isl_basic_set_add_constraint_list(__isl_take isl_constraint *c,
13 void *user) {
14 _isl_constraint_list *list;
15
16 list = (_isl_constraint_list *) user;
17 return PyList_SetItem(list->constraints, list->cursor++,
18 PyLong_FromVoidPtr(c));
19 }
20
21 static PyObject * _isl_isl_basic_set_constraints(PyObject *self,
22 PyObject* args) {
23 long ptr;
24 isl_basic_set *bset;
25 int n;
26 PyObject *constraints;
27 _isl_constraint_list *list;
28
29 if (!PyArg_ParseTuple(args, "l", &ptr))
30 return NULL;
31 bset = (isl_basic_set*) ptr;
32 n = isl_basic_set_n_constraint(bset);
33 constraints = PyList_New(n);
34 list = malloc(sizeof(_isl_constraint_list));
35 list->cursor = 0;
36 list->constraints = constraints;
37 isl_basic_set_foreach_constraint(bset,
38 _isl_isl_basic_set_add_constraint_list, list);
39 free(list);
40 return constraints;
41 }
42
43 static PyMethodDef _isl_methods[] = {
44 {"isl_basic_set_constraints", _isl_isl_basic_set_constraints, METH_VARARGS, NULL},
45 {NULL, NULL, 0, NULL}
46 };
47
48 static struct PyModuleDef _islmodule = {
49 PyModuleDef_HEAD_INIT,
50 "_isl",
51 NULL,
52 -1,
53 _isl_methods
54 };
55
56 PyMODINIT_FUNC PyInit__isl(void) {
57 PyObject *m;
58 m = PyModule_Create(&_islmodule);
59 if (m == NULL)
60 return NULL;
61
62 PyModule_AddObject(m, "isl_dim_set", PyLong_FromLong(isl_dim_set));
63
64 return m;
65 }