[pypy-svn] r28121 - in pypy/dist/pypy/rpython: lltypesystem/module module ootypesystem/module test
nik at codespeak.net
nik at codespeak.net
Fri Jun 2 19:25:17 CEST 2006
Author: nik
Date: Fri Jun 2 19:25:16 2006
New Revision: 28121
Modified:
pypy/dist/pypy/rpython/lltypesystem/module/ll_os.py
pypy/dist/pypy/rpython/module/ll_os.py
pypy/dist/pypy/rpython/ootypesystem/module/ll_os.py
pypy/dist/pypy/rpython/test/test_rbuiltin.py
Log:
(antocuni, nik)
move os.write and os.open to typesystem-specific ll_os modules. add and
pass test for this.
Modified: pypy/dist/pypy/rpython/lltypesystem/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/module/ll_os.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/module/ll_os.py Fri Jun 2 19:25:16 2006
@@ -1,5 +1,13 @@
import os
-from pypy.rpython.module.support import to_rstr
+from pypy.rpython.module.support import from_rstr, to_rstr
+
+def ll_os_open(fname, flag, mode):
+ return os.open(from_rstr(fname), flag, mode)
+ll_os_open.suggested_primitive = True
+
+def ll_os_write(fd, astring):
+ return os.write(fd, from_rstr(astring))
+ll_os_write.suggested_primitive = True
def ll_os_getcwd():
return to_rstr(os.getcwd())
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 Fri Jun 2 19:25:16 2006
@@ -21,11 +21,6 @@
from pypy.rpython import ros
from pypy.rpython.rarithmetic import r_longlong
-def ll_os_open(fname, flag, mode):
- return os.open(from_rstr(fname), flag, mode)
-ll_os_open.suggested_primitive = True
-
-
def ll_read_into(fd, buffer):
data = os.read(fd, len(buffer.chars))
_ll_strfill(buffer, data, len(data))
@@ -45,10 +40,6 @@
return buffer
-def ll_os_write(fd, astring):
- return os.write(fd, from_rstr(astring))
-ll_os_write.suggested_primitive = True
-
def ll_os_close(fd):
os.close(fd)
Modified: pypy/dist/pypy/rpython/ootypesystem/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/module/ll_os.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/module/ll_os.py Fri Jun 2 19:25:16 2006
@@ -1,7 +1,15 @@
import os
-from pypy.rpython.ootypesystem.ootype import oostring
+from pypy.rpython.ootypesystem.module.support import from_rstr, to_rstr
+
+def ll_os_open(fname, flag, mode):
+ return os.open(from_rstr(fname), flag, mode)
+ll_os_open.suggested_primitive = True
+
+def ll_os_write(fd, astring):
+ return os.write(fd, from_rstr(astring))
+ll_os_write.suggested_primitive = True
def ll_os_getcwd():
- return oostring(os.getcwd(), -1)
+ return to_rstr(os.getcwd())
ll_os_getcwd.suggested_primitive = True
Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py Fri Jun 2 19:25:16 2006
@@ -103,7 +103,7 @@
res = interpret(f, [])
os.close(res)
count = 0
- from pypy.rpython.module import ll_os
+ from pypy.rpython.lltypesystem.module import ll_os
for dir_call in enum_direct_calls(test_llinterp.typer.annotator.translator, wr_open):
cfptr = dir_call.args[0]
assert cfptr.value._obj._callable == ll_os.ll_os_open
@@ -340,6 +340,19 @@
res = self.interpret(fn, [])
assert self.ll_to_string(res) == fn()
+ def test_os_write(self):
+ tmpdir = str(udir.udir.join("os_write_test"))
+ import os
+ def wr_open(fname):
+ fd = os.open(fname, os.O_WRONLY|os.O_CREAT, 0777)
+ os.write(fd, "hello world")
+ return fd
+ def f():
+ return wr_open(tmpdir)
+ res = self.interpret(f, [])
+ os.close(res)
+ hello = open(tmpdir).read()
+ assert hello == "hello world"
class TestOOtype(BaseTestExtfunc, OORtypeMixin):
pass
More information about the Pypy-commit
mailing list