c2dc7ba
From d7b9d509458a0945d1d314b4d93fd2aaac30de96 Mon Sep 17 00:00:00 2001
c2dc7ba
From: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
c2dc7ba
Date: Tue, 15 Sep 2020 22:19:32 +0200
c2dc7ba
Subject: [PATCH 1/2] Fix several testing issues on m32 architectures
c2dc7ba
c2dc7ba
- Do not overflow using 2**32
c2dc7ba
- Be explicit about array type
c2dc7ba
c2dc7ba
This is a partial fix for #1639
c2dc7ba
---
c2dc7ba
 pythran/tests/test_numpy_func0.py | 4 ++--
c2dc7ba
 pythran/tests/test_numpy_func2.py | 2 +-
c2dc7ba
 2 files changed, 3 insertions(+), 3 deletions(-)
c2dc7ba
c2dc7ba
diff --git a/pythran/tests/test_numpy_func0.py b/pythran/tests/test_numpy_func0.py
c2dc7ba
index 0ab6f26cc..ed6c26285 100644
c2dc7ba
--- a/pythran/tests/test_numpy_func0.py
c2dc7ba
+++ b/pythran/tests/test_numpy_func0.py
c2dc7ba
@@ -420,7 +420,7 @@ def test_tofile1(self):
c2dc7ba
 
c2dc7ba
     def test_tofile2(self):
c2dc7ba
         temp_name = tempfile.mkstemp()[1]
c2dc7ba
-        x = numpy.random.randint(0,2**32,1000).astype(numpy.uint32)
c2dc7ba
+        x = numpy.random.randint(0,2**31,1000).astype(numpy.uint32)
c2dc7ba
         try:
c2dc7ba
             self.run_test("def np_tofile2(x,file): import numpy ; x.tofile(file); return numpy.fromfile(file)", x, temp_name, np_tofile2=[NDArray[numpy.uint32,:], str])
c2dc7ba
         finally:
c2dc7ba
@@ -462,7 +462,7 @@ def test_fromfile1(self):
c2dc7ba
 
c2dc7ba
     def test_fromfile2(self):
c2dc7ba
         temp_name = tempfile.mkstemp()[1]
c2dc7ba
-        x = numpy.random.randint(0,2**32,1000).astype(numpy.uint32)
c2dc7ba
+        x = numpy.random.randint(0,2**31,1000).astype(numpy.uint32)
c2dc7ba
         x.tofile(temp_name)
c2dc7ba
         try:
c2dc7ba
             self.run_test("def np_fromfile2(file): from numpy import fromfile, uint32 ; return fromfile(file, uint32)", temp_name, np_fromfile2=[str])
c2dc7ba
diff --git a/pythran/tests/test_numpy_func2.py b/pythran/tests/test_numpy_func2.py
c2dc7ba
index e378b6501..0ff090a55 100644
c2dc7ba
--- a/pythran/tests/test_numpy_func2.py
c2dc7ba
+++ b/pythran/tests/test_numpy_func2.py
c2dc7ba
@@ -491,7 +491,7 @@ def test_asarray4(self):
c2dc7ba
         self.run_test("def np_asarray4(a):\n from numpy import asarray\n return asarray(a[1:])", [(1,2),(3,4)], np_asarray4=[List[Tuple[int, int]]])
c2dc7ba
 
c2dc7ba
     def test_asarray5(self):
c2dc7ba
-        self.run_test("def np_asarray5(a):\n from numpy import asarray\n return asarray(a)", 1, np_asarray5=[int])
c2dc7ba
+        self.run_test("def np_asarray5(a):\n from numpy import asarray\n return asarray(a)", 1., np_asarray5=[float])
c2dc7ba
 
c2dc7ba
     def test_asarray6(self):
c2dc7ba
         self.run_test("def np_asarray6(a):\n from numpy import asarray\n return asarray(a, dtype=int)", 1.5, np_asarray6=[float])
c2dc7ba
c2dc7ba
From f59b69c9f08bfb69c391bf3c4ddfa10e3612ac84 Mon Sep 17 00:00:00 2001
c2dc7ba
From: serge-sans-paille <serge.guelton@telecom-bretagne.eu>
c2dc7ba
Date: Wed, 16 Sep 2020 09:47:17 +0200
c2dc7ba
Subject: [PATCH 2/2] Avoid overflow when comparing ranges
c2dc7ba
c2dc7ba
---
c2dc7ba
 pythran/pythonic/builtins/range.hpp | 3 ++-
c2dc7ba
 1 file changed, 2 insertions(+), 1 deletion(-)
c2dc7ba
c2dc7ba
diff --git a/pythran/pythonic/builtins/range.hpp b/pythran/pythonic/builtins/range.hpp
c2dc7ba
index 75ace78d1..3214ddbbe 100644
c2dc7ba
--- a/pythran/pythonic/builtins/range.hpp
c2dc7ba
+++ b/pythran/pythonic/builtins/range.hpp
c2dc7ba
@@ -64,7 +64,8 @@ namespace builtins
c2dc7ba
 
c2dc7ba
   bool range_iterator::operator<(range_iterator const &other) const
c2dc7ba
   {
c2dc7ba
-    return step_ * value_ < step_ * other.value_;
c2dc7ba
+    const long sign = +1 | (step_ >> (sizeof(long) * CHAR_BIT - 1));
c2dc7ba
+    return sign * value_ < sign * other.value_;
c2dc7ba
   }
c2dc7ba
 
c2dc7ba
   long range_iterator::operator-(range_iterator const &other) const