[pypy-commit] pypy default: Avoid crashing obscurely if NonConstant() is called on something

arigo pypy.commits at gmail.com
Mon Jul 11 16:22:06 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r85662:e8c967178a5d
Date: 2016-07-11 22:23 +0200
http://bitbucket.org/pypy/pypy/changeset/e8c967178a5d/

Log:	Avoid crashing obscurely if NonConstant() is called on something
	that is already not a constant

diff --git a/rpython/rlib/nonconst.py b/rpython/rlib/nonconst.py
--- a/rpython/rlib/nonconst.py
+++ b/rpython/rlib/nonconst.py
@@ -39,7 +39,4 @@
 
     def specialize_call(self, hop):
         hop.exception_cannot_occur()
-        retval = Constant(hop.r_result.convert_const(hop.args_v[0].value))
-        retval.concretetype = hop.r_result.lowleveltype
-        return retval
-
+        return hop.inputarg(hop.r_result, arg=0)
diff --git a/rpython/rlib/test/test_nonconst.py b/rpython/rlib/test/test_nonconst.py
--- a/rpython/rlib/test/test_nonconst.py
+++ b/rpython/rlib/test/test_nonconst.py
@@ -7,6 +7,7 @@
 from rpython.annotator.annrpython import RPythonAnnotator
 from rpython.conftest import option
 from rpython.annotator.model import SomeInstance
+from rpython.rtyper.test.test_llinterp import interpret
 
 def test_nonconst():
     def nonconst_f():
@@ -18,7 +19,6 @@
     assert s.knowntype is int
     assert not hasattr(s, 'const')
 
-
 def test_nonconst_list():
     def nonconst_l():
         a = NonConstant([1, 2, 3])
@@ -56,3 +56,8 @@
 
     if option.view:
         a.translator.view()
+
+def test_already_not_const():
+    def fn(x):
+        return NonConstant(x)
+    assert interpret(fn, [5]) == 5


More information about the pypy-commit mailing list