[pypy-svn] r45468 - in pypy/dist/pypy: rpython rpython/module rpython/module/test translator/c translator/c/src
arigo at codespeak.net
arigo at codespeak.net
Thu Aug 2 20:30:05 CEST 2007
Author: arigo
Date: Thu Aug 2 20:30:03 2007
New Revision: 45468
Modified:
pypy/dist/pypy/rpython/extfunctable.py
pypy/dist/pypy/rpython/module/ll_os.py
pypy/dist/pypy/rpython/module/test/test_ll_os.py
pypy/dist/pypy/translator/c/extfunc.py
pypy/dist/pypy/translator/c/src/ll_os.h
Log:
Convert os.access().
Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py (original)
+++ pypy/dist/pypy/rpython/extfunctable.py Thu Aug 2 20:30:03 2007
@@ -179,7 +179,6 @@
# external function declarations
posix = __import__(os.name)
-declare(os.access , int , 'll_os/access')
declare(os.lseek , r_longlong , 'll_os/lseek')
declare(os.isatty , bool , 'll_os/isatty')
if hasattr(posix, 'ftruncate'):
Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py (original)
+++ pypy/dist/pypy/rpython/module/ll_os.py Thu Aug 2 20:30:03 2007
@@ -13,8 +13,8 @@
from pypy.tool.staticmethods import ClassMethods
import stat
from pypy.rpython.extfunc import BaseLazyRegistering, registering
-from pypy.annotation.model import SomeString, SomeInteger, s_ImpossibleValue, \
- s_None
+from pypy.annotation.model import SomeString, SomeInteger
+from pypy.annotation.model import s_ImpossibleValue, s_None, s_Bool
from pypy.rpython.lltypesystem import rffi
from pypy.rpython.lltypesystem.rffi import platform
from pypy.rpython.lltypesystem import lltype
@@ -296,6 +296,26 @@
self.register(os.close, [int], s_None, llimpl=close_lltypeimpl,
export_name="ll_os.ll_os_close", oofakeimpl=os.close)
+ @registering(os.access)
+ def register_os_access(self):
+ os_access = rffi.llexternal('access',
+ [rffi.CCHARP, rffi.INT],
+ rffi.INT)
+
+ def access_lltypeimpl(path, mode):
+ path = rffi.str2charp(path)
+ mode = rffi.cast(rffi.INT, mode)
+ error = rffi.cast(lltype.Signed, os_access(path, mode))
+ rffi.free_charp(path)
+ return error == 0
+
+ def os_access_oofakeimpl(path, mode):
+ return os.access(OOSupport.from_rstr(path), mode)
+
+ self.register(os.access, [str, int], s_Bool, llimpl=access_lltypeimpl,
+ export_name="ll_os.ll_os_access",
+ oofakeimpl=os_access_oofakeimpl)
+
# ------------------------------- os.W* ---------------------------------
w_star = ['WCOREDUMP', 'WIFCONTINUED', 'WIFSTOPPED',
@@ -354,10 +374,6 @@
return cls.to_rstr(os.getcwd())
ll_os_getcwd.suggested_primitive = True
- def ll_os_access(cls, path, mode):
- return os.access(cls.from_rstr(path), mode)
- ll_os_access.suggested_primitive = True
-
def ll_os_lseek(cls, fd,pos,how):
return r_longlong(os.lseek(fd,pos,how))
ll_os_lseek.suggested_primitive = True
Modified: pypy/dist/pypy/rpython/module/test/test_ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/test/test_ll_os.py (original)
+++ pypy/dist/pypy/rpython/module/test/test_ll_os.py Thu Aug 2 20:30:03 2007
@@ -3,19 +3,22 @@
from pypy.tool.pytest.modcheck import skipimporterror
from pypy.translator.c.test.test_genc import compile
+from pypy.rpython import extregistry
from pypy.rpython.lltypesystem.module.ll_os import Implementation as impl
import sys
import py
+def getllimpl(fn):
+ return extregistry.lookup(fn).lltypeimpl
+
def test_access():
filename = str(udir.join('test_access.txt'))
- rsfilename = impl.to_rstr(filename)
-
fd = file(filename, 'w')
fd.close()
for mode in os.R_OK, os.W_OK, os.X_OK, os.R_OK | os.W_OK | os.X_OK:
- assert os.access(filename, mode) == impl.ll_os_access(rsfilename, mode)
+ result = getllimpl(os.access)(filename, mode)
+ assert result == os.access(filename, mode)
def test_getcwd():
Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py (original)
+++ pypy/dist/pypy/translator/c/extfunc.py Thu Aug 2 20:30:03 2007
@@ -23,7 +23,6 @@
# references to functions, so we cannot insert classmethods here.
EXTERNALS = {
- impl.ll_os_access.im_func: 'LL_os_access',
impl.ll_os_stat.im_func: 'LL_os_stat',
impl.ll_os_fstat.im_func: 'LL_os_fstat',
impl.ll_os_lstat.im_func: 'LL_os_lstat',
Modified: pypy/dist/pypy/translator/c/src/ll_os.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_os.h (original)
+++ pypy/dist/pypy/translator/c/src/ll_os.h Thu Aug 2 20:30:03 2007
@@ -51,7 +51,6 @@
/* prototypes */
-int LL_os_access(RPyString *filename, int mode);
RPySTAT_RESULT* _stat_construct_result_helper(STRUCT_STAT st);
RPySTAT_RESULT* LL_os_stat(RPyString * fname);
RPySTAT_RESULT* LL_os_lstat(RPyString * fname);
@@ -99,11 +98,6 @@
#include "ll_osdefs.h"
-int LL_os_access(RPyString *filename, int mode) {
- int n = access(RPyString_AsString(filename), mode);
- return (n == 0);
-}
-
#ifdef LL_NEED_OS_STAT
RPySTAT_RESULT* _stat_construct_result_helper(STRUCT_STAT st) {
More information about the pypy-svn
mailing list