[pypy-commit] pypy py3k: hg merge default

arigo pypy.commits at gmail.com
Sun Aug 21 15:13:13 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3k
Changeset: r86382:6f96b85e2f64
Date: 2016-08-21 21:11 +0200
http://bitbucket.org/pypy/pypy/changeset/6f96b85e2f64/

Log:	hg merge default

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
@@ -862,6 +862,8 @@
     try:
         path = space.fsencode_w(w_path)
     except OperationError as operr:
+        if operr.async(space):
+            raise
         if not rposix.HAVE_FDOPENDIR:
             raise oefmt(space.w_TypeError,
                 "listdir: illegal type for path argument")
diff --git a/rpython/rlib/rposix_scandir.py b/rpython/rlib/rposix_scandir.py
--- a/rpython/rlib/rposix_scandir.py
+++ b/rpython/rlib/rposix_scandir.py
@@ -1,6 +1,6 @@
 from rpython.rlib import rposix
 from rpython.rlib.objectmodel import specialize
-from rpython.rtyper.lltypesystem import rffi
+from rpython.rtyper.lltypesystem import lltype, rffi
 
 
 @specialize.argtype(0)
@@ -17,21 +17,22 @@
 def closedir(dirp):
     rposix.c_closedir(dirp)
 
+NULL_DIRP = lltype.nullptr(rposix.DIRENT)
+
 def nextentry(dirp):
     """Read the next entry and returns an opaque object.
     Use the methods has_xxx() and get_xxx() to read from that
     opaque object.  The opaque object is valid until the next
     time nextentry() or closedir() is called.  This may raise
-    StopIteration, or OSError.  Note that this doesn't filter
-    out the "." and ".." entries.
+    OSError, or return a NULL pointer when exhausted.  Note
+    that this doesn't filter out the "." and ".." entries.
     """
     direntp = rposix.c_readdir(dirp)
     if direntp:
-        return direntp
-    error = rposix.get_saved_errno()
-    if error:
-        raise OSError(error, "readdir failed")
-    raise StopIteration
+        error = rposix.get_saved_errno()
+        if error:
+            raise OSError(error, "readdir failed")
+    return direntp
 
 def has_name_bytes(direntp):
     return True
@@ -40,20 +41,12 @@
     namep = rffi.cast(rffi.CCHARP, direntp.c_d_name)
     return rffi.charp2str(namep)
 
-DT_UNKNOWN = rposix.dirent_config.get('DT_UNKNOWN', None)
-DT_REG = rposix.dirent_config.get('DT_REG', None)
-DT_DIR = rposix.dirent_config.get('DT_DIR', None)
-DT_LNK = rposix.dirent_config.get('DT_LNK', None)
+DT_UNKNOWN = rposix.dirent_config.get('DT_UNKNOWN', 0)
+DT_REG = rposix.dirent_config.get('DT_REG', -1)
+DT_DIR = rposix.dirent_config.get('DT_DIR', -1)
+DT_LNK = rposix.dirent_config.get('DT_LNK', -1)
 
-def has_type(direntp):
-    return (DT_UNKNOWN is not None and
-            rffi.getintfield(direntp, 'c_d_type') != DT_UNKNOWN)
-
-def type_is_regular(direntp):
-    return rffi.getintfield(direntp, 'c_d_type') == DT_REG
-
-def type_is_dir(direntp):
-    return rffi.getintfield(direntp, 'c_d_type') == DT_DIR
-
-def type_is_link(direntp):
-    return rffi.getintfield(direntp, 'c_d_type') == DT_LNK
+def get_known_type(direntp):
+    if rposix.HAVE_D_TYPE:
+        return rffi.getintfield(direntp, 'c_d_type')
+    return DT_UNKNOWN
diff --git a/rpython/rlib/test/test_rposix_scandir.py b/rpython/rlib/test/test_rposix_scandir.py
--- a/rpython/rlib/test/test_rposix_scandir.py
+++ b/rpython/rlib/test/test_rposix_scandir.py
@@ -10,9 +10,8 @@
         scan = rposix_scandir.opendir('/')
         found = []
         while True:
-            try:
-                p = rposix_scandir.nextentry(scan)
-            except StopIteration:
+            p = rposix_scandir.nextentry(scan)
+            if not p:
                 break
             assert rposix_scandir.has_name_bytes(p)
             found.append(rposix_scandir.get_name_bytes(p))


More information about the pypy-commit mailing list