[pypy-commit] pypy py3k: Merge with upstream.

marky1991 pypy.commits at gmail.com
Mon Jun 20 18:16:42 EDT 2016


Author: Mark Young <marky1991 at gmail.com>
Branch: py3k
Changeset: r85272:abc95a8adea5
Date: 2016-05-24 13:04 -0400
http://bitbucket.org/pypy/pypy/changeset/abc95a8adea5/

Log:	Merge with upstream.

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -18,6 +18,8 @@
     "exceptions", "_io", "sys", "builtins", "posix", "_warnings",
     "itertools", "_frozen_importlib",
 ])
+if sys.platform == "win32":
+    essential_modules.add("_winreg")
 
 default_modules = essential_modules.copy()
 default_modules.update([
@@ -60,7 +62,6 @@
 # XXX this should move somewhere else, maybe to platform ("is this posixish"
 #     check or something)
 if sys.platform == "win32":
-    working_modules.add("_winreg")
     # unix only modules
     for name in ["crypt", "fcntl", "pwd", "termios", "_minimal_curses",
                  "_posixsubprocess"]:
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -593,9 +593,6 @@
         # lives in pypy/module/exceptions, we rename it below for
         # sys.builtin_module_names
         bootstrap_modules = set(('sys', 'imp', 'builtins', 'exceptions'))
-        if sys.platform.startswith("win"):
-            self.setbuiltinmodule('_winreg')
-            bootstrap_modules.add('_winreg')
         installed_builtin_modules = list(bootstrap_modules)
 
         exception_types_w = self.export_builtin_exceptions()
diff --git a/pypy/module/imp/test/support.py b/pypy/module/imp/test/support.py
--- a/pypy/module/imp/test/support.py
+++ b/pypy/module/imp/test/support.py
@@ -4,8 +4,10 @@
 
     def setup_class(cls):
         space = cls.space
-        cls.w_testfn_unencodable = space.wrap(get_unencodable())
-        cls.w_special_char = space.wrap(get_special_char())
+        cls.testfn_unencodable = get_unencodable()
+        cls.w_testfn_unencodable = space.wrap(cls.testfn_unencodable)
+        cls.special_char = get_special_char()
+        cls.w_special_char = space.wrap(cls.special_char)
 
 def get_unencodable():
     """Copy of the stdlib's support.TESTFN_UNENCODABLE:
diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -133,10 +133,9 @@
              line2 = "# encoding: iso-8859-1\n",
              bad = "# encoding: uft-8\n")
 
-    w_special_char = getattr(cls, 'w_special_char', None)
-    if not space.is_none(w_special_char):
-        special_char = space.unicode_w(w_special_char).encode(
-            sys.getfilesystemencoding())
+    special_char = cls.special_char
+    if special_char is not None:
+        special_char = special_char.encode(sys.getfilesystemencoding())
         p.join(special_char + '.py').write('pass')
 
     # create a .pyw file
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -166,7 +166,8 @@
 def path_or_fd(allow_fd=True):
     return _PathOrFd if allow_fd else _JustPath
 
-DEFAULT_DIR_FD = getattr(rposix, 'AT_FDCWD', -100)
+_HAVE_AT_FDCWD = getattr(rposix, 'AT_FDCWD', None) is not None
+DEFAULT_DIR_FD = rposix.AT_FDCWD if _HAVE_AT_FDCWD else -100
 DIR_FD_AVAILABLE = False
 
 @specialize.arg(2)
@@ -222,11 +223,11 @@
 dir_fd may not be implemented on your platform.
   If it is unavailable, using it will raise a NotImplementedError."""
     try:
-        if dir_fd == DEFAULT_DIR_FD:
-            fd = dispatch_filename(rposix.open)(space, w_path, flags, mode)
-        else:
+        if rposix.HAVE_OPENAT and dir_fd != DEFAULT_DIR_FD:
             path = space.fsencode_w(w_path)
             fd = rposix.openat(path, flags, mode, dir_fd)
+        else:
+            fd = dispatch_filename(rposix.open)(space, w_path, flags, mode)
     except OSError as e:
         raise wrap_oserror2(space, e, w_path)
     return space.wrap(fd)
@@ -555,7 +556,7 @@
     dir_fd=DirFD(rposix.HAVE_FACCESSAT), effective_ids=kwonly(bool),
     follow_symlinks=kwonly(bool))
 def access(space, w_path, mode,
-        dir_fd=DEFAULT_DIR_FD, effective_ids=True, follow_symlinks=True):
+        dir_fd=DEFAULT_DIR_FD, effective_ids=False, follow_symlinks=True):
     """\
 access(path, mode, *, dir_fd=None, effective_ids=False, follow_symlinks=True)
 
@@ -585,12 +586,14 @@
             raise argument_unavailable(space, "access", "effective_ids")
 
     try:
-        if dir_fd == DEFAULT_DIR_FD and follow_symlinks and not effective_ids:
-            ok = dispatch_filename(rposix.access)(space, w_path, mode)
-        else:
+        if (rposix.HAVE_FACCESSAT and
+            (dir_fd != DEFAULT_DIR_FD or not follow_symlinks or
+             effective_ids)):
             path = space.fsencode_w(w_path)
             ok = rposix.faccessat(path, mode,
                 dir_fd, effective_ids, follow_symlinks)
+        else:
+            ok = dispatch_filename(rposix.access)(space, w_path, mode)
     except OSError as e:
         raise wrap_oserror2(space, e, w_path)
     else:
@@ -635,11 +638,11 @@
 dir_fd may not be implemented on your platform.
   If it is unavailable, using it will raise a NotImplementedError."""
     try:
-        if dir_fd == DEFAULT_DIR_FD:
-            dispatch_filename(rposix.unlink)(space, w_path)
-        else:
+        if rposix.HAVE_UNLINKAT and dir_fd != DEFAULT_DIR_FD:
             path = space.fsencode_w(w_path)
             rposix.unlinkat(path, dir_fd, removedir=False)
+        else:
+            dispatch_filename(rposix.unlink)(space, w_path)
     except OSError as e:
         raise wrap_oserror2(space, e, w_path)
 
@@ -654,11 +657,11 @@
 dir_fd may not be implemented on your platform.
   If it is unavailable, using it will raise a NotImplementedError."""
     try:
-        if dir_fd == DEFAULT_DIR_FD:
-            dispatch_filename(rposix.unlink)(space, w_path)
-        else:
+        if rposix.HAVE_UNLINKAT and dir_fd != DEFAULT_DIR_FD:
             path = space.fsencode_w(w_path)
             rposix.unlinkat(path, dir_fd, removedir=False)
+        else:
+            dispatch_filename(rposix.unlink)(space, w_path)
     except OSError as e:
         raise wrap_oserror2(space, e, w_path)
 
@@ -721,11 +724,11 @@
 
 The mode argument is ignored on Windows."""
     try:
-        if dir_fd == DEFAULT_DIR_FD:
-            dispatch_filename(rposix.mkdir)(space, w_path, mode)
-        else:
+        if rposix.HAVE_MKDIRAT and dir_fd != DEFAULT_DIR_FD:
             path = space.fsencode_w(w_path)
             rposix.mkdirat(path, mode, dir_fd)
+        else:
+            dispatch_filename(rposix.mkdir)(space, w_path, mode)
     except OSError as e:
         raise wrap_oserror2(space, e, w_path)
 
@@ -740,11 +743,11 @@
 dir_fd may not be implemented on your platform.
   If it is unavailable, using it will raise a NotImplementedError."""
     try:
-        if dir_fd == DEFAULT_DIR_FD:
-            dispatch_filename(rposix.rmdir)(space, w_path)
-        else:
+        if rposix.HAVE_UNLINKAT and dir_fd != DEFAULT_DIR_FD:
             path = space.fsencode_w(w_path)
             rposix.unlinkat(path, dir_fd, removedir=True)
+        else:
+            dispatch_filename(rposix.rmdir)(space, w_path)
     except OSError as e:
         raise wrap_oserror2(space, e, w_path)
 
@@ -976,7 +979,8 @@
 src_dir_fd and dst_dir_fd, may not be implemented on your platform.
   If they are unavailable, using them will raise a NotImplementedError."""
     try:
-        if (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD):
+        if (rposix.HAVE_RENAMEAT and
+            (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD)):
             src = space.fsencode_w(w_src)
             dst = space.fsencode_w(w_dst)
             rposix.renameat(src, dst, src_dir_fd, dst_dir_fd)
@@ -999,7 +1003,8 @@
 src_dir_fd and dst_dir_fd, may not be implemented on your platform.
   If they are unavailable, using them will raise a NotImplementedError."""
     try:
-        if (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD):
+        if (rposix.HAVE_RENAMEAT and
+            (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD)):
             src = space.fsencode_w(w_src)
             dst = space.fsencode_w(w_dst)
             rposix.renameat(src, dst, src_dir_fd, dst_dir_fd)
@@ -1110,8 +1115,9 @@
   platform.  If they are unavailable, using them will raise a
   NotImplementedError."""
     try:
-        if (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD
-                or not follow_symlinks):
+        if (rposix.HAVE_LINKAT and
+            (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD
+             or not follow_symlinks)):
             rposix.linkat(src, dst, src_dir_fd, dst_dir_fd, follow_symlinks)
         else:
             rposix.link(src, dst)
@@ -1442,31 +1448,32 @@
             # see comment above
             raise wrap_oserror(space, e)
 
+    if (rposix.HAVE_LUTIMES and
+        (dir_fd == DEFAULT_DIR_FD and not follow_symlinks)):
+        path_b = path.as_bytes
+        if path_b is None:
+            raise oefmt(space.w_NotImplementedError,
+                        "utime: unsupported value for 'path'")
+        try:
+            if now:
+                rposix.lutimes(path_b, None)
+            else:
+                rposix.lutimes(path_b, (atime_s, atime_ns))
+            return
+        except OSError as e:
+            # see comment above
+            raise wrap_oserror(space, e)
+
+    # XXX: missing utime_dir_fd support
+
     if not follow_symlinks:
         raise argument_unavailable(space, "utime", "follow_symlinks")
 
-    if not space.is_w(w_ns, space.w_None):
-        raise oefmt(space.w_NotImplementedError,
-            "utime: 'ns' unsupported on this platform on PyPy")
-    if now:
-        try:
+    try:
+        if now:
             call_rposix(utime_now, path, None)
-        except OSError as e:
-            # see comment above
-            raise wrap_oserror(space, e)
-    try:
-        msg = "utime() arg 2 must be a tuple (atime, mtime) or None"
-        args_w = space.fixedview(w_times)
-        if len(args_w) != 2:
-            raise oefmt(space.w_TypeError, msg)
-        actime = space.float_w(args_w[0], allow_conversion=False)
-        modtime = space.float_w(args_w[1], allow_conversion=False)
-    except OperationError as e:
-        if not e.match(space, space.w_TypeError):
-            raise
-        raise oefmt(space.w_TypeError, msg)
-    try:
-        call_rposix(rposix.utime, path, (actime, modtime))
+        else:
+            call_rposix(rposix.utime, path, (atime_s, mtime_s))
     except OSError as e:
         # see comment above
         raise wrap_oserror(space, e)
diff --git a/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py b/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py
--- a/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py
+++ b/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py
@@ -1,4 +1,4 @@
-import os, random, struct
+import sys, os, random, struct
 import py
 from rpython.jit.backend.x86 import rx86
 from rpython.rlib.rarithmetic import intmask
@@ -257,6 +257,9 @@
         g.close()
         error = [line for line in got.splitlines() if 'error' in line.lower()]
         if error:
+            if (sys.maxint <= 2**32 and
+                    'no compiled in support for x86_64' in error[0]):
+                py.test.skip(error)
             raise Exception("Assembler got an error: %r" % error[0])
         error = [line for line in got.splitlines()
                  if 'warning' in line.lower()]
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -1219,21 +1219,14 @@
         if times is None:
             error = c_utime(path, lltype.nullptr(UTIMBUFP.TO))
         else:
-            actime, modtime = times
             if HAVE_UTIMES:
-                import math
-                l_times = lltype.malloc(TIMEVAL2P.TO, 2, flavor='raw')
-                fracpart, intpart = math.modf(actime)
-                rffi.setintfield(l_times[0], 'c_tv_sec', int(intpart))
-                rffi.setintfield(l_times[0], 'c_tv_usec', int(fracpart * 1e6))
-                fracpart, intpart = math.modf(modtime)
-                rffi.setintfield(l_times[1], 'c_tv_sec', int(intpart))
-                rffi.setintfield(l_times[1], 'c_tv_usec', int(fracpart * 1e6))
-                error = c_utimes(path, l_times)
-                lltype.free(l_times, flavor='raw')
+                with lltype.scoped_alloc(TIMEVAL2P.TO, 2) as l_timeval2p:
+                    times_to_timeval2p(times, l_timeval2p)
+                    error = c_utimes(path, l_timeval2p)
             else:
                 # we only have utime(), which does not allow
                 # sub-second resolution
+                actime, modtime = times
                 l_utimbuf = lltype.malloc(UTIMBUFP.TO, flavor='raw')
                 l_utimbuf.c_actime  = rffi.r_time_t(actime)
                 l_utimbuf.c_modtime = rffi.r_time_t(modtime)
@@ -1276,6 +1269,17 @@
             lltype.free(atime, flavor='raw')
             lltype.free(mtime, flavor='raw')
 
+def times_to_timeval2p(times, l_timeval2p):
+    actime, modtime = times
+    _time_to_timeval(actime, l_timeval2p[0])
+    _time_to_timeval(modtime, l_timeval2p[1])
+
+def _time_to_timeval(t, l_timeval):
+    import math
+    fracpart, intpart = math.modf(t)
+    rffi.setintfield(l_timeval, 'c_tv_sec', int(intpart))
+    rffi.setintfield(l_timeval, 'c_tv_usec', int(fracpart * 1e6))
+
 if not _WIN32:
     TMSP = lltype.Ptr(TMS)
     c_times = external('times', [TMSP], CLOCK_T,
@@ -1763,6 +1767,7 @@
 class CConfig:
     _compilation_info_ = ExternalCompilationInfo(
         includes=['sys/stat.h',
+                  'sys/time.h',
                   'unistd.h',
                   'fcntl.h'],
     )
@@ -1918,6 +1923,21 @@
         lltype.free(l_times, flavor='raw')
         handle_posix_error('utimensat', error)
 
+if HAVE_LUTIMES:
+    c_lutimes = external('lutimes',
+        [rffi.CCHARP, TIMEVAL2P], rffi.INT,
+        save_err=rffi.RFFI_SAVE_ERRNO)
+
+    @specialize.argtype(1)
+    def lutimes(pathname, times):
+        if times is None:
+            error = c_lutimes(pathname, lltype.nullptr(TIMEVAL2P.TO))
+        else:
+            with lltype.scoped_alloc(TIMEVAL2P.TO, 2) as l_timeval2p:
+                times_to_timeval2p(times, l_timeval2p)
+                error = c_lutimes(pathname, l_timeval2p)
+        handle_posix_error('lutimes', error)
+
 if HAVE_MKDIRAT:
     c_mkdirat = external('mkdirat',
         [rffi.INT, rffi.CCHARP, rffi.INT], rffi.INT,


More information about the pypy-commit mailing list