[pypy-commit] pypy default: Quasi-test and fix for warnings given by the C compiler.

arigo noreply at buildbot.pypy.org
Mon Dec 3 16:42:41 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r59292:959b9d690918
Date: 2012-12-03 07:42 -0800
http://bitbucket.org/pypy/pypy/changeset/959b9d690918/

Log:	Quasi-test and fix for warnings given by the C compiler.

diff --git a/pypy/translator/c/node.py b/pypy/translator/c/node.py
--- a/pypy/translator/c/node.py
+++ b/pypy/translator/c/node.py
@@ -10,7 +10,7 @@
 from pypy.translator.c.support import c_char_array_constant, barebonearray
 from pypy.translator.c.primitive import PrimitiveType, name_signed
 from pypy.rlib import exports
-from pypy.rlib.rfloat import isfinite
+from pypy.rlib.rfloat import isfinite, isinf
 from pypy.rlib.rstackovf import _StackOverflow
 from pypy.translator.c import extfunc
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
@@ -733,8 +733,11 @@
                 yield '\t%s{' % length
             for j in range(len(self.obj.items)):
                 value = self.obj.items[j]
+                basename = self.name
+                if basename.endswith('.b'):
+                    basename = basename[:-2] + '.a'
                 lines = generic_initializationexpr(self.db, value,
-                                                '%s.items[%d]' % (self.name, j),
+                                                '%s.items[%d]' % (basename, j),
                                                 '%s%d' % (decoration, j))
                 for line in lines:
                     yield '\t' + line
@@ -791,8 +794,11 @@
         comma = ','
         if typeOf(value) == Float and not isfinite(value):
             db.late_initializations.append(('%s' % access_expr, db.get(value)))
-            expr = '0.0 /* patched later by %sinfinity */' % (
-                '-+'[value > 0])
+            if isinf(value):
+                name = '-+'[value > 0] + 'inf'
+            else:
+                name = 'NaN'
+            expr = '0.0 /* patched later with %s */' % (name,)
         else:
             expr = db.get(value)
             if typeOf(value) is Void:
diff --git a/pypy/translator/c/test/test_genc.py b/pypy/translator/c/test/test_genc.py
--- a/pypy/translator/c/test/test_genc.py
+++ b/pypy/translator/c/test/test_genc.py
@@ -356,6 +356,19 @@
     res = f1(3)
     assert res == 1.5
 
+def test_infinite_float_in_array():
+    from pypy.rlib.rfloat import INFINITY, NAN, isnan
+    lst = [INFINITY, -INFINITY, NAN]
+    def fn(i):
+        return lst[i]
+    f1 = compile(fn, [int])
+    res = f1(0)
+    assert res == INFINITY
+    res = f1(1)
+    assert res == -INFINITY
+    res = f1(2)
+    assert isnan(res)
+
 def test_nan_and_special_values():
     from pypy.rlib.rfloat import isnan, isinf, isfinite, copysign
     inf = 1e300 * 1e300


More information about the pypy-commit mailing list