[pypy-commit] pypy refactor-buffer-api: unicodeobject has old buffer interface
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70923:bd46658a05eb Date: 2014-04-24 03:38 -0400 http://bitbucket.org/pypy/pypy/changeset/bd46658a05eb/ Log:unicodeobject has old buffer interface diff --git a/pypy/module/__pypy__/test/test_bytebuffer.py b/pypy/module/__pypy__/test/test_bytebuffer.py --- a/pypy/module/__pypy__/test/test_bytebuffer.py +++ b/pypy/module/__pypy__/test/test_bytebuffer.py @@ -25,3 +25,5 @@ assert str(b) == "\x00xy" + "\x00" * 7 b[4:8:2] = 'zw' assert str(b) == "\x00xy\x00z\x00w" + "\x00" * 3 +b[6:10] = u'#' +assert str(b) == "\x00xy\x00z\x00#" + "\x00" * 3 diff --git a/pypy/module/_io/test/test_bufferedio.py b/pypy/module/_io/test/test_bufferedio.py --- a/pypy/module/_io/test/test_bufferedio.py +++ b/pypy/module/_io/test/test_bufferedio.py @@ -139,6 +139,8 @@ raw = _io.FileIO(self.tmpfile) f = _io.BufferedReader(raw) assert f.readinto(a) == 5 +exc = raises(TypeError, f.readinto, u"hello") +assert str(exc.value) == "cannot use unicode as modifiable buffer" exc = raises(TypeError, f.readinto, buffer(b"hello")) assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, f.readinto, memoryview(b"hello")) @@ -239,7 +241,8 @@ import _io raw = _io.FileIO(self.tmpfile, 'w') f = _io.BufferedWriter(raw) -f.write("abcd") +f.write("ab") +f.write(u"cd") f.close() assert self.readfile() == "abcd" diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py --- a/pypy/module/_io/test/test_bytesio.py +++ b/pypy/module/_io/test/test_bytesio.py @@ -38,6 +38,8 @@ f = _io.BytesIO() assert f.write("") == 0 assert f.write("hello") == 5 +exc = raises(TypeError, f.write, u"lo") +assert str(exc.value) == "'unicode' does not have the buffer interface" import gc; gc.collect() assert f.getvalue() == "hello" f.close() @@ -97,6 +99,8 @@ a2 = bytearray('testing') assert b.readinto(a1) == 1 assert b.readinto(a2) == 4 +exc = raises(TypeError, b.readinto, u"hello") +assert str(exc.value) == "cannot use unicode as modifiable buffer" exc = raises(TypeError, b.readinto, buffer(b"hello")) assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, b.readinto, memoryview(b"hello")) diff --git a/pypy/module/_io/test/test_fileio.py b/pypy/module/_io/test/test_fileio.py --- a/pypy/module/_io/test/test_fileio.py +++ b/pypy/module/_io/test/test_fileio.py @@ -82,7 +82,8 @@ import _io filename = self.tmpfile + '_w' f = _io.FileIO(filename, 'wb') -f.write("test") +f.write("te") +f.write(u"st") # try without flushing f2 = _io.FileIO(filename, 'rb') assert f2.read() == "test" @@ -135,6 +136,8 @@ a = bytearray('x' * 10) f = _io.FileIO(self.tmpfile, 'r+') assert f.readinto(a) == 10 +exc = raises(TypeError, f.readinto, u"hello") +assert str(exc.value) == "cannot use unicode as modifiable buffer" exc = raises(TypeError, f.readinto, buffer(b"hello")) assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, f.readinto, memoryview(b"hello")) diff --git a/pypy/objspace/std/bufferobject.py b/pypy/objspace/std/bufferobject.py --- a/pypy/objspace/std/bufferobject.py +++ b/pypy/objspace/std/bufferobject.py @@ -37,18 +37,7 @@ @staticmethod @unwrap_spec(offset=int, size=int) def descr_new_buffer(space, w_subtype, w_object, offset=0, size=-1): -if space.isinstance_w(w_object, space.w_unicode): -# unicode objects support the old buffer interface -# but not the new buffer interface (change in python 2.7) -from rpython.rlib.rstruct.unichar import pack_unichar, UNICODE_SIZE -unistr = space.unicode_w(w_object) -builder = StringBuilder(len(unistr) * UNICODE_SIZE) -for unich in unistr: -pack_unichar(unich, builder) -buf = StringBuffer(builder.build()) -else: -buf = space.readbuf_w(w_object) - +buf = space.readbuf_w(w_object) if offset == 0 and size == -1: return W_Buffer(buf) # handle buffer slices diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -2,7 +2,8 @@ from rpython.rlib.objectmodel import ( compute_hash, compute_unique_id, import_from_mixin) -from rpython.rlib.rstring import UnicodeBuilder +from rpython.rlib.buffer import StringBuffer +from rpython.rlib.rstring import StringBuilder, UnicodeBuilder from rpython.rlib.runicode import (
[pypy-commit] pypy refactor-buffer-api: fix _socket recv_into
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70922:1b134cf7acc4 Date: 2014-04-24 01:55 -0400 http://bitbucket.org/pypy/pypy/changeset/1b134cf7acc4/ Log:fix _socket recv_into 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 @@ -419,7 +419,7 @@ @unwrap_spec(nbytes=int, flags=int) def recv_into_w(self, space, w_buffer, nbytes=0, flags=0): -rwbuffer = space.writebuf_w(w_buffer) +rwbuffer = space.getarg_w('w*', w_buffer) lgt = rwbuffer.getlength() if nbytes == 0 or nbytes > lgt: nbytes = lgt @@ -430,7 +430,7 @@ @unwrap_spec(nbytes=int, flags=int) def recvfrom_into_w(self, space, w_buffer, nbytes=0, flags=0): -rwbuffer = space.writebuf_w(w_buffer) +rwbuffer = space.getarg_w('w*', w_buffer) lgt = rwbuffer.getlength() if nbytes == 0 or nbytes > lgt: nbytes = lgt 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 @@ -682,6 +682,13 @@ msg = buf.tostring()[:len(MSG)] assert msg == MSG +conn.send(MSG) +buf = bytearray(1024) +nbytes = cli.recv_into(memoryview(buf)) +assert nbytes == len(MSG) +msg = buf[:len(MSG)] +assert msg == MSG + def test_recvfrom_into(self): import socket import array @@ -697,6 +704,13 @@ msg = buf.tostring()[:len(MSG)] assert msg == MSG +conn.send(MSG) +buf = bytearray(1024) +nbytes, addr = cli.recvfrom_into(memoryview(buf)) +assert nbytes == len(MSG) +msg = buf[:len(MSG)] +assert msg == MSG + def test_family(self): import socket cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: correct _codecs.{char, read}buffer_encode
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70924:1569ceab7693 Date: 2014-04-24 03:20 -0400 http://bitbucket.org/pypy/pypy/changeset/1569ceab7693/ Log:correct _codecs.{char,read}buffer_encode diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1411,7 +1411,7 @@ if self.is_none(w_obj): name = "None" else: -name = self.type(w_obj).getname(self) +name = self.type(w_obj).get_module_type_name() raise oefmt(self.w_TypeError, "must be %s, not %s", expected, name) @specialize.arg(1) @@ -1429,6 +1429,15 @@ return w_obj.readbuf_w(self) except TypeError: self._getarg_error("string or buffer", w_obj) +elif code == 's#': +if self.isinstance_w(w_obj, self.w_str): +return w_obj.str_w(self) +if self.isinstance_w(w_obj, self.w_unicode): +return self.str(w_obj).str_w(self) +try: +return w_obj.readbuf_w(self).as_str() +except TypeError: +self._getarg_error("string or read-only buffer") elif code == 'w*': try: try: @@ -1441,6 +1450,11 @@ return w_obj.writebuf_w(self) except TypeError: self._getarg_error("read-write buffer", w_obj) +elif code == 't#': +try: +return w_obj.charbuf_w(self) +except TypeError: +self._getarg_error("string or read-only character buffer", w_obj) else: assert False diff --git a/pypy/module/_codecs/__init__.py b/pypy/module/_codecs/__init__.py --- a/pypy/module/_codecs/__init__.py +++ b/pypy/module/_codecs/__init__.py @@ -72,8 +72,8 @@ 'utf_32_le_decode' : 'interp_codecs.utf_32_le_decode', 'utf_32_le_encode' : 'interp_codecs.utf_32_le_encode', 'utf_32_ex_decode' : 'interp_codecs.utf_32_ex_decode', - 'charbuffer_encode': 'interp_codecs.buffer_encode', - 'readbuffer_encode': 'interp_codecs.buffer_encode', + 'charbuffer_encode': 'interp_codecs.charbuffer_encode', + 'readbuffer_encode': 'interp_codecs.readbuffer_encode', 'charmap_decode' : 'interp_codecs.charmap_decode', 'charmap_encode' : 'interp_codecs.charmap_encode', 'escape_encode': 'interp_codecs.escape_encode', diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py --- a/pypy/module/_codecs/interp_codecs.py +++ b/pypy/module/_codecs/interp_codecs.py @@ -321,8 +321,14 @@ w_res = space.call_function(w_encoder, w_obj, space.wrap(errors)) return space.getitem(w_res, space.wrap(0)) -@unwrap_spec(s='bufferstr', errors='str_or_None') -def buffer_encode(space, s, errors='strict'): +@unwrap_spec(errors='str_or_None') +def readbuffer_encode(space, w_data, errors='strict'): +s = space.getarg_w('s#', w_data) +return space.newtuple([space.wrap(s), space.wrap(len(s))]) + +@unwrap_spec(errors='str_or_None') +def charbuffer_encode(space, w_data, errors='strict'): +s = space.getarg_w('t#', w_data) return space.newtuple([space.wrap(s), space.wrap(len(s))]) @unwrap_spec(errors=str) diff --git a/pypy/module/_codecs/test/test_codecs.py b/pypy/module/_codecs/test/test_codecs.py --- a/pypy/module/_codecs/test/test_codecs.py +++ b/pypy/module/_codecs/test/test_codecs.py @@ -420,9 +420,13 @@ for (i, line) in enumerate(reader): assert line == s[i] -def test_array(self): +def test_buffer_encode(self): import _codecs, array -_codecs.readbuffer_encode(array.array('c', 'spam')) == ('spam', 4) +assert _codecs.readbuffer_encode(array.array('c', 'spam')) == ('spam', 4) +exc = raises(TypeError, _codecs.charbuffer_encode, array.array('c', 'spam')) +assert str(exc.value) == "must be string or read-only character buffer, not array.array" +assert _codecs.readbuffer_encode(u"test") == ('test', 4) +assert _codecs.charbuffer_encode(u"test") == ('test', 4) def test_utf8sig(self): import codecs diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py --- a/pypy/objspace/fake/objspace.py +++ b/pypy/objspace/fake/objspace.py @@ -73,6 +73,9 @@ def get_module(self): return w_some_obj() +def get_module_type_name(self): +return self.name + def w_some_obj(): if NonConstant(False): return W_Root() diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -76,6 +76,8 @@ raise OperationError(space.w_TypeError, space.wrap( "cannot use unicode as modifiable buffer")) +charbuf_w = str_w + def
[pypy-commit] pypy refactor-buffer-api: fix buffer conversion when readonly
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70921:1e39f97163c6 Date: 2014-04-24 01:49 -0400 http://bitbucket.org/pypy/pypy/changeset/1e39f97163c6/ Log:fix buffer conversion when readonly diff --git a/pypy/module/_io/test/test_bufferedio.py b/pypy/module/_io/test/test_bufferedio.py --- a/pypy/module/_io/test/test_bufferedio.py +++ b/pypy/module/_io/test/test_bufferedio.py @@ -139,6 +139,8 @@ raw = _io.FileIO(self.tmpfile) f = _io.BufferedReader(raw) assert f.readinto(a) == 5 +exc = raises(TypeError, f.readinto, buffer(b"hello")) +assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, f.readinto, memoryview(b"hello")) assert str(exc.value) == "must be read-write buffer, not memoryview" f.close() diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py --- a/pypy/module/_io/test/test_bytesio.py +++ b/pypy/module/_io/test/test_bytesio.py @@ -97,6 +97,8 @@ a2 = bytearray('testing') assert b.readinto(a1) == 1 assert b.readinto(a2) == 4 +exc = raises(TypeError, b.readinto, buffer(b"hello")) +assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, b.readinto, memoryview(b"hello")) assert str(exc.value) == "must be read-write buffer, not memoryview" b.close() diff --git a/pypy/module/_io/test/test_fileio.py b/pypy/module/_io/test/test_fileio.py --- a/pypy/module/_io/test/test_fileio.py +++ b/pypy/module/_io/test/test_fileio.py @@ -135,6 +135,8 @@ a = bytearray('x' * 10) f = _io.FileIO(self.tmpfile, 'r+') assert f.readinto(a) == 10 +exc = raises(TypeError, f.readinto, buffer(b"hello")) +assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, f.readinto, memoryview(b"hello")) assert str(exc.value) == "must be read-write buffer, not memoryview" f.close() diff --git a/pypy/objspace/std/bufferobject.py b/pypy/objspace/std/bufferobject.py --- a/pypy/objspace/std/bufferobject.py +++ b/pypy/objspace/std/bufferobject.py @@ -22,6 +22,7 @@ self.buf = buf def buffer_w(self, space, flags): +space.check_buf_flags(flags, self.buf.readonly) return self.buf def readbuf_w(self, space): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: clean up buffer/memoryview setitem
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70920:fc458f88faff Date: 2014-04-24 01:44 -0400 http://bitbucket.org/pypy/pypy/changeset/fc458f88faff/ Log:clean up buffer/memoryview setitem diff --git a/pypy/module/__pypy__/test/test_bytebuffer.py b/pypy/module/__pypy__/test/test_bytebuffer.py --- a/pypy/module/__pypy__/test/test_bytebuffer.py +++ b/pypy/module/__pypy__/test/test_bytebuffer.py @@ -13,3 +13,15 @@ assert b[-1] == '*' assert b[-2] == '-' assert b[-3] == '+' +exc = raises(TypeError, "b[3] = 'abc'") +assert str(exc.value) == "right operand must be a single byte" +exc = raises(TypeError, "b[3:5] = 'abc'") +assert str(exc.value) == "right operand length must match slice length" +exc = raises(TypeError, "b[3:7:2] = 'abc'") +assert str(exc.value) == "right operand length must match slice length" + +b = bytebuffer(10) +b[1:3] = 'xy' +assert str(b) == "\x00xy" + "\x00" * 7 +b[4:8:2] = 'zw' +assert str(b) == "\x00xy\x00z\x00w" + "\x00" * 3 diff --git a/pypy/objspace/std/bufferobject.py b/pypy/objspace/std/bufferobject.py --- a/pypy/objspace/std/bufferobject.py +++ b/pypy/objspace/std/bufferobject.py @@ -10,7 +10,6 @@ from pypy.interpreter.typedef import TypeDef from rpython.rlib.objectmodel import compute_hash from rpython.rlib.rstring import StringBuilder -from pypy.objspace.std.memoryobject import _buffer_setitem class W_Buffer(W_Root): @@ -71,12 +70,26 @@ res = self.buf.getslice(start, stop, step, size) return space.wrap(res) -@unwrap_spec(newstring='bufferstr') -def descr_setitem(self, space, w_index, newstring): +def descr_setitem(self, space, w_index, w_obj): if not self.buf.is_writable(): raise OperationError(space.w_TypeError, space.wrap("buffer is read-only")) -_buffer_setitem(space, self.buf, w_index, newstring) +start, stop, step, size = space.decode_index4(w_index, self.buf.getlength()) +value = space.readbuf_w(w_obj) +if step == 0: # index only +if value.getlength() != 1: +msg = "right operand must be a single byte" +raise OperationError(space.w_TypeError, space.wrap(msg)) +self.buf.setitem(start, value.getitem(0)) +else: +if value.getlength() != size: +msg = "right operand length must match slice length" +raise OperationError(space.w_TypeError, space.wrap(msg)) +if step == 1: +self.buf.setslice(start, value.as_str()) +else: +for i in range(size): +self.buf.setitem(start + i * step, value.getitem(i)) def descr_str(self, space): return space.wrap(self.buf.as_str()) diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py --- a/pypy/objspace/std/memoryobject.py +++ b/pypy/objspace/std/memoryobject.py @@ -10,25 +10,6 @@ from pypy.interpreter.typedef import TypeDef, GetSetProperty -def _buffer_setitem(space, buf, w_index, newstring): -start, stop, step, size = space.decode_index4(w_index, buf.getlength()) -if step == 0: # index only -if len(newstring) != 1: -msg = 'buffer[index]=x: x must be a single character' -raise OperationError(space.w_TypeError, space.wrap(msg)) -char = newstring[0] # annotator hint -buf.setitem(start, char) -elif step == 1: -if len(newstring) != size: -msg = "right operand length must match slice length" -raise OperationError(space.w_ValueError, space.wrap(msg)) -buf.setslice(start, newstring) -else: -raise OperationError(space.w_ValueError, - space.wrap("buffer object does not support" -" slicing with a step")) - - class W_MemoryView(W_Root): """Implement the built-in 'memoryview' type as a wrapper around an interp-level buffer. @@ -40,7 +21,8 @@ self.buf = buf def buffer_w(self, space, flags): -return space.buffer_w(self.obj, flags) +space.check_buf_flags(flags, self.buf.readonly) +return self.buf @staticmethod def descr_new_memoryview(space, w_subtype, w_object): @@ -101,22 +83,28 @@ def descr_getitem(self, space, w_index): start, stop, step = space.decode_index(w_index, self.getlength()) +if step not in (0, 1): +raise OperationError(space.w_NotImplementedError, space.wrap("")) if step == 0: # index only return space.wrap(self.buf.getitem(start)) +res = self.getslice(start, stop) +return space.wrap(res) + +def descr_setitem(self, space, w_index, w_obj): +if not self.buf.is_writable(): +raise OperationError(space.w_TypeError, space.wrap( +
[pypy-commit] pypy refactor-buffer-api: fix translation
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70925:9859bb1e1b5e Date: 2014-04-24 03:50 -0400 http://bitbucket.org/pypy/pypy/changeset/9859bb1e1b5e/ Log:fix translation diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1437,7 +1437,7 @@ try: return w_obj.readbuf_w(self).as_str() except TypeError: -self._getarg_error("string or read-only buffer") +self._getarg_error("string or read-only buffer", w_obj) elif code == 'w*': try: try: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: fix cffi MiniBuffer setslice exception type
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70926:efb387f6f091 Date: 2014-04-24 04:16 -0400 http://bitbucket.org/pypy/pypy/changeset/efb387f6f091/ Log:fix cffi MiniBuffer setslice exception type diff --git a/pypy/module/_cffi_backend/cbuffer.py b/pypy/module/_cffi_backend/cbuffer.py --- a/pypy/module/_cffi_backend/cbuffer.py +++ b/pypy/module/_cffi_backend/cbuffer.py @@ -1,4 +1,4 @@ -from pypy.interpreter.error import oefmt +from pypy.interpreter.error import oefmt, OperationError from pypy.interpreter.gateway import unwrap_spec, interp2app from pypy.interpreter.typedef import TypeDef, make_weakref_descr from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray @@ -47,6 +47,14 @@ W_Buffer.__init__(self, buffer) self.keepalive = keepalive +def descr_setitem(self, space, w_index, w_obj): +try: +W_Buffer.descr_setitem(self, space, w_index, w_obj) +except OperationError as e: +if e.match(space, space.w_TypeError): +e.w_type = space.w_ValueError +raise + MiniBuffer.typedef = TypeDef( "buffer", __module__ = "_cffi_backend", ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] benchmarks default: shutdown thread pools at the end of benchmark runs
Author: Remi Meier Branch: Changeset: r252:f232348bc821 Date: 2014-04-24 13:18 +0200 http://bitbucket.org/pypy/benchmarks/changeset/f232348bc821/ Log:shutdown thread pools at the end of benchmark runs diff --git a/multithread/btree/btree.py b/multithread/btree/btree.py --- a/multithread/btree/btree.py +++ b/multithread/btree/btree.py @@ -347,6 +347,9 @@ # print "tree:" # print tree +# shutdown current pool +set_thread_pool(None) + diff --git a/multithread/common/abstract_threading.py b/multithread/common/abstract_threading.py --- a/multithread/common/abstract_threading.py +++ b/multithread/common/abstract_threading.py @@ -49,6 +49,8 @@ def set_thread_pool(th): global _thread_pool +if _thread_pool: +_thread_pool.shutdown() _thread_pool = th diff --git a/multithread/mandelbrot/mandelbrot.py b/multithread/mandelbrot/mandelbrot.py --- a/multithread/mandelbrot/mandelbrot.py +++ b/multithread/mandelbrot/mandelbrot.py @@ -1,4 +1,4 @@ -from common.abstract_threading import Future, atomic +from common.abstract_threading import atomic, Future, set_thread_pool, ThreadPool import sys @@ -59,6 +59,7 @@ br, bi = 1.0, 1.5 width, height = 4096, 4096 +set_thread_pool(ThreadPool(threads)) step = (bi - ai) / threads res = [] ai = -1.5 @@ -71,6 +72,8 @@ )) res = [f() for f in res] + +set_thread_pool(None) return merge_imgs(res) diff --git a/multithread/raytrace/raytrace.py b/multithread/raytrace/raytrace.py --- a/multithread/raytrace/raytrace.py +++ b/multithread/raytrace/raytrace.py @@ -165,6 +165,10 @@ print f() del futures[:] +# shutdown current pool +set_thread_pool(None) + + if __name__ == '__main__': run() diff --git a/multithread/skiplist/skiplist.py b/multithread/skiplist/skiplist.py --- a/multithread/skiplist/skiplist.py +++ b/multithread/skiplist/skiplist.py @@ -130,6 +130,10 @@ # print "list:" # slist.printList() +# shutdown current pool +set_thread_pool(None) + + ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc default: do not signal a transaction to commit more than once. this is necessary to not
Author: Remi Meier Branch: Changeset: r1181:7713ed439985 Date: 2014-04-24 13:47 +0200 http://bitbucket.org/pypy/stmgc/changeset/7713ed439985/ Log:do not signal a transaction to commit more than once. this is necessary to not hurt performance (if this mechanism turns out to be useful at all) diff --git a/c7/stm/contention.c b/c7/stm/contention.c --- a/c7/stm/contention.c +++ b/c7/stm/contention.c @@ -263,7 +263,10 @@ /* we should commit soon, we caused an abort */ //signal_other_to_commit_soon(get_priv_segment(STM_SEGMENT->segment_num)); -stmcb_commit_soon(); +if (!STM_PSEGMENT->signalled_to_commit_soon) { +STM_PSEGMENT->signalled_to_commit_soon = true; +stmcb_commit_soon(); +} } } diff --git a/c7/stm/core.c b/c7/stm/core.c --- a/c7/stm/core.c +++ b/c7/stm/core.c @@ -192,6 +192,7 @@ assert(STM_PSEGMENT->transaction_state == TS_NONE); change_timing_state(STM_TIME_RUN_CURRENT); STM_PSEGMENT->start_time = tl->_timing_cur_start; +STM_PSEGMENT->signalled_to_commit_soon = false; STM_PSEGMENT->safe_point = SP_RUNNING; STM_PSEGMENT->transaction_state = (jmpbuf != NULL ? TS_REGULAR : TS_INEVITABLE); diff --git a/c7/stm/core.h b/c7/stm/core.h --- a/c7/stm/core.h +++ b/c7/stm/core.h @@ -162,6 +162,9 @@ struct stm_shadowentry_s *shadowstack_at_start_of_transaction; object_t *threadlocal_at_start_of_transaction; +/* Already signalled to commit soon: */ +bool signalled_to_commit_soon; + /* For debugging */ #ifndef NDEBUG pthread_t running_pthread; diff --git a/c7/stm/sync.c b/c7/stm/sync.c --- a/c7/stm/sync.c +++ b/c7/stm/sync.c @@ -269,9 +269,11 @@ assert(_has_mutex()); /* never overwrite abort signals or safepoint requests (too messy to deal with) */ -if (!is_abort(other_pseg->pub.nursery_end) -&& !pause_signalled) +if (!other_pseg->signalled_to_commit_soon +&& !is_abort(other_pseg->pub.nursery_end) +&& !pause_signalled) { other_pseg->pub.nursery_end = NSE_SIGCOMMITSOON; +} } static void signal_everybody_to_pause_running(void) @@ -342,6 +344,7 @@ previous_state = change_timing_state(STM_TIME_SYNC_COMMIT_SOON); } +STM_PSEGMENT->signalled_to_commit_soon = true; stmcb_commit_soon(); if (!pause_signalled) { STM_SEGMENT->nursery_end = NURSERY_END; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-smalltalk default: reenabled automatic configuration of stm in targetimageloadingsmalltalk
Author: Patrick Rein Branch: Changeset: r795:a12c5ad93421 Date: 2014-04-24 15:56 +0100 http://bitbucket.org/pypy/lang-smalltalk/changeset/a12c5ad93421/ Log:reenabled automatic configuration of stm in targetimageloadingsmalltalk diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py --- a/targetimageloadingsmalltalk.py +++ b/targetimageloadingsmalltalk.py @@ -223,9 +223,8 @@ # driver.config.translation.gcrootfinder = "stm" from rpython.rlib import rgc if hasattr(rgc, "stm_is_enabled"): -pass -#driver.config.translation.stm = True -#driver.config.translation.thread = True +driver.config.translation.stm = True +driver.config.translation.thread = True return entry_point, None ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: test/fix struct pack_into/unpack_from behavior
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70928:c25773816a8a Date: 2014-04-24 13:04 -0400 http://bitbucket.org/pypy/pypy/changeset/c25773816a8a/ Log:test/fix struct pack_into/unpack_from behavior diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1416,6 +1416,10 @@ @specialize.arg(1) def getarg_w(self, code, w_obj): +if code == 'z*': +if self.is_none(w_obj): +return None +code = 's*' if code == 's*': if self.isinstance_w(w_obj, self.w_str): return w_obj.readbuf_w(self) diff --git a/pypy/module/struct/__init__.py b/pypy/module/struct/__init__.py --- a/pypy/module/struct/__init__.py +++ b/pypy/module/struct/__init__.py @@ -48,13 +48,13 @@ interpleveldefs = { 'calcsize': 'interp_struct.calcsize', 'pack': 'interp_struct.pack', +'pack_into': 'interp_struct.pack_into', 'unpack': 'interp_struct.unpack', +'unpack_from': 'interp_struct.unpack_from', 'Struct': 'interp_struct.W_Struct', } appleveldefs = { 'error': 'app_struct.error', -'pack_into': 'app_struct.pack_into', -'unpack_from': 'app_struct.unpack_from', } diff --git a/pypy/module/struct/app_struct.py b/pypy/module/struct/app_struct.py --- a/pypy/module/struct/app_struct.py +++ b/pypy/module/struct/app_struct.py @@ -2,23 +2,8 @@ """ Application-level definitions for the struct module. """ -import struct class error(Exception): """Exception raised on various occasions; argument is a string describing what is wrong.""" - -# XXX inefficient -def pack_into(fmt, buf, offset, *args): -data = struct.pack(fmt, *args) -buffer(buf)[offset:offset+len(data)] = data - -# XXX inefficient -def unpack_from(fmt, buf, offset=0): -size = struct.calcsize(fmt) -data = buffer(buf)[offset:offset+size] -if len(data) != size: -raise error("unpack_from requires a buffer of at least %d bytes" -% (size,)) -return struct.unpack(fmt, data) diff --git a/pypy/module/struct/interp_struct.py b/pypy/module/struct/interp_struct.py --- a/pypy/module/struct/interp_struct.py +++ b/pypy/module/struct/interp_struct.py @@ -5,7 +5,7 @@ from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.gateway import interp2app, unwrap_spec -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.typedef import TypeDef, interp_attrproperty from pypy.module.struct.formatiterator import ( PackFormatIterator, UnpackFormatIterator @@ -29,6 +29,7 @@ raise OperationError(w_error, space.wrap(e.msg)) return fmtiter.totalsize + @unwrap_spec(format=str) def pack(space, format, args_w): if jit.isconstant(format): @@ -47,6 +48,23 @@ return space.wrap(fmtiter.result.build()) +# XXX inefficient +@unwrap_spec(format=str, offset=int) +def pack_into(space, format, w_buf, offset, args_w): +res = pack(space, format, args_w).str_w(space) +buf = space.writebuf_w(w_buf) +if offset < 0: +offset += buf.getlength() +size = len(res) +if offset < 0 or (buf.getlength() - offset) < size: +w_module = space.getbuiltinmodule('struct') +w_error = space.getattr(w_module, space.wrap('error')) +raise oefmt(w_error, +"pack_into requires a buffer of at least %d bytes", +size) +buf.setslice(offset, res) + + @unwrap_spec(format=str, input='bufferstr') def unpack(space, format, input): fmtiter = UnpackFormatIterator(space, input) @@ -61,6 +79,27 @@ return space.newtuple(fmtiter.result_w[:]) +# XXX inefficient +@unwrap_spec(format=str, offset=int) +def unpack_from(space, format, w_buf, offset=0): +size = _calcsize(space, format) +buf = space.getarg_w('z*', w_buf) +if buf is None: +w_module = space.getbuiltinmodule('struct') +w_error = space.getattr(w_module, space.wrap('error')) +raise oefmt(w_error, "unpack_from requires a buffer argument") +if offset < 0: +offset += buf.getlength() +if offset < 0 or (buf.getlength() - offset) < size: +w_module = space.getbuiltinmodule('struct') +w_error = space.getattr(w_module, space.wrap('error')) +raise oefmt(w_error, +"unpack_from requires a buffer of at least %d bytes", +size) +data = buf.getslice(offset, offset + size, 1, size) +return unpack(space, format, data) + + class W_Struct(W_Root): _immutable_fields_ = ["format", "size"] 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 @@ -2,12 +2,11 @@ Tests for the
[pypy-commit] pypy refactor-buffer-api: proper exception is now raised here
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70929:c913c204f19d Date: 2014-04-24 13:13 -0400 http://bitbucket.org/pypy/pypy/changeset/c913c204f19d/ Log:proper exception is now raised here diff --git a/lib-python/2.7/test/test_memoryview.py b/lib-python/2.7/test/test_memoryview.py --- a/lib-python/2.7/test/test_memoryview.py +++ b/lib-python/2.7/test/test_memoryview.py @@ -115,8 +115,8 @@ self.assertRaises(TypeError, setitem, (0,), b"a") self.assertRaises(TypeError, setitem, "a", b"a") # Trying to resize the memory object -self.assertRaises((ValueError, TypeError), setitem, 0, b"") -self.assertRaises((ValueError, TypeError), setitem, 0, b"ab") +self.assertRaises(ValueError, setitem, 0, b"") +self.assertRaises(ValueError, setitem, 0, b"ab") self.assertRaises(ValueError, setitem, slice(1,1), b"a") self.assertRaises(ValueError, setitem, slice(0,2), b"a") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: simplify buffer.readonly/is_writable()
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70927:1b961b9e0f74 Date: 2014-04-24 04:29 -0400 http://bitbucket.org/pypy/pypy/changeset/1b961b9e0f74/ Log:simplify buffer.readonly/is_writable() diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py --- a/pypy/module/micronumpy/ndarray.py +++ b/pypy/module/micronumpy/ndarray.py @@ -1218,7 +1218,7 @@ return W_NDimArray.from_shape_and_storage(space, shape, storage, dtype, w_subtype=w_subtype, w_base=w_buffer, - writable=buf.is_writable()) + writable=not buf.readonly) order = order_converter(space, w_order, NPY.CORDER) if order == NPY.CORDER: diff --git a/pypy/objspace/std/bufferobject.py b/pypy/objspace/std/bufferobject.py --- a/pypy/objspace/std/bufferobject.py +++ b/pypy/objspace/std/bufferobject.py @@ -61,7 +61,7 @@ return space.wrap(res) def descr_setitem(self, space, w_index, w_obj): -if not self.buf.is_writable(): +if self.buf.readonly: raise OperationError(space.w_TypeError, space.wrap("buffer is read-only")) start, stop, step, size = space.decode_index4(w_index, self.buf.getlength()) @@ -117,10 +117,10 @@ return space.call_method(w_string, '__mul__', w_times) def descr_repr(self, space): -if self.buf.is_writable(): +if self.buf.readonly: +info = 'read-only buffer' +else: info = 'read-write buffer' -else: -info = 'read-only buffer' addrstring = self.getaddrstring(space) return space.wrap("<%s for 0x%s, size %d>" % diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py --- a/pypy/objspace/std/memoryobject.py +++ b/pypy/objspace/std/memoryobject.py @@ -91,7 +91,7 @@ return space.wrap(res) def descr_setitem(self, space, w_index, w_obj): -if not self.buf.is_writable(): +if self.buf.readonly: raise OperationError(space.w_TypeError, space.wrap( "cannot modify read-only memory")) start, stop, step, size = space.decode_index4(w_index, self.buf.getlength()) @@ -119,7 +119,7 @@ return space.wrap(1) def w_is_readonly(self, space): -return space.wrap(not self.buf.is_writable()) +return space.wrap(self.buf.readonly) def w_get_shape(self, space): return space.newtuple([space.wrap(self.getlength())]) diff --git a/rpython/rlib/buffer.py b/rpython/rlib/buffer.py --- a/rpython/rlib/buffer.py +++ b/rpython/rlib/buffer.py @@ -37,9 +37,6 @@ def get_raw_address(self): raise ValueError("no raw buffer") -def is_writable(self): -return not self.readonly - class StringBuffer(Buffer): __slots__ = ['value'] ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: fix bytearray buffer readonly flag
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70931:ad400df172a4 Date: 2014-04-24 15:13 -0400 http://bitbucket.org/pypy/pypy/changeset/ad400df172a4/ Log:fix bytearray buffer readonly flag diff --git a/pypy/module/_io/test/test_bufferedio.py b/pypy/module/_io/test/test_bufferedio.py --- a/pypy/module/_io/test/test_bufferedio.py +++ b/pypy/module/_io/test/test_bufferedio.py @@ -143,6 +143,8 @@ assert str(exc.value) == "cannot use unicode as modifiable buffer" exc = raises(TypeError, f.readinto, buffer(b"hello")) assert str(exc.value) == "must be read-write buffer, not buffer" +exc = raises(TypeError, f.readinto, buffer(bytearray("hello"))) +assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, f.readinto, memoryview(b"hello")) assert str(exc.value) == "must be read-write buffer, not memoryview" f.close() diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py --- a/pypy/module/_io/test/test_bytesio.py +++ b/pypy/module/_io/test/test_bytesio.py @@ -103,6 +103,8 @@ assert str(exc.value) == "cannot use unicode as modifiable buffer" exc = raises(TypeError, b.readinto, buffer(b"hello")) assert str(exc.value) == "must be read-write buffer, not buffer" +exc = raises(TypeError, b.readinto, buffer(bytearray("hello"))) +assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, b.readinto, memoryview(b"hello")) assert str(exc.value) == "must be read-write buffer, not memoryview" b.close() diff --git a/pypy/module/_io/test/test_fileio.py b/pypy/module/_io/test/test_fileio.py --- a/pypy/module/_io/test/test_fileio.py +++ b/pypy/module/_io/test/test_fileio.py @@ -140,6 +140,8 @@ assert str(exc.value) == "cannot use unicode as modifiable buffer" exc = raises(TypeError, f.readinto, buffer(b"hello")) assert str(exc.value) == "must be read-write buffer, not buffer" +exc = raises(TypeError, f.readinto, buffer(bytearray("hello"))) +assert str(exc.value) == "must be read-write buffer, not buffer" exc = raises(TypeError, f.readinto, memoryview(b"hello")) assert str(exc.value) == "must be read-write buffer, not memoryview" f.close() diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py --- a/pypy/objspace/std/bytearrayobject.py +++ b/pypy/objspace/std/bytearrayobject.py @@ -28,13 +28,13 @@ return "%s(%s)" % (w_self.__class__.__name__, ''.join(w_self.data)) def buffer_w(self, space, flags): -return BytearrayBuffer(self.data) +return BytearrayBuffer(self.data, False) def readbuf_w(self, space): -return BytearrayBuffer(self.data) +return BytearrayBuffer(self.data, True) def writebuf_w(self, space): -return BytearrayBuffer(self.data) +return BytearrayBuffer(self.data, False) def charbuf_w(self, space): return ''.join(self.data) @@ -1131,9 +1131,9 @@ class BytearrayBuffer(Buffer): _immutable_ = True -def __init__(self, data): +def __init__(self, data, readonly): self.data = data -self.readonly = False +self.readonly = readonly def getlength(self): return len(self.data) diff --git a/pypy/objspace/std/test/test_bytearrayobject.py b/pypy/objspace/std/test/test_bytearrayobject.py --- a/pypy/objspace/std/test/test_bytearrayobject.py +++ b/pypy/objspace/std/test/test_bytearrayobject.py @@ -426,10 +426,10 @@ b = bytearray('abcdefghi') buf = buffer(b) assert buf[2] == 'c' -buf[3] = 'D' -assert b == 'abcDefghi' -buf[4:6] = 'EF' -assert b == 'abcDEFghi' +exc = raises(TypeError, "buf[2] = 'D'") +assert str(exc.value) == "buffer is read-only" +exc = raises(TypeError, "buf[4:6] = 'EF'") +assert str(exc.value) == "buffer is read-only" def test_decode(self): b = bytearray('abcdefghi') ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: fix readonly check in buffer.writebuf_w
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70932:494600a98b1a Date: 2014-04-24 15:31 -0400 http://bitbucket.org/pypy/pypy/changeset/494600a98b1a/ Log:fix readonly check in buffer.writebuf_w 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 @@ -369,6 +369,8 @@ assert str(buffer(b)) == ('\x00' * 2 + 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) == "buffer is read-only" exc = raises(TypeError, self.struct.pack_into, "ii", 'test', 0, 17, 42) assert str(exc.value) == "Cannot use string as modifiable buffer" exc = raises(self.struct.error, self.struct.pack_into, "ii", b[0:1], 0, 17, 42) diff --git a/pypy/objspace/std/bufferobject.py b/pypy/objspace/std/bufferobject.py --- a/pypy/objspace/std/bufferobject.py +++ b/pypy/objspace/std/bufferobject.py @@ -29,6 +29,9 @@ return self.buf def writebuf_w(self, space): +if self.buf.readonly: +raise OperationError(space.w_TypeError, space.wrap( +"buffer is read-only")) return self.buf def charbuf_w(self, space): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: cleanup
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70930:69b1380478f3 Date: 2014-04-24 13:55 -0400 http://bitbucket.org/pypy/pypy/changeset/69b1380478f3/ Log:cleanup diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py --- a/pypy/objspace/std/bytearrayobject.py +++ b/pypy/objspace/std/bytearrayobject.py @@ -58,10 +58,10 @@ raise oefmt(space.w_IndexError, "bytearray index out of range") return space.wrap(ord(character)) -def _val(self, space): -return space.buffer_w(self, space.BUF_SIMPLE).as_str() +_val = charbuf_w -def _op_val(self, space, w_other): +@staticmethod +def _op_val(space, w_other): return space.buffer_w(w_other, space.BUF_SIMPLE).as_str() def _chr(self, char): diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py --- a/pypy/objspace/std/bytesobject.py +++ b/pypy/objspace/std/bytesobject.py @@ -477,8 +477,7 @@ def _len(self): return len(self._value) -def _val(self, space): -return self._value +_val = str_w @staticmethod def _op_val(space, w_other): diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -100,10 +100,10 @@ def _len(self): return len(self._value) -def _val(self, space): -return self._value +_val = unicode_w -def _op_val(self, space, w_other): +@staticmethod +def _op_val(space, w_other): if isinstance(w_other, W_UnicodeObject): return w_other._value if space.isinstance_w(w_other, space.w_str): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: cleanup fcntl/ioctl behavior
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70933:2f1472af7614 Date: 2014-04-24 15:33 -0400 http://bitbucket.org/pypy/pypy/changeset/2f1472af7614/ Log:cleanup fcntl/ioctl behavior diff --git a/pypy/module/fcntl/interp_fcntl.py b/pypy/module/fcntl/interp_fcntl.py --- a/pypy/module/fcntl/interp_fcntl.py +++ b/pypy/module/fcntl/interp_fcntl.py @@ -1,6 +1,6 @@ from rpython.rtyper.tool import rffi_platform as platform from rpython.rtyper.lltypesystem import rffi, lltype -from pypy.interpreter.error import OperationError, wrap_oserror +from pypy.interpreter.error import OperationError, wrap_oserror, oefmt from pypy.interpreter.gateway import unwrap_spec, WrappedDefault from rpython.rlib import rposix from rpython.translator.tool.cbuild import ExternalCompilationInfo @@ -92,33 +92,27 @@ op = rffi.cast(rffi.INT, op)# C long => C int try: -intarg = space.int_w(w_arg) -except OperationError, e: -if not e.match(space, space.w_TypeError): -raise -else: -intarg = rffi.cast(rffi.INT, intarg) # C long => C int -rv = fcntl_int(fd, op, intarg) -if rv < 0: -raise _get_error(space, "fcntl") -return space.wrap(rv) - -try: -arg = space.bufferstr_w(w_arg) +arg = space.getarg_w('s#', w_arg) except OperationError, e: if not e.match(space, space.w_TypeError): raise else: ll_arg = rffi.str2charp(arg) -rv = fcntl_str(fd, op, ll_arg) -arg = rffi.charpsize2str(ll_arg, len(arg)) -lltype.free(ll_arg, flavor='raw') -if rv < 0: -raise _get_error(space, "fcntl") -return space.wrap(arg) +try: +rv = fcntl_str(fd, op, ll_arg) +if rv < 0: +raise _get_error(space, "fcntl") +arg = rffi.charpsize2str(ll_arg, len(arg)) +return space.wrap(arg) +finally: +lltype.free(ll_arg, flavor='raw') -raise OperationError(space.w_TypeError, - space.wrap("int or string or buffer required")) +intarg = space.int_w(w_arg) +intarg = rffi.cast(rffi.INT, intarg) # C long => C int +rv = fcntl_int(fd, op, intarg) +if rv < 0: +raise _get_error(space, "fcntl") +return space.wrap(rv) @unwrap_spec(op=int) def flock(space, w_fd, op): @@ -207,50 +201,50 @@ fd = space.c_filedescriptor_w(w_fd) op = rffi.cast(rffi.INT, op)# C long => C int -if mutate_flag != 0: -try: -rwbuffer = space.writebuf_w(w_arg) -except OperationError, e: -if not e.match(space, space.w_TypeError): -raise -if mutate_flag > 0: -raise -else: -arg = rwbuffer.as_str() -ll_arg = rffi.str2charp(arg) -rv = ioctl_str(fd, op, ll_arg) -arg = rffi.charpsize2str(ll_arg, len(arg)) -lltype.free(ll_arg, flavor='raw') -if rv < 0: -raise _get_error(space, "ioctl") -rwbuffer.setslice(0, arg) -return space.wrap(rv) - try: -intarg = space.int_w(w_arg) +rwbuffer = space.writebuf_w(w_arg) except OperationError, e: if not e.match(space, space.w_TypeError): raise else: -intarg = rffi.cast(rffi.INT, intarg) # C long => C int -rv = ioctl_int(fd, op, intarg) -if rv < 0: -raise _get_error(space, "ioctl") -return space.wrap(rv) +arg = rwbuffer.as_str() +ll_arg = rffi.str2charp(arg) +try: +rv = ioctl_str(fd, op, ll_arg) +if rv < 0: +raise _get_error(space, "ioctl") +arg = rffi.charpsize2str(ll_arg, len(arg)) +if mutate_flag != 0: +rwbuffer.setslice(0, arg) +return space.wrap(rv) +return space.wrap(arg) +finally: +lltype.free(ll_arg, flavor='raw') + +if mutate_flag != -1: +raise OperationError(space.w_TypeError, space.wrap( +"ioctl requires a file or file descriptor, an integer " +"and optionally an integer or buffer argument")) try: -arg = space.bufferstr_w(w_arg) +arg = space.getarg_w('s#', w_arg) except OperationError, e: if not e.match(space, space.w_TypeError): raise else: ll_arg = rffi.str2charp(arg) -rv = ioctl_str(fd, op, ll_arg) -arg = rffi.charpsize2str(ll_arg, len(arg)) -lltype.free(ll_arg, flavor='raw') -if rv < 0: -raise _get_error(space, "ioctl") -return space.wrap(arg) +try: +rv = ioctl_str(fd, op, ll_arg) +if rv < 0: +raise _get_error(space, "ioctl") +arg = rffi.charpsize2str(ll_arg, len(arg)) +return space.wrap(arg) +finally: +
[pypy-commit] pypy.org extradoc: render (c) literally, not as a copyright symbol
Author: Matti Picus Branch: extradoc Changeset: r492:2cd907095b25 Date: 2014-04-24 23:11 +0300 http://bitbucket.org/pypy/pypy.org/changeset/2cd907095b25/ Log:render (c) literally, not as a copyright symbol diff --git a/numpydonate.html b/numpydonate.html --- a/numpydonate.html +++ b/numpydonate.html @@ -76,7 +76,7 @@ at the latest, we will try our best to make PyPy support NumPy anyway. We however reserve the right to shift any unused funds to other PyPy activities when that date is reached. Of course, since the Conservancy is a -501©(3) charitable organization incorporated in NY, USA, all funds will, +501(c)(3) charitable organization incorporated in NY, USA, all funds will, regardless of their use, be spent in a way that benefits the general public, the advancement of Open Source and Free Software, and in particular the PyPy community and the PyPy codebase. diff --git a/py3donate.html b/py3donate.html --- a/py3donate.html +++ b/py3donate.html @@ -85,7 +85,7 @@ at the latest, we will try our best to make PyPy support Python 3 anyway. We however reserve the right to shift any unused funds to other PyPy activities when that date is reached. Of course, since the Conservancy is a -501©(3) charitable organization incorporated in NY, USA, all funds will, +501(c)(3) charitable organization incorporated in NY, USA, all funds will, regardless of their use, be spent in a way that benefits the general public, the advancement of Open Source and Free Software, and in particular the PyPy community and the PyPy codebase. ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy.org extradoc: formatting
Author: Matti Picus Branch: extradoc Changeset: r493:f2d7cb004fcf Date: 2014-04-24 23:30 +0300 http://bitbucket.org/pypy/pypy.org/changeset/f2d7cb004fcf/ Log:formatting diff --git a/don1.html b/don1.html --- a/don1.html +++ b/don1.html @@ -21,7 +21,7 @@ -This donation will go towards supporting python 3 in PyPy Read proposal + This donation will go towards supporting python 3 in PyPy Read proposal diff --git a/don3.html b/don3.html --- a/don3.html +++ b/don3.html @@ -21,7 +21,7 @@ -This donation will go towards supporting NumPy in PyPy Read proposal + This donation will go towards supporting NumPy in PyPy Read proposal diff --git a/don4.html b/don4.html --- a/don4.html +++ b/don4.html @@ -23,7 +23,7 @@ -This donation will go towards supporting the Transactional Memory in PyPy. Read proposal (2nd call) + This donation will go towards supporting the Transactional Memory in PyPy. Read proposal (2nd call) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: reduce diff with vendor/stdlib
Author: Brian Kearns Branch: Changeset: r70934:4f887c004422 Date: 2014-04-24 13:28 -0400 http://bitbucket.org/pypy/pypy/changeset/4f887c004422/ Log:reduce diff with vendor/stdlib diff --git a/lib-python/2.7/test/test_itertools.py b/lib-python/2.7/test/test_itertools.py --- a/lib-python/2.7/test/test_itertools.py +++ b/lib-python/2.7/test/test_itertools.py @@ -139,7 +139,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_combinations_tuple_reuse(self): -# Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, combinations('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3), 1) @@ -211,7 +210,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_combinations_with_replacement_tuple_reuse(self): -# Test implementation detail: tuple re-use cwr = combinations_with_replacement self.assertEqual(len(set(map(id, cwr('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3), 1) @@ -278,7 +276,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_permutations_tuple_reuse(self): -# Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, permutations('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3), 1) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: flesh out buffer flags
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70936:bac2a6251789 Date: 2014-04-24 16:03 -0400 http://bitbucket.org/pypy/pypy/changeset/bac2a6251789/ Log:flesh out buffer flags diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1364,12 +1364,18 @@ self.wrap('cannot convert negative integer ' 'to unsigned int')) -# XXX define these flags correctly, possibly put elsewhere? -BUF_SIMPLE = 0 -BUF_FULL_RO = 1 -BUF_CONTIG = 2 -BUF_CONTIG_RO = 3 -BUF_WRITABLE = 4 +BUF_SIMPLE = 0x +BUF_WRITABLE = 0x0001 +BUF_FORMAT = 0x0004 +BUF_ND = 0x0008 +BUF_STRIDES = 0x0010 | BUF_ND +BUF_INDIRECT = 0x0100 | BUF_STRIDES + +BUF_CONTIG_RO = BUF_ND +BUF_CONTIG= BUF_ND | BUF_WRITABLE + +BUF_FULL_RO = BUF_INDIRECT | BUF_FORMAT +BUF_FULL= BUF_INDIRECT | BUF_FORMAT | BUF_WRITABLE def check_buf_flags(self, flags, readonly): if readonly and flags & self.BUF_WRITABLE == self.BUF_WRITABLE: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: merge default
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70943:513cd84a914e Date: 2014-04-24 16:51 -0400 http://bitbucket.org/pypy/pypy/changeset/513cd84a914e/ Log:merge default diff --git a/pypy/doc/cppyy.rst b/pypy/doc/cppyy.rst --- a/pypy/doc/cppyy.rst +++ b/pypy/doc/cppyy.rst @@ -560,6 +560,12 @@ Fixing these bootstrap problems is on the TODO list. The global namespace is ``cppyy.gbl``. +* **NULL**: Is represented as ``cppyy.gbl.nullptr``. + In C++11, the keyword ``nullptr`` is used to represent ``NULL``. + For clarity of intent, it is recommended to use this instead of ``None`` + (or the integer ``0``, which can serve in some cases), as ``None`` is better + understood as ``void`` in C++. + * **operator conversions**: If defined in the C++ class and a python equivalent exists (i.e. all builtin integer and floating point types, as well as ``bool``), it will map onto that python conversion. diff --git a/pypy/doc/extending.rst b/pypy/doc/extending.rst --- a/pypy/doc/extending.rst +++ b/pypy/doc/extending.rst @@ -66,58 +66,26 @@ Reflex == -This method is still experimental. It adds the `cppyy`_ module. -The method works by using the `Reflex package`_ to provide reflection -information of the C++ code, which is then used to automatically generate -bindings at runtime. -From a python standpoint, there is no difference between generating bindings -at runtime, or having them "statically" generated and available in scripts -or compiled into extension modules: python classes and functions are always -runtime structures, created when a script or module loads. +The builtin `cppyy`_ module uses reflection information, provided by +`Reflex`_ (which needs to be `installed separately`_), of C/C++ code to +automatically generate bindings at runtime. +In Python, classes and functions are always runtime structures, so when they +are generated matters not for performance. However, if the backend itself is capable of dynamic behavior, it is a much -better functional match to python, allowing tighter integration and more -natural language mappings. -Full details are `available here`_. +better functional match, allowing tighter integration and more natural +language mappings. + +The `cppyy`_ module is written in RPython, thus PyPy's JIT is able to remove +most cross-language call overhead. + +`Full details`_ are `available here`_. .. _`cppyy`: cppyy.html -.. _`reflex-support`: cppyy.html -.. _`Reflex package`: http://root.cern.ch/drupal/content/reflex +.. _`installed separately`: http://cern.ch/wlav/reflex-2013-08-14.tar.bz2 +.. _`Reflex`: http://root.cern.ch/drupal/content/reflex +.. _`Full details`: cppyy.html .. _`available here`: cppyy.html -Pros - - -The cppyy module is written in RPython, which makes it possible to keep the -code execution visible to the JIT all the way to the actual point of call into -C++, thus allowing for a very fast interface. -Reflex is currently in use in large software environments in High Energy -Physics (HEP), across many different projects and packages, and its use can be -virtually completely automated in a production environment. -One of its uses in HEP is in providing language bindings for CPython. -Thus, it is possible to use Reflex to have bound code work on both CPython and -on PyPy. -In the medium-term, Reflex will be replaced by `cling`_, which is based on -`llvm`_. -This will affect the backend only; the python-side interface is expected to -remain the same, except that cling adds a lot of dynamic behavior to C++, -enabling further language integration. - -.. _`cling`: http://root.cern.ch/drupal/content/cling -.. _`llvm`: http://llvm.org/ - -Cons - - -C++ is a large language, and cppyy is not yet feature-complete. -Still, the experience gained in developing the equivalent bindings for CPython -means that adding missing features is a simple matter of engineering, not a -question of research. -The module is written so that currently missing features should do no harm if -you don't use them, if you do need a particular feature, it may be necessary -to work around it in python or with a C++ helper function. -Although Reflex works on various platforms, the bindings with PyPy have only -been tested on Linux. - RPython Mixed Modules = diff --git a/pypy/module/cppyy/src/dummy_backend.cxx b/pypy/module/cppyy/src/dummy_backend.cxx --- a/pypy/module/cppyy/src/dummy_backend.cxx +++ b/pypy/module/cppyy/src/dummy_backend.cxx @@ -38,6 +38,24 @@ typedef std::map Scopes_t; static Scopes_t s_scopes; +class PseudoExample01 { +public: +PseudoExample01() : m_somedata(-99) {} +PseudoExample01(int a) : m_somedata(a) {} +PseudoExample01(const PseudoExample01& e) : m_somedata(e.m_somedata) {} +PseudoExample01& operator=(const PseudoExample01& e) { +if (this != &e) m_somedata = e.m_somedata; +return *this; +} + virtual ~PseudoExample01() {} + +public: +int m_somedata; +}; + +static int
[pypy-commit] pypy default: fix marshal unknown type code message
Author: Brian Kearns Branch: Changeset: r70939:18b81200f942 Date: 2014-04-24 16:38 -0400 http://bitbucket.org/pypy/pypy/changeset/18b81200f942/ Log:fix marshal unknown type code message diff --git a/pypy/module/marshal/interp_marshal.py b/pypy/module/marshal/interp_marshal.py --- a/pypy/module/marshal/interp_marshal.py +++ b/pypy/module/marshal/interp_marshal.py @@ -327,21 +327,8 @@ def invalid_typecode(space, u, tc): -# %r not supported in rpython -#u.raise_exc('invalid typecode in unmarshal: %r' % tc) -c = ord(tc) -if c < 16: -s = '\\x0%x' % c -elif c < 32 or c > 126: -s = '\\x%x' % c -elif tc == '\\': -s = r'\\' -else: -s = tc -q = "'" -if s[0] == "'": -q = '"' -u.raise_exc('invalid typecode in unmarshal: ' + q + s + q) +u.raise_exc("bad marshal data (unknown type code)") + def register(codes, func): """NOT_RPYTHON""" diff --git a/pypy/module/marshal/test/test_marshal.py b/pypy/module/marshal/test/test_marshal.py --- a/pypy/module/marshal/test/test_marshal.py +++ b/pypy/module/marshal/test/test_marshal.py @@ -14,11 +14,14 @@ print(repr(s)) x = marshal.loads(s) assert x == case and type(x) is type(case) -f = StringIO.StringIO() -marshal.dump(case, f) -f.seek(0) -x = marshal.load(f) -assert x == case and type(x) is type(case) + +import sys +if '__pypy__' in sys.builtin_module_names: +f = StringIO.StringIO() +marshal.dump(case, f) +f.seek(0) +x = marshal.load(f) +assert x == case and type(x) is type(case) return x def test_None(self): @@ -191,7 +194,7 @@ def test_bad_typecode(self): import marshal exc = raises(ValueError, marshal.loads, chr(1)) -assert r"'\x01'" in exc.value.message +assert str(exc.value) == "bad marshal data (unknown type code)" class AppTestSmallLong(AppTestMarshal): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: fix usage of bufferstr in cStringIO
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70937:a8c7805f00a3 Date: 2014-04-24 16:23 -0400 http://bitbucket.org/pypy/pypy/changeset/a8c7805f00a3/ Log:fix usage of bufferstr in cStringIO diff --git a/pypy/module/cStringIO/interp_stringio.py b/pypy/module/cStringIO/interp_stringio.py --- a/pypy/module/cStringIO/interp_stringio.py +++ b/pypy/module/cStringIO/interp_stringio.py @@ -160,10 +160,10 @@ raise OperationError(space.w_IOError, space.wrap("negative size")) self.truncate(size) -@unwrap_spec(buffer='bufferstr') -def descr_write(self, buffer): +def descr_write(self, space, w_buffer): +buffer = space.getarg_w('s*', w_buffer) self.check_closed() -self.write(buffer) +self.write(buffer.as_str()) def descr_writelines(self, w_lines): self.check_closed() @@ -236,5 +236,5 @@ if space.is_none(w_string): return space.wrap(W_OutputType(space)) else: -string = space.bufferstr_w(w_string) +string = space.getarg_w('s*', w_string).as_str() return space.wrap(W_InputType(space, string)) diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py --- a/pypy/objspace/fake/objspace.py +++ b/pypy/objspace/fake/objspace.py @@ -4,7 +4,7 @@ from pypy.interpreter.typedef import TypeDef, GetSetProperty from pypy.objspace.std.stdtypedef import StdTypeDef from pypy.objspace.std.sliceobject import W_SliceObject -from rpython.rlib.buffer import Buffer +from rpython.rlib.buffer import StringBuffer from rpython.rlib.objectmodel import instantiate, we_are_translated, specialize from rpython.rlib.nonconst import NonConstant from rpython.rlib.rarithmetic import r_uint, r_singlefloat @@ -41,7 +41,7 @@ is_root(w_subtype) def buffer_w(self, space, flags): -return Buffer() +return StringBuffer("foobar") def str_w(self, space): return NonConstant("foobar") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: replace usage of bufferstr_w in marshal
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70938:4027486ec885 Date: 2014-04-24 16:34 -0400 http://bitbucket.org/pypy/pypy/changeset/4027486ec885/ Log:replace usage of bufferstr_w in marshal diff --git a/pypy/module/marshal/interp_marshal.py b/pypy/module/marshal/interp_marshal.py --- a/pypy/module/marshal/interp_marshal.py +++ b/pypy/module/marshal/interp_marshal.py @@ -476,13 +476,7 @@ # Unmarshaller with inlined buffer string def __init__(self, space, w_str): Unmarshaller.__init__(self, space, None) -try: -self.bufstr = space.bufferstr_w(w_str) -except OperationError, e: -if not e.match(space, space.w_TypeError): -raise -raise OperationError(space.w_TypeError, space.wrap( -'marshal.loads() arg must be string or buffer')) +self.bufstr = space.getarg_w('s#', w_str) self.bufpos = 0 self.limit = len(self.bufstr) diff --git a/pypy/module/marshal/test/test_marshal.py b/pypy/module/marshal/test/test_marshal.py --- a/pypy/module/marshal/test/test_marshal.py +++ b/pypy/module/marshal/test/test_marshal.py @@ -14,6 +14,10 @@ print(repr(s)) x = marshal.loads(s) assert x == case and type(x) is type(case) + +exc = raises(TypeError, marshal.loads, memoryview(s)) +assert str(exc.value) == "must be string or read-only buffer, not memoryview" + f = StringIO.StringIO() marshal.dump(case, f) f.seek(0) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: merge default
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70940:5313394cecd3 Date: 2014-04-24 16:39 -0400 http://bitbucket.org/pypy/pypy/changeset/5313394cecd3/ Log:merge default diff --git a/lib-python/2.7/test/test_itertools.py b/lib-python/2.7/test/test_itertools.py --- a/lib-python/2.7/test/test_itertools.py +++ b/lib-python/2.7/test/test_itertools.py @@ -139,7 +139,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_combinations_tuple_reuse(self): -# Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, combinations('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3), 1) @@ -211,7 +210,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_combinations_with_replacement_tuple_reuse(self): -# Test implementation detail: tuple re-use cwr = combinations_with_replacement self.assertEqual(len(set(map(id, cwr('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3), 1) @@ -278,7 +276,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_permutations_tuple_reuse(self): -# Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, permutations('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3), 1) diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -881,8 +881,8 @@ def LOAD_NAME(self, nameindex, next_instr): if self.w_locals is not self.w_globals: -w_varname = self.getname_w(nameindex) -w_value = self.space.finditem(self.w_locals, w_varname) +varname = self.getname_u(nameindex) +w_value = self.space.finditem_str(self.w_locals, varname) if w_value is not None: self.pushvalue(w_value) return diff --git a/pypy/module/marshal/interp_marshal.py b/pypy/module/marshal/interp_marshal.py --- a/pypy/module/marshal/interp_marshal.py +++ b/pypy/module/marshal/interp_marshal.py @@ -327,21 +327,8 @@ def invalid_typecode(space, u, tc): -# %r not supported in rpython -#u.raise_exc('invalid typecode in unmarshal: %r' % tc) -c = ord(tc) -if c < 16: -s = '\\x0%x' % c -elif c < 32 or c > 126: -s = '\\x%x' % c -elif tc == '\\': -s = r'\\' -else: -s = tc -q = "'" -if s[0] == "'": -q = '"' -u.raise_exc('invalid typecode in unmarshal: ' + q + s + q) +u.raise_exc("bad marshal data (unknown type code)") + def register(codes, func): """NOT_RPYTHON""" diff --git a/pypy/module/marshal/test/test_marshal.py b/pypy/module/marshal/test/test_marshal.py --- a/pypy/module/marshal/test/test_marshal.py +++ b/pypy/module/marshal/test/test_marshal.py @@ -18,11 +18,13 @@ exc = raises(TypeError, marshal.loads, memoryview(s)) assert str(exc.value) == "must be string or read-only buffer, not memoryview" -f = StringIO.StringIO() -marshal.dump(case, f) -f.seek(0) -x = marshal.load(f) -assert x == case and type(x) is type(case) +import sys +if '__pypy__' in sys.builtin_module_names: +f = StringIO.StringIO() +marshal.dump(case, f) +f.seek(0) +x = marshal.load(f) +assert x == case and type(x) is type(case) return x def test_None(self): @@ -195,7 +197,7 @@ def test_bad_typecode(self): import marshal exc = raises(ValueError, marshal.loads, chr(1)) -assert r"'\x01'" in exc.value.message +assert str(exc.value) == "bad marshal data (unknown type code)" class AppTestSmallLong(AppTestMarshal): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge heads
Author: Brian Kearns Branch: Changeset: r70942:ea86924e88fb Date: 2014-04-24 16:51 -0400 http://bitbucket.org/pypy/pypy/changeset/ea86924e88fb/ Log:merge heads diff --git a/lib-python/2.7/test/test_itertools.py b/lib-python/2.7/test/test_itertools.py --- a/lib-python/2.7/test/test_itertools.py +++ b/lib-python/2.7/test/test_itertools.py @@ -139,7 +139,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_combinations_tuple_reuse(self): -# Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, combinations('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3), 1) @@ -211,7 +210,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_combinations_with_replacement_tuple_reuse(self): -# Test implementation detail: tuple re-use cwr = combinations_with_replacement self.assertEqual(len(set(map(id, cwr('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3), 1) @@ -278,7 +276,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_permutations_tuple_reuse(self): -# Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, permutations('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3), 1) diff --git a/pypy/module/marshal/interp_marshal.py b/pypy/module/marshal/interp_marshal.py --- a/pypy/module/marshal/interp_marshal.py +++ b/pypy/module/marshal/interp_marshal.py @@ -327,21 +327,8 @@ def invalid_typecode(space, u, tc): -# %r not supported in rpython -#u.raise_exc('invalid typecode in unmarshal: %r' % tc) -c = ord(tc) -if c < 16: -s = '\\x0%x' % c -elif c < 32 or c > 126: -s = '\\x%x' % c -elif tc == '\\': -s = r'\\' -else: -s = tc -q = "'" -if s[0] == "'": -q = '"' -u.raise_exc('invalid typecode in unmarshal: ' + q + s + q) +u.raise_exc("bad marshal data (unknown type code)") + def register(codes, func): """NOT_RPYTHON""" diff --git a/pypy/module/marshal/test/test_marshal.py b/pypy/module/marshal/test/test_marshal.py --- a/pypy/module/marshal/test/test_marshal.py +++ b/pypy/module/marshal/test/test_marshal.py @@ -14,11 +14,14 @@ print(repr(s)) x = marshal.loads(s) assert x == case and type(x) is type(case) -f = StringIO.StringIO() -marshal.dump(case, f) -f.seek(0) -x = marshal.load(f) -assert x == case and type(x) is type(case) + +import sys +if '__pypy__' in sys.builtin_module_names: +f = StringIO.StringIO() +marshal.dump(case, f) +f.seek(0) +x = marshal.load(f) +assert x == case and type(x) is type(case) return x def test_None(self): @@ -191,7 +194,7 @@ def test_bad_typecode(self): import marshal exc = raises(ValueError, marshal.loads, chr(1)) -assert r"'\x01'" in exc.value.message +assert str(exc.value) == "bad marshal data (unknown type code)" class AppTestSmallLong(AppTestMarshal): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: object reference no longer necessary here
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70935:58c1b432afdb Date: 2014-04-24 15:43 -0400 http://bitbucket.org/pypy/pypy/changeset/58c1b432afdb/ Log:object reference no longer necessary here diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py --- a/pypy/objspace/std/memoryobject.py +++ b/pypy/objspace/std/memoryobject.py @@ -15,9 +15,8 @@ an interp-level buffer. """ -def __init__(self, obj, buf): +def __init__(self, buf): assert isinstance(buf, Buffer) -self.obj = obj self.buf = buf def buffer_w(self, space, flags): @@ -26,7 +25,7 @@ @staticmethod def descr_new_memoryview(space, w_subtype, w_object): -return W_MemoryView(w_object, space.buffer_w(w_object, space.BUF_FULL_RO)) +return W_MemoryView(space.buffer_w(w_object, space.BUF_FULL_RO)) def _make_descr__cmp(name): def descr__cmp(self, space, w_other): @@ -69,7 +68,7 @@ if size < 0: size = 0 buf = SubBuffer(self.buf, start, size) -return W_MemoryView(self.obj, buf) +return W_MemoryView(buf) def descr_tobytes(self, space): return space.wrap(self.as_str()) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: fix float.__new__ bufferstr behavior
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70941:47fd7571d5f0 Date: 2014-04-24 16:49 -0400 http://bitbucket.org/pypy/pypy/changeset/47fd7571d5f0/ Log:fix float.__new__ bufferstr behavior diff --git a/pypy/objspace/std/floattype.py b/pypy/objspace/std/floattype.py --- a/pypy/objspace/std/floattype.py +++ b/pypy/objspace/std/floattype.py @@ -23,7 +23,7 @@ register_all(vars(), globals()) -@unwrap_spec(w_x = WrappedDefault(0.0)) +@unwrap_spec(w_x=WrappedDefault(0.0)) def descr__new__(space, w_floattype, w_x): from pypy.objspace.std.floatobject import W_FloatObject w_value = w_x # 'x' is the keyword argument name in CPython @@ -32,15 +32,19 @@ if space.is_w(w_floattype, space.w_float): return w_obj value = space.float_w(w_obj) -elif (space.isinstance_w(w_value, space.w_str) or - space.isinstance_w(w_value, space.w_bytearray)): -value = _string_to_float(space, w_value, space.bufferstr_w(w_value)) elif space.isinstance_w(w_value, space.w_unicode): from unicodeobject import unicode_to_decimal_w value = _string_to_float(space, w_value, unicode_to_decimal_w(space, w_value)) else: -value = space.float_w(w_x) +try: +value = space.charbuf_w(w_value) +except OperationError as e: +if e.match(space, space.w_TypeError): +raise OperationError(space.w_TypeError, space.wrap( +"float() argument must be a string or a number")) +raise +value = _string_to_float(space, w_value, value) w_obj = space.allocate_instance(W_FloatObject, w_floattype) W_FloatObject.__init__(w_obj, value) return w_obj diff --git a/pypy/objspace/std/test/test_floatobject.py b/pypy/objspace/std/test/test_floatobject.py --- a/pypy/objspace/std/test/test_floatobject.py +++ b/pypy/objspace/std/test/test_floatobject.py @@ -61,7 +61,7 @@ class AppTestAppFloatTest: spaceconfig = dict(usemodules=['binascii', 'rctime']) - + def setup_class(cls): cls.w_py26 = cls.space.wrap(sys.version_info >= (2, 6)) @@ -138,6 +138,11 @@ assert repr(float("+nan")) == "nan" assert repr(float("-nAn")) == "nan" +assert float(buffer("inf")) == inf +assert float(bytearray("inf")) == inf +exc = raises(TypeError, float, memoryview("inf")) +assert str(exc.value) == "float() argument must be a string or a number" + def test_float_unicode(self): # u00A0 and u2000 are some kind of spaces assert 42.75 == float(unichr(0x00A0)+unicode("42.75")+unichr(0x2000)) @@ -812,7 +817,7 @@ def check(a, b): assert (a, math.copysign(1.0, a)) == (b, math.copysign(1.0, b)) - + check(mod(-1.0, 1.0), 0.0) check(mod(-1e-100, 1.0), 1.0) check(mod(-0.0, 1.0), 0.0) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: replace bufferstr in _multiprocessing
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70945:9d4e8bf5ea02 Date: 2014-04-24 17:02 -0400 http://bitbucket.org/pypy/pypy/changeset/9d4e8bf5ea02/ Log:replace bufferstr in _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 @@ -80,8 +80,9 @@ raise OperationError(space.w_IOError, space.wrap("connection is read-only")) -@unwrap_spec(buf='bufferstr', offset='index', size='index') -def send_bytes(self, space, buf, offset=0, size=PY_SSIZE_T_MIN): +@unwrap_spec(offset='index', size='index') +def send_bytes(self, space, w_buf, offset=0, size=PY_SSIZE_T_MIN): +buf = space.getarg_w('s*', w_buf).as_str() length = len(buf) self._check_writable(space) if offset < 0: @@ -149,7 +150,7 @@ w_pickled = space.call_method( w_picklemodule, "dumps", w_obj, w_protocol) -buf = space.bufferstr_w(w_pickled) +buf = space.str_w(w_pickled) self.do_send_string(space, buf, 0, len(buf)) def recv(self, space): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: correct a use of bufferstr_w in marshal_impl
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70944:73a08eb40847 Date: 2014-04-24 16:58 -0400 http://bitbucket.org/pypy/pypy/changeset/73a08eb40847/ Log:correct a use of bufferstr_w in marshal_impl diff --git a/pypy/module/marshal/test/test_marshalimpl.py b/pypy/module/marshal/test/test_marshalimpl.py --- a/pypy/module/marshal/test/test_marshalimpl.py +++ b/pypy/module/marshal/test/test_marshalimpl.py @@ -43,6 +43,8 @@ s = marshal.dumps(array.array('c', 'asd')) t = marshal.loads(s) assert type(t) is str and t == 'asd' +exc = raises(ValueError, marshal.dumps, memoryview('asd')) +assert str(exc.value) == "unmarshallable object" def test_unmarshal_evil_long(self): import marshal diff --git a/pypy/objspace/std/marshal_impl.py b/pypy/objspace/std/marshal_impl.py --- a/pypy/objspace/std/marshal_impl.py +++ b/pypy/objspace/std/marshal_impl.py @@ -460,12 +460,12 @@ # any unknown object implementing the buffer protocol is # accepted and encoded as a plain string try: -s = space.bufferstr_w(w_obj) +s = space.readbuf_w(w_obj) except OperationError, e: if not e.match(space, space.w_TypeError): raise else: -m.atom_str(TYPE_STRING, s) +m.atom_str(TYPE_STRING, s.as_str()) return raise_exception(space, "unmarshallable object") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: fix _cffi_backend test_ztranslation
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70946:62510b3da5bf Date: 2014-04-24 17:27 -0400 http://bitbucket.org/pypy/pypy/changeset/62510b3da5bf/ Log:fix _cffi_backend test_ztranslation diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1841,6 +1841,7 @@ 'AssertionError', 'AttributeError', 'BaseException', +'BufferError', 'DeprecationWarning', 'EOFError', 'EnvironmentError', ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy refactor-buffer-api: close branch for merging
Author: Brian Kearns Branch: refactor-buffer-api Changeset: r70947:b221c1831061 Date: 2014-04-24 17:32 -0400 http://bitbucket.org/pypy/pypy/changeset/b221c1831061/ Log:close branch for merging ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix whatsnew
Author: Brian Kearns Branch: Changeset: r70949:ba1169097696 Date: 2014-04-24 17:38 -0400 http://bitbucket.org/pypy/pypy/changeset/ba1169097696/ Log:fix whatsnew 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 @@ -9,3 +9,6 @@ Improve optimiziation of small allocation-heavy loops in the JIT .. branch: reflex-support + +.. branch: refactor-buffer-api +Properly implement old/new buffer API for objects and start work on replacing bufferstr usage ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix test
Author: Matti Picus Branch: Changeset: r70950:253828267285 Date: 2014-04-24 23:53 +0300 http://bitbucket.org/pypy/pypy/changeset/253828267285/ Log:fix test diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py --- a/rpython/rlib/test/test_rposix.py +++ b/rpython/rlib/test/test_rposix.py @@ -104,9 +104,11 @@ def f(): if isinstance(udir.as_unicode(), str): _udir = udir.as_unicode() +_res = ', ' else: _udir = udir -return u', '.join(rposix.listdir(_udir)) +_res = u', ' +return _res.join(rposix.listdir(_udir)) result = interpret(f, []) assert os.path.basename(self.ufilename) in ll_to_string(result) else: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: array.fromstring accepts buffers
Author: Brian Kearns Branch: Changeset: r70951:a6ca15aed189 Date: 2014-04-24 19:33 -0400 http://bitbucket.org/pypy/pypy/changeset/a6ca15aed189/ Log:array.fromstring accepts buffers diff --git a/lib-python/2.7/test/test_array.py b/lib-python/2.7/test/test_array.py --- a/lib-python/2.7/test/test_array.py +++ b/lib-python/2.7/test/test_array.py @@ -298,6 +298,7 @@ b = array.array(self.badtypecode()) with self.assertRaises(TypeError): a + b + with self.assertRaises(TypeError): a + 'bad' @@ -320,6 +321,7 @@ b = array.array(self.badtypecode()) with self.assertRaises(TypeError): a += b + with self.assertRaises(TypeError): a += 'bad' diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py --- a/pypy/module/array/interp_array.py +++ b/pypy/module/array/interp_array.py @@ -42,7 +42,7 @@ if len(__args__.arguments_w) > 0: w_initializer = __args__.arguments_w[0] if space.type(w_initializer) is space.w_str: -a.descr_fromstring(space, space.str_w(w_initializer)) +a.descr_fromstring(space, w_initializer) elif space.type(w_initializer) is space.w_list: a.descr_fromlist(space, w_initializer) else: @@ -232,13 +232,13 @@ self._charbuf_stop() return self.space.wrap(s) -@unwrap_spec(s=str) -def descr_fromstring(self, space, s): +def descr_fromstring(self, space, w_s): """ fromstring(string) Appends items from the string, interpreting it as an array of machine values,as if it had been read from a file using the fromfile() method). """ +s = space.getarg_w('s#', w_s) if len(s) % self.itemsize != 0: msg = 'string length not a multiple of item size' raise OperationError(self.space.w_ValueError, self.space.wrap(msg)) @@ -270,10 +270,10 @@ elems = max(0, len(item) - (len(item) % self.itemsize)) if n != 0: item = item[0:elems] -self.descr_fromstring(space, item) +self.descr_fromstring(space, space.wrap(item)) msg = "not enough items in file" raise OperationError(space.w_EOFError, space.wrap(msg)) -self.descr_fromstring(space, item) +self.descr_fromstring(space, w_item) @unwrap_spec(w_f=W_File) def descr_tofile(self, space, w_f): diff --git a/pypy/module/array/test/test_array.py b/pypy/module/array/test/test_array.py --- a/pypy/module/array/test/test_array.py +++ b/pypy/module/array/test/test_array.py @@ -155,6 +155,11 @@ a.fromstring('Hi!') assert a[0] == 'H' and a[1] == 'i' and a[2] == '!' and len(a) == 3 a = self.array('c') +a.fromstring(buffer('xyz')) +exc = raises(TypeError, a.fromstring, memoryview('xyz')) +assert str(exc.value) == "must be string or read-only buffer, not memoryview" +assert a[0] == 'x' and a[1] == 'y' and a[2] == 'z' and len(a) == 3 +a = self.array('c') a.fromstring('') assert not len(a) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: merge default (ea86924e88fb)
Author: Philip Jenvey Branch: py3k Changeset: r70952:e0ce5503a026 Date: 2014-04-24 16:58 -0700 http://bitbucket.org/pypy/pypy/changeset/e0ce5503a026/ Log:merge default (ea86924e88fb) diff --git a/lib-python/2.7/test/test_itertools.py b/lib-python/2.7/test/test_itertools.py --- a/lib-python/2.7/test/test_itertools.py +++ b/lib-python/2.7/test/test_itertools.py @@ -139,7 +139,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_combinations_tuple_reuse(self): -# Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, combinations('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3), 1) @@ -211,7 +210,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_combinations_with_replacement_tuple_reuse(self): -# Test implementation detail: tuple re-use cwr = combinations_with_replacement self.assertEqual(len(set(map(id, cwr('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3), 1) @@ -278,7 +276,6 @@ @test_support.impl_detail("tuple reuse is specific to CPython") def test_permutations_tuple_reuse(self): -# Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, permutations('abcde', 3, 1) self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3), 1) diff --git a/pypy/doc/cppyy.rst b/pypy/doc/cppyy.rst --- a/pypy/doc/cppyy.rst +++ b/pypy/doc/cppyy.rst @@ -560,6 +560,12 @@ Fixing these bootstrap problems is on the TODO list. The global namespace is ``cppyy.gbl``. +* **NULL**: Is represented as ``cppyy.gbl.nullptr``. + In C++11, the keyword ``nullptr`` is used to represent ``NULL``. + For clarity of intent, it is recommended to use this instead of ``None`` + (or the integer ``0``, which can serve in some cases), as ``None`` is better + understood as ``void`` in C++. + * **operator conversions**: If defined in the C++ class and a python equivalent exists (i.e. all builtin integer and floating point types, as well as ``bool``), it will map onto that python conversion. diff --git a/pypy/doc/extending.rst b/pypy/doc/extending.rst --- a/pypy/doc/extending.rst +++ b/pypy/doc/extending.rst @@ -66,58 +66,26 @@ Reflex == -This method is still experimental. It adds the `cppyy`_ module. -The method works by using the `Reflex package`_ to provide reflection -information of the C++ code, which is then used to automatically generate -bindings at runtime. -From a python standpoint, there is no difference between generating bindings -at runtime, or having them "statically" generated and available in scripts -or compiled into extension modules: python classes and functions are always -runtime structures, created when a script or module loads. +The builtin `cppyy`_ module uses reflection information, provided by +`Reflex`_ (which needs to be `installed separately`_), of C/C++ code to +automatically generate bindings at runtime. +In Python, classes and functions are always runtime structures, so when they +are generated matters not for performance. However, if the backend itself is capable of dynamic behavior, it is a much -better functional match to python, allowing tighter integration and more -natural language mappings. -Full details are `available here`_. +better functional match, allowing tighter integration and more natural +language mappings. + +The `cppyy`_ module is written in RPython, thus PyPy's JIT is able to remove +most cross-language call overhead. + +`Full details`_ are `available here`_. .. _`cppyy`: cppyy.html -.. _`reflex-support`: cppyy.html -.. _`Reflex package`: http://root.cern.ch/drupal/content/reflex +.. _`installed separately`: http://cern.ch/wlav/reflex-2013-08-14.tar.bz2 +.. _`Reflex`: http://root.cern.ch/drupal/content/reflex +.. _`Full details`: cppyy.html .. _`available here`: cppyy.html -Pros - - -The cppyy module is written in RPython, which makes it possible to keep the -code execution visible to the JIT all the way to the actual point of call into -C++, thus allowing for a very fast interface. -Reflex is currently in use in large software environments in High Energy -Physics (HEP), across many different projects and packages, and its use can be -virtually completely automated in a production environment. -One of its uses in HEP is in providing language bindings for CPython. -Thus, it is possible to use Reflex to have bound code work on both CPython and -on PyPy. -In the medium-term, Reflex will be replaced by `cling`_, which is based on -`llvm`_. -This will affect the backend only; the python-side interface is expected to -remain the same, except that cling adds a lot of dynamic behavior to C++, -enabling further language integration. - -.. _`cling`: http://root.cern.ch/drupal/content/cling -.. _`llvm`: http://llvm.org/ - -Cons - - -C++ is a large language, and cp
[pypy-commit] pypy default: fix usage of bufferstr_w in _winreg
Author: Brian Kearns Branch: Changeset: r70953:b78e00087934 Date: 2014-04-24 17:37 -0700 http://bitbucket.org/pypy/pypy/changeset/b78e00087934/ Log:fix usage of bufferstr_w in _winreg diff --git a/pypy/module/_winreg/interp_winreg.py b/pypy/module/_winreg/interp_winreg.py --- a/pypy/module/_winreg/interp_winreg.py +++ b/pypy/module/_winreg/interp_winreg.py @@ -2,7 +2,7 @@ from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, GetSetProperty -from pypy.interpreter.error import OperationError, wrap_windowserror +from pypy.interpreter.error import OperationError, wrap_windowserror, oefmt from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rlib import rwinreg, rwin32 from rpython.rlib.rarithmetic import r_uint, intmask @@ -327,7 +327,14 @@ buf = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw') buf[0] = '\0' else: -value = space.bufferstr_w(w_value) +try: +value = w_value.readbuf_w(space) +except TypeError: +raise oefmt(space.w_TypeError, +"Objects of type '%T' can not be used as binary " +"registry values", w_value) +else: +value = value.as_str() buflen = len(value) buf = rffi.str2charp(value) diff --git a/pypy/module/_winreg/test/test_winreg.py b/pypy/module/_winreg/test/test_winreg.py --- a/pypy/module/_winreg/test/test_winreg.py +++ b/pypy/module/_winreg/test/test_winreg.py @@ -137,11 +137,15 @@ assert 0, "Did not raise" def test_SetValueEx(self): -from _winreg import CreateKey, SetValueEx +from _winreg import CreateKey, SetValueEx, REG_BINARY key = CreateKey(self.root_key, self.test_key_name) sub_key = CreateKey(key, "sub_key") for name, value, type in self.test_data: SetValueEx(sub_key, name, 0, type, value) +exc = raises(TypeError, SetValueEx, sub_key, 'test_name', None, +REG_BINARY, memoryview('abc')) +assert str(exc.value) == ("Objects of type 'memoryview' can not " + "be used as binary registry values") def test_readValues(self): from _winreg import OpenKey, EnumValue, QueryValueEx, EnumKey ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: reduce diff with upstream
Author: Brian Kearns Branch: Changeset: r70954:ba11a9b9aab5 Date: 2014-04-24 21:03 -0400 http://bitbucket.org/pypy/pypy/changeset/ba11a9b9aab5/ Log:reduce diff with upstream diff --git a/lib-python/2.7/test/test_file2k.py b/lib-python/2.7/test/test_file2k.py --- a/lib-python/2.7/test/test_file2k.py +++ b/lib-python/2.7/test/test_file2k.py @@ -479,11 +479,10 @@ def _create_file(self): if self.use_buffering: -f = open(self.filename, "w+", buffering=1024*16) +self.f = open(self.filename, "w+", buffering=1024*16) else: -f = open(self.filename, "w+") -self.f = f -self.all_files.append(f) +self.f = open(self.filename, "w+") +self.all_files.append(self.f) oldf = self.all_files.pop(0) if oldf is not None: oldf.close() ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix test_bytebuffer on win32
Author: Brian Kearns Branch: Changeset: r70955:8a2e9e0c1676 Date: 2014-04-24 21:16 -0400 http://bitbucket.org/pypy/pypy/changeset/8a2e9e0c1676/ Log:fix test_bytebuffer on win32 diff --git a/pypy/module/__pypy__/test/test_bytebuffer.py b/pypy/module/__pypy__/test/test_bytebuffer.py --- a/pypy/module/__pypy__/test/test_bytebuffer.py +++ b/pypy/module/__pypy__/test/test_bytebuffer.py @@ -25,5 +25,6 @@ assert str(b) == "\x00xy" + "\x00" * 7 b[4:8:2] = 'zw' assert str(b) == "\x00xy\x00z\x00w" + "\x00" * 3 -b[6:10] = u'#' -assert str(b) == "\x00xy\x00z\x00#" + "\x00" * 3 +r = str(buffer(u'#')) +b[6:6+len(r)] = u'#' +assert str(b[:6+len(r)]) == "\x00xy\x00z\x00" + r ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k-fix-strategies: close it when finished
Author: Philip Jenvey Branch: py3k-fix-strategies Changeset: r70957:4cbca19dc221 Date: 2014-04-24 18:34 -0700 http://bitbucket.org/pypy/pypy/changeset/4cbca19dc221/ Log:close it when finished (grafted from 308ded060ac8ffbf1b1a16d88486558980b4bc1b) diff --git a/lib_pypy/_testcapi.py b/lib_pypy/_testcapi.py --- a/lib_pypy/_testcapi.py +++ b/lib_pypy/_testcapi.py @@ -1,4 +1,5 @@ -import imp, os +import imp +import os try: import cpyext @@ -12,6 +13,9 @@ try: fp, filename, description = imp.find_module('_testcapi', path=[output_dir]) -imp.load_module('_testcapi', fp, filename, description) +try: +imp.load_module('_testcapi', fp, filename, description) +finally: +fp.close() except ImportError: _pypy_testcapi.compile_shared(cfile, '_testcapi', output_dir) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: close it when finished
Author: Philip Jenvey Branch: Changeset: r70956:308ded060ac8 Date: 2014-04-24 18:34 -0700 http://bitbucket.org/pypy/pypy/changeset/308ded060ac8/ Log:close it when finished diff --git a/lib_pypy/_testcapi.py b/lib_pypy/_testcapi.py --- a/lib_pypy/_testcapi.py +++ b/lib_pypy/_testcapi.py @@ -1,4 +1,5 @@ -import imp, os +import imp +import os try: import cpyext @@ -12,6 +13,9 @@ try: fp, filename, description = imp.find_module('_testcapi', path=[output_dir]) -imp.load_module('_testcapi', fp, filename, description) +try: +imp.load_module('_testcapi', fp, filename, description) +finally: +fp.close() except ImportError: _pypy_testcapi.compile_shared(cfile, '_testcapi', output_dir) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: close it in _ctypes_test too
Author: Philip Jenvey Branch: Changeset: r70958:b2c55136868a Date: 2014-04-24 18:44 -0700 http://bitbucket.org/pypy/pypy/changeset/b2c55136868a/ Log:close it in _ctypes_test too diff --git a/lib_pypy/_ctypes_test.py b/lib_pypy/_ctypes_test.py --- a/lib_pypy/_ctypes_test.py +++ b/lib_pypy/_ctypes_test.py @@ -1,4 +1,5 @@ -import imp, os +import imp +import os try: import cpyext @@ -17,7 +18,8 @@ output_dir = _pypy_testcapi.get_hashed_dir(os.path.join(thisdir, cfile)) try: fp, filename, description = imp.find_module('_ctypes_test', path=[output_dir]) -imp.load_module('_ctypes_test', fp, filename, description) +with fp: +imp.load_module('_ctypes_test', fp, filename, description) except ImportError: print('could not find _ctypes_test in %s' % output_dir) _pypy_testcapi.compile_shared('_ctypes_test.c', '_ctypes_test', output_dir) diff --git a/lib_pypy/_testcapi.py b/lib_pypy/_testcapi.py --- a/lib_pypy/_testcapi.py +++ b/lib_pypy/_testcapi.py @@ -13,9 +13,7 @@ try: fp, filename, description = imp.find_module('_testcapi', path=[output_dir]) -try: +with fp: imp.load_module('_testcapi', fp, filename, description) -finally: -fp.close() except ImportError: _pypy_testcapi.compile_shared(cfile, '_testcapi', output_dir) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge reflex-support: disable tests when -A and no genreflex
Author: Wim Lavrijsen Branch: Changeset: r70960:377369757ddc Date: 2014-04-24 19:03 -0700 http://bitbucket.org/pypy/pypy/changeset/377369757ddc/ Log:merge reflex-support: disable tests when -A and no genreflex diff --git a/pypy/module/cppyy/test/conftest.py b/pypy/module/cppyy/test/conftest.py --- a/pypy/module/cppyy/test/conftest.py +++ b/pypy/module/cppyy/test/conftest.py @@ -15,6 +15,10 @@ not re.search("test0[1-36]", item.location[2]): py.test.skip("genreflex is not installed") +def pytest_ignore_collect(path, config): +if py.path.local.sysfind('genreflex') is None and config.option.runappdirect: +return True # "can't run dummy tests in -A" + def pytest_configure(config): if py.path.local.sysfind('genreflex') is None: import pypy.module.cppyy.capi.loadable_capi as lcapi @@ -22,6 +26,9 @@ import ctypes ctypes.CDLL(lcapi.reflection_library) except Exception, e: +if config.option.runappdirect: +return # "can't run dummy tests in -A" + # build dummy backend (which has reflex info and calls hard-wired) import os from rpython.translator.tool.cbuild import ExternalCompilationInfo ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy reflex-support: disable all tests if run with -A and genreflex not available
Author: Wim Lavrijsen Branch: reflex-support Changeset: r70959:534ad693bc66 Date: 2014-04-24 19:02 -0700 http://bitbucket.org/pypy/pypy/changeset/534ad693bc66/ Log:disable all tests if run with -A and genreflex not available diff --git a/pypy/module/cppyy/test/conftest.py b/pypy/module/cppyy/test/conftest.py --- a/pypy/module/cppyy/test/conftest.py +++ b/pypy/module/cppyy/test/conftest.py @@ -15,6 +15,10 @@ not re.search("test0[1-36]", item.location[2]): py.test.skip("genreflex is not installed") +def pytest_ignore_collect(path, config): +if py.path.local.sysfind('genreflex') is None and config.option.runappdirect: +return True # "can't run dummy tests in -A" + def pytest_configure(config): if py.path.local.sysfind('genreflex') is None: import pypy.module.cppyy.capi.loadable_capi as lcapi @@ -22,6 +26,9 @@ import ctypes ctypes.CDLL(lcapi.reflection_library) except Exception, e: +if config.option.runappdirect: +return # "can't run dummy tests in -A" + # build dummy backend (which has reflex info and calls hard-wired) import os from rpython.translator.tool.cbuild import ExternalCompilationInfo ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix typo in doc
Author: Wim Lavrijsen Branch: Changeset: r70961:61191b4a5eac Date: 2014-04-24 23:53 -0700 http://bitbucket.org/pypy/pypy/changeset/61191b4a5eac/ Log:fix typo in doc diff --git a/pypy/doc/cppyy.rst b/pypy/doc/cppyy.rst --- a/pypy/doc/cppyy.rst +++ b/pypy/doc/cppyy.rst @@ -583,7 +583,7 @@ Special care needs to be taken for global operator overloads in C++: first, make sure that they are actually reflected, especially for the global overloads for ``operator==`` and ``operator!=`` of STL vector iterators in - the case of gcc (note that they are not needed to iterator over a vector). + the case of gcc (note that they are not needed to iterate over a vector). Second, make sure that reflection info is loaded in the proper order. I.e. that these global overloads are available before use. ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit