[pypy-commit] pypy stmgc-c7: Test and fix for inf/nan values in prebuilt structures

arigo noreply at buildbot.pypy.org
Wed Mar 12 11:47:30 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r69895:8384a52fc3af
Date: 2014-03-12 11:46 +0100
http://bitbucket.org/pypy/pypy/changeset/8384a52fc3af/

Log:	Test and fix for inf/nan values in prebuilt structures

diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -824,6 +824,11 @@
     print >> f, 'char *RPython_StartupCode(void) {'
     print >> f, '\tchar *error = NULL;'
 
+    # put float infinities in global constants, we should not have so many of them for now to make
+    # a table+loop preferable
+    for dest, value in database.late_initializations:
+        print >> f, "\t%s = %s;" % (dest, value)
+
     if database.with_stm:
         print >> f, '\tpypy_stm_setup();'
         print >> f, '\tpypy_stm_setup_prebuilt();'
@@ -831,11 +836,6 @@
     for line in database.gcpolicy.gc_startup_code():
         print >> f,"\t" + line
 
-    # put float infinities in global constants, we should not have so many of them for now to make
-    # a table+loop preferable
-    for dest, value in database.late_initializations:
-        print >> f, "\t%s = %s;" % (dest, value)
-
     firsttime = True
     for node in database.containerlist:
         lines = list(node.startupcode())
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -816,7 +816,6 @@
     else:
         comma = ','
         if typeOf(value) == Float and not isfinite(value):
-            XXX   # check and reimplement me
             db.late_initializations.append(('%s' % access_expr,
                                             db.get(value, static=True)))
             if isinf(value):
diff --git a/rpython/translator/stm/test/test_ztranslated.py b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -419,3 +419,17 @@
                                'stm_ignored_stop']
         data = cbuilder.cmdexec('')
         assert 'did not crash 84\n' in data
+
+    def test_float_inf_nan_in_struct(self):
+        mylist = [float("inf"), float("-inf"), float("nan")]
+        def main(argv):
+            print ':', mylist[int(argv[1])]
+            return 0
+
+        t, cbuilder = self.compile(main)
+        data = cbuilder.cmdexec('0')
+        assert ': inf\n' in data
+        data = cbuilder.cmdexec('1')
+        assert ': -inf\n' in data
+        data = cbuilder.cmdexec('2')
+        assert ': nan\n' in data


More information about the pypy-commit mailing list