Author: Armin Rigo <[email protected]>
Branch: py3k
Changeset: r86375:52ba32002a16
Date: 2016-08-21 18:59 +0200
http://bitbucket.org/pypy/pypy/changeset/52ba32002a16/
Log: hg merge default
diff --git a/pypy/module/_cffi_backend/test/test_re_python.py
b/pypy/module/_cffi_backend/test/test_re_python.py
--- a/pypy/module/_cffi_backend/test/test_re_python.py
+++ b/pypy/module/_cffi_backend/test/test_re_python.py
@@ -69,21 +69,13 @@
sub_ffi.set_source('re_py_subsrc', None)
sub_ffi.emit_python_code(str(tmpdir.join('re_py_subsrc.py')))
#
- cls.w_ffi = space.appexec([space.wrap(str(tmpdir))], """(path):
- import _cffi_backend # force it to be initialized
- import sys
- sys.path.insert(0, path)
- from re_python_pysrc import ffi
- del sys.path[0]
- return ffi
- """)
- cls.w_sub_ffi = space.appexec([space.wrap(str(tmpdir))], """(path):
- import _cffi_backend # force it to be initialized
- import sys
- sys.path.insert(0, path)
- from re_py_subsrc import ffi
- del sys.path[0]
- return ffi
+ cls.w_fix_path = space.appexec([space.wrap(str(tmpdir))], """(path):
+ def fix_path(ignored=None):
+ import _cffi_backend # force it to be initialized
+ import sys
+ if path not in sys.path:
+ sys.path.insert(0, path)
+ return fix_path
""")
def teardown_method(self, meth):
@@ -97,25 +89,29 @@
def test_constant_1(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
assert ffi.integer_const('FOOBAR') == -42
assert ffi.integer_const('FOOBAZ') == -43
def test_large_constant(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
assert ffi.integer_const('BIGPOS') == 420000000000
assert ffi.integer_const('BIGNEG') == -420000000000
def test_function(self):
import _cffi_backend
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
lib = ffi.dlopen(self.extmod)
assert lib.add42(-10) == 32
assert type(lib.add42) is _cffi_backend.FFI.CData
def test_dlclose(self):
import _cffi_backend
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
lib = ffi.dlopen(self.extmod)
ffi.dlclose(lib)
e = raises(ffi.error, ffi.dlclose, lib)
@@ -126,18 +122,21 @@
"library '%s' has been closed" % (self.extmod,))
def test_constant_via_lib(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
lib = ffi.dlopen(self.extmod)
assert lib.FOOBAR == -42
assert lib.FOOBAZ == -43
def test_opaque_struct(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
ffi.cast("struct foo_s *", 0)
raises(TypeError, ffi.new, "struct foo_s *")
def test_nonopaque_struct(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
for p in [ffi.new("struct bar_s *", [5, b"foobar"]),
ffi.new("bar_t *", [5, b"foobar"])]:
assert p.x == 5
@@ -145,13 +144,15 @@
assert p.a[5] == ord('r')
def test_enum(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
assert ffi.integer_const("BB") == 1
e = ffi.cast("enum foo_e", 2)
assert ffi.string(e) == "CC"
def test_include_1(self):
- ffi = self.sub_ffi
+ self.fix_path()
+ from re_py_subsrc import ffi
assert ffi.integer_const('FOOBAR') == -42
assert ffi.integer_const('FOOBAZ') == -43
assert ffi.integer_const('k2') == 121212
@@ -164,7 +165,8 @@
assert p.a[4] == ord('a')
def test_global_var(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
lib = ffi.dlopen(self.extmod)
assert lib.globalvar42 == 1234
p = ffi.addressof(lib, 'globalvar42')
@@ -174,25 +176,29 @@
assert lib.globalvar42 == 1238
def test_global_const_int(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
lib = ffi.dlopen(self.extmod)
assert lib.globalconst42 == 4321
raises(AttributeError, ffi.addressof, lib, 'globalconst42')
def test_global_const_nonint(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
lib = ffi.dlopen(self.extmod)
assert ffi.string(lib.globalconsthello, 8) == b"hello"
raises(AttributeError, ffi.addressof, lib, 'globalconsthello')
def test_rtld_constants(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
ffi.RTLD_NOW # check that we have the attributes
ffi.RTLD_LAZY
ffi.RTLD_GLOBAL
def test_no_such_function_or_global_var(self):
- ffi = self.ffi
+ self.fix_path()
+ from re_python_pysrc import ffi
lib = ffi.dlopen(self.extmod)
e = raises(ffi.error, getattr, lib, 'no_such_function')
assert str(e.value).startswith(
diff --git a/pypy/module/posix/test/test_posix2.py
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -593,6 +593,7 @@
assert os.geteuid() == self.geteuid
if hasattr(os, 'setuid'):
+ @py.test.mark.skipif("sys.version_info < (2, 7, 4)")
def test_os_setuid_error(self):
os = self.posix
raises(OverflowError, os.setuid, -2)
@@ -640,6 +641,7 @@
raises(OSError, os.getpgid, 1234567)
if hasattr(os, 'setgid'):
+ @py.test.mark.skipif("sys.version_info < (2, 7, 4)")
def test_os_setgid_error(self):
os = self.posix
raises(OverflowError, os.setgid, -2)
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -250,6 +250,7 @@
OFF_T_SIZE = rffi_platform.SizeOf('off_t')
HAVE_UTIMES = rffi_platform.Has('utimes')
+ HAVE_D_TYPE = rffi_platform.Has('DT_UNKNOWN')
UTIMBUF = rffi_platform.Struct('struct %sutimbuf' % UNDERSCORE_ON_WIN32,
[('actime', rffi.INT),
('modtime', rffi.INT)])
@@ -603,11 +604,17 @@
class CConfig:
_compilation_info_ = eci
DIRENT = rffi_platform.Struct('struct dirent',
- [('d_name', lltype.FixedSizeArray(rffi.CHAR, 1))])
+ [('d_name', lltype.FixedSizeArray(rffi.CHAR, 1))]
+ + [('d_type', rffi.INT)] if HAVE_D_TYPE else [])
+ if HAVE_D_TYPE:
+ DT_UNKNOWN = rffi_platform.ConstantInteger('DT_UNKNOWN')
+ DT_REG = rffi_platform.ConstantInteger('DT_REG')
+ DT_DIR = rffi_platform.ConstantInteger('DT_DIR')
+ DT_LNK = rffi_platform.ConstantInteger('DT_LNK')
DIRP = rffi.COpaquePtr('DIR')
- config = rffi_platform.configure(CConfig)
- DIRENT = config['DIRENT']
+ dirent_config = rffi_platform.configure(CConfig)
+ DIRENT = dirent_config['DIRENT']
DIRENTP = lltype.Ptr(DIRENT)
c_opendir = external('opendir',
[rffi.CCHARP], DIRP, save_err=rffi.RFFI_SAVE_ERRNO)
@@ -617,7 +624,9 @@
# dirent struct (which depends on defines)
c_readdir = external('readdir', [DIRP], DIRENTP,
macro=True, save_err=rffi.RFFI_FULL_ERRNO_ZERO)
- c_closedir = external('closedir', [DIRP], rffi.INT)
+ c_closedir = external('closedir', [DIRP], rffi.INT, releasegil=False)
+else:
+ dirent_config = {}
def _listdir(dirp):
result = []
diff --git a/rpython/rlib/rposix_scandir.py b/rpython/rlib/rposix_scandir.py
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/rposix_scandir.py
@@ -0,0 +1,59 @@
+from rpython.rlib import rposix
+from rpython.rlib.objectmodel import specialize
+from rpython.rtyper.lltypesystem import rffi
+
+
[email protected](0)
+def opendir(path):
+ path = rposix._as_bytes0(path)
+ return opendir_bytes(path)
+
+def opendir_bytes(path):
+ dirp = rposix.c_opendir(path)
+ if not dirp:
+ raise OSError(rposix.get_saved_errno(), "opendir failed")
+ return dirp
+
+def closedir(dirp):
+ rposix.c_closedir(dirp)
+
+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.
+ """
+ direntp = rposix.c_readdir(dirp)
+ if direntp:
+ return direntp
+ error = rposix.get_saved_errno()
+ if error:
+ raise OSError(error, "readdir failed")
+ raise StopIteration
+
+def has_name_bytes(direntp):
+ return True
+
+def get_name_bytes(direntp):
+ 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)
+
+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
diff --git a/rpython/rlib/test/test_rposix_scandir.py
b/rpython/rlib/test/test_rposix_scandir.py
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/test/test_rposix_scandir.py
@@ -0,0 +1,22 @@
+import sys, os
+import py
+from rpython.rlib import rposix_scandir
+
+
+class TestScanDir(object):
+
+ @py.test.mark.skipif("sys.platform == 'win32'") # XXX
+ def test_name_bytes(self):
+ scan = rposix_scandir.opendir('/')
+ found = []
+ while True:
+ try:
+ p = rposix_scandir.nextentry(scan)
+ except StopIteration:
+ break
+ assert rposix_scandir.has_name_bytes(p)
+ found.append(rposix_scandir.get_name_bytes(p))
+ rposix_scandir.closedir(scan)
+ found.remove('.')
+ found.remove('..')
+ assert sorted(found) == sorted(os.listdir('/'))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit