From c7e8fbdeee009c58ba5c9f5e5d03fc53fcb37c5f Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Sat, 22 Aug 2015 12:07:57 -0500
Subject: [PATCH] Fix secondary return pointers (reported by Tobias Grosser)

---
 gen_wrap.py      | 6 +++---
 test/test_isl.py | 7 +++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gen_wrap.py b/gen_wrap.py
index a439c86..5d329c2 100644
--- a/gen_wrap.py
+++ b/gen_wrap.py
@@ -1281,17 +1281,17 @@ def write_method_wrapper(gen, cls_name, meth):
                 raise SignatureNotSupported("non-give secondary ptr return value")
 
             pre_call(
-                    '_retptr_{name} = ffi.new("{cls} *")'
+                    '_retptr_{name} = ffi.new("{cls} **")'
                     .format(name=arg.name, cls=arg.base_type))
 
-            passed_args.append("ffi.addressof(_retptr_{name})".format(name=arg.name))
+            passed_args.append("_retptr_{name}".format(name=arg.name))
 
             py_cls = isl_class_to_py_class(arg.base_type)
             safety("""
                 if _retptr_{name} == ffi.NULL:
                     _ret_{name} = None
                 else:
-                    _ret_{name} = {py_cls}(_data=_retptr_{name})
+                    _ret_{name} = {py_cls}(_data=_retptr_{name}[0])
                 """
                 .format(name=arg.name, cls=arg.base_type, py_cls=py_cls))
 
diff --git a/test/test_isl.py b/test/test_isl.py
index ee4f7d9..506d89c 100644
--- a/test/test_isl.py
+++ b/test/test_isl.py
@@ -197,6 +197,13 @@ def test_schedule():
     print(printer.get_str())
 
 
+def test_union_map():
+    d = isl.UnionSet("[start, num] -> {S[i,j] : start <= i,j < start + num}")
+    s = isl.UnionMap("{S[i,j] -> [i,j]}").intersect_domain(d)
+    aw = isl.UnionMap("{S[i,j] -> B[1024 i + j]}")
+    aw.compute_flow(aw, aw, s)
+
+
 if __name__ == "__main__":
     import sys
     if len(sys.argv) > 1:
-- 
GitLab