a7b4f3325edc67b36720d81a5dcdfb38a1f23d9b
[linpy.git] / pypol / _islhelper.c
1 #include <Python.h>
2
3 #include <isl/constraint.h>
4 #include <isl/set.h>
5
6
7 static inline int _append_pointer_to_list(void *pointer, void *user) {
8 PyObject *list, *item;
9 list = (PyObject *) user;
10 item = PyLong_FromVoidPtr(pointer);
11 if (item == NULL) {
12 return -1;
13 }
14 return PyList_Append(list, item);
15 }
16
17 static int _append_constraint_to_list(isl_constraint *constraint, void *user) {
18 return _append_pointer_to_list((void *) constraint, user);
19 }
20
21 static PyObject * isl_basic_set_constraints(PyObject *self, PyObject *args) {
22 long pointer;
23 isl_basic_set *bset;
24 PyObject *list;
25 if (!PyArg_ParseTuple(args, "l", &pointer)) {
26 return NULL;
27 }
28 bset = (isl_basic_set *) pointer;
29 list = PyList_New(0);
30 if (list == NULL) {
31 return NULL;
32 }
33 if (isl_basic_set_foreach_constraint(bset, _append_constraint_to_list, list) == -1) {
34 PyErr_SetString(PyExc_RuntimeError,
35 "an error occurred in isl_basic_set_foreach_constraint");
36 Py_DECREF(list);
37 return NULL;
38 }
39 return list;
40 }
41
42 static int _append_basic_set_to_list(isl_basic_set *bset, void *user) {
43 return _append_pointer_to_list((void *) bset, user);
44 }
45
46 static PyObject * isl_set_basic_sets(PyObject *self, PyObject *args) {
47 long pointer;
48 isl_set *set;
49 PyObject *list;
50 if (!PyArg_ParseTuple(args, "l", &pointer)) {
51 return NULL;
52 }
53 set = (isl_set *) pointer;
54 list = PyList_New(0);
55 if (list == NULL) {
56 return NULL;
57 }
58 if (isl_set_foreach_basic_set(set, _append_basic_set_to_list, list) == -1) {
59 PyErr_SetString(PyExc_RuntimeError,
60 "an error occurred in isl_set_foreach_basic_set");
61 Py_DECREF(list);
62 return NULL;
63 }
64 return list;
65 }
66
67 static int _append_point_to_list(isl_point *point, void* user) {
68 return _append_pointer_to_list((void *) point, user);
69 }
70
71 static PyObject * isl_set_points(PyObject *self, PyObject *args) {
72 long pointer;
73 isl_set *set;
74 PyObject *list;
75 if (!PyArg_ParseTuple(args, "l", &pointer)) {
76 return NULL;
77 }
78 set = (isl_set *) pointer;
79 list = PyList_New(0);
80 if (list == NULL) {
81 return NULL;
82 }
83 if (isl_set_foreach_point(set, _append_point_to_list, list) == -1) {
84 PyErr_SetString(PyExc_RuntimeError,
85 "an error occurred in isl_set_foreach_point");
86 Py_DECREF(list);
87 return NULL;
88 }
89 return list;
90 }
91
92
93 static PyMethodDef _islhelper_methods[] = {
94 {"isl_basic_set_constraints", isl_basic_set_constraints, METH_VARARGS, NULL},
95 {"isl_set_basic_sets", isl_set_basic_sets, METH_VARARGS, NULL},
96 {"isl_set_points", isl_set_points, METH_VARARGS, NULL},
97 {NULL, NULL, 0, NULL}
98 };
99
100 static struct PyModuleDef _islhelpermodule = {
101 PyModuleDef_HEAD_INIT,
102 "_islhelper",
103 NULL,
104 0,
105 _islhelper_methods
106 };
107
108 PyMODINIT_FUNC PyInit__islhelper(void) {
109 PyObject *m;
110 m = PyModule_Create(&_islhelpermodule);
111 if (m == NULL) {
112 return NULL;
113 }
114
115 if (PyModule_AddObject(m, "dim_set", PyLong_FromLong(isl_dim_set)) == -1) {
116 return NULL;
117 }
118
119 return m;
120 }