[pypy-svn] r43789 - in pypy/branch/kill-ctypes/pypy: rpython rpython/module rpython/module/test translator/c
fijal at codespeak.net
fijal at codespeak.net
Mon May 28 15:06:51 CEST 2007
Author: fijal
Date: Mon May 28 15:06:50 2007
New Revision: 43789
Modified:
pypy/branch/kill-ctypes/pypy/rpython/extfunctable.py
pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py
pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py
pypy/branch/kill-ctypes/pypy/translator/c/extfunc.py
Log:
Untangling the mess part one - os.open
Modified: pypy/branch/kill-ctypes/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/rpython/extfunctable.py (original)
+++ pypy/branch/kill-ctypes/pypy/rpython/extfunctable.py Mon May 28 15:06:50 2007
@@ -179,7 +179,6 @@
# external function declarations
posix = __import__(os.name)
-declare(os.open , int , 'll_os/open')
declare(os.read , str , 'll_os/read')
declare(os.write , posannotation , 'll_os/write')
declare(os.close , noneannotation, 'll_os/close')
Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py (original)
+++ pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py Mon May 28 15:06:50 2007
@@ -104,14 +104,22 @@
register_external(ros.utime_tuple, [str, (int, int)],
llimpl=utime_tuple_lltypeimpl)
+os_open = rffi.llexternal('open', [rffi.CCHARP, lltype.Signed, rffi.MODE_T],
+ lltype.Signed)
+
+def os_open_lltypeimpl(path, flags, mode):
+ l_path = rffi.str2charp(path)
+ result = os_open(l_path, flags, mode)
+ lltype.free(l_path, flavor='raw')
+ if result == -1:
+ raise OSError(rffi.c_errno, "os_open failed")
+ return result
+register_external(os.open, [str, int, int], int, export_name="open",
+ llimpl=os_open_lltypeimpl)
class BaseOS:
__metaclass__ = ClassMethods
- def ll_os_open(cls, fname, flag, mode):
- return os.open(cls.from_rstr(fname), flag, mode)
- ll_os_open.suggested_primitive = True
-
def ll_os_write(cls, fd, astring):
return os.write(fd, cls.from_rstr(astring))
ll_os_write.suggested_primitive = True
Modified: pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py (original)
+++ pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py Mon May 28 15:06:50 2007
@@ -16,22 +16,6 @@
assert os.access(filename, mode) == impl.ll_os_access(rsfilename, mode)
-def test_open_read_write_close():
- filename = str(udir.join('test_open_read_write_close.txt'))
- rsfilename = impl.to_rstr(filename)
-
- fd = impl.ll_os_open(rsfilename, os.O_WRONLY | os.O_CREAT, 0777)
- count = impl.ll_os_write(fd, impl.to_rstr("hello world\n"))
- assert count == len("hello world\n")
- impl.ll_os_close(fd)
-
- fd = impl.ll_os_open(rsfilename, os.O_RDONLY, 0777)
- data = impl.ll_os_read(fd, 500)
- assert impl.from_rstr(data) == "hello world\n"
- impl.ll_os_close(fd)
-
- os.unlink(filename)
-
def test_getcwd():
data = impl.ll_os_getcwd()
assert impl.from_rstr(data) == os.getcwd()
Modified: pypy/branch/kill-ctypes/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/translator/c/extfunc.py (original)
+++ pypy/branch/kill-ctypes/pypy/translator/c/extfunc.py Mon May 28 15:06:50 2007
@@ -23,7 +23,6 @@
# references to functions, so we cannot insert classmethods here.
EXTERNALS = {
- impl.ll_os_open.im_func: 'LL_os_open',
impl.ll_read_into: 'LL_read_into', # it's a staticmethod
impl.ll_os_write.im_func: 'LL_os_write',
impl.ll_os_close.im_func: 'LL_os_close',
More information about the Pypy-commit
mailing list