[pypy-svn] r29753 - in pypy/dist/pypy/rpython: lltypesystem/module module ootypesystem/module test
antocuni at codespeak.net
antocuni at codespeak.net
Fri Jul 7 17:36:37 CEST 2006
Author: antocuni
Date: Fri Jul 7 17:36:32 2006
New Revision: 29753
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:
Moved os.read to lltypesystem, and added an ootypesystem version as
well.
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 Jul 7 17:36:32 2006
@@ -1,4 +1,6 @@
+import os, errno
from pypy.rpython.module.support import LLSupport
+from pypy.rpython.module.support import ll_strcpy
from pypy.rpython.module.ll_os import BaseOS
from pypy.rpython.lltypesystem import lltype, rtupletype
from pypy.rpython.rarithmetic import intmask
@@ -24,3 +26,14 @@
return tup
ll_stat_result = staticmethod(ll_stat_result)
+ def ll_os_read(cls, fd, count):
+ from pypy.rpython.lltypesystem.rstr import STR
+ if count < 0:
+ raise OSError(errno.EINVAL, None)
+ buffer = lltype.malloc(STR, count)
+ n = cls.ll_read_into(fd, buffer)
+ if n != count:
+ s = lltype.malloc(STR, n)
+ ll_strcpy(s, buffer, n)
+ buffer = s
+ return buffer
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 Jul 7 17:36:32 2006
@@ -14,8 +14,6 @@
# and buffer preparation stuff is not useful.
import os, errno
-from pypy.rpython.lltypesystem.lltype import \
- GcStruct, Signed, Array, Char, Ptr, malloc
from pypy.rpython.module.support import ll_strcpy, _ll_strfill
from pypy.rpython.module.support import to_opaque_object, from_opaque_object
from pypy.rpython import ros
@@ -23,9 +21,6 @@
from pypy.tool.staticmethods import ClassMethods
import stat
-
-
-
class BaseOS:
__metaclass__ = ClassMethods
@@ -48,26 +43,10 @@
ll_read_into.suggested_primitive = True
ll_read_into = staticmethod(ll_read_into)
- def ll_os_read(cls, fd, count):
- from pypy.rpython.lltypesystem.rstr import STR
- if count < 0:
- raise OSError(errno.EINVAL, None)
- buffer = malloc(STR, count)
- n = cls.ll_read_into(fd, buffer)
- if n != count:
- s = malloc(STR, n)
- ll_strcpy(s, buffer, n)
- buffer = s
- return buffer
-
-
-
def ll_os_close(cls, fd):
os.close(fd)
ll_os_close.suggested_primitive = True
-
-
def ll_os_dup(cls, fd):
return os.dup(fd)
ll_os_dup.suggested_primitive = True
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 Jul 7 17:36:32 2006
@@ -1,3 +1,4 @@
+import os
from pypy.rpython.module.support import OOSupport
from pypy.rpython.module.ll_os import BaseOS
from pypy.rpython.ootypesystem import ootype
@@ -27,4 +28,6 @@
return tup
ll_stat_result = staticmethod(ll_stat_result)
-
+ def ll_os_read(cls, fd, count):
+ return cls.to_rstr(os.read(fd, count))
+ ll_os_read.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 Jul 7 17:36:32 2006
@@ -167,6 +167,18 @@
hello = open(tmpdir).read()
assert hello == "hello world"
+ def test_os_read(self):
+ import os
+ tmpfile = str(udir.udir.join("os_read_test"))
+ f = file(tmpfile, 'w')
+ f.write('hello world')
+ f.close()
+ def f():
+ fd = os.open(tmpfile, os.O_RDONLY, 0777)
+ return os.read(fd, 4096)
+ res = self.interpret(f, [])
+ assert self.ll_to_string(res) == 'hello world'
+
def test_os_dup(self):
import os
def fn(fd):
More information about the Pypy-commit
mailing list