[pypy-svn] r14376 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Thu Jul 7 13:10:24 CEST 2005


Author: arigo
Date: Thu Jul  7 13:10:22 2005
New Revision: 14376

Modified:
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/test/test_rbuiltin.py
Log:
Fixed the low-level implementations of the external functions.


Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Thu Jul  7 13:10:22 2005
@@ -25,29 +25,35 @@
             return bookkeeper.getbookkeeper().valueoftype(typ)
     table[func] = ExtFuncInfo(func, annotation, ll_function, ll_annotable, backend_functiontemplate)
 
-# low-level helpers representing the external functions
-def ll_os_open(fname, mode):
-    return os.open(''.join(fname.chars), mode)
+# utility conversion functions
+def to_rstr(s):
+    from pypy.rpython import rstr
+    p = rstr.malloc(rstr.STR, len(s))
+    for i in range(len(s)):
+        p.chars[i] = s[i]
+    return p
+
+def from_rstr(rs):
+    return ''.join(rs.chars)
+
+# dummy low-level implementations for the external functions
+def ll_os_open(fname, flag, mode):
+    return os.open(from_rstr(fname), flag, mode)
 
 def ll_os_read(fd, n):
-    return os.read(fd, n)
+    return to_rstr(os.read(fd, n))
     
 def ll_os_write(fd, astring):
-    return os.write(fd, astring)
-    
+    return os.write(fd, from_rstr(astring))
+
 def ll_os_close(fd):
     os.close(fd)
     
 def ll_os_getcwd():
-    cwd = os.getcwd()
-    from pypy.rpython import rstr
-    p = rstr.malloc(rstr.STR, len(cwd))
-    for i in range(len(cwd)):
-        p.chars[i] = cwd[i]
-    return p
+    return to_rstr(os.getcwd())
 
 def ll_os_dup(fd):
-    return 999
+    return os.dup(fd)
 
 def ll_time_time():
     return time.time()
@@ -58,7 +64,8 @@
 def ll_time_sleep(t):
     time.sleep(t)
 
-nonefactory = lambda a: None
+
+nonefactory = lambda *args: None
 
 # external function declarations
 declare(os.open   , int        , ll_os_open)

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	Thu Jul  7 13:10:22 2005
@@ -88,10 +88,10 @@
     def fn(fd):
         return os.dup(fd)
     res = interpret(fn, [0])
-    #try:
-    #    os.close(res)
-    #except OSError:
-    #    pass
+    try:
+        os.close(res)
+    except OSError:
+        pass
     count = 0
     from pypy.rpython import extfunctable
     for dir_call in enum_direct_calls(test_llinterp.typer.annotator.translator, fn):
@@ -104,7 +104,7 @@
     tmpdir = str(udir.udir.join("os_open_test"))
     import os
     def wr_open(fname):
-        return os.open(fname, os.O_WRONLY|os.O_CREAT)
+        return os.open(fname, os.O_WRONLY|os.O_CREAT, 0777)
     def f():
         return wr_open(tmpdir)
     res = interpret(f, [])



More information about the Pypy-commit mailing list