Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r90563:e26d7faea9bc
Date: 2017-03-05 12:22 +0100
http://bitbucket.org/pypy/pypy/changeset/e26d7faea9bc/
Log: hg merge default
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
@@ -182,3 +182,14 @@
Improve handling of the Py3-style buffer slots in cpyext: fix memoryviews
keeping objects alive forever (missing decref), and make sure that
bf_releasebuffer is called when it should, e.g. from PyBuffer_Release.
+
+.. branch: fix-global
+
+Fix bug (bad reported info) when asked to translate SyntaxWarning to
+SyntaxError.
+
+.. branch: optinfo-into-bridges-3
+
+Improve the optimization of branchy Python code by retaining more
+information across failing guards. This is done by appending some
+carefully encoded extra information into the resume code.
diff --git a/pypy/module/_io/interp_bufferedio.py
b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -15,7 +15,7 @@
W_IOBase, DEFAULT_BUFFER_SIZE, convert_size, trap_eintr,
check_readable_w, check_writable_w, check_seekable_w)
from rpython.rlib import rthread
-from rpython.rlib.rgc import nonmoving_raw_ptr_for_resizable_list
+from rpython.rtyper.lltypesystem import rffi
STATE_ZERO, STATE_OK, STATE_DETACHED = range(3)
@@ -174,7 +174,8 @@
self.buf[index] = char
def get_raw_address(self):
- return nonmoving_raw_ptr_for_resizable_list(self.buf)
+ ptr = nonmoving_raw_ptr_for_resizable_list(self.buf)
+ return rffi.ptradd(ptr, self.start)
class BufferedMixin:
_mixin_ = True
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -1,10 +1,10 @@
from pypy.interpreter.typedef import TypeDef, interp_attrproperty,
GetSetProperty
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.error import (
- OperationError, oefmt, wrap_oserror, wrap_oserror2, exception_from_errno)
+ OperationError, oefmt, wrap_oserror, wrap_oserror2)
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib.rarithmetic import r_longlong
-from rpython.rlib.rposix import get_saved_errno
+from rpython.rlib.rposix import c_read, get_saved_errno
from rpython.rlib.rstring import StringBuilder
from rpython.rlib import rposix
from rpython.rlib.rposix_stat import STAT_FIELD_TYPES
@@ -130,14 +130,6 @@
return currentsize + SMALLCHUNK
-_WIN32 = sys.platform.startswith('win')
-UNDERSCORE_ON_WIN32 = '_' if _WIN32 else ''
-
-os_read = rffi.llexternal(UNDERSCORE_ON_WIN32 + 'read',
- [rffi.INT, rffi.CCHARP, rffi.SIZE_T],
- rffi.SSIZE_T, save_err=rffi.RFFI_SAVE_ERRNO)
-
-
class W_FileIO(W_RawIOBase):
def __init__(self, space):
W_RawIOBase.__init__(self, space)
@@ -485,7 +477,7 @@
# optimized case: reading more than 64 bytes into a rwbuffer
# with a valid raw address
# XXX TODO(mjacob): implement PEP 475 here!
- got = os_read(self.fd, target_address, length)
+ got = c_read(self.fd, target_address, length)
keepalive_until_here(rwbuffer)
got = rffi.cast(lltype.Signed, got)
if got >= 0:
@@ -494,7 +486,8 @@
err = get_saved_errno()
if err == errno.EAGAIN:
return space.w_None
- raise exception_from_errno(space, space.w_IOError, err)
+ e = OSError(err, "read failed")
+ raise wrap_oserror(space, e, exception_name='w_IOError')
def readall_w(self, space):
self._check_closed(space)
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
@@ -12,6 +12,9 @@
tmpfile = udir.join('tmpfile')
tmpfile.write("a\nb\nc", mode='wb')
cls.w_tmpfile = cls.space.wrap(str(tmpfile))
+ bigtmpfile = udir.join('bigtmpfile')
+ bigtmpfile.write("a\nb\nc" * 20, mode='wb')
+ cls.w_bigtmpfile = cls.space.wrap(str(bigtmpfile))
def test_simple_read(self):
import _io
@@ -287,7 +290,21 @@
raises(_io.UnsupportedOperation, bufio.tell)
class AppTestBufferedReaderWithThreads(AppTestBufferedReader):
- spaceconfig = dict(usemodules=['_io', 'thread'])
+ spaceconfig = dict(usemodules=['_io', 'thread', 'time'])
+
+ def test_readinto_small_parts(self):
+ import _io, os, thread, time
+ read_fd, write_fd = os.pipe()
+ raw = _io.FileIO(read_fd)
+ f = _io.BufferedReader(raw)
+ a = bytearray(b'x' * 10)
+ os.write(write_fd, b"abcde")
+ def write_more():
+ time.sleep(0.5)
+ os.write(write_fd, b"fghij")
+ thread.start_new_thread(write_more, ())
+ assert f.readinto(a) == 10
+ assert a == 'abcdefghij'
class AppTestBufferedWriter:
diff --git a/rpython/jit/metainterp/optimizeopt/info.py
b/rpython/jit/metainterp/optimizeopt/info.py
--- a/rpython/jit/metainterp/optimizeopt/info.py
+++ b/rpython/jit/metainterp/optimizeopt/info.py
@@ -773,24 +773,33 @@
from rpython.jit.metainterp.optimizeopt.intutils import ConstIntBound,\
IntLowerBound
- if mode is None:
+ length = self.getstrlen1(mode)
+ if length < 0:
# XXX we can do better if we know it's an array
return IntLowerBound(0)
- else:
- return ConstIntBound(self.getstrlen1(mode))
+ return ConstIntBound(length)
def getstrlen(self, op, string_optimizer, mode):
- return ConstInt(self.getstrlen1(mode))
+ length = self.getstrlen1(mode)
+ if length < 0:
+ return None
+ return ConstInt(length)
def getstrlen1(self, mode):
from rpython.jit.metainterp.optimizeopt import vstring
-
+
if mode is vstring.mode_string:
s = self._unpack_str(vstring.mode_string)
+ if s is None:
+ return -1
+ return len(s)
+ elif mode is vstring.mode_unicode:
+ s = self._unpack_str(vstring.mode_unicode)
+ if s is None:
+ return -1
return len(s)
else:
- s = self._unpack_str(vstring.mode_unicode)
- return len(s)
+ return -1
def getstrhash(self, op, mode):
from rpython.jit.metainterp.optimizeopt import vstring
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -254,6 +254,7 @@
PRIO_PGRP = rffi_platform.DefinedConstantInteger('PRIO_PGRP')
PRIO_USER = rffi_platform.DefinedConstantInteger('PRIO_USER')
O_NONBLOCK = rffi_platform.DefinedConstantInteger('O_NONBLOCK')
+ OFF_T = rffi_platform.SimpleType('off_t')
OFF_T_SIZE = rffi_platform.SizeOf('off_t')
HAVE_UTIMES = rffi_platform.Has('utimes')
@@ -2427,3 +2428,21 @@
def set_status_flags(fd, flags):
res = c_set_status_flags(fd, flags)
handle_posix_error('set_status_flags', res)
+
+if not _WIN32:
+ sendfile_eci = ExternalCompilationInfo(includes=["sys/sendfile.h"])
+ _OFF_PTR_T = rffi.CArrayPtr(OFF_T)
+ c_sendfile = rffi.llexternal('sendfile',
+ [rffi.INT, rffi.INT, _OFF_PTR_T, rffi.SIZE_T],
+ rffi.SSIZE_T, compilation_info=sendfile_eci)
+
+ def sendfile(out_fd, in_fd, offset, count):
+ with lltype.scoped_alloc(_OFF_PTR_T.TO, 1) as p_offset:
+ p_offset[0] = rffi.cast(OFF_T, offset)
+ res = c_sendfile(out_fd, in_fd, p_offset, count)
+ return handle_posix_error('sendfile', res)
+
+ def sendfile_no_offset(out_fd, in_fd, count):
+ """Passes offset==NULL; not support on all OSes"""
+ res = c_sendfile(out_fd, in_fd, lltype.nullptr(_OFF_PTR_T.TO), count)
+ return handle_posix_error('sendfile', res)
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
@@ -676,3 +676,36 @@
prio = rposix.getpriority(rposix.PRIO_PROCESS, 0)
rposix.setpriority(rposix.PRIO_PROCESS, 0, prio)
py.test.raises(OSError, rposix.getpriority, rposix.PRIO_PGRP, 123456789)
+
+if sys.platform != 'win32':
+ def test_sendfile():
+ from rpython.rlib import rsocket
+ s1, s2 = rsocket.socketpair()
+ relpath = 'test_sendfile'
+ filename = str(udir.join(relpath))
+ fd = os.open(filename, os.O_RDWR|os.O_CREAT, 0777)
+ os.write(fd, 'abcdefghij')
+ res = rposix.sendfile(s1.fd, fd, 3, 5)
+ assert res == 5
+ data = os.read(s2.fd, 10)
+ assert data == 'defgh'
+ os.close(fd)
+ s2.close()
+ s1.close()
+
+if sys.platform.startswith('linux'):
+ def test_sendfile_no_offset():
+ from rpython.rlib import rsocket
+ s1, s2 = rsocket.socketpair()
+ relpath = 'test_sendfile'
+ filename = str(udir.join(relpath))
+ fd = os.open(filename, os.O_RDWR|os.O_CREAT, 0777)
+ os.write(fd, 'abcdefghij')
+ os.lseek(fd, 3, 0)
+ res = rposix.sendfile_no_offset(s1.fd, fd, 5)
+ assert res == 5
+ data = os.read(s2.fd, 10)
+ assert data == 'defgh'
+ os.close(fd)
+ s2.close()
+ s1.close()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit