[pypy-svn] r68835 - in pypy/branch/logging/pypy: rlib rlib/test rpython

arigo at codespeak.net arigo at codespeak.net
Wed Oct 28 20:43:08 CET 2009


Author: arigo
Date: Wed Oct 28 20:43:08 2009
New Revision: 68835

Modified:
   pypy/branch/logging/pypy/rlib/rlog.py
   pypy/branch/logging/pypy/rlib/rlog_ll.py
   pypy/branch/logging/pypy/rlib/test/test_rlog.py
   pypy/branch/logging/pypy/rpython/llinterp.py
Log:
Managed to write a test that checks that rlog does not
use the GC.  Fixed a few remaining places thus found.  Phew.


Modified: pypy/branch/logging/pypy/rlib/rlog.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/rlog.py	(original)
+++ pypy/branch/logging/pypy/rlib/rlog.py	Wed Oct 28 20:43:08 2009
@@ -163,6 +163,7 @@
 
 
 class LogCategory(object):
+    _alloc_flavor_ = 'raw'
     seen_by = None
 
     def __init__(self, category, message, index):
@@ -221,6 +222,7 @@
 
 
 class AbstractLogWriter(object):
+    _alloc_flavor_ = "raw"
     get_time = time.time
     always_flush = False
 
@@ -240,8 +242,11 @@
         # write the header
         if self.enabled:
             self.create_buffer()
-            for c in 'RLog\n':
-                self.write_int(ord(c))
+            self.write_int(ord('R'))
+            self.write_int(ord('L'))
+            self.write_int(ord('o'))
+            self.write_int(ord('g'))
+            self.write_int(ord('\n'))
             # Write two numbers at the start, to ensure that the log is
             # considered invalid on machines with different endianness
             # or word size.  They also play the role of version numbers.

Modified: pypy/branch/logging/pypy/rlib/rlog_ll.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/rlog_ll.py	(original)
+++ pypy/branch/logging/pypy/rlib/rlog_ll.py	Wed Oct 28 20:43:08 2009
@@ -8,10 +8,10 @@
 
 os_write = rffi.llexternal(underscore_on_windows+'write',
                            [rffi.INT, rffi.CCHARP, rffi.SIZE_T],
-                           rffi.SIZE_T)
+                           rffi.SIZE_T, _nowrapper=True)
 os_open = rffi.llexternal(underscore_on_windows+'open',
                           [rffi.CCHARP, rffi.INT, rffi.MODE_T],
-                          rffi.INT)
+                          rffi.INT, _nowrapper=True)
 
 l_pypylog = rffi.str2charp('PYPYLOG')
 
@@ -21,6 +21,7 @@
 #
 
 class LLLogWriter(AbstractLogWriter):
+    _alloc_flavor_ = "raw"
     BUFSIZE = 8192
 
     fd = -1

Modified: pypy/branch/logging/pypy/rlib/test/test_rlog.py
==============================================================================
--- pypy/branch/logging/pypy/rlib/test/test_rlog.py	(original)
+++ pypy/branch/logging/pypy/rlib/test/test_rlog.py	Wed Oct 28 20:43:08 2009
@@ -2,7 +2,7 @@
 from pypy.rlib import rlog, rlog_ll, rlog_parsing
 from pypy.rlib.rarithmetic import intmask
 from pypy.tool.udir import udir
-from pypy.rpython.test.test_llinterp import interpret
+from pypy.rpython.test.test_llinterp import interpret, get_interpreter
 
 
 def test_log_direct():
@@ -267,7 +267,9 @@
         assert entries[5][2] == ['(null)']
 
     def test_interpret_f(self):
-        interpret(self.f.im_func, [132], malloc_check=False)
+        interp, graph = get_interpreter(self.f.im_func, [132])
+        interp.heap = None    # make sure this does not use any GC operation
+        interp.eval_graph(graph, [132])
         self.check_result()
 
     def test_interpret_g(self):

Modified: pypy/branch/logging/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/logging/pypy/rpython/llinterp.py	(original)
+++ pypy/branch/logging/pypy/rpython/llinterp.py	Wed Oct 28 20:43:08 2009
@@ -604,9 +604,13 @@
 
     def op_setfield(self, obj, fieldname, fieldvalue):
         # obj should be pointer
-        FIELDTYPE = getattr(lltype.typeOf(obj).TO, fieldname)
-        if FIELDTYPE is not lltype.Void:
+        STRUCT = lltype.typeOf(obj).TO
+        FIELDTYPE = getattr(STRUCT, fieldname)
+        if (STRUCT._gckind == 'gc' and isinstance(FIELDTYPE, lltype.Ptr)
+                                   and FIELDTYPE.TO._gckind == 'gc'):
             self.heap.setfield(obj, fieldname, fieldvalue)
+        elif FIELDTYPE is not lltype.Void:
+            setattr(obj, fieldname, fieldvalue)
 
     def op_bare_setfield(self, obj, fieldname, fieldvalue):
         # obj should be pointer
@@ -654,9 +658,13 @@
 
     def op_setarrayitem(self, array, index, item):
         # array should be a pointer
-        ITEMTYPE = lltype.typeOf(array).TO.OF
-        if ITEMTYPE is not lltype.Void:
+        ARRAY = lltype.typeOf(array).TO
+        ITEMTYPE = ARRAY.OF
+        if (ARRAY._gckind == 'gc' and isinstance(ITEMTYPE, lltype.Ptr)
+                                  and ITEMTYPE.TO._gckind == 'gc'):
             self.heap.setarrayitem(array, index, item)
+        elif ITEMTYPE is not lltype.Void:
+            array[index] = item
 
     def op_bare_setarrayitem(self, array, index, item):
         # array should be a pointer
@@ -721,9 +729,12 @@
             result = self.heap.malloc(obj, zero=zero, flavor='raw')
             self.alloca_objects.append(result)
             return result
-        ptr = self.heap.malloc(obj, zero=zero, flavor=flavor)
-        if flavor == 'raw' and self.llinterpreter.malloc_check:
-            self.llinterpreter.remember_malloc(ptr, self)
+        if flavor == 'raw':
+            ptr = lltype.malloc(obj, zero=zero, flavor=flavor)
+            if self.llinterpreter.malloc_check:
+                self.llinterpreter.remember_malloc(ptr, self)
+        else:
+            ptr = self.heap.malloc(obj, zero=zero, flavor=flavor)
         return ptr
 
     def op_malloc_varsize(self, obj, flags, size):
@@ -731,9 +742,12 @@
         zero = flags.get('zero', False)
         assert flavor in ('gc', 'raw')
         try:
-            ptr = self.heap.malloc(obj, size, zero=zero, flavor=flavor)
-            if flavor == 'raw' and self.llinterpreter.malloc_check:
-                self.llinterpreter.remember_malloc(ptr, self)
+            if flavor == 'raw':
+                ptr = lltype.malloc(obj, size, zero=zero, flavor=flavor)
+                if self.llinterpreter.malloc_check:
+                    self.llinterpreter.remember_malloc(ptr, self)
+            else:
+                ptr = self.heap.malloc(obj, size, zero=zero, flavor=flavor)
             return ptr
         except MemoryError:
             self.make_llexception()
@@ -761,9 +775,12 @@
 
     def op_free(self, obj, flavor):
         assert isinstance(flavor, str)
-        if flavor == 'raw' and self.llinterpreter.malloc_check:
-            self.llinterpreter.remember_free(obj)
-        self.heap.free(obj, flavor=flavor)
+        if flavor == 'raw':
+            if self.llinterpreter.malloc_check:
+                self.llinterpreter.remember_free(obj)
+            lltype.free(obj, flavor=flavor)
+        else:
+            self.heap.free(obj, flavor=flavor)
 
     def op_zero_gc_pointers_inside(self, obj):
         raise NotImplementedError("zero_gc_pointers_inside")



More information about the Pypy-commit mailing list