[pypy-svn] r32047 - in pypy/dist/pypy: rpython/lltypesystem translator/c

arigo at codespeak.net arigo at codespeak.net
Thu Sep 7 14:25:46 CEST 2006


Author: arigo
Date: Thu Sep  7 14:25:44 2006
New Revision: 32047

Modified:
   pypy/dist/pypy/rpython/lltypesystem/lloperation.py
   pypy/dist/pypy/rpython/lltypesystem/opimpl.py
   pypy/dist/pypy/rpython/lltypesystem/rlist.py
   pypy/dist/pypy/translator/c/funcgen.py
Log:
A 'debug_assert' low-level operation for quick checks of conditions.
It goes away in C code.


Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py	Thu Sep  7 14:25:44 2006
@@ -397,7 +397,8 @@
     'debug_view':           LLOp(),
     'debug_print':          LLOp(),
     'debug_pdb':            LLOp(),
-    'debug_log_exc':        LLOp()
+    'debug_log_exc':        LLOp(),
+    'debug_assert':         LLOp(canfold=True),
 }
 
     # __________ operations on PyObjects __________

Modified: pypy/dist/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/opimpl.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/opimpl.py	Thu Sep  7 14:25:44 2006
@@ -355,6 +355,15 @@
         raise TypeError("cannot fold getfield on mutable array")
     return p[index]
 
+
+def op_debug_assert(expr, *ll_args):
+    if not isinstance(expr, str):
+        expr = ''.join(expr.chars)
+    names = ['v%d' % i for i in range(len(ll_args))]
+    d = dict(zip(names, ll_args))
+    names = tuple(names)
+    assert eval(expr % names, d)
+
 # ____________________________________________________________
 
 def get_op_impl(opname):

Modified: pypy/dist/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rlist.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rlist.py	Thu Sep  7 14:25:44 2006
@@ -387,10 +387,14 @@
 def ll_items(l):
     return l.items
 
+from pypy.rpython.lltypesystem.lloperation import llop
+
 def ll_getitem_fast(l, index):
+    llop.debug_assert(Void, "%s < %s.length # getitem out of bounds", index, l)
     return l.ll_items()[index]
 
 def ll_setitem_fast(l, index, item):
+    llop.debug_assert(Void, "%s < %s.length # setitem out of bounds", index, l)
     l.ll_items()[index] = item
 
 # fixed size versions

Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Thu Sep  7 14:25:44 2006
@@ -720,4 +720,7 @@
         exc_type = self.expr(op.args[0])
         return 'RPY_LOG_EXC(%s);' % exc_type
 
+    def OP_DEBUG_ASSERT(self, op):
+        return '/* debug_assert removed */'
+
 assert not USESLOTS or '__dict__' not in dir(FunctionCodeGenerator)



More information about the Pypy-commit mailing list