[pypy-svn] r79989 - in pypy/branch/more-posix/pypy: rpython/module translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Sat Dec 11 17:33:32 CET 2010
Author: arigo
Date: Sat Dec 11 17:33:30 2010
New Revision: 79989
Modified:
pypy/branch/more-posix/pypy/rpython/module/ll_os.py
pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py
Log:
Translate os.mknod() and os.mkfifo().
Modified: pypy/branch/more-posix/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/more-posix/pypy/rpython/module/ll_os.py (original)
+++ pypy/branch/more-posix/pypy/rpython/module/ll_os.py Sat Dec 11 17:33:30 2010
@@ -99,7 +99,7 @@
return 'll_os.ll_os_w' + name
def registering_str_unicode(posixfunc, condition=True):
- if not condition:
+ if not condition or posixfunc is None:
return registering(None, condition=False)
func_name = posixfunc.__name__
@@ -1323,6 +1323,33 @@
return extdef([traits.str, traits.str], s_None, llimpl=rename_llimpl,
export_name=traits.ll_os_name('rename'))
+ @registering_str_unicode(getattr(os, 'mkfifo', None))
+ def register_os_mkfifo(self, traits):
+ os_mkfifo = self.llexternal(traits.posix_function_name('mkfifo'),
+ [traits.CCHARP, rffi.MODE_T], rffi.INT)
+
+ def mkfifo_llimpl(path, mode):
+ res = rffi.cast(lltype.Signed, os_mkfifo(path, mode))
+ if res < 0:
+ raise OSError(rposix.get_errno(), "os_mkfifo failed")
+
+ return extdef([traits.str, int], s_None, llimpl=mkfifo_llimpl,
+ export_name=traits.ll_os_name('mkfifo'))
+
+ @registering_str_unicode(getattr(os, 'mknod', None))
+ def register_os_mknod(self, traits):
+ os_mknod = self.llexternal(traits.posix_function_name('mknod'),
+ [traits.CCHARP, rffi.MODE_T, rffi.INT],
+ rffi.INT) # xxx: actually ^^^ dev_t
+
+ def mknod_llimpl(path, mode, dev):
+ res = rffi.cast(lltype.Signed, os_mknod(path, mode, dev))
+ if res < 0:
+ raise OSError(rposix.get_errno(), "os_mknod failed")
+
+ return extdef([traits.str, int, int], s_None, llimpl=mknod_llimpl,
+ export_name=traits.ll_os_name('mknod'))
+
@registering(os.umask)
def register_os_umask(self):
os_umask = self.llexternal(underscore_on_windows+'umask', [rffi.MODE_T], rffi.MODE_T)
Modified: pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py (original)
+++ pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py Sat Dec 11 17:33:30 2010
@@ -404,6 +404,28 @@
assert os.path.exists(tmpfile2)
assert not os.path.exists(tmpfile1)
+if hasattr(os, 'mkfifo'):
+ def test_os_mkfifo():
+ tmpfile = str(udir.join('test_os_mkfifo.txt'))
+ def does_stuff():
+ os.mkfifo(tmpfile, 0666)
+ f1 = compile(does_stuff, [])
+ f1()
+ import stat
+ st = os.lstat(tmpfile)
+ assert stat.S_ISFIFO(st.st_mode)
+
+if hasattr(os, 'mknod'):
+ def test_os_mknod():
+ import stat
+ tmpfile = str(udir.join('test_os_mknod.txt'))
+ def does_stuff():
+ os.mknod(tmpfile, 0600 | stat.S_IFIFO, 0)
+ f1 = compile(does_stuff, [])
+ f1()
+ st = os.lstat(tmpfile)
+ assert stat.S_ISFIFO(st.st_mode)
+
def test_os_umask():
def does_stuff():
mask1 = os.umask(0660)
More information about the Pypy-commit
mailing list