Add helper function islhelper.isl_set_points()
authorVivien Maisonneuve <v.maisonneuve@gmail.com>
Fri, 4 Jul 2014 08:53:29 +0000 (10:53 +0200)
committerVivien Maisonneuve <v.maisonneuve@gmail.com>
Fri, 4 Jul 2014 08:53:29 +0000 (10:53 +0200)
pypol/_islhelper.c
pypol/islhelper.py

index eaacc67..37e7c31 100644 (file)
@@ -120,9 +120,46 @@ static PyObject * isl_set_basic_sets(PyObject *self, PyObject *args) {
 }
 
 
+static int pointer_list_append_point(isl_point *point, void *user) {
+    PyObject *pointers, *value;
+
+    pointers = (PyObject *) user;
+    value = PyLong_FromVoidPtr(point);
+    if (value == NULL) {
+        return -1;
+    }
+    return PyList_Append(pointers, value);
+}
+
+static PyObject * isl_set_points(PyObject *self, PyObject *args) {
+    long ptr;
+    isl_set *set;
+    int n;
+    PyObject *pointers;
+
+    if (!PyArg_ParseTuple(args, "l", &ptr)) {
+        return NULL;
+    }
+    set = (isl_set *) ptr;
+    pointers = PyList_New(0);
+    if (pointers == NULL) {
+        return NULL;
+    }
+    n = isl_set_foreach_point(set, pointer_list_append_point, pointers);
+    if (n == -1) {
+        PyErr_SetString(PyExc_RuntimeError,
+            "an error occurred in isl_set_foreach_point");
+        Py_DECREF(pointers);
+        return NULL;
+    }
+    return pointers;
+}
+
+
 static PyMethodDef _islhelper_methods[] = {
     {"isl_basic_set_constraints", isl_basic_set_constraints, METH_VARARGS, NULL},
     {"isl_set_basic_sets", isl_set_basic_sets, METH_VARARGS, NULL},
+    {"isl_set_points", isl_set_points, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
 };
 
index 539a33f..e796618 100644 (file)
@@ -1,7 +1,7 @@
 import ctypes, ctypes.util
 
 from . import _islhelper
-from ._islhelper import isl_basic_set_constraints, isl_set_basic_sets
+from ._islhelper import *
 
 
 __all__ = [
@@ -11,6 +11,7 @@ __all__ = [
     'isl_val_to_int',
     'isl_basic_set_to_str', 'isl_basic_set_constraints',
     'isl_set_to_str', 'isl_set_basic_sets',
+    'isl_set_points',
 ]