Author: mattip <matti.pi...@gmail.com> Branch: run-create_cffi_imports Changeset: r78233:2217963bdd14 Date: 2015-06-21 22:32 +0300 http://bitbucket.org/pypy/pypy/changeset/2217963bdd14/
Log: merge default into branch diff --git a/lib_pypy/_tkinter/tklib_build.py b/lib_pypy/_tkinter/tklib_build.py --- a/lib_pypy/_tkinter/tklib_build.py +++ b/lib_pypy/_tkinter/tklib_build.py @@ -179,6 +179,7 @@ typedef int... Tcl_WideInt; int Tcl_GetWideIntFromObj(Tcl_Interp *interp, Tcl_Obj *obj, Tcl_WideInt *value); +Tcl_Obj *Tcl_NewWideIntObj(Tcl_WideInt value); """) if HAVE_LIBTOMMATH: diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -11,3 +11,8 @@ .. branch: stdlib-2.7.10 Update stdlib to version 2.7.10 + +.. branch: issue2062 + +.. branch: disable-unroll-for-short-loops +The JIT no longer performs loop unrolling if the loop compiles to too much code. diff --git a/pypy/interpreter/pytraceback.py b/pypy/interpreter/pytraceback.py --- a/pypy/interpreter/pytraceback.py +++ b/pypy/interpreter/pytraceback.py @@ -60,7 +60,6 @@ def check_traceback(space, w_tb, msg): - from pypy.interpreter.typedef import PyTraceback if w_tb is None or not space.isinstance_w(w_tb, space.gettypeobject(PyTraceback.typedef)): raise OperationError(space.w_TypeError, space.wrap(msg)) return w_tb diff --git a/pypy/module/_cffi_backend/lib_obj.py b/pypy/module/_cffi_backend/lib_obj.py --- a/pypy/module/_cffi_backend/lib_obj.py +++ b/pypy/module/_cffi_backend/lib_obj.py @@ -173,6 +173,8 @@ if w_value is None: if is_getattr and attr == '__all__': return self.dir1(ignore_type=cffi_opcode.OP_GLOBAL_VAR) + if is_getattr and attr == '__dict__': + return self.full_dict_copy() raise oefmt(self.space.w_AttributeError, "cffi library '%s' has no function, constant " "or global variable named '%s'", @@ -212,6 +214,17 @@ names_w.append(space.wrap(rffi.charp2str(g[i].c_name))) return space.newlist(names_w) + def full_dict_copy(self): + space = self.space + total = rffi.getintfield(self.ctx, 'c_num_globals') + g = self.ctx.c_globals + w_result = space.newdict() + for i in range(total): + w_attr = space.wrap(rffi.charp2str(g[i].c_name)) + w_value = self._get_attr(w_attr) + space.setitem(w_result, w_attr, w_value) + return w_result + def address_of_func_or_global_var(self, varname): # rebuild a string object from 'varname', to do typechecks and # to force a unicode back to a plain string diff --git a/pypy/module/_cffi_backend/test/test_recompiler.py b/pypy/module/_cffi_backend/test/test_recompiler.py --- a/pypy/module/_cffi_backend/test/test_recompiler.py +++ b/pypy/module/_cffi_backend/test/test_recompiler.py @@ -276,6 +276,15 @@ """) lib.aa = 5 assert dir(lib) == ['aa', 'ff', 'my_constant'] + # + aaobj = lib.__dict__['aa'] + assert not isinstance(aaobj, int) # some internal object instead + assert lib.__dict__ == { + 'ff': lib.ff, + 'aa': aaobj, + 'my_constant': -45} + lib.__dict__['ff'] = "??" + assert lib.ff(10) == 15 def test_verify_opaque_struct(self): ffi, lib = self.prepare( @@ -984,5 +993,5 @@ assert sys.modules['_CFFI_test_import_from_lib.lib'] is lib from _CFFI_test_import_from_lib.lib import MYFOO assert MYFOO == 42 - assert not hasattr(lib, '__dict__') + assert hasattr(lib, '__dict__') assert lib.__all__ == ['MYFOO', 'mybar'] # but not 'myvar' diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py --- a/pypy/module/_io/interp_textio.py +++ b/pypy/module/_io/interp_textio.py @@ -548,6 +548,10 @@ remain buffered in the decoder, yet to be converted.""" if not self.w_decoder: + # very unsure about the following check, but some tests seem + # to expect a ValueError instead of an IOError in case the + # file was already closed. + self._check_closed(space) raise OperationError(space.w_IOError, space.wrap("not readable")) if self.telling: @@ -601,6 +605,10 @@ def read_w(self, space, w_size=None): self._check_attached(space) if not self.w_decoder: + # very unsure about the following check, but some tests seem + # to expect a ValueError instead of an IOError in case the + # file was already closed. + self._check_closed(space) raise OperationError(space.w_IOError, space.wrap("not readable")) size = convert_size(space, w_size) diff --git a/pypy/module/_socket/__init__.py b/pypy/module/_socket/__init__.py --- a/pypy/module/_socket/__init__.py +++ b/pypy/module/_socket/__init__.py @@ -18,6 +18,10 @@ from rpython.rlib.rsocket import rsocket_startup rsocket_startup() + def shutdown(self, space): + from pypy.module._socket.interp_socket import close_all_sockets + close_all_sockets(space) + def buildloaders(cls): from rpython.rlib import rsocket for name in """ diff --git a/pypy/module/_socket/interp_func.py b/pypy/module/_socket/interp_func.py --- a/pypy/module/_socket/interp_func.py +++ b/pypy/module/_socket/interp_func.py @@ -142,7 +142,7 @@ sock = rsocket.fromfd(fd, family, type, proto) except SocketError, e: raise converted_error(space, e) - return space.wrap(W_Socket(sock)) + return space.wrap(W_Socket(space, sock)) @unwrap_spec(family=int, type=int, proto=int) def socketpair(space, family=rsocket.socketpair_default_family, @@ -160,8 +160,8 @@ except SocketError, e: raise converted_error(space, e) return space.newtuple([ - space.wrap(W_Socket(sock1)), - space.wrap(W_Socket(sock2)) + space.wrap(W_Socket(space, sock1)), + space.wrap(W_Socket(space, sock2)) ]) # The following 4 functions refuse all negative numbers, like CPython 2.6. 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 @@ -1,4 +1,5 @@ -from rpython.rlib import rsocket +import sys +from rpython.rlib import rsocket, rweaklist from rpython.rlib.rarithmetic import intmask from rpython.rlib.rsocket import ( RSocket, AF_INET, SOCK_STREAM, SocketError, SocketErrorWithErrno, @@ -153,8 +154,9 @@ class W_Socket(W_Root): - def __init__(self, sock): + def __init__(self, space, sock): self.sock = sock + register_socket(space, sock) def get_type_w(self, space): return space.wrap(self.sock.type) @@ -183,7 +185,7 @@ fd, addr = self.sock.accept() sock = rsocket.make_socket( fd, self.sock.family, self.sock.type, self.sock.proto) - return space.newtuple([space.wrap(W_Socket(sock)), + return space.newtuple([space.wrap(W_Socket(space, sock)), addr_as_object(addr, sock.fd, space)]) except SocketError as e: raise converted_error(space, e) @@ -248,7 +250,7 @@ def dup_w(self, space): try: sock = self.sock.dup() - return W_Socket(sock) + return W_Socket(space, sock) except SocketError as e: raise converted_error(space, e) @@ -592,10 +594,50 @@ sock = RSocket(family, type, proto) except SocketError as e: raise converted_error(space, e) - W_Socket.__init__(self, sock) + W_Socket.__init__(self, space, sock) return space.wrap(self) descr_socket_new = interp2app(newsocket) + +# ____________________________________________________________ +# Automatic shutdown()/close() + +# On some systems, the C library does not guarantee that when the program +# finishes, all data sent so far is really sent even if the socket is not +# explicitly closed. This behavior has been observed on Windows but not +# on Linux, so far. +NEED_EXPLICIT_CLOSE = (sys.platform == 'win32') + +class OpenRSockets(rweaklist.RWeakListMixin): + pass +class OpenRSocketsState: + def __init__(self, space): + self.openrsockets = OpenRSockets() + self.openrsockets.initialize() + +def getopenrsockets(space): + if NEED_EXPLICIT_CLOSE and space.config.translation.rweakref: + return space.fromcache(OpenRSocketsState).openrsockets + else: + return None + +def register_socket(space, socket): + openrsockets = getopenrsockets(space) + if openrsockets is not None: + openrsockets.add_handle(socket) + +def close_all_sockets(space): + openrsockets = getopenrsockets(space) + if openrsockets is not None: + for sock_wref in openrsockets.get_all_handles(): + sock = sock_wref() + if sock is not None: + try: + sock.close() + except SocketError: + pass + + # ____________________________________________________________ # Error handling 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 @@ -309,10 +309,16 @@ class AppTestSocket: + spaceconfig = dict(usemodules=['_socket', '_weakref', 'struct']) + def setup_class(cls): cls.space = space cls.w_udir = space.wrap(str(udir)) + def teardown_class(cls): + if not cls.runappdirect: + cls.space.sys.getmodule('_socket').shutdown(cls.space) + def test_module(self): import _socket assert _socket.socket.__name__ == 'socket' @@ -614,6 +620,12 @@ finally: os.chdir(oldcwd) + def test_automatic_shutdown(self): + # doesn't really test anything, but at least should not explode + # in close_all_sockets() + import _socket + self.foo = _socket.socket() + class AppTestPacket: def setup_class(cls): diff --git a/pypy/module/cpyext/test/test_version.py b/pypy/module/cpyext/test/test_version.py --- a/pypy/module/cpyext/test/test_version.py +++ b/pypy/module/cpyext/test/test_version.py @@ -16,7 +16,7 @@ } """ module = self.import_module(name='foo', init=init) - assert module.py_version == sys.version[:5] + assert module.py_version == '%d.%d.%d' % sys.version_info[:3] assert module.py_major_version == sys.version_info.major assert module.py_minor_version == sys.version_info.minor assert module.py_micro_version == sys.version_info.micro diff --git a/pypy/module/struct/test/test_struct.py b/pypy/module/struct/test/test_struct.py --- a/pypy/module/struct/test/test_struct.py +++ b/pypy/module/struct/test/test_struct.py @@ -390,9 +390,9 @@ self.struct.pack("ii", 17, 42) + '\x00' * (19-sz-2)) exc = raises(TypeError, self.struct.pack_into, "ii", buffer(b), 0, 17, 42) - assert str(exc.value) == "argument must be read-write buffer, not buffer" + assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, self.struct.pack_into, "ii", 'test', 0, 17, 42) - assert str(exc.value) == "argument must be read-write buffer, not str" + assert str(exc.value) == "must be read-write buffer, not str" exc = raises(self.struct.error, self.struct.pack_into, "ii", b[0:1], 0, 17, 42) assert str(exc.value) == "pack_into requires a buffer of at least 8 bytes" diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py @@ -266,6 +266,15 @@ """) lib.aa = 5 assert dir(lib) == ['aa', 'ff', 'my_constant'] + # + aaobj = lib.__dict__['aa'] + assert not isinstance(aaobj, int) # some internal object instead + assert lib.__dict__ == { + 'ff': lib.ff, + 'aa': aaobj, + 'my_constant': -45} + lib.__dict__['ff'] = "??" + assert lib.ff(10) == 15 def test_verify_opaque_struct(): ffi = FFI() @@ -1053,5 +1062,5 @@ assert sys.modules['_CFFI_test_import_from_lib.lib'] is lib from _CFFI_test_import_from_lib.lib import MYFOO assert MYFOO == 42 - assert not hasattr(lib, '__dict__') + assert hasattr(lib, '__dict__') assert lib.__all__ == ['MYFOO', 'mybar'] # but not 'myvar' diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py --- a/rpython/flowspace/flowcontext.py +++ b/rpython/flowspace/flowcontext.py @@ -1207,7 +1207,8 @@ def nomoreblocks(self, ctx): w_exc = self.w_exc if w_exc.w_type == const(ImportError): - msg = 'import statement always raises %s' % self + msg = 'ImportError is raised in RPython: %s' % ( + getattr(w_exc.w_value, 'value', '<not a constant message>'),) raise ImportError(msg) link = Link([w_exc.w_type, w_exc.w_value], ctx.graph.exceptblock) ctx.recorder.crnt_block.closeblock(link) diff --git a/rpython/flowspace/test/cant_import.py b/rpython/flowspace/test/cant_import.py new file mode 100644 --- /dev/null +++ b/rpython/flowspace/test/cant_import.py @@ -0,0 +1,1 @@ +raise ImportError("some explanation here") diff --git a/rpython/flowspace/test/test_objspace.py b/rpython/flowspace/test/test_objspace.py --- a/rpython/flowspace/test/test_objspace.py +++ b/rpython/flowspace/test/test_objspace.py @@ -816,6 +816,12 @@ from rpython import this_does_not_exist py.test.raises(ImportError, 'self.codetest(f)') + def test_importerror_3(self): + def f(): + import rpython.flowspace.test.cant_import + e = py.test.raises(ImportError, 'self.codetest(f)') + assert "some explanation here" in str(e.value) + def test_relative_import(self): def f(): from ..objspace import build_flow _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit