[pypy-svn] r71286 - in pypy/branch/debug-vref/pypy: rpython/memory/gc translator/c translator/c/src

arigo at codespeak.net arigo at codespeak.net
Thu Feb 18 11:01:07 CET 2010


Author: arigo
Date: Thu Feb 18 11:01:06 2010
New Revision: 71286

Modified:
   pypy/branch/debug-vref/pypy/rpython/memory/gc/base.py
   pypy/branch/debug-vref/pypy/translator/c/funcgen.py
   pypy/branch/debug-vref/pypy/translator/c/src/mem.h
   pypy/branch/debug-vref/pypy/translator/c/src/support.h
Log:
More debugging support.


Modified: pypy/branch/debug-vref/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/debug-vref/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/debug-vref/pypy/rpython/memory/gc/base.py	Thu Feb 18 11:01:06 2010
@@ -42,7 +42,7 @@
     # collection.  It is automatically set to True by test_gc.py.  The
     # checking logic is translatable, so the flag can be set to True
     # here before translation.
-    DEBUG = False
+    DEBUG = True
 
     def set_query_functions(self, is_varsize, has_gcptr_in_varsize,
                             is_gcarrayofgcptr,

Modified: pypy/branch/debug-vref/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/branch/debug-vref/pypy/translator/c/funcgen.py	(original)
+++ pypy/branch/debug-vref/pypy/translator/c/funcgen.py	Thu Feb 18 11:01:06 2010
@@ -465,19 +465,21 @@
     def generic_get(self, op, sourceexpr):
         T = self.lltypemap(op.result)
         newvalue = self.expr(op.result, special_case_void=False)
-        result = ['%s = %s;' % (newvalue, sourceexpr)]
-        result = '\n'.join(result)
+        result = '%s = %s;' % (newvalue, sourceexpr)
         if T is Void:
             result = '/* %s */' % result
+        elif isinstance(T, Ptr) and T.TO._gckind == 'gc':
+            result = '%s RPyValidPtr(%s);' % (result, newvalue)
         return result
 
     def generic_set(self, op, targetexpr):
         newvalue = self.expr(op.args[-1], special_case_void=False)
-        result = ['%s = %s;' % (targetexpr, newvalue)]
+        result = '%s = %s;' % (targetexpr, newvalue)
         T = self.lltypemap(op.args[-1])
-        result = '\n'.join(result)
         if T is Void:
             result = '/* %s */' % result
+        elif isinstance(T, Ptr) and T.TO._gckind == 'gc':
+            result = 'RPyValidPtr(%s); %s' % (newvalue, result)
         return result
 
     def OP_GETFIELD(self, op, ampersand=''):

Modified: pypy/branch/debug-vref/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/branch/debug-vref/pypy/translator/c/src/mem.h	(original)
+++ pypy/branch/debug-vref/pypy/translator/c/src/mem.h	Thu Feb 18 11:01:06 2010
@@ -95,7 +95,7 @@
 
 #endif
 
-#define OP_RAW_FREE(p, r) PyObject_Free(p); COUNT_FREE;
+#define OP_RAW_FREE(p, r) *(int*)p = -0x22222223; PyObject_Free(p);   /* 0xdddddddd */
 
 #define OP_RAW_MEMCLEAR(p, size, r) memset((void*)p, 0, size)
 

Modified: pypy/branch/debug-vref/pypy/translator/c/src/support.h
==============================================================================
--- pypy/branch/debug-vref/pypy/translator/c/src/support.h	(original)
+++ pypy/branch/debug-vref/pypy/translator/c/src/support.h	Thu Feb 18 11:01:06 2010
@@ -74,6 +74,7 @@
  * attackers.
  */
 #  define RPyCHECK(x)           ((x) || RPyAbort())
+#  define RPyValidPtr(x)  ((!(x))||(unsigned int)(((*(unsigned int*)(x))-1)<0x7FFFFFF)||RPyAbort())
 #  define RPyField(ptr, name)   ((RPyCHECK(ptr), (ptr))->name)
 #  define RPyItem(array, index)                                             \
      ((RPyCHECK((index) >= 0 && (index) < (array)->length),                 \
@@ -96,6 +97,7 @@
 #endif
 
 #else
+#  define RPyValidPtr(x)                     /* nothing */
 #  define RPyField(ptr, name)                ((ptr)->name)
 #  define RPyItem(array, index)              ((array)->items[index])
 #  define RPyFxItem(ptr, index, fixedsize)   ((ptr)[index])



More information about the Pypy-commit mailing list