Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3.3 Changeset: r75004:eea8f92e03d4 Date: 2014-12-18 00:36 +0100 http://bitbucket.org/pypy/pypy/changeset/eea8f92e03d4/
Log: Be sure to initialize all fields in the socket object, even if __init__ is not called. 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 @@ -144,6 +144,7 @@ def descr_new(space, w_subtype, __args__): sock = space.allocate_instance(W_Socket, w_subtype) + W_Socket.__init__(sock, RSocket.empty_rsocket()) return space.wrap(sock) @unwrap_spec(family=int, type=int, proto=int, diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py --- a/pypy/module/_socket/test/test_sock_app.py +++ b/pypy/module/_socket/test/test_sock_app.py @@ -589,7 +589,7 @@ finally: os.chdir(oldcwd) - def test_subclass(self): + def test_subclass_init(self): # Socket is not created in __new__, but in __init__. import socket class Socket_IPV6(socket.socket): @@ -597,6 +597,18 @@ socket.socket.__init__(self, family=socket.AF_INET6) assert Socket_IPV6().family == socket.AF_INET6 + def test_subclass_noinit(self): + from _socket import socket + class MySock(socket): + def __init__(self, *args): + pass # don't call super + s = MySock() + assert s.type == 0 + assert s.proto == 0 + assert s.family == 0 + assert s.fileno() < 0 + raises(OSError, s.bind, ('localhost', 0)) + def test_dealloc_warn(self): import _socket import gc diff --git a/rpython/rlib/rsocket.py b/rpython/rlib/rsocket.py --- a/rpython/rlib/rsocket.py +++ b/rpython/rlib/rsocket.py @@ -497,6 +497,10 @@ """RPython-level socket object. """ fd = _c.INVALID_SOCKET + family = 0 + type = 0 + proto = 0 + timeout = -1.0 def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fd=_c.INVALID_SOCKET): @@ -512,6 +516,11 @@ self.proto = proto self.timeout = defaults.timeout + @staticmethod + def empty_rsocket(): + rsocket = instantiate(RSocket) + return rsocket + @rgc.must_be_light_finalizer def __del__(self): fd = self.fd _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit