Commits

Maciej Fijalkowski committed 874f26a Draft Merge

merge

Comments (0)

Files changed (13)

pypy/doc/ctypes-implementation.rst

 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

pypy/doc/discussion/improve-rpython.rst

 
 - 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
 -------------------------------------

pypy/doc/stackless.rst

 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

pypy/module/_io/interp_bytesio.py

         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)
 
 
     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),

pypy/module/_io/test/test_bytesio.py

         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'
Add a comment to this file

rpython/annotator/test/test_annrpython.py

File contents unchanged.

rpython/rtyper/lltypesystem/rlist.py

 
     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)))

rpython/rtyper/lltypesystem/rstr.py

     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)))
     iter.index = index + 1
     return chars[index]
 
+def ll_getnextindex(iter):
+    return iter.index
+
 string_repr.iterator_repr = StringIteratorRepr()
 unicode_repr.iterator_repr = UnicodeIteratorRepr()
 

rpython/rtyper/ootypesystem/rstr.py

 
 
 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})
 
     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()

rpython/rtyper/rrange.py

         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)

rpython/rtyper/test/test_rstr.py

         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):

rpython/translator/c/src/mem.h

 
 #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
 
 

rpython/translator/c/src/stack.h

 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 */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.