-
- (vmprof)[brick:~/src/pypy] $ hg diff
- obsolete feature not enabled but 157 markers found!
- diff --git a/rpython/translator/backendopt/canraise.py b/rpython/translator/backendopt/canraise.py
- --- a/rpython/translator/backendopt/canraise.py
- +++ b/rpython/translator/backendopt/canraise.py
- @@ -1,4 +1,6 @@
- from rpython.rtyper.lltypesystem.lloperation import LL_OPERATIONS
- +from rpython.rtyper.lltypesystem import lltype
- +from rpython.rtyper import rclass
- from rpython.tool.ansi_print import AnsiLogger
- from rpython.translator.backendopt import graphanalyze
-
- @@ -8,6 +10,14 @@
- class RaiseAnalyzer(graphanalyze.BoolGraphAnalyzer):
- ignore_exact_class = None
-
- + def __init__(self, translator):
- + graphanalyze.BoolGraphAnalyzer.__init__(self, translator)
- + ed = translator.rtyper.exceptiondata
- + self.ll_assert_error = ed.get_standard_ll_exc_instance_by_class(
- + AssertionError)
- + self.ll_not_impl_error = ed.get_standard_ll_exc_instance_by_class(
- + NotImplementedError)
- +
- def do_ignore_memory_error(self):
- self.ignore_exact_class = MemoryError
-
- @@ -38,7 +48,22 @@
- # it doesn't count. We'll see the place that really
- # raises the exception in the first place.
- return False
- - return True
- + # find all the blocks leading to the raise block
- + blocks = []
- + for candidate in graph.iterblocks():
- + if len(candidate.exits) != 1:
- + continue
- + if candidate.exits[0].target is block:
- + blocks.append(candidate)
- + ignored = 0
- + for preblock in blocks:
- + assert len(preblock.operations) == 4
- + op = preblock.operations[0]
- + assert op.opname == 'same_as'
- + p = lltype.cast_pointer(rclass.OBJECTPTR, op.args[0].value)
- + if p == self.ll_assert_error or p == self.ll_not_impl_error:
- + ignored += 1
- + return ignored < len(blocks)
-
- # backward compatible interface
- def can_raise(self, op, seen=None):
- diff --git a/rpython/translator/backendopt/test/test_canraise.py b/rpython/translator/backendopt/test/test_canraise.py
- --- a/rpython/translator/backendopt/test/test_canraise.py
- +++ b/rpython/translator/backendopt/test/test_canraise.py
- @@ -1,7 +1,8 @@
- +from rpython.conftest import option
- +from rpython.rtyper.lltypesystem import rffi
- from rpython.translator.translator import TranslationContext, graphof
- from rpython.translator.backendopt.canraise import RaiseAnalyzer
- from rpython.translator.backendopt.all import backend_optimizations
- -from rpython.conftest import option
-
- class TestCanRaise(object):
- def translate(self, func, sig):
- @@ -253,3 +254,13 @@
- ra.do_ignore_memory_error() # but it's potentially a KeyError
- result = ra.analyze_direct_call(graphof(t, h))
- assert result
- +
- + def test_charp2str(self):
- + def f(a):
- + return len(rffi.charp2str(a))
- +
- + t, ra = self.translate(f, [rffi.CCHARP])
- + ra.do_ignore_memory_error()
- + result = ra.analyze_direct_call(graphof(t, f))
- + assert not result # ignore AssertionError
- +
-