3 #include <isl/constraint.h>
12 typedef struct pointer_list pointer_list
;
15 static int pointer_list_append_constraint(isl_constraint
*c
, void *user
) {
19 list
= (pointer_list
*) user
;
20 value
= PyLong_FromVoidPtr(c
);
24 PyList_SET_ITEM(list
->pointers
, list
->cursor
++, value
);
28 static PyObject
* isl_basic_set_constraints(PyObject
*self
, PyObject
* args
) {
35 if (!PyArg_ParseTuple(args
, "l", &ptr
)) {
38 bset
= (isl_basic_set
*) ptr
;
39 bset
= isl_basic_set_finalize(bset
); // this instruction should not be required
40 n
= isl_basic_set_n_constraint(bset
);
42 PyErr_SetString(PyExc_RuntimeError
,
43 "an error occurred in isl_basic_set_n_constraint");
46 pointers
= PyList_New(n
);
47 if (pointers
== NULL
) {
50 list
= malloc(sizeof(pointer_list
));
53 return PyErr_NoMemory();
56 list
->pointers
= pointers
;
57 n
= isl_basic_set_foreach_constraint(bset
, pointer_list_append_constraint
,
61 PyErr_SetString(PyExc_RuntimeError
,
62 "an error occurred in isl_basic_set_foreach_constraint");
70 static int pointer_list_append_basic_set(isl_basic_set
*bset
, void *user
) {
74 list
= (pointer_list
*) user
;
75 value
= PyLong_FromVoidPtr(bset
);
79 PyList_SET_ITEM(list
->pointers
, list
->cursor
++, value
);
83 static PyObject
* isl_set_basic_sets(PyObject
*self
, PyObject
*args
) {
90 if (!PyArg_ParseTuple(args
, "l", &ptr
)) {
93 set
= (isl_set
*) ptr
;
94 n
= isl_set_n_basic_set(set
);
96 PyErr_SetString(PyExc_RuntimeError
,
97 "an error occurred in isl_set_n_basic_set");
100 pointers
= PyList_New(n
);
101 if (pointers
== NULL
) {
104 list
= malloc(sizeof(pointer_list
));
107 return PyErr_NoMemory();
110 list
->pointers
= pointers
;
111 n
= isl_set_foreach_basic_set(set
, pointer_list_append_basic_set
, list
);
114 PyErr_SetString(PyExc_RuntimeError
,
115 "an error occurred in isl_set_foreach_basic_set");
123 static int pointer_list_append_point(isl_point
*point
, void *user
) {
124 PyObject
*pointers
, *value
;
126 pointers
= (PyObject
*) user
;
127 value
= PyLong_FromVoidPtr(point
);
131 return PyList_Append(pointers
, value
);
134 static PyObject
* isl_set_points(PyObject
*self
, PyObject
*args
) {
140 if (!PyArg_ParseTuple(args
, "l", &ptr
)) {
143 set
= (isl_set
*) ptr
;
144 pointers
= PyList_New(0);
145 if (pointers
== NULL
) {
148 n
= isl_set_foreach_point(set
, pointer_list_append_point
, pointers
);
150 PyErr_SetString(PyExc_RuntimeError
,
151 "an error occurred in isl_set_foreach_point");
159 static PyMethodDef _islhelper_methods
[] = {
160 {"isl_basic_set_constraints", isl_basic_set_constraints
, METH_VARARGS
, NULL
},
161 {"isl_set_basic_sets", isl_set_basic_sets
, METH_VARARGS
, NULL
},
162 {"isl_set_points", isl_set_points
, METH_VARARGS
, NULL
},
163 {NULL
, NULL
, 0, NULL
}
166 static struct PyModuleDef _islhelpermodule
= {
167 PyModuleDef_HEAD_INIT
,
174 PyMODINIT_FUNC
PyInit__islhelper(void) {
176 m
= PyModule_Create(&_islhelpermodule
);
181 if (PyModule_AddObject(m
, "dim_set", PyLong_FromLong(isl_dim_set
)) == -1) {