spacepaste

  1.  
  2. (vmprof)[brick:~/src/pypy] $ hg diff
  3. obsolete feature not enabled but 157 markers found!
  4. diff --git a/rpython/translator/backendopt/canraise.py b/rpython/translator/backendopt/canraise.py
  5. --- a/rpython/translator/backendopt/canraise.py
  6. +++ b/rpython/translator/backendopt/canraise.py
  7. @@ -1,4 +1,6 @@
  8. from rpython.rtyper.lltypesystem.lloperation import LL_OPERATIONS
  9. +from rpython.rtyper.lltypesystem import lltype
  10. +from rpython.rtyper import rclass
  11. from rpython.tool.ansi_print import AnsiLogger
  12. from rpython.translator.backendopt import graphanalyze
  13. @@ -8,6 +10,14 @@
  14. class RaiseAnalyzer(graphanalyze.BoolGraphAnalyzer):
  15. ignore_exact_class = None
  16. + def __init__(self, translator):
  17. + graphanalyze.BoolGraphAnalyzer.__init__(self, translator)
  18. + ed = translator.rtyper.exceptiondata
  19. + self.ll_assert_error = ed.get_standard_ll_exc_instance_by_class(
  20. + AssertionError)
  21. + self.ll_not_impl_error = ed.get_standard_ll_exc_instance_by_class(
  22. + NotImplementedError)
  23. +
  24. def do_ignore_memory_error(self):
  25. self.ignore_exact_class = MemoryError
  26. @@ -38,7 +48,22 @@
  27. # it doesn't count. We'll see the place that really
  28. # raises the exception in the first place.
  29. return False
  30. - return True
  31. + # find all the blocks leading to the raise block
  32. + blocks = []
  33. + for candidate in graph.iterblocks():
  34. + if len(candidate.exits) != 1:
  35. + continue
  36. + if candidate.exits[0].target is block:
  37. + blocks.append(candidate)
  38. + ignored = 0
  39. + for preblock in blocks:
  40. + assert len(preblock.operations) == 4
  41. + op = preblock.operations[0]
  42. + assert op.opname == 'same_as'
  43. + p = lltype.cast_pointer(rclass.OBJECTPTR, op.args[0].value)
  44. + if p == self.ll_assert_error or p == self.ll_not_impl_error:
  45. + ignored += 1
  46. + return ignored < len(blocks)
  47. # backward compatible interface
  48. def can_raise(self, op, seen=None):
  49. diff --git a/rpython/translator/backendopt/test/test_canraise.py b/rpython/translator/backendopt/test/test_canraise.py
  50. --- a/rpython/translator/backendopt/test/test_canraise.py
  51. +++ b/rpython/translator/backendopt/test/test_canraise.py
  52. @@ -1,7 +1,8 @@
  53. +from rpython.conftest import option
  54. +from rpython.rtyper.lltypesystem import rffi
  55. from rpython.translator.translator import TranslationContext, graphof
  56. from rpython.translator.backendopt.canraise import RaiseAnalyzer
  57. from rpython.translator.backendopt.all import backend_optimizations
  58. -from rpython.conftest import option
  59. class TestCanRaise(object):
  60. def translate(self, func, sig):
  61. @@ -253,3 +254,13 @@
  62. ra.do_ignore_memory_error() # but it's potentially a KeyError
  63. result = ra.analyze_direct_call(graphof(t, h))
  64. assert result
  65. +
  66. + def test_charp2str(self):
  67. + def f(a):
  68. + return len(rffi.charp2str(a))
  69. +
  70. + t, ra = self.translate(f, [rffi.CCHARP])
  71. + ra.do_ignore_memory_error()
  72. + result = ra.analyze_direct_call(graphof(t, f))
  73. + assert not result # ignore AssertionError
  74. +
  75.