[pypy-commit] pypy gc-del: Fix sockets

arigo noreply at buildbot.pypy.org
Thu Apr 25 18:16:16 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: gc-del
Changeset: r63610:10da333786e1
Date: 2013-04-25 17:10 +0200
http://bitbucket.org/pypy/pypy/changeset/10da333786e1/

Log:	Fix sockets

diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py
--- a/pypy/module/_socket/interp_socket.py
+++ b/pypy/module/_socket/interp_socket.py
@@ -132,9 +132,9 @@
 
 
 class W_RSocket(Wrappable, RSocket):
-    def __del__(self):
+    def invoke_finalizer(self):
         self.clear_all_weakrefs()
-        RSocket.__del__(self)
+        RSocket.invoke_finalizer(self)
 
     def accept_w(self, space):
         """accept() -> (socket object, address info)
diff --git a/rpython/rlib/rsocket.py b/rpython/rlib/rsocket.py
--- a/rpython/rlib/rsocket.py
+++ b/rpython/rlib/rsocket.py
@@ -79,6 +79,7 @@
         self.addrlen = addrlen
 
     def __del__(self):
+        "Lightweight destructor"
         if self.addr_p:
             lltype.free(self.addr_p, flavor='raw')
 
@@ -493,8 +494,15 @@
         self.type = type
         self.proto = proto
         self.timeout = defaults.timeout
-        
-    def __del__(self):
+        self.register_finalizer()
+
+    def register_finalizer(self):
+        """This version is overriden in pypy/module/_socket with the
+        one from W_Root"""
+        from rpython.rlib import rgc
+        rgc.register_finalizer(self.invoke_finalizer)
+
+    def invoke_finalizer(self):
         fd = self.fd
         if fd != _c.INVALID_SOCKET:
             self.fd = _c.INVALID_SOCKET


More information about the pypy-commit mailing list