[pypy-svn] r44644 - in pypy/dist/pypy/rpython/module: . test
fijal at codespeak.net
fijal at codespeak.net
Sat Jun 30 13:16:49 CEST 2007
Author: fijal
Date: Sat Jun 30 13:16:49 2007
New Revision: 44644
Modified:
pypy/dist/pypy/rpython/module/ll_os.py
pypy/dist/pypy/rpython/module/test/test_ll_os.py
Log:
add os.w_*, 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 Sat Jun 30 13:16:49 2007
@@ -136,22 +136,43 @@
register_external(os.open, [str, int, int], int, "ll_os.ll_os_open",
llimpl=os_open_lltypeimpl, oofakeimpl=os_open_oofakeimpl)
-# ------------------------------- os.WIFSIGNALED ------------------------
-# XXX this needs to be generated automatically for all os.W*
+# ------------------------------- os.* ----------------------------------
-if hasattr(os, 'WIFSIGNALED'):
- def fake_WIFSIGNALED(status):
- return int(os.WIFSIGNALED(status))
-
- os_WIFSIGNALED = rffi.llexternal('WIFSIGNALED', [lltype.Signed],
- lltype.Signed,
- _callable=fake_WIFSIGNALED)
-
- def WIFSIGNALED_lltypeimpl(status):
- return bool(os_WIFSIGNALED(status))
-
- register_external(os.WIFSIGNALED, [int], bool, "ll_os.WIFSIGNALED",
- llimpl=WIFSIGNALED_lltypeimpl)
+w_star = ['WCOREDUMP', 'WIFCONTINUED', 'WIFSTOPPED',
+ 'WIFSIGNALED', 'WIFEXITED', 'WEXITSTATUS',
+ 'WSTOPSIG', 'WTERMSIG']
+# last 3 are returning int
+w_star_returning_int = dict.fromkeys(w_star[-3:])
+
+def declare_new_w_star(name):
+ """ stupid workaround for the python late-binding
+ 'feature'
+ """
+ def fake(status):
+ return int(getattr(os, name)(status))
+ fake.func_name = 'fake_' + name
+
+ os_c_func = rffi.llexternal(name, [lltype.Signed],
+ lltype.Signed,
+ _callable=fake,
+ includes=["sys/wait.h", "sys/types.h"])
+
+ if name in w_star_returning_int:
+ def lltypeimpl(status):
+ return os_c_func(status)
+ resulttype = int
+ else:
+ def lltypeimpl(status):
+ return bool(os_c_func(status))
+ resulttype = bool
+ lltypeimpl.func_name = name + '_lltypeimpl'
+ register_external(getattr(os, name), [int], resulttype, "ll_os."+name,
+ llimpl=lltypeimpl)
+
+
+for name in w_star:
+ if hasattr(os, name):
+ declare_new_w_star(name)
# ------------------------------- os.ttyname ----------------------------
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 Sat Jun 30 13:16:49 2007
@@ -102,13 +102,15 @@
compared_with.sort()
assert result == compared_with
-def test_os_wifsignaled():
- def fun(s):
- return os.WIFSIGNALED(s)
+def test_os_wstar():
+ from pypy.rpython.module.ll_os import w_star
+ for name in w_star:
+ def fun(s):
+ return getattr(os, name)(s)
- fn = compile(fun, [int])
- assert fn(0) == False
- assert fn(1) == True
+ fn = compile(fun, [int])
+ for value in [0, 1, 127, 128, 255]:
+ assert fn(value) == fun(value)
class ExpectTestOs:
def setup_class(cls):
More information about the Pypy-commit
mailing list