Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3.3 Changeset: r74925:e563bf673157 Date: 2014-11-01 12:01 +0100 http://bitbucket.org/pypy/pypy/changeset/e563bf673157/
Log: Start to define posix._have_functions diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py --- a/pypy/module/posix/__init__.py +++ b/pypy/module/posix/__init__.py @@ -188,7 +188,8 @@ # os.py uses this list to build os.supports_dir_fd() and os.supports_fd(). # Fill with e.g. HAVE_FCHDIR, when os.chdir() supports file descriptors. - interpleveldefs['_have_functions'] = 'space.newlist([])' + interpleveldefs['_have_functions'] = ( + 'space.newlist([space.wrap(x) for x in interp_posix.have_functions])') def startup(self, space): from pypy.module.posix import interp_posix 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 @@ -1436,3 +1436,8 @@ except OSError as e: raise wrap_oserror2(space, e, w_path) return space.wrap(result) + +have_functions = [] +for name in """FSTAT FCHDIR OPENAT""".split(): + if getattr(rposix, "HAVE_%s" % name): + have_functions.append("HAVE_%s" % name) 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 @@ -1248,3 +1248,16 @@ f.write(source) child = self.spawn([str(f)]) child.expect('ok!') + + +class AppTestFdVariants: + # Tests variant functions which also accept file descriptors, + # dir_fd and follow_symlinks. + def test_have_functions(self): + import os + assert os.stat in os.supports_fd # fstat() is supported everywhere + if os.name != 'nt': + assert os.chdir in os.supports_fd # fchdir() + if os.name == 'posix': + assert os.open in os.supports_dir_fd # openat() + diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -1,5 +1,6 @@ import os from rpython.rtyper.lltypesystem.rffi import CConstant, CExternVariable, INT +from rpython.rtyper.tool import rffi_platform from rpython.rtyper.lltypesystem import ll2ctypes, rffi from rpython.translator.tool.cbuild import ExternalCompilationInfo from rpython.rlib.rarithmetic import intmask @@ -8,6 +9,19 @@ from rpython.translator.platform import platform +class CConfig: + _compilation_info_ = ExternalCompilationInfo( + includes=['sys/stat.h', + 'unistd.h', + 'fcntl.h'], + ) + HAVE_FSTAT = rffi_platform.Has('fstat') + HAVE_FCHDIR = rffi_platform.Has('fchdir') + HAVE_OPENAT = rffi_platform.Has('openat') +cConfig = rffi_platform.configure(CConfig) +globals().update(cConfig) + + class CConstantErrno(CConstant): # these accessors are used when calling get_errno() or set_errno() # on top of CPython _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit