Author: Armin Rigo <[email protected]>
Branch: use-gc-del-3
Changeset: r84255:96181861aba3
Date: 2016-05-06 10:18 +0200
http://bitbucket.org/pypy/pypy/changeset/96181861aba3/

Log:    Fix _multiprocessing

diff --git a/pypy/module/_multiprocessing/interp_connection.py 
b/pypy/module/_multiprocessing/interp_connection.py
--- a/pypy/module/_multiprocessing/interp_connection.py
+++ b/pypy/module/_multiprocessing/interp_connection.py
@@ -40,14 +40,17 @@
     BUFFER_SIZE = 1024
     buffer = lltype.nullptr(rffi.CCHARP.TO)
 
-    def __init__(self, flags):
+    def __init__(self, space, flags):
         self.flags = flags
         self.buffer = lltype.malloc(rffi.CCHARP.TO, self.BUFFER_SIZE,
                                     flavor='raw')
+        self.register_finalizer(space)
 
-    def __del__(self):
-        if self.buffer:
-            lltype.free(self.buffer, flavor='raw')
+    def _finalize_(self):
+        buf = self.buffer
+        if buf:
+            self.buffer = lltype.nullptr(rffi.CCHARP.TO)
+            lltype.free(buf, flavor='raw')
         try:
             self.do_close()
         except OSError:
@@ -242,7 +245,7 @@
     def __init__(self, space, fd, flags):
         if fd == self.INVALID_HANDLE_VALUE or fd < 0:
             raise oefmt(space.w_IOError, "invalid handle %d", fd)
-        W_BaseConnection.__init__(self, flags)
+        W_BaseConnection.__init__(self, space, flags)
         self.fd = fd
 
     @unwrap_spec(fd=int, readable=bool, writable=bool)
@@ -363,8 +366,8 @@
     if sys.platform == 'win32':
         from rpython.rlib.rwin32 import INVALID_HANDLE_VALUE
 
-    def __init__(self, handle, flags):
-        W_BaseConnection.__init__(self, flags)
+    def __init__(self, space, handle, flags):
+        W_BaseConnection.__init__(self, space, flags)
         self.handle = handle
 
     @unwrap_spec(readable=bool, writable=bool)
@@ -375,7 +378,7 @@
         flags = (readable and READABLE) | (writable and WRITABLE)
 
         self = space.allocate_instance(W_PipeConnection, w_subtype)
-        W_PipeConnection.__init__(self, handle, flags)
+        W_PipeConnection.__init__(self, space, handle, flags)
         return space.wrap(self)
 
     def descr_repr(self, space):
diff --git a/pypy/module/_multiprocessing/interp_semaphore.py 
b/pypy/module/_multiprocessing/interp_semaphore.py
--- a/pypy/module/_multiprocessing/interp_semaphore.py
+++ b/pypy/module/_multiprocessing/interp_semaphore.py
@@ -430,11 +430,12 @@
 
 
 class W_SemLock(W_Root):
-    def __init__(self, handle, kind, maxvalue):
+    def __init__(self, space, handle, kind, maxvalue):
         self.handle = handle
         self.kind = kind
         self.count = 0
         self.maxvalue = maxvalue
+        self.register_finalizer(space)
 
     def kind_get(self, space):
         return space.newint(self.kind)
@@ -508,7 +509,7 @@
     @unwrap_spec(kind=int, maxvalue=int)
     def rebuild(space, w_cls, w_handle, kind, maxvalue):
         self = space.allocate_instance(W_SemLock, w_cls)
-        self.__init__(handle_w(space, w_handle), kind, maxvalue)
+        self.__init__(space, handle_w(space, w_handle), kind, maxvalue)
         return space.wrap(self)
 
     def enter(self, space):
@@ -517,7 +518,7 @@
     def exit(self, space, __args__):
         self.release(space)
 
-    def __del__(self):
+    def _finalize_(self):
         delete_semaphore(self.handle)
 
 @unwrap_spec(kind=int, value=int, maxvalue=int)
@@ -534,7 +535,7 @@
         raise wrap_oserror(space, e)
 
     self = space.allocate_instance(W_SemLock, w_subtype)
-    self.__init__(handle, kind, maxvalue)
+    self.__init__(space, handle, kind, maxvalue)
 
     return space.wrap(self)
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to