1. Pypy
  2. Untitled project
  3. pypy

Commits

Armin Rigo  committed 1a9bed8

Fixes. Now an -O2 translates :-)

  • Participants
  • Parent commits 022f615
  • Branches gc-del

Comments (0)

Files changed (4)

File pypy/module/_multibytecodec/interp_incremental.py

View file
         self.name = codec.name
         self._initialize()
 
-    def __del__(self):
-        self._free()
-
     def reset_w(self):
         self._free()
         self._initialize()
 
 
 class MultibyteIncrementalDecoder(MultibyteIncrementalBase):
+    def __del__(self):
+        self._free()
 
     def _initialize(self):
         self.decodebuf = c_codecs.pypy_cjk_dec_new(self.codec)
         self.pending = ""
 
     def _free(self):
-        self.pending = None
         if self.decodebuf:
             c_codecs.pypy_cjk_dec_free(self.decodebuf)
             self.decodebuf = lltype.nullptr(c_codecs.DECODEBUF_P.TO)
 
 
 class MultibyteIncrementalEncoder(MultibyteIncrementalBase):
+    def __del__(self):
+        self._free()
 
     def _initialize(self):
         self.encodebuf = c_codecs.pypy_cjk_enc_new(self.codec)
         self.pending = u""
 
     def _free(self):
-        self.pending = None
         if self.encodebuf:
             c_codecs.pypy_cjk_enc_free(self.encodebuf)
             self.encodebuf = lltype.nullptr(c_codecs.ENCODEBUF_P.TO)

File pypy/module/_rawffi/callback.py

View file
         except LibFFIError:
             raise got_libffi_error(space)
         self.ll_buffer = rffi.cast(rffi.VOIDP, self.ll_callback.ll_closure)
-        if tracker.DO_TRACING:
+        if tracker.do_tracing():
             addr = rffi.cast(lltype.Signed, self.ll_callback.ll_closure)
             tracker.trace_allocation(addr, self)
 
     def free(self):
-        if tracker.DO_TRACING:
+        if tracker.do_tracing():
             addr = rffi.cast(lltype.Signed, self.ll_callback.ll_closure)
             tracker.trace_free(addr)
         global_counter.remove(self.number)

File pypy/module/_rawffi/interp_rawffi.py

View file
         else:
             self.ll_buffer = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw',
                                            zero=True, add_memory_pressure=True)
-            if tracker.DO_TRACING:
+            if tracker.do_tracing():
                 ll_buf = rffi.cast(lltype.Signed, self.ll_buffer)
                 tracker.trace_allocation(ll_buf, self)
 
         self._free()
 
     def _free(self):
-        if tracker.DO_TRACING:
+        if tracker.do_tracing():
             ll_buf = rffi.cast(lltype.Signed, self.ll_buffer)
             tracker.trace_free(ll_buf)
         lltype.free(self.ll_buffer, flavor='raw')
         from pypy.module._rawffi.array import ARRAY_OF_PTRS
         array = ARRAY_OF_PTRS.allocate(space, 1)
         array.setitem(space, 0, self.getbuffer(space))
-        if tracker.DO_TRACING:
+        if tracker.do_tracing():
             # XXX this is needed, because functions tend to live forever
             #     hence our testing is not performing that well
             del tracker.alloced[rffi.cast(lltype.Signed, array.ll_buffer)]

File pypy/module/_rawffi/tracker.py

View file
 """ The file that keeps track about freed/kept-alive objects allocated
 by _rawffi. Used for debugging ctypes
 """
+from rpython.rlib.objectmodel import we_are_translated
+
 
 class Tracker(object):
     DO_TRACING = True
     def __init__(self):
         self.alloced = {}
 
+    def do_tracing(self):
+        return not we_are_translated() and self.DO_TRACING
+
     def trace_allocation(self, address, obj):
-        self.alloced[address] = None
+        if not we_are_translated():
+            self.alloced[address] = None
 
     def trace_free(self, address):
-        if address in self.alloced:
-            del self.alloced[address]
+        if not we_are_translated():
+            if address in self.alloced:
+                del self.alloced[address]
 
 # single, global, static object to keep all tracker info
 tracker = Tracker()