Author: Armin Rigo <[email protected]>
Branch:
Changeset: r76665:dac9223bca11
Date: 2015-03-31 18:43 +0200
http://bitbucket.org/pypy/pypy/changeset/dac9223bca11/
Log: Test and fix for a very rare case
diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py
--- a/rpython/rtyper/rpbc.py
+++ b/rpython/rtyper/rpbc.py
@@ -6,7 +6,7 @@
from rpython.rtyper import rclass, callparse
from rpython.rtyper.rclass import CLASSTYPE, OBJECT_VTABLE, OBJECTPTR
from rpython.rtyper.error import TyperError
-from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rtyper.rmodel import (Repr, inputconst, CanBeNull, mangle,
warning, impossible_repr)
from rpython.tool.pairtype import pair, pairtype
@@ -205,11 +205,15 @@
# this row
llfn = self.rtyper.type_system.null_callable(row.fntype)
llfns[row.attrname] = llfn
- if not found_anything:
- raise TyperError("%r not in %r" % (funcdesc,
- self.s_pbc.descriptions))
if len(self.uniquerows) == 1:
- result = llfn # from the loop above
+ if found_anything:
+ result = llfn # from the loop above
+ else:
+ # extremely rare case, shown only sometimes by
+ # test_bug_callfamily: don't emit NULL, because that
+ # would be interpreted as equal to None... It should
+ # never be called anyway.
+ result = rffi.cast(self.lowleveltype, ~len(self.funccache))
else:
# build a Struct with all the values collected in 'llfns'
result = self.create_specfunc()
diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py
--- a/rpython/rtyper/test/test_rpbc.py
+++ b/rpython/rtyper/test/test_rpbc.py
@@ -1658,16 +1658,17 @@
def test_bug_callfamily(self):
def cb1():
- pass
+ xxx # never actually called
def cb2():
pass
- def g(cb):
- pass
+ def g(cb, result):
+ assert (cb is None) == (result == 0)
def h(cb):
cb()
def f():
- g(cb1)
- g(cb2)
+ g(None, 0)
+ g(cb1, 1)
+ g(cb2, 2)
h(cb2)
return 42
res = self.interpret(f, [])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit