[pypy-svn] r45271 - in pypy/dist/pypy/rpython/module: . test
fijal at codespeak.net
fijal at codespeak.net
Mon Jul 23 14:23:32 CEST 2007
Author: fijal
Date: Mon Jul 23 14:23:30 2007
New Revision: 45271
Modified:
pypy/dist/pypy/rpython/module/ll_os.py
pypy/dist/pypy/rpython/module/test/test_posix.py
Log:
A simple factory and getuid implementation (RPython level)
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 Mon Jul 23 14:23:30 2007
@@ -18,6 +18,19 @@
from pypy.rpython.lltypesystem import rffi
from pypy.rpython.lltypesystem import lltype
+# a simple, yet usefull factory
+def register_os_function_returning_int(fun, name, **kwds):
+ c_func = rffi.llexternal(name, [], rffi.INT, **kwds)
+ def c_func_lltypeimpl():
+ res = c_func()
+ if res == -1:
+ raise OSError(rffi.c_errno, "%s failed" % name)
+ return res
+ c_func_lltypeimpl.func_name = name + '_llimpl'
+
+ register_external(fun, [], int, llimpl=c_func_lltypeimpl,
+ export_name='ll_os.ll_os_' + name)
+
# ------------------------------- os.execv ------------------------------
if hasattr(os, 'execv'):
@@ -138,6 +151,14 @@
register_external(os.uname, [], (str, str, str, str, str),
"ll_os.ll_uname", llimpl=uname_lltypeimpl)
+# ------------------------------- os.getuid/geteuid ---------------------
+
+getuid_incl = ['unistd.h', 'sys/types.h']
+register_os_function_returning_int(os.getuid, 'getuid',
+ includes=getuid_incl)
+register_os_function_returning_int(os.geteuid, 'geteuid',
+ includes=getuid_incl)
+
# ------------------------------- os.open -------------------------------
if os.name == 'nt':
Modified: pypy/dist/pypy/rpython/module/test/test_posix.py
==============================================================================
--- pypy/dist/pypy/rpython/module/test/test_posix.py (original)
+++ pypy/dist/pypy/rpython/module/test/test_posix.py Mon Jul 23 14:23:30 2007
@@ -101,11 +101,17 @@
func = self.interpret(f,[fi,6])
assert os.fstat(fi).st_size == 6
+ def test_getuid(self):
+ def f():
+ return os.getuid()
+ assert self.interpret(f, []) == f()
+
if not hasattr(os, 'ftruncate'):
del BaseTestPosix.test_ftruncate
class TestLLtype(BaseTestPosix, LLRtypeMixin):
# XXX segfaulting while run on top of llinterp
+ # XXX but should be there for backends reusing it
if hasattr(os, 'uname'):
def test_os_uname(self):
from pypy.translator.c.test.test_genc import compile
More information about the Pypy-commit
mailing list