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