[pypy-svn] r14395 - in pypy/dist/pypy/translator/llvm2: . test

ericvrp at codespeak.net ericvrp at codespeak.net
Thu Jul 7 19:04:49 CEST 2005


Author: ericvrp
Date: Thu Jul  7 19:04:48 2005
New Revision: 14395

Modified:
   pypy/dist/pypy/translator/llvm2/extfunction.py
   pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
Log:
os.read working now in LLVM


Modified: pypy/dist/pypy/translator/llvm2/extfunction.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/extfunction.py	(original)
+++ pypy/dist/pypy/translator/llvm2/extfunction.py	Thu Jul  7 19:04:48 2005
@@ -110,8 +110,19 @@
 }
 
 %st.rpy_string.0* %ll_os_read(int %fd, int %buffersize) {
-    ;TODO: read(fd, buffersize) -> string
-    ret %st.rpy_string.0* null
+    ;This is a bit simplistic! It really allocated a large enough buffer to hold all the data in.
+    %str = call %st.rpy_string.0* %new.st.var.rpy_string.0(int %buffersize)
+
+    ;load the actual data
+    %destptr   = getelementptr %st.rpy_string.0* %str, int 0, uint 1, uint 1
+    %dest      = cast [0 x sbyte]* %destptr to sbyte*
+    %bytesread = call int %read(int %fd, sbyte* %dest, int %buffersize)
+    
+    ;set str.length to number of bytes read
+    %reallengthptr = getelementptr %st.rpy_string.0* %str, int 0, uint 1, uint 0
+    store int %bytesread, int* %reallengthptr
+
+    ret %st.rpy_string.0* %str
 }
 
 ; End of external functions

Modified: pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_extfunc.py	Thu Jul  7 19:04:48 2005
@@ -82,9 +82,10 @@
         os.unlink(path)
     f = compile_function(openwriteclose, [int] * len(path))
     result = f(*map(ord, path))
-    assert os.path.exists(path) and open(path).read() == path
+    assert os.path.exists(path)
+    assert open(path).read() == path
 
-def DONTtest_os_file_ops_open_write_read_close(): 
+def test_os_file_ops_open_write_read_close(): 
     # the test is overly complicated because
     # we don't have prebuilt string constants yet 
     import os
@@ -92,18 +93,21 @@
         s = chr(a) + chr(b) + chr(c) + chr(d) + chr(e) + chr(f)
 
         fd = os.open(s, os.O_CREAT|os.O_RDWR) 
-        byteswritten = os.write(fd, s)
+        byteswritten = os.write(fd, s+s+s)
         os.close(fd)
 
-        fd = os.open(s, os.os.O_RD) 
-        r = os.read(fd, n=1000)
+        fd = os.open(s, os.O_RDWR) 
+        maxread = 1000
+        r = os.read(fd, maxread)
         os.close(fd)
 
-        return r
+        return len(r)
 
     path = '/tmp/b'
     if os.path.exists(path):
         os.unlink(path)
     f = compile_function(openwriteclose_openreadclose, [int] * len(path))
     result = f(*map(ord, path))
-    assert os.path.exists(path) and open(path).read() is path and result is path
+    assert os.path.exists(path)
+    assert open(path).read() == path * 3
+    assert result is len(path) * 3



More information about the Pypy-commit mailing list