Author: Alex Gaynor <alex.gay...@gmail.com>
Branch: kill-someobject
Changeset: r57884:bf2fa5d5c6d1
Date: 2012-10-08 11:05 +0200
http://bitbucket.org/pypy/pypy/changeset/bf2fa5d5c6d1/

Log:    Merged default in.

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
@@ -41,9 +41,6 @@
   llexternal functions. For a typical usage, see
   `pypy.rlib.rsocket.RSocket.getsockopt_int`.
 
-- Support context managers and the `with` statement. This could be a workaround
-  before the previous point is available.
-
 Extensible type system for llexternal
 -------------------------------------
 
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -185,7 +185,7 @@
             return stream.readline()
         else:
             # very inefficient unless there is a peek()
-            result = []
+            result = StringBuilder()
             while size > 0:
                 # "peeks" on the underlying stream to see how many chars
                 # we can safely read without reading past an end-of-line
@@ -200,7 +200,7 @@
                 if c.endswith('\n'):
                     break
                 size -= len(c)
-            return ''.join(result)
+            return result.build()
 
     @unwrap_spec(size=int)
     def direct_readlines(self, size=0):
diff --git a/pypy/module/_file/test/test_file.py 
b/pypy/module/_file/test/test_file.py
--- a/pypy/module/_file/test/test_file.py
+++ b/pypy/module/_file/test/test_file.py
@@ -428,6 +428,18 @@
             pass
         assert f.subclass_closed
 
+    def test_readline_unbuffered_should_read_one_line_only(self):
+        import posix
+
+        with self.file(self.temppath, 'w') as f:
+            f.write('foo\nbar\n')
+
+        with self.file(self.temppath, 'r', 0) as f:
+            s = f.readline()
+            assert s == 'foo\n'
+            s = posix.read(f.fileno(), 10)
+            assert s == 'bar\n'
+
 def test_flush_at_exit():
     from pypy import conftest
     from pypy.tool.option import make_config, make_objspace
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -644,8 +644,7 @@
             # j  = (m+) % SHIFT = (m+) - (i * SHIFT)
             # (computed without doing "i * SHIFT", which might overflow)
             j = size_b % 5
-            if j != 0:
-                j = 5 - j
+            j = _jmapping[j]
             if not we_are_translated():
                 assert j == (size_b*SHIFT+4)//5*5 - size_b*SHIFT
             #
@@ -866,6 +865,12 @@
 ONENEGATIVERBIGINT = rbigint([ONEDIGIT], -1, 1)
 NULLRBIGINT = rbigint()
 
+_jmapping = [(5 * SHIFT) % 5,
+             (4 * SHIFT) % 5,
+             (3 * SHIFT) % 5,
+             (2 * SHIFT) % 5,
+             (1 * SHIFT) % 5]
+
 #_________________________________________________________________
 
 # Helper Functions
diff --git a/pypy/rlib/rsre/rsre_re.py b/pypy/rlib/rsre/rsre_re.py
--- a/pypy/rlib/rsre/rsre_re.py
+++ b/pypy/rlib/rsre/rsre_re.py
@@ -75,7 +75,7 @@
             else:
                 item = match.groups("")
             matchlist.append(item)
-        return matchlist        
+        return matchlist
 
     def finditer(self, string, pos=0, endpos=sys.maxint):
         return iter(self.scanner(string, pos, endpos).search, None)
diff --git a/pypy/rlib/streamio.py b/pypy/rlib/streamio.py
--- a/pypy/rlib/streamio.py
+++ b/pypy/rlib/streamio.py
@@ -41,6 +41,7 @@
 from pypy.rlib.objectmodel import specialize, we_are_translated
 from pypy.rlib.rarithmetic import r_longlong, intmask
 from pypy.rlib import rposix
+from pypy.rlib.rstring import StringBuilder
 
 from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC
 O_BINARY = getattr(os, "O_BINARY", 0)
@@ -141,8 +142,7 @@
 def construct_stream_tower(stream, buffering, universal, reading, writing,
                            binary):
     if buffering == 0:   # no buffering
-        if reading:      # force some minimal buffering for readline()
-            stream = ReadlineInputStream(stream)
+        pass
     elif buffering == 1:   # line-buffering
         if writing:
             stream = LineBufferingOutputStream(stream)
@@ -303,6 +303,26 @@
                     raise
                 # else try again
 
+    def readline(self):
+        # mostly inefficient, but not as laughably bad as with the default
+        # readline() from Stream
+        result = StringBuilder()
+        while True:
+            try:
+                c = os.read(self.fd, 1)
+            except OSError, e:
+                if e.errno != errno.EINTR:
+                    raise
+                else:
+                    continue   # try again
+            if not c:
+                break
+            c = c[0]
+            result.append(c)
+            if c == '\n':
+                break
+        return result.build()
+
     def write(self, data):
         while data:
             try:
@@ -700,113 +720,6 @@
                                               flush_buffers=False)
 
 
-class ReadlineInputStream(Stream):
-
-    """Minimal buffering input stream.
-
-    Only does buffering for readline().  The other kinds of reads, and
-    all writes, are not buffered at all.
-    """
-
-    bufsize = 2**13 # 8 K
-
-    def __init__(self, base, bufsize=-1):
-        self.base = base
-        self.do_read = base.read   # function to fill buffer some more
-        self.do_seek = base.seek   # seek to a byte offset
-        if bufsize == -1:     # Get default from the class
-            bufsize = self.bufsize
-        self.bufsize = bufsize  # buffer size (hint only)
-        self.buf = None         # raw data (may contain "\n")
-        self.bufstart = 0
-
-    def flush_buffers(self):
-        if self.buf is not None:
-            try:
-                self.do_seek(self.bufstart-len(self.buf), 1)
-            except (MyNotImplementedError, OSError):
-                pass
-            else:
-                self.buf = None
-                self.bufstart = 0
-
-    def readline(self):
-        if self.buf is not None:
-            i = self.buf.find('\n', self.bufstart)
-        else:
-            self.buf = ''
-            i = -1
-        #
-        if i < 0:
-            self.buf = self.buf[self.bufstart:]
-            self.bufstart = 0
-            while True:
-                bufsize = max(self.bufsize, len(self.buf) >> 2)
-                data = self.do_read(bufsize)
-                if not data:
-                    result = self.buf              # end-of-file reached
-                    self.buf = None
-                    return result
-                startsearch = len(self.buf)   # there is no '\n' in buf so far
-                self.buf += data
-                i = self.buf.find('\n', startsearch)
-                if i >= 0:
-                    break
-        #
-        i += 1
-        result = self.buf[self.bufstart:i]
-        self.bufstart = i
-        return result
-
-    def peek(self):
-        if self.buf is None:
-            return ''
-        if self.bufstart > 0:
-            self.buf = self.buf[self.bufstart:]
-            self.bufstart = 0
-        return self.buf
-
-    def tell(self):
-        pos = self.base.tell()
-        if self.buf is not None:
-            pos -= (len(self.buf) - self.bufstart)
-        return pos
-
-    def readall(self):
-        result = self.base.readall()
-        if self.buf is not None:
-            result = self.buf[self.bufstart:] + result
-            self.buf = None
-            self.bufstart = 0
-        return result
-
-    def read(self, n):
-        if self.buf is None:
-            return self.do_read(n)
-        else:
-            m = n - (len(self.buf) - self.bufstart)
-            start = self.bufstart
-            if m > 0:
-                result = self.buf[start:] + self.do_read(m)
-                self.buf = None
-                self.bufstart = 0
-                return result
-            elif n >= 0:
-                self.bufstart = start + n
-                return self.buf[start : self.bufstart]
-            else:
-                return ''
-
-    seek       = PassThrough("seek",      flush_buffers=True)
-    write      = PassThrough("write",     flush_buffers=True)
-    truncate   = PassThrough("truncate",  flush_buffers=True)
-    flush      = PassThrough("flush",     flush_buffers=True)
-    flushable  = PassThrough("flushable", flush_buffers=False)
-    close      = PassThrough("close",     flush_buffers=False)
-    try_to_find_file_descriptor = PassThrough("try_to_find_file_descriptor",
-                                              flush_buffers=False)
-
-
 class BufferingOutputStream(Stream):
 
     """Standard buffering output stream.
diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -396,6 +396,14 @@
             v = two.pow(t, rbigint.fromint(n))
             assert v.toint() == pow(2, t.tolong(), n)
 
+    def test_pow_lll_bug2(self):
+        x = rbigint.fromlong(2)
+        y = 
rbigint.fromlong(5100894665148900058249470019412564146962964987365857466751243988156579407594163282788332839328303748028644825680244165072186950517295679131100799612871613064597)
+        z = rbigint.fromlong(538564)
+        expected = rbigint.fromlong(163464)
+        got = x.pow(y, z)
+        assert got.eq(expected)
+
     def test_pow_lln(self):
         x = 10L
         y = 2L
diff --git a/pypy/rlib/test/test_streamio.py b/pypy/rlib/test/test_streamio.py
--- a/pypy/rlib/test/test_streamio.py
+++ b/pypy/rlib/test/test_streamio.py
@@ -1026,7 +1026,7 @@
             base.tell = f
         if not seek:
             base.seek = f
-        return streamio.ReadlineInputStream(base, bufsize)
+        return base
 
     def test_readline(self):
         for file in [self.makeStream(), self.makeStream(bufsize=2)]:
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -545,7 +545,7 @@
                     localpath = py.path.local(g.filename)
                     pypkgpath = localpath.pypkgpath()
                     if pypkgpath:
-                        relpypath =  localpath.relto(pypkgpath)
+                        relpypath = localpath.relto(pypkgpath.dirname)
                         return relpypath.replace('.py', '.c')
             return None
         if hasattr(node.obj, 'graph'):
diff --git a/pypy/translator/c/test/test_dlltool.py 
b/pypy/translator/c/test/test_dlltool.py
--- a/pypy/translator/c/test/test_dlltool.py
+++ b/pypy/translator/c/test/test_dlltool.py
@@ -28,4 +28,4 @@
         d = DLLDef('lib', [(f, [int]), (b, [int])])
         so = d.compile()
         dirpath = py.path.local(so).dirpath()
-        assert dirpath.join('translator_c_test_test_dlltool.c').check()
+        assert dirpath.join('pypy_translator_c_test_test_dlltool.c').check()
diff --git a/pypy/translator/c/test/test_standalone.py 
b/pypy/translator/c/test/test_standalone.py
--- a/pypy/translator/c/test/test_standalone.py
+++ b/pypy/translator/c/test/test_standalone.py
@@ -57,9 +57,9 @@
 
         # Verify that the generated C files have sane names:
         gen_c_files = [str(f) for f in cbuilder.extrafiles]
-        for expfile in ('rlib_rposix.c', 
-                        'rpython_lltypesystem_rstr.c',
-                        'translator_c_test_test_standalone.c'):
+        for expfile in ('pypy_rlib_rposix.c',
+                        'pypy_rpython_lltypesystem_rstr.c',
+                        'pypy_translator_c_test_test_standalone.c'):
             assert cbuilder.targetdir.join(expfile) in gen_c_files
 
     def test_print(self):
diff --git a/pypy/translator/platform/__init__.py 
b/pypy/translator/platform/__init__.py
--- a/pypy/translator/platform/__init__.py
+++ b/pypy/translator/platform/__init__.py
@@ -240,12 +240,15 @@
 
 
 if sys.platform.startswith('linux'):
-    from pypy.translator.platform.linux import Linux, Linux64
+    from pypy.translator.platform.linux import Linux, LinuxPIC
     import platform
-    if platform.architecture()[0] == '32bit':
+    # Only required on armhf and mips{,el}, not armel. But there's no way to
+    # detect armhf without shelling out
+    if (platform.architecture()[0] == '64bit'
+            or platform.machine().startswith(('arm', 'mips'))):
+        host_factory = LinuxPIC
+    else:
         host_factory = Linux
-    else:
-        host_factory = Linux64
 elif sys.platform == 'darwin':
     from pypy.translator.platform.darwin import Darwin_i386, Darwin_x86_64, 
Darwin_PowerPC
     import platform
@@ -257,6 +260,13 @@
         host_factory = Darwin_i386
     else:
         host_factory = Darwin_x86_64
+elif "gnukfreebsd" in sys.platform:
+    from pypy.translator.platform.freebsd import GNUkFreebsd, GNUkFreebsd_64
+    import platform
+    if platform.architecture()[0] == '32bit':
+        host_factory = GNUkFreebsd
+    else:
+        host_factory = GNUkFreebsd_64
 elif "freebsd" in sys.platform:
     from pypy.translator.platform.freebsd import Freebsd, Freebsd_64
     import platform
diff --git a/pypy/translator/platform/freebsd.py 
b/pypy/translator/platform/freebsd.py
--- a/pypy/translator/platform/freebsd.py
+++ b/pypy/translator/platform/freebsd.py
@@ -52,3 +52,9 @@
 
 class Freebsd_64(Freebsd):
     shared_only = ('-fPIC',)
+
+class GNUkFreebsd(Freebsd):
+    extra_libs = ('-lrt',)
+
+class GNUkFreebsd_64(Freebsd_64):
+    extra_libs = ('-lrt',)
diff --git a/pypy/translator/platform/linux.py 
b/pypy/translator/platform/linux.py
--- a/pypy/translator/platform/linux.py
+++ b/pypy/translator/platform/linux.py
@@ -48,5 +48,5 @@
         shared_only = () # it seems that on 32-bit linux, compiling with -fPIC
                          # gives assembler that asmgcc is not happy about.
 
-class Linux64(BaseLinux):
+class LinuxPIC(BaseLinux):
     pass
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to