[pypy-commit] pypy faster-rstruct-2: I don't know why this popped out now as it seems unrelated with my recent changes: scoped_nonmovingbuffer expects data to be non-null, so we enforce the annotation
Author: Antonio Cuni Branch: faster-rstruct-2 Changeset: r91240:beae5a5ccb0b Date: 2017-05-11 10:03 +0100 http://bitbucket.org/pypy/pypy/changeset/beae5a5ccb0b/ Log:I don't know why this popped out now as it seems unrelated with my recent changes: scoped_nonmovingbuffer expects data to be non-null, so we enforce the annotation to get an early error. Then, we fix the problem in interp_bz2.py diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py --- a/pypy/module/bz2/interp_bz2.py +++ b/pypy/module/bz2/interp_bz2.py @@ -1,4 +1,5 @@ from __future__ import with_statement +from rpython.annotator import model as annmodel from rpython.rtyper.tool import rffi_platform as platform from rpython.rtyper.lltypesystem import rffi from rpython.rtyper.lltypesystem import lltype @@ -552,6 +553,7 @@ to compress, call the flush() method to finish the compression process, and return what is left in the internal buffers.""" +assert data is not None datasize = len(data) if datasize == 0: @@ -662,6 +664,7 @@ was found after the end of stream, it'll be ignored and saved in unused_data attribute.""" +assert data is not None if not self.running: raise oefmt(self.space.w_EOFError, "end of stream was already found") @@ -715,6 +718,7 @@ use an instance of BZ2Compressor instead. The compresslevel parameter, if given, must be a number between 1 and 9.""" +assert data is not None if compresslevel < 1 or compresslevel > 9: raise oefmt(space.w_ValueError, "compresslevel must be between 1 and 9") @@ -757,6 +761,7 @@ Decompress data in one shot. If you want to decompress data sequentially, use an instance of BZ2Decompressor instead.""" +assert data is not None in_bufsize = len(data) if in_bufsize == 0: return space.newbytes("") diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py --- a/rpython/rtyper/lltypesystem/rffi.py +++ b/rpython/rtyper/lltypesystem/rffi.py @@ -1232,8 +1232,11 @@ class scoped_nonmovingbuffer: + def __init__(self, data): self.data = data +__init__._annenforceargs_ = [None, annmodel.SomeString(can_be_None=False)] + def __enter__(self): self.buf, self.flag = get_nonmovingbuffer(self.data) return self.buf ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Rewrite itertools.groupby(), following CPython instead of having many
Author: Armin Rigo Branch: Changeset: r91241:6093ff1a44e6 Date: 2017-05-11 11:22 +0200 http://bitbucket.org/pypy/pypy/changeset/6093ff1a44e6/ Log:Rewrite itertools.groupby(), following CPython instead of having many flags to get a result that differs subtly diff --git a/pypy/module/itertools/interp_itertools.py b/pypy/module/itertools/interp_itertools.py --- a/pypy/module/itertools/interp_itertools.py +++ b/pypy/module/itertools/interp_itertools.py @@ -920,90 +920,42 @@ class W_GroupBy(W_Root): def __init__(self, space, w_iterable, w_fun): self.space = space -self.w_iterable = self.space.iter(w_iterable) -if space.is_none(w_fun): -self.w_fun = None -else: -self.w_fun = w_fun -self.index = 0 -self.lookahead = False -self.exhausted = False -self.started = False -# new_group - new group not started yet, next should not skip any items -self.new_group = True -self.w_lookahead = self.space.w_None -self.w_key = self.space.w_None +self.w_iterator = self.space.iter(w_iterable) +if w_fun is None: +w_fun = space.w_None +self.w_keyfunc = w_fun +self.w_tgtkey = None +self.w_currkey = None +self.w_currvalue = None def iter_w(self): return self def next_w(self): -if self.exhausted: -raise OperationError(self.space.w_StopIteration, self.space.w_None) +self._skip_to_next_iteration_group() +w_key = self.w_tgtkey = self.w_currkey +w_grouper = W_GroupByIterator(self, w_key) +return self.space.newtuple([w_key, w_grouper]) -if not self.new_group: -self._consume_unwanted_input() +def _skip_to_next_iteration_group(self): +space = self.space +while True: +if self.w_currkey is None: +pass +elif self.w_tgtkey is None: +break +else: +if not space.eq_w(self.w_tgtkey, self.w_currkey): +break -if not self.started: -self.started = True -try: -w_obj = self.space.next(self.w_iterable) -except OperationError as e: -if e.match(self.space, self.space.w_StopIteration): -self.exhausted = True -raise +w_newvalue = space.next(self.w_iterator) +if space.is_w(self.w_keyfunc, space.w_None): +w_newkey = w_newvalue else: -self.w_lookahead = w_obj -if self.w_fun is None: -self.w_key = w_obj -else: -self.w_key = self.space.call_function(self.w_fun, w_obj) -self.lookahead = True +w_newkey = space.call_function(self.w_keyfunc, w_newvalue) -self.new_group = False -w_iterator = W_GroupByIterator(self.space, self.index, self) -return self.space.newtuple([self.w_key, w_iterator]) - -def _consume_unwanted_input(self): -# Consume unwanted input until we reach the next group -try: -while True: -self.group_next(self.index) -except StopIteration: -pass -if self.exhausted: -raise OperationError(self.space.w_StopIteration, self.space.w_None) - -def group_next(self, group_index): -if group_index < self.index: -raise StopIteration -else: -if self.lookahead: -self.lookahead = False -return self.w_lookahead - -try: -w_obj = self.space.next(self.w_iterable) -except OperationError as e: -if e.match(self.space, self.space.w_StopIteration): -self.exhausted = True -raise StopIteration -else: -raise -else: -if self.w_fun is None: -w_new_key = w_obj -else: -w_new_key = self.space.call_function(self.w_fun, w_obj) -if self.space.eq_w(self.w_key, w_new_key): -return w_obj -else: -self.index += 1 -self.w_lookahead = w_obj -self.w_key = w_new_key -self.lookahead = True -self.new_group = True #new group -raise StopIteration +self.w_currkey = w_newkey +self.w_currvalue = w_newvalue def W_GroupBy___new__(space, w_subtype, w_iterable, w_key=None): r = space.allocate_instance(W_GroupBy, w_subtype) @@ -1036,26 +988,33 @@ class W_GroupByIterator(W_Root): -def __init__(self, space, index, groupby): -self.space = space -self.index = index +def __init__(self, groupby
[pypy-commit] pypy py3.5: Manual merge of 6093ff1a44e6, plus reduce/setstate
Author: Armin Rigo Branch: py3.5 Changeset: r91242:cd0822695fae Date: 2017-05-11 11:38 +0200 http://bitbucket.org/pypy/pypy/changeset/cd0822695fae/ Log:Manual merge of 6093ff1a44e6, plus reduce/setstate diff --git a/pypy/module/itertools/interp_itertools.py b/pypy/module/itertools/interp_itertools.py --- a/pypy/module/itertools/interp_itertools.py +++ b/pypy/module/itertools/interp_itertools.py @@ -971,109 +971,57 @@ class W_GroupBy(W_Root): def __init__(self, space, w_iterable, w_fun): self.space = space -self.w_iterable = self.space.iter(w_iterable) -if space.is_none(w_fun): -self.w_fun = None -else: -self.w_fun = w_fun -self.index = 0 -self.lookahead = False -self.exhausted = False -self.started = False -# new_group - new group not started yet, next should not skip any items -self.new_group = True -self.w_lookahead = self.space.w_None -self.w_key = self.space.w_None +self.w_iterator = self.space.iter(w_iterable) +if w_fun is None: +w_fun = space.w_None +self.w_keyfunc = w_fun +self.w_tgtkey = None +self.w_currkey = None +self.w_currvalue = None def iter_w(self): return self def next_w(self): -if self.exhausted: -raise OperationError(self.space.w_StopIteration, self.space.w_None) +self._skip_to_next_iteration_group() +w_key = self.w_tgtkey = self.w_currkey +w_grouper = W_GroupByIterator(self, w_key) +return self.space.newtuple([w_key, w_grouper]) -if not self.new_group: -self._consume_unwanted_input() +def _skip_to_next_iteration_group(self): +space = self.space +while True: +if self.w_currkey is None: +pass +elif self.w_tgtkey is None: +break +else: +if not space.eq_w(self.w_tgtkey, self.w_currkey): +break -if not self.started: -self.started = True -try: -w_obj = self.space.next(self.w_iterable) -except OperationError as e: -if e.match(self.space, self.space.w_StopIteration): -self.exhausted = True -raise +w_newvalue = space.next(self.w_iterator) +if space.is_w(self.w_keyfunc, space.w_None): +w_newkey = w_newvalue else: -self.w_lookahead = w_obj -if self.w_fun is None: -self.w_key = w_obj -else: -self.w_key = self.space.call_function(self.w_fun, w_obj) -self.lookahead = True +w_newkey = space.call_function(self.w_keyfunc, w_newvalue) -self.new_group = False -w_iterator = W_GroupByIterator(self.space, self.index, self) -return self.space.newtuple([self.w_key, w_iterator]) - -def _consume_unwanted_input(self): -# Consume unwanted input until we reach the next group -try: -while True: -self.group_next(self.index) -except StopIteration: -pass -if self.exhausted: -raise OperationError(self.space.w_StopIteration, self.space.w_None) - -def group_next(self, group_index): -if group_index < self.index: -raise StopIteration -else: -if self.lookahead: -self.lookahead = False -return self.w_lookahead - -try: -w_obj = self.space.next(self.w_iterable) -except OperationError as e: -if e.match(self.space, self.space.w_StopIteration): -self.exhausted = True -raise StopIteration -else: -raise -else: -if self.w_fun is None: -w_new_key = w_obj -else: -w_new_key = self.space.call_function(self.w_fun, w_obj) -if self.space.eq_w(self.w_key, w_new_key): -return w_obj -else: -self.index += 1 -self.w_lookahead = w_obj -self.w_key = w_new_key -self.lookahead = True -self.new_group = True #new group -raise StopIteration +self.w_currkey = w_newkey +self.w_currvalue = w_newvalue def descr_reduce(self, space): -if self.started: -return space.newtuple([ -space.type(self), +items_w = [space.type(self), + space.newtuple([ + self.w_iterator, + self.w_keyfunc])] +if (self.w_tgtkey is not None and self.w_currkey is not None +a
[pypy-commit] pypy faster-rstruct-2: we cannot malloc(STR, zero=True) because the GC does not support it. So, simplify a bit the code, remove the needs_zeros flag and always write zeros when it's need
Author: Antonio Cuni Branch: faster-rstruct-2 Changeset: r91243:582e284508de Date: 2017-05-11 11:25 +0200 http://bitbucket.org/pypy/pypy/changeset/582e284508de/ Log:we cannot malloc(STR, zero=True) because the GC does not support it. So, simplify a bit the code, remove the needs_zeros flag and always write zeros when it's needed diff --git a/pypy/module/struct/formatiterator.py b/pypy/module/struct/formatiterator.py --- a/pypy/module/struct/formatiterator.py +++ b/pypy/module/struct/formatiterator.py @@ -16,7 +16,6 @@ self.args_index = 0 self.pos = 0 self.result = MutableStringBuffer(size) -self.needs_zeros = False # MutableStringBuffer is already 0-inizialized def advance(self, count): self.pos += count @@ -37,6 +36,7 @@ @jit.unroll_safe def align(self, mask): pad = (-self.pos) & mask +self.result.setzeros(self.pos, pad) self.advance(pad) def finished(self): diff --git a/rpython/rlib/mutbuffer.py b/rpython/rlib/mutbuffer.py --- a/rpython/rlib/mutbuffer.py +++ b/rpython/rlib/mutbuffer.py @@ -1,6 +1,6 @@ -from rpython.rtyper.lltypesystem import lltype, llmemory +from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.lloperation import llop -from rpython.rtyper.lltypesystem.rstr import STR +from rpython.rtyper.lltypesystem.rstr import STR, mallocstr from rpython.rtyper.annlowlevel import llstr, hlstr from rpython.rlib.buffer import Buffer @@ -21,10 +21,8 @@ def __init__(self, size): self.readonly = False -# rstr.mallocstr does not pass zero=True, so we call lltype.malloc -# directly self.size = size -self.ll_val = lltype.malloc(STR, size, zero=True) +self.ll_val = mallocstr(size) def getlength(self): return self.size @@ -40,5 +38,13 @@ def as_str(self): raise ValueError('as_str() is not supported. Use finish() instead') +def _hlstr(self): +assert not we_are_translated() # debug only +return hlstr(self.ll_val) + def setitem(self, index, char): self.ll_val.chars[index] = char + +def setzeros(self, index, count): +for i in range(index, index+count): +self.setitem(i, '\x00') diff --git a/rpython/rlib/rstruct/standardfmttable.py b/rpython/rlib/rstruct/standardfmttable.py --- a/rpython/rlib/rstruct/standardfmttable.py +++ b/rpython/rlib/rstruct/standardfmttable.py @@ -21,10 +21,7 @@ native_is_ieee754 = float.__getformat__('double').startswith('IEEE') def pack_pad(fmtiter, count): -if fmtiter.needs_zeros: -pos = fmtiter.pos -for i in range(count): -fmtiter.result.setitem(pos+i, '\x00') +fmtiter.result.setzeros(fmtiter.pos, count) fmtiter.advance(count) def pack_char(fmtiter): @@ -43,11 +40,9 @@ def _pack_string(fmtiter, string, count): pos = fmtiter.pos if len(string) < count: +n = len(string) fmtiter.result.setslice(pos, string) -if fmtiter.needs_zeros: -pos += len(string) -for i in range(count - len(string)): -fmtiter.result.setitem(pos+i, '\x00') +fmtiter.result.setzeros(pos+n, count-n) else: assert count >= 0 fmtiter.result.setslice(pos, string[:count]) diff --git a/rpython/rlib/rstruct/test/test_pack.py b/rpython/rlib/rstruct/test/test_pack.py --- a/rpython/rlib/rstruct/test/test_pack.py +++ b/rpython/rlib/rstruct/test/test_pack.py @@ -10,11 +10,7 @@ self.value = value self.bigendian = bigendian self.result = MutableStringBuffer(size) -# we set the buffer to non-zero, so ensure that we actively write 0s -# where it's needed -self.result.setslice(0, '\xff'*size) self.pos = 0 -self.needs_zeros = True def advance(self, count): self.pos += count diff --git a/rpython/rlib/test/test_mutbuffer.py b/rpython/rlib/test/test_mutbuffer.py --- a/rpython/rlib/test/test_mutbuffer.py +++ b/rpython/rlib/test/test_mutbuffer.py @@ -22,3 +22,9 @@ buf = MutableStringBuffer(6) buf.setslice(2, 'ABCD') assert buf.finish() == '\x00\x00ABCD' + +def test_setzeros(self): +buf = MutableStringBuffer(8) +buf.setslice(0, 'ABCDEFGH') +buf.setzeros(2, 3) +assert buf.finish() == 'AB\x00\x00\x00FGH' ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy faster-rstruct-2: remove the last remainder of the killed strstorage
Author: Antonio Cuni Branch: faster-rstruct-2 Changeset: r91244:a12006f0de48 Date: 2017-05-11 11:29 +0200 http://bitbucket.org/pypy/pypy/changeset/a12006f0de48/ Log:remove the last remainder of the killed strstorage diff --git a/rpython/jit/backend/x86/test/test_strstorage.py b/rpython/jit/backend/x86/test/test_strstorage.py deleted file mode 100644 --- a/rpython/jit/backend/x86/test/test_strstorage.py +++ /dev/null @@ -1,8 +0,0 @@ -from rpython.jit.backend.x86.test.test_basic import Jit386Mixin -from rpython.jit.metainterp.test.test_strstorage import TestStrStorage as _TestStrStorage - - -class TestStrStorage(Jit386Mixin, _TestStrStorage): -# for the individual tests see -# > ../../../metainterp/test/test_strstorage.py -pass ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: in theory, this is a fix
Author: Armin Rigo Branch: Changeset: r91245:5ebcb8f995fd Date: 2017-05-11 12:10 +0200 http://bitbucket.org/pypy/pypy/changeset/5ebcb8f995fd/ Log:in theory, this is a fix diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py --- a/pypy/objspace/std/intobject.py +++ b/pypy/objspace/std/intobject.py @@ -625,7 +625,7 @@ # use r_uint to perform a single comparison (this whole function is # getting inlined into every caller so keeping the branching to a # minimum is a good idea) -index = r_uint(x - lower) +index = r_uint(x) - r_uint(lower) if index >= r_uint(upper - lower): w_res = instantiate(W_IntObject) else: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Merged in sthalik/pypy-1/sthalik/fix-signed-integer-sizes-1494493539409 (pull request #543)
Author: Armin Rigo Branch: Changeset: r91247:400ffc527c25 Date: 2017-05-11 10:39 + http://bitbucket.org/pypy/pypy/changeset/400ffc527c25/ Log:Merged in sthalik/pypy-1/sthalik/fix-signed-integer- sizes-1494493539409 (pull request #543) fix signed integer sizes diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst --- a/pypy/doc/windows.rst +++ b/pypy/doc/windows.rst @@ -11,7 +11,7 @@ To build pypy-c you need a working python environment, and a C compiler. It is possible to translate with a CPython 2.6 or later, but this is not -the preferred way, because it will take a lot longer to run – depending +the preferred way, because it will take a lot longer to run � depending on your architecture, between two and three times as long. So head to `our downloads`_ and get the latest stable version. @@ -343,9 +343,9 @@ integer. The simplest fix is to make sure that it is so, but it will give the following incompatibility between CPython and PyPy on Win64: -CPython: ``sys.maxint == 2**32-1, sys.maxsize == 2**64-1`` +CPython: ``sys.maxint == 2**31-1, sys.maxsize == 2**63-1`` -PyPy: ``sys.maxint == sys.maxsize == 2**64-1`` +PyPy: ``sys.maxint == sys.maxsize == 2**63-1`` ...and, correspondingly, PyPy supports ints up to the larger value of sys.maxint before they are converted to ``long``. The first decision ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy sthalik/fix-signed-integer-sizes-1494493539409: fix signed integer sizes
Author: Stanisław Halik Branch: sthalik/fix-signed-integer-sizes-1494493539409 Changeset: r91246:cb8ca968878f Date: 2017-05-11 09:06 + http://bitbucket.org/pypy/pypy/changeset/cb8ca968878f/ Log:fix signed integer sizes diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst --- a/pypy/doc/windows.rst +++ b/pypy/doc/windows.rst @@ -11,7 +11,7 @@ To build pypy-c you need a working python environment, and a C compiler. It is possible to translate with a CPython 2.6 or later, but this is not -the preferred way, because it will take a lot longer to run – depending +the preferred way, because it will take a lot longer to run � depending on your architecture, between two and three times as long. So head to `our downloads`_ and get the latest stable version. @@ -343,9 +343,9 @@ integer. The simplest fix is to make sure that it is so, but it will give the following incompatibility between CPython and PyPy on Win64: -CPython: ``sys.maxint == 2**32-1, sys.maxsize == 2**64-1`` +CPython: ``sys.maxint == 2**31-1, sys.maxsize == 2**63-1`` -PyPy: ``sys.maxint == sys.maxsize == 2**64-1`` +PyPy: ``sys.maxint == sys.maxsize == 2**63-1`` ...and, correspondingly, PyPy supports ints up to the larger value of sys.maxint before they are converted to ``long``. The first decision ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy faster-rstruct-2: add the JIT version of test_llop
Author: Antonio Cuni Branch: faster-rstruct-2 Changeset: r91250:892ab4160ec6 Date: 2017-05-11 16:21 +0200 http://bitbucket.org/pypy/pypy/changeset/892ab4160ec6/ Log:add the JIT version of test_llop diff --git a/rpython/jit/backend/x86/test/test_llop.py b/rpython/jit/backend/x86/test/test_llop.py new file mode 100644 --- /dev/null +++ b/rpython/jit/backend/x86/test/test_llop.py @@ -0,0 +1,9 @@ +from rpython.jit.backend.x86.test.test_basic import Jit386Mixin +from rpython.jit.metainterp.test.test_llop import TestLLOp as _TestLLOp + + +class TestLLOp(Jit386Mixin, _TestLLOp): +# for the individual tests see +# > ../../../metainterp/test/test_llop.py +pass + diff --git a/rpython/jit/metainterp/test/test_llop.py b/rpython/jit/metainterp/test/test_llop.py new file mode 100644 --- /dev/null +++ b/rpython/jit/metainterp/test/test_llop.py @@ -0,0 +1,49 @@ +import py +import sys +import struct +from rpython.rtyper.lltypesystem import lltype, rffi +from rpython.rtyper.test.test_llop import BaseLLOpTest, str_gc_load +from rpython.jit.codewriter import longlong +from rpython.jit.metainterp.history import getkind +from rpython.jit.metainterp.test.support import LLJitMixin + +class TestLLOp(BaseLLOpTest, LLJitMixin): + +# for the individual tests see +# > ../../../rtyper/test/test_llop.py + +def gc_load_from_string(self, TYPE, buf, offset): +def f(offset): +return str_gc_load(TYPE, buf, offset) +res = self.interp_operations(f, [offset], supports_singlefloats=True) +# +kind = getkind(TYPE)[0] # 'i' or 'f' +self.check_operations_history({'gc_load_indexed_%s' % kind: 1, + 'finish': 1}) +# +if TYPE == lltype.SingleFloat: +# interp_operations returns the int version of r_singlefloat, but +# our tests expects to receive an r_singlefloat: let's convert it +# back! +return longlong.int2singlefloat(res) +return res + +def test_force_virtual_str_storage(self): +byteorder = sys.byteorder +size = rffi.sizeof(lltype.Signed) +def f(val): +if byteorder == 'little': +x = chr(val) + '\x00'*(size-1) +else: +x = '\x00'*(size-1) + chr(val) +return str_gc_load(lltype.Signed, x, 0) +res = self.interp_operations(f, [42], supports_singlefloats=True) +assert res == 42 +self.check_operations_history({ +'newstr': 1, # str forcing +'strsetitem': 1, # str forcing +'call_pure_r': 1, # str forcing (copystrcontent) +'guard_no_exception': 1, # str forcing +'gc_load_indexed_i': 1, # str_storage_getitem +'finish': 1 +}) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy faster-rstruct-2: deleting strstorage tests was a mistake, because they were the only ones to test llop.gc_load_indexed. Rewrite them in a more direct way
Author: Antonio Cuni Branch: faster-rstruct-2 Changeset: r91248:22c587e1da2b Date: 2017-05-11 16:09 +0200 http://bitbucket.org/pypy/pypy/changeset/22c587e1da2b/ Log:deleting strstorage tests was a mistake, because they were the only ones to test llop.gc_load_indexed. Rewrite them in a more direct way diff --git a/rpython/rtyper/test/test_llop.py b/rpython/rtyper/test/test_llop.py new file mode 100644 --- /dev/null +++ b/rpython/rtyper/test/test_llop.py @@ -0,0 +1,46 @@ +import struct +from rpython.rtyper.test.tool import BaseRtypingTest +from rpython.rtyper.lltypesystem import lltype, llmemory, rffi +from rpython.rtyper.lltypesystem.lloperation import llop +from rpython.rtyper.lltypesystem.rstr import STR +from rpython.rtyper.annlowlevel import llstr +from rpython.rlib.rarithmetic import r_singlefloat + +def str_offset(): +base_ofs = (llmemory.offsetof(STR, 'chars') + +llmemory.itemoffsetof(STR.chars, 0)) +scale_factor = llmemory.sizeof(lltype.Char) +return base_ofs, scale_factor + +class BaseLLOpTest(object): + +def test_gc_load_indexed(self): +buf = struct.pack('dfi', 123.456, 123.456, 0x12345678) +val = self.gc_load_from_string(rffi.DOUBLE, buf, 0) +assert val == 123.456 +# +val = self.gc_load_from_string(rffi.FLOAT, buf, 8) +assert val == r_singlefloat(123.456) +# +val = self.gc_load_from_string(rffi.INT, buf, 12) +assert val == 0x12345678 + + +class TestDirect(BaseLLOpTest): + +def gc_load_from_string(self, TYPE, buf, offset): +base_ofs, scale_factor = str_offset() +lls = llstr(buf) +return llop.gc_load_indexed(TYPE, lls, offset, +scale_factor, base_ofs) + + +class TestRTyping(BaseLLOpTest, BaseRtypingTest): + +def gc_load_from_string(self, TYPE, buf, offset): +def fn(offset): +lls = llstr(buf) +base_ofs, scale_factor = str_offset() +return llop.gc_load_indexed(TYPE, lls, offset, +scale_factor, base_ofs) +return self.interpret(fn, [offset]) diff --git a/rpython/translator/c/test/test_llop.py b/rpython/translator/c/test/test_llop.py new file mode 100644 --- /dev/null +++ b/rpython/translator/c/test/test_llop.py @@ -0,0 +1,31 @@ +from rpython.rtyper.lltypesystem import lltype, llmemory, rffi +from rpython.rtyper.lltypesystem.lloperation import llop +from rpython.rtyper.annlowlevel import llstr +from rpython.rtyper.test.test_llop import BaseLLOpTest, str_offset +from rpython.translator.c.test.test_genc import compile + + +class TestLLOp(BaseLLOpTest): +cache = {} + +def gc_load_from_string(self, TYPE, buf, offset): +if TYPE not in self.cache: +assert isinstance(TYPE, lltype.Primitive) +if TYPE in (lltype.Float, lltype.SingleFloat): +TARGET_TYPE = lltype.Float +else: +TARGET_TYPE = lltype.Signed + +def llf(buf, offset): +base_ofs, scale_factor = str_offset() +lls = llstr(buf) +x = llop.gc_load_indexed(TYPE, lls, offset, + scale_factor, base_ofs) +return lltype.cast_primitive(TARGET_TYPE, x) + +fn = compile(llf, [str, int]) +self.cache[TYPE] = fn +# +fn = self.cache[TYPE] +x = fn(buf, offset) +return lltype.cast_primitive(TYPE, x) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy faster-rstruct-2: reduce code duplication
Author: Antonio Cuni Branch: faster-rstruct-2 Changeset: r91249:be9e1d6fe67b Date: 2017-05-11 16:14 +0200 http://bitbucket.org/pypy/pypy/changeset/be9e1d6fe67b/ Log:reduce code duplication diff --git a/rpython/rtyper/test/test_llop.py b/rpython/rtyper/test/test_llop.py --- a/rpython/rtyper/test/test_llop.py +++ b/rpython/rtyper/test/test_llop.py @@ -6,11 +6,13 @@ from rpython.rtyper.annlowlevel import llstr from rpython.rlib.rarithmetic import r_singlefloat -def str_offset(): +def str_gc_load(TYPE, buf, offset): base_ofs = (llmemory.offsetof(STR, 'chars') + llmemory.itemoffsetof(STR.chars, 0)) scale_factor = llmemory.sizeof(lltype.Char) -return base_ofs, scale_factor +lls = llstr(buf) +return llop.gc_load_indexed(TYPE, lls, offset, +scale_factor, base_ofs) class BaseLLOpTest(object): @@ -29,18 +31,11 @@ class TestDirect(BaseLLOpTest): def gc_load_from_string(self, TYPE, buf, offset): -base_ofs, scale_factor = str_offset() -lls = llstr(buf) -return llop.gc_load_indexed(TYPE, lls, offset, -scale_factor, base_ofs) - +return str_gc_load(TYPE, buf, offset) class TestRTyping(BaseLLOpTest, BaseRtypingTest): def gc_load_from_string(self, TYPE, buf, offset): def fn(offset): -lls = llstr(buf) -base_ofs, scale_factor = str_offset() -return llop.gc_load_indexed(TYPE, lls, offset, -scale_factor, base_ofs) +return str_gc_load(TYPE, buf, offset) return self.interpret(fn, [offset]) diff --git a/rpython/translator/c/test/test_llop.py b/rpython/translator/c/test/test_llop.py --- a/rpython/translator/c/test/test_llop.py +++ b/rpython/translator/c/test/test_llop.py @@ -1,7 +1,5 @@ from rpython.rtyper.lltypesystem import lltype, llmemory, rffi -from rpython.rtyper.lltypesystem.lloperation import llop -from rpython.rtyper.annlowlevel import llstr -from rpython.rtyper.test.test_llop import BaseLLOpTest, str_offset +from rpython.rtyper.test.test_llop import BaseLLOpTest, str_gc_load from rpython.translator.c.test.test_genc import compile @@ -17,10 +15,7 @@ TARGET_TYPE = lltype.Signed def llf(buf, offset): -base_ofs, scale_factor = str_offset() -lls = llstr(buf) -x = llop.gc_load_indexed(TYPE, lls, offset, - scale_factor, base_ofs) +x = str_gc_load(TYPE, buf, offset) return lltype.cast_primitive(TARGET_TYPE, x) fn = compile(llf, [str, int]) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy PyBuffer-backport: fix _rawffi
Author: Ronan Lamy Branch: PyBuffer-backport Changeset: r91252:4574a68bea35 Date: 2017-05-11 16:09 +0100 http://bitbucket.org/pypy/pypy/changeset/4574a68bea35/ Log:fix _rawffi diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py --- a/pypy/module/_rawffi/interp_rawffi.py +++ b/pypy/module/_rawffi/interp_rawffi.py @@ -374,6 +374,12 @@ def buffer_w(self, space, flags): return SimpleView(RawFFIBuffer(self)) +def readbuf_w(self, space): +return RawFFIBuffer(self) + +def writebuf_w(self, space): +return RawFFIBuffer(self) + def getrawsize(self): raise NotImplementedError("abstract base class") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy PyBuffer-backport: fix micronumpy
Author: Ronan Lamy Branch: PyBuffer-backport Changeset: r91253:2372a325f694 Date: 2017-05-11 16:43 +0100 http://bitbucket.org/pypy/pypy/changeset/2372a325f694/ Log:fix micronumpy diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py --- a/pypy/module/micronumpy/concrete.py +++ b/pypy/module/micronumpy/concrete.py @@ -762,3 +762,6 @@ def getstrides(self): return self.impl.strides + +def get_raw_address(self): +return self.data.get_raw_address() diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py --- a/pypy/module/micronumpy/ctors.py +++ b/pypy/module/micronumpy/ctors.py @@ -91,7 +91,7 @@ w_base = w_object if read_only: w_base = None -return W_NDimArray.from_shape_and_storage(space, shape, w_data, +return W_NDimArray.from_shape_and_storage(space, shape, w_data, dtype, w_base=w_base, strides=strides, start=offset), read_only if w_data is None: @@ -104,11 +104,11 @@ #print 'create view from shape',shape,'dtype',dtype,'data',data if strides is not None: raise oefmt(space.w_NotImplementedError, - "__array_interface__ strides not fully supported yet") + "__array_interface__ strides not fully supported yet") arr = frombuffer(space, w_data, dtype, support.product(shape), offset) new_impl = arr.implementation.reshape(arr, shape) return W_NDimArray(new_impl), False - + except OperationError as e: if e.match(space, space.w_AttributeError): return None, False @@ -120,7 +120,7 @@ return descr msg = "invalid PEP 3118 format string: '%s'" % c_format space.warn(space.newtext(msg), space.w_RuntimeWarning) -return None +return None def _array_from_buffer_3118(space, w_object, dtype): try: @@ -139,12 +139,12 @@ raise oefmt(space.w_NotImplementedError, "creating an array from a memoryview while specifying dtype " "not supported") -if descr.elsize != space.int_w(space.getattr(w_buf, space.newbytes('itemsize'))): +if descr.elsize != space.int_w(space.getattr(w_buf, space.newbytes('itemsize'))): msg = ("Item size computed from the PEP 3118 buffer format " "string does not match the actual item size.") space.warn(space.newtext(msg), space.w_RuntimeWarning) return w_object -dtype = descr +dtype = descr elif not dtype: dtype = descriptor.get_dtype_cache(space).w_stringdtype dtype.elsize = space.int_w(space.getattr(w_buf, space.newbytes('itemsize'))) @@ -181,7 +181,7 @@ raise e writable = not space.bool_w(space.getattr(w_buf, space.newbytes('readonly'))) w_ret = W_NDimArray.from_shape_and_storage(space, shape, w_data, - storage_bytes=buflen, dtype=dtype, w_base=w_object, + storage_bytes=buflen, dtype=dtype, w_base=w_object, writable=writable, strides=strides) if w_ret: return w_ret @@ -212,7 +212,7 @@ if not isinstance(w_object, W_NDimArray): w_array = try_array_method(space, w_object, w_dtype) if w_array is None: -if (not space.isinstance_w(w_object, space.w_bytes) and +if (not space.isinstance_w(w_object, space.w_bytes) and not space.isinstance_w(w_object, space.w_unicode) and not isinstance(w_object, W_GenericBox)): # use buffer interface @@ -551,7 +551,7 @@ except OperationError as e: if not e.match(space, space.w_TypeError): raise -w_buffer = space.call_method(w_buffer, '__buffer__', +w_buffer = space.call_method(w_buffer, '__buffer__', space.newint(space.BUF_FULL_RO)) buf = _getbuffer(space, w_buffer) 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 @@ -807,6 +807,15 @@ def buffer_w(self, space, flags): return self.implementation.get_buffer(space, flags) +def readbuf_w(self, space): +return self.implementation.get_buffer(space, space.BUF_FULL_RO).as_readbuf() + +def writebuf_w(self, space): +return self.implementation.get_buffer(space, space.BUF_FULL).as_writebuf() + +def charbuf_w(self, space): +return self.implementation.get_buffer(space, space.BUF_FULL_RO).as_str() + def descr_get_data(self, space): return space.newbuffer( self.implementation.get_buffer(space, space.BUF_FULL).as_writebuf()) diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py --- a/pypy/module/mic
[pypy-commit] pypy PyBuffer-backport: Fix memoryview.__setitem__, again
Author: Ronan Lamy Branch: PyBuffer-backport Changeset: r91251:3ebd85b5b58e Date: 2017-05-11 16:02 +0100 http://bitbucket.org/pypy/pypy/changeset/3ebd85b5b58e/ Log:Fix memoryview.__setitem__, again 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 @@ -144,18 +144,11 @@ is_slice = space.isinstance_w(w_index, space.w_slice) start, stop, step, slicelength = self._decode_index(space, w_index, is_slice) itemsize = self.getitemsize() -if step == 0: # index only -value = space.buffer_w(w_obj, space.BUF_CONTIG_RO) -if value.getitemsize() != itemsize: -raise oefmt(space.w_TypeError, -"mismatching itemsizes for %T and %T", self, w_obj) -self.view.setbytes(start * itemsize, value.getbytes(0, itemsize)) -elif step == 1: -value = space.buffer_w(w_obj, space.BUF_CONTIG_RO) -if value.getlength() != slicelength * itemsize: -raise oefmt(space.w_ValueError, -"cannot modify size of memoryview object") -self.view.setbytes(start * itemsize, value.as_str()) +value = space.buffer_w(w_obj, space.BUF_CONTIG_RO) +if value.getlength() != slicelength * itemsize: +raise oefmt(space.w_ValueError, +"cannot modify size of memoryview object") +self.view.setbytes(start * itemsize, value.as_str()) def descr_len(self, space): self._check_released(space) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy PyBuffer-backport: Restrict marshalling to old-style buffers
Author: Ronan Lamy Branch: PyBuffer-backport Changeset: r91254:647b63731eca Date: 2017-05-11 16:53 +0100 http://bitbucket.org/pypy/pypy/changeset/647b63731eca/ Log:Restrict marshalling to old-style buffers 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 @@ -7,6 +7,7 @@ from pypy.interpreter.special import Ellipsis from pypy.interpreter.pycode import PyCode from pypy.interpreter import unicodehelper +from pypy.interpreter.buffer import BufferInterfaceNotFound from pypy.objspace.std.boolobject import W_BoolObject from pypy.objspace.std.bytesobject import W_BytesObject from pypy.objspace.std.complexobject import W_ComplexObject @@ -73,14 +74,12 @@ func(space, w_obj, m) return -# any unknown object implementing the buffer protocol is +# any unknown object implementing the old-style buffer protocol is # accepted and encoded as a plain string try: -s = space.readbuf_w(w_obj) -except OperationError as e: -if e.match(space, space.w_TypeError): -raise oefmt(space.w_ValueError, "unmarshallable object") -raise +s = w_obj.readbuf_w(space) +except BufferInterfaceNotFound: +raise oefmt(space.w_ValueError, "unmarshallable object") m.atom_str(TYPE_STRING, s.as_str()) def get_unmarshallers(): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy PyBuffer-backport: Don't bother preventing _numpypy.frombuffer() from working on memoryviews
Author: Ronan Lamy Branch: PyBuffer-backport Changeset: r91255:89ffc4931b4b Date: 2017-05-11 16:57 +0100 http://bitbucket.org/pypy/pypy/changeset/89ffc4931b4b/ Log:Don't bother preventing _numpypy.frombuffer() from working on memoryviews diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py --- a/pypy/module/micronumpy/test/test_ndarray.py +++ b/pypy/module/micronumpy/test/test_ndarray.py @@ -3611,8 +3611,6 @@ import numpy as np exc = raises(AttributeError, np.frombuffer, None) assert str(exc.value) == "'NoneType' object has no attribute '__buffer__'" -exc = raises(AttributeError, np.frombuffer, memoryview(self.data)) -assert str(exc.value) == "'memoryview' object has no attribute '__buffer__'" exc = raises(ValueError, np.frombuffer, self.data, 'S0') assert str(exc.value) == "itemsize cannot be zero in type" exc = raises(ValueError, np.frombuffer, self.data, offset=-1) @@ -3684,7 +3682,7 @@ assert y.format == 'T{b:a:xxxi:b:T{b:f0:i:f1:}:sub:xxxi:c:}' else: assert y.format == 'T{b:a:xxxi:b:T{b:f0:=i:f1:}:sub:xxx@i:c:}' - + dt1 = np.dtype( [('a', 'b'), ('b', 'i'), ('sub', np.dtype('b,i')), ('c', 'i')], @@ -3695,7 +3693,7 @@ assert y.format == 'T{b:a:xxxi:b:T{b:f0:i:f1:}:sub:xxxi:c:}' else: assert y.format == 'T{b:a:xxxi:b:T{b:f0:=i:f1:}:sub:xxx@i:c:}' - + def test_fromstring(self): import sys ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy str-measure: improve the wrapper
Author: fijal Branch: str-measure Changeset: r91256:92c947349352 Date: 2017-05-11 18:20 +0200 http://bitbucket.org/pypy/pypy/changeset/92c947349352/ Log:improve the wrapper 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 @@ -96,6 +96,12 @@ return space.text_w(space.str(self)) def unicode_w(self, space): +from pypy.module.__pypy__.interp_debug import get_str_debug_file +w_file = get_str_debug_file(space) +if w_file is not None: +space.call_function(space.getattr(w_file, space.newtext("write")), +space.newtext("unicode_w %d\n" % (self._string_id,))) + return self._value def readbuf_w(self, space): @@ -986,8 +992,18 @@ def setup(): from pypy.module.__pypy__.interp_debug import get_str_debug_file +def lines_for_arg(argname, func): +return [ +"if isinstance(%s, W_UnicodeObject):" % argname, +"txt = '%s ' + str(self._string_id) + ' ' + str(%s._string_id) + '\\n'" % (func.func_name, argname), +"else:", +"txt = '%s ' + str(self._string_id) + ' string\\n'" % func.func_name +] + + def wrap(func): -d = {'orig': func, 'get_str_debug_file': get_str_debug_file} +d = {'orig': func, 'get_str_debug_file': get_str_debug_file, +'W_UnicodeObject': W_UnicodeObject} name = func.__name__ orig_args = list(func.__code__.co_varnames[:func.__code__.co_argcount]) args = orig_args[:] @@ -999,8 +1015,20 @@ func_args = ", ".join(args) lines = ["def %s(%s):" % (name, func_args), "w_file = get_str_debug_file(space)", -"if w_file is not None:", -"txt = '%s ' + str(self._string_id) + '\\n'" % func.func_name, +"if w_file is not None:"] +if name in ['descr_eq', 'descr_add', 'descr_ne', 'descr_lt', 'descr_gt', 'descr_ge', 'descr_le']: +lines += lines_for_arg('w_other', func) +elif name == 'descr_startswith': +lines += lines_for_arg('w_prefix', func) +elif name == 'descr_endswith': +lines += lines_for_arg('w_suffix', func) +elif name in ['descr_find', 'descr_rfind', 'descr_index', 'descr_count']: +lines += lines_for_arg('w_sub', func) +else: +lines += [ +"txt = '%s ' + str(self._string_id) + '\\n'" % func.func_name, +] +lines += [ "space.call_function(space.getattr(w_file, space.newtext('write')), space.newtext(txt))", "return orig(%s)" % (", ".join(orig_args),)] exec "\n".join(lines) in d ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Disable an assert that fails also on CPython, where failure is better just ignored at least on PyPy
Author: Armin Rigo Branch: Changeset: r91257:e300fd927c59 Date: 2017-05-11 23:13 +0200 http://bitbucket.org/pypy/pypy/changeset/e300fd927c59/ Log:Disable an assert that fails also on CPython, where failure is better just ignored at least on PyPy diff --git a/pypy/module/itertools/interp_itertools.py b/pypy/module/itertools/interp_itertools.py --- a/pypy/module/itertools/interp_itertools.py +++ b/pypy/module/itertools/interp_itertools.py @@ -1004,7 +1004,8 @@ w_newkey = w_newvalue else: w_newkey = space.call_function(groupby.w_keyfunc, w_newvalue) -assert groupby.w_currvalue is None +#assert groupby.w_currvalue is None +# ^^^ check disabled, see http://bugs.python.org/issue30347 groupby.w_currkey = w_newkey groupby.w_currvalue = w_newvalue ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit