Author: Armin Rigo <[email protected]>
Branch: conditional_call_value_4
Changeset: r88570:db9ba07ec696
Date: 2016-11-23 10:27 +0100
http://bitbucket.org/pypy/pypy/changeset/db9ba07ec696/

Log:    Fix the logic: "not value" is not enough, we need "value is None"

diff --git a/rpython/jit/metainterp/test/test_call.py 
b/rpython/jit/metainterp/test/test_call.py
--- a/rpython/jit/metainterp/test/test_call.py
+++ b/rpython/jit/metainterp/test/test_call.py
@@ -77,6 +77,8 @@
             l = jit.conditional_call_value(l, f, n)
             return len(l)
 
+        assert main(10) == 0
+        assert main(5) == 1
         assert self.interp_operations(main, [10]) == 0
         assert self.interp_operations(main, [5]) == 1
 
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -1221,20 +1221,27 @@
 def conditional_call_value(value, function, *args):
     """Does the same as:
 
-        if not value:
+        if value == <0 or None>:
             value = function(*args)
         return value
 
     For the JIT.  Allows one branch which doesn't create a bridge,
     typically used for caching.  The function must be @elidable.
     The value and the function's return type must match and cannot
-    be a float.
+    be a float: they must be either regular 'int', or something
+    that turns into a pointer.
     """
     if we_are_jitted():
         return _jit_conditional_call_value(value, function, *args)
     else:
-        if not value:
-            value = function(*args)
+        if isinstance(value, int):
+            if value == 0:
+                value = function(*args)
+                assert isinstance(value, int)
+        else:
+            if value is None:
+                value = function(*args)
+                assert not isinstance(value, int)
         return value
 conditional_call_value._always_inline_ = True
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to