Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r61594:874f26aca217 Date: 2013-02-22 12:44 +0200 http://bitbucket.org/pypy/pypy/changeset/874f26aca217/
Log: merge diff --git a/pypy/doc/ctypes-implementation.rst b/pypy/doc/ctypes-implementation.rst --- a/pypy/doc/ctypes-implementation.rst +++ b/pypy/doc/ctypes-implementation.rst @@ -38,7 +38,7 @@ in dynamic libraries through libffi. Freeing objects in most cases and making sure that objects referring to each other are kept alive is responsibility of the higher levels. -This module uses bindings to libffi which are defined in ``pypy/rlib/libffi.py``. +This module uses bindings to libffi which are defined in ``rpython/rlib/libffi.py``. We tried to keep this module as small as possible. It is conceivable that other implementations (e.g. Jython) could use our ctypes diff --git a/pypy/doc/discussion/improve-rpython.rst b/pypy/doc/discussion/improve-rpython.rst --- a/pypy/doc/discussion/improve-rpython.rst +++ b/pypy/doc/discussion/improve-rpython.rst @@ -39,7 +39,7 @@ - Allocate variables on the stack, and pass their address ("by reference") to llexternal functions. For a typical usage, see - `pypy.rlib.rsocket.RSocket.getsockopt_int`. + `rpython.rlib.rsocket.RSocket.getsockopt_int`. Extensible type system for llexternal ------------------------------------- diff --git a/pypy/doc/stackless.rst b/pypy/doc/stackless.rst --- a/pypy/doc/stackless.rst +++ b/pypy/doc/stackless.rst @@ -273,7 +273,7 @@ more information about them please see the documentation in the C source at `rpython/translator/c/src/stacklet/stacklet.h`_. -The module ``pypy.rlib.rstacklet`` is a thin wrapper around the above +The module ``rpython.rlib.rstacklet`` is a thin wrapper around the above functions. The key point is that new() and switch() always return a fresh stacklet handle (or an empty one), and switch() additionally consumes one. It makes no sense to have code in which the returned diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py --- a/pypy/module/_io/interp_bytesio.py +++ b/pypy/module/_io/interp_bytesio.py @@ -52,6 +52,25 @@ self.pos += size return space.wrap(output) + def readline_w(self, space, w_limit=None): + self._check_closed(space) + limit = convert_size(space, w_limit) + + cur_pos = self.pos + if limit < 0: + end_pos = self.string_size + else: + end_pos = min(cur_pos + limit, self.string_size) + while cur_pos != end_pos: + if self.buf[cur_pos] == '\n': + cur_pos += 1 + break + cur_pos += 1 + + output = buffer2string(self.buf, self.pos, cur_pos) + self.pos = cur_pos + return space.wrap(output) + def read1_w(self, space, w_size): return self.read_w(space, w_size) @@ -209,6 +228,7 @@ read = interp2app(W_BytesIO.read_w), read1 = interp2app(W_BytesIO.read1_w), + readline = interp2app(W_BytesIO.readline_w), readinto = interp2app(W_BytesIO.readinto_w), write = interp2app(W_BytesIO.write_w), truncate = interp2app(W_BytesIO.truncate_w), 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 @@ -75,3 +75,19 @@ b = _io.BytesIO("hello") b.close() raises(ValueError, b.readinto, bytearray("hello")) + + def test_readline(self): + import _io + f = _io.BytesIO(b'abc\ndef\nxyzzy\nfoo\x00bar\nanother line') + assert f.readline() == b'abc\n' + assert f.readline(10) == b'def\n' + assert f.readline(2) == b'xy' + assert f.readline(4) == b'zzy\n' + assert f.readline() == b'foo\x00bar\n' + assert f.readline(None) == b'another line' + raises(TypeError, f.readline, 5.3) + + def test_overread(self): + import _io + f = _io.BytesIO(b'abc') + assert f.readline(10) == b'abc' diff --git a/rpython/rtyper/lltypesystem/rlist.py b/rpython/rtyper/lltypesystem/rlist.py --- a/rpython/rtyper/lltypesystem/rlist.py +++ b/rpython/rtyper/lltypesystem/rlist.py @@ -419,6 +419,7 @@ def __init__(self, r_list): self.r_list = r_list + self.external_item_repr = r_list.external_item_repr self.lowleveltype = Ptr(GcStruct('listiter', ('list', r_list.lowleveltype), ('index', Signed))) diff --git a/rpython/rtyper/lltypesystem/rstr.py b/rpython/rtyper/lltypesystem/rstr.py --- a/rpython/rtyper/lltypesystem/rstr.py +++ b/rpython/rtyper/lltypesystem/rstr.py @@ -1054,15 +1054,18 @@ def __init__(self): self.ll_striter = ll_striter self.ll_strnext = ll_strnext + self.ll_getnextindex = ll_getnextindex class StringIteratorRepr(BaseStringIteratorRepr): + external_item_repr = char_repr lowleveltype = Ptr(GcStruct('stringiter', ('string', string_repr.lowleveltype), ('index', Signed))) class UnicodeIteratorRepr(BaseStringIteratorRepr): + external_item_repr = unichar_repr lowleveltype = Ptr(GcStruct('unicodeiter', ('string', unicode_repr.lowleveltype), ('index', Signed))) @@ -1087,6 +1090,9 @@ iter.index = index + 1 return chars[index] +def ll_getnextindex(iter): + return iter.index + string_repr.iterator_repr = StringIteratorRepr() unicode_repr.iterator_repr = UnicodeIteratorRepr() diff --git a/rpython/rtyper/ootypesystem/rstr.py b/rpython/rtyper/ootypesystem/rstr.py --- a/rpython/rtyper/ootypesystem/rstr.py +++ b/rpython/rtyper/ootypesystem/rstr.py @@ -428,14 +428,17 @@ class StringIteratorRepr(AbstractStringIteratorRepr): + external_item_repr = char_repr lowleveltype = ootype.Record({'string': string_repr.lowleveltype, 'index': ootype.Signed}) def __init__(self): self.ll_striter = ll_striter self.ll_strnext = ll_strnext + self.ll_getnextindex = ll_getnextindex class UnicodeIteratorRepr(AbstractStringIteratorRepr): + external_item_repr = unichar_repr lowleveltype = ootype.Record({'string': unicode_repr.lowleveltype, 'index': ootype.Signed}) @@ -463,6 +466,9 @@ iter.index = index + 1 return string.ll_stritem_nonneg(index) +def ll_getnextindex(iter): + return iter.index + StringRepr.string_iterator_repr = StringIteratorRepr() UnicodeRepr.string_iterator_repr = UnicodeIteratorRepr() diff --git a/rpython/rtyper/rrange.py b/rpython/rtyper/rrange.py --- a/rpython/rtyper/rrange.py +++ b/rpython/rtyper/rrange.py @@ -207,7 +207,7 @@ v_index = hop.gendirectcall(self.ll_getnextindex, v_enumerate) hop2 = hop.copy() hop2.args_r = [self.r_baseiter] - r_item_src = self.r_baseiter.r_list.external_item_repr + r_item_src = self.r_baseiter.external_item_repr r_item_dst = hop.r_result.items_r[1] v_item = self.r_baseiter.rtype_next(hop2) v_item = hop.llops.convertvar(v_item, r_item_src, r_item_dst) diff --git a/rpython/rtyper/test/test_rstr.py b/rpython/rtyper/test/test_rstr.py --- a/rpython/rtyper/test/test_rstr.py +++ b/rpython/rtyper/test/test_rstr.py @@ -1035,6 +1035,17 @@ got = self.interpret(f, [7]) assert self.ll_to_string(got) == 'None' + def test_enumerate(self): + const = self.const + def fn(n): + s = const('abcde') + for i, x in enumerate(s): + if i == n: + return x + return 'x' + res = self.interpret(fn, [2]) + assert res == 'c' + def FIXME_test_str_to_pystringobj(): def f(n): diff --git a/rpython/translator/c/src/mem.h b/rpython/translator/c/src/mem.h --- a/rpython/translator/c/src/mem.h +++ b/rpython/translator/c/src/mem.h @@ -4,7 +4,7 @@ #include <string.h> -/* used by pypy.rlib.rstack, but also by asmgcc */ +/* used by rpython.rlib.rstack, but also by asmgcc */ #define OP_STACK_CURRENT(r) r = (Signed)&r diff --git a/rpython/translator/c/src/stack.h b/rpython/translator/c/src/stack.h --- a/rpython/translator/c/src/stack.h +++ b/rpython/translator/c/src/stack.h @@ -18,7 +18,7 @@ char LL_stack_too_big_slowpath(long); /* returns 0 (ok) or 1 (too big) */ void LL_stack_set_length_fraction(double); -/* some macros referenced from pypy.rlib.rstack */ +/* some macros referenced from rpython.rlib.rstack */ #define LL_stack_get_end() ((long)_LLstacktoobig_stack_end) #define LL_stack_get_length() _LLstacktoobig_stack_length #define LL_stack_get_end_adr() ((long)&_LLstacktoobig_stack_end) /* JIT */ _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit