[pypy-svn] r14807 - in pypy/dist/pypy: module/posix module/posix/test rpython rpython/module

ale at codespeak.net ale at codespeak.net
Wed Jul 20 13:53:59 CEST 2005


Author: ale
Date: Wed Jul 20 13:53:56 2005
New Revision: 14807

Modified:
   pypy/dist/pypy/module/posix/__init__.py
   pypy/dist/pypy/module/posix/interp_posix.py
   pypy/dist/pypy/module/posix/test/test_posix.py
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/module/ll_os.py
Log:
This is an intermeddiate checkin. Mostly it works (I have 6 failures in the standard tests).

	- changed interp_posix to use unwrap<-spec correctly
	- added better tests for the functions
	- added OSError
	- added ll functions 

Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py	(original)
+++ pypy/dist/pypy/module/posix/__init__.py	Wed Jul 20 13:53:56 2005
@@ -3,6 +3,7 @@
     
 class Module(MixedModule):
     appleveldefs = {
+    'error'     : 'app_posix.error'
     }
     interpleveldefs = {
     'open'      : 'interp_posix.open',

Modified: pypy/dist/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/interp_posix.py	(original)
+++ pypy/dist/pypy/module/posix/interp_posix.py	Wed Jul 20 13:53:56 2005
@@ -12,38 +12,38 @@
     return space.wrap(fd)
 
 
-def lseek(space, w_fd, pos, how):
+def lseek(space, fd, pos, how):
     os.lseek(fd,pos,how)
-lseek.unwrap_spec = [ObjSpace, W_Root, int, int]
+lseek.unwrap_spec = [ObjSpace, int, int, int]
 
-def isatty(space, w_fd):
-    return os.isatty(fd)
-lseek.unwrap_spec = [ObjSpace, W_Root, int, int]
-
-def read(space, w_fd, buffersize):
-    return os.read(w_fd,buffersize)
-read.unwrap_spec = [ObjSpace, W_Root, int]
-
-def write(space, w_fd, data):
-    return os.write( w_fd, data)
-write.unwrap_spec = [ObjSpace, W_Root, str]
-
-def close(space, w_fd):
-    os.close(w_fd)
-close.unwrap_spec = [ObjSpace, W_Root]
-
-def ftruncate(space, w_fd, length):
-    os.ftruncate(w_fd, length)
-ftruncate.unwrap_spec = [ObjSpace, W_Root, int]
-
-def fstat(space, w_fd):
-    return os.fstat(w_fd)
-fstat.unwrap_spec = [ObjSpace, W_Root]
+def isatty(space, fd):
+    return os.isatty(w_fd)
+lseek.unwrap_spec = [ObjSpace, int]
+
+def read(space, fd, buffersize):
+    return os.read(fd,buffersize)
+read.unwrap_spec = [ObjSpace, int, int]
+
+def write(space, fd, data):
+    return os.write( fd, data)
+write.unwrap_spec = [ObjSpace, int, str]
+
+def close(space, fd):
+    os.close(fd)
+close.unwrap_spec = [ObjSpace, int]
+
+def ftruncate(space, fd, length):
+    os.ftruncate(fd, length)
+ftruncate.unwrap_spec = [ObjSpace, int, int]
+
+def fstat(space, fd):
+    return os.fstat(fd)
+fstat.unwrap_spec = [ObjSpace, int]
 
 def getcwd(space):
     return os.getcwd()
 getcwd.unwrap_spec = [ObjSpace]
 
-def dup(space, w_fd):
-    return os.dup(w_fd)
-dup.unwrap_spec = [ObjSpace, W_Root]
\ No newline at end of file
+def dup(space, fd):
+    return os.dup(fd)
+dup.unwrap_spec = [ObjSpace, int]
\ No newline at end of file

Modified: pypy/dist/pypy/module/posix/test/test_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/test/test_posix.py	(original)
+++ pypy/dist/pypy/module/posix/test/test_posix.py	Wed Jul 20 13:53:56 2005
@@ -1,28 +1,102 @@
 from pypy.rpython.test.test_llinterp import interpret
+from pypy.tool.udir import udir 
+import os, posix
+
+def setup_module(module):
+    testf = udir.join('test.txt')
+    testfile = testf.open('w')
+    testfile.write('This is a test')
+    testfile.close()
+    module.path = testf.strpath
 
 def test_open():
     def f():
-        import os
-        ff = os.open('test_posix.py',0,0755)
+        ff = posix.open(path,posix.O_RDONLY,0777)
         return ff
     func = interpret(f,[])
-    assert func
+    assert type(func) == int
 
 def test_dup():
-    def ff():
-        import os
-        fi = os.open('test_posix.py',0,0755)
-        g = os.dup(fi)
-        #fi.close()
+    def ff(fi):
+        g = posix.dup(fi)
         return g
-    func = interpret(ff,[])
-    assert func
+    fi = os.open(path,os.O_RDONLY,0755)
+    g = interpret(ff,[fi])
+    assert os.fstat(g) == os.fstat(fi)
     
 def test_fstat():
-    def fo():
-        import os
-        fi = os.open('test_posix.py',0,0755)
-        g = os.fstat(fi)
+    def fo(fi):
+        g = posix.fstat(fi)
         return g
-    func = interpret(fo,[],True)
-    assert func
+    fi = os.open(path,os.O_RDONLY,0777)
+    func = interpret(fo,[fi])
+    stat = os.fstat(fi)
+    for i in range(len(stat)):
+        stat0 = getattr(func, 'item%d' % i)
+        assert stat0 == stat[i]
+            
+def test_lseek():
+    def f(fi,pos):
+        posix.lseek(fi,pos,0)
+    fi = os.open(path,os.O_RDONLY,0777)
+    func = interpret(f,[fi,5]) 
+    res = os.read(fi,2)
+    assert res =='is'
+
+def test_isatty():
+    def f(fi):
+        posix.isatty(fi)
+    fi = os.open(path,os.O_RDONLY,0777)
+    func = interpret(f,[fi])
+    assert not func
+    os.close(fi)
+    func = interpret(f,[fi])
+    assert not func
+
+def test_getcwd():
+    def f():
+        return posix.getcwd()
+    res = interpret(f,[])
+    cwd = os.getcwd()
+    print res.chars,cwd
+    assert ''.join([x for x in res.chars]) == cwd
+
+def test_write():
+    def f(fi):
+        text = 'This is a test'
+        return posix.write(fi,text)
+    fi = os.open(path,os.O_WRONLY,0777)
+    text = 'This is a test'
+    func = interpret(f,[fi])
+    os.close(fi)
+    fi = os.open(path,os.O_RDONLY,0777)
+    res = os.read(fi,20)
+    assert res == text
+
+def test_read():
+    def f(fi,len):
+        return posix.read(fi,len)
+    fi = os.open(path,os.O_WRONLY,0777)
+    text = 'This is a test'
+    os.write(fi,text)
+    os.close(fi)
+    fi = os.open(path,os.O_RDONLY,0777)
+    res = interpret(f,[fi,20])
+    assert ''.join([x for x in res.chars]) == text
+
+def test_close():
+    def f(fi):
+        return posix.close(fi)
+    fi = os.open(path,os.O_WRONLY,0777)
+    text = 'This is a test'
+    os.write(fi,text)
+    res = interpret(f,[fi])
+    raises( OSError(), os.fstat(fi))
+
+def test_ftruncate():
+    def f(fi,len):
+        posix.ftruncate(fi,len)
+    fi = os.open(path,os.O_RDWR,0777)
+    func = interpret(f,[fi,6]) 
+    assert os.fstat(fi).st_size == 6
+    

Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Wed Jul 20 13:53:56 2005
@@ -4,6 +4,7 @@
 import os
 import time
 import types
+from pypy.annotation.model import SomeInteger, SomeTuple
 
 
 class ExtFuncInfo:
@@ -49,15 +50,19 @@
 # _____________________________________________________________
 
 nonefactory = lambda *args: None
+tuplefactory = lambda *args: SomeTuple((SomeInteger(),)*10)
 
 # external function declarations
-declare(os.open   , int        , 'll_os/open')
-declare(os.read   , str        , 'll_os/read')
-declare(os.write  , int        , 'll_os/write')
-declare(os.close  , nonefactory, 'll_os/close')
-declare(os.getcwd , str        , 'll_os/getcwd')
-declare(os.dup    , int        , 'll_os/dup')
-declare(os.fstat  , int        , 'll_os/fstat')
-declare(time.time , float      , 'll_time/time')
-declare(time.clock, float      , 'll_time/clock')
-declare(time.sleep, nonefactory, 'll_time/sleep')
+declare(os.open     , int        , 'll_os/open')
+declare(os.read     , str        , 'll_os/read')
+declare(os.write    , int        , 'll_os/write')
+declare(os.close    , nonefactory, 'll_os/close')
+declare(os.getcwd   , str        , 'll_os/getcwd')
+declare(os.dup      , int        , 'll_os/dup')
+declare(os.lseek    , int        , 'll_os/lseek')
+declare(os.isatty   , bool       , 'll_os/isatty')
+declare(os.ftruncate, nonefactory, 'll_os/ftruncate')
+declare(os.fstat    , tuplefactory, 'll_os/fstat')
+declare(time.time   , float      , 'll_time/time')
+declare(time.clock  , float      , 'll_time/clock')
+declare(time.sleep  , nonefactory, 'll_time/sleep')

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	Wed Jul 20 13:53:56 2005
@@ -17,7 +17,6 @@
 from pypy.rpython.rstr import STR
 from pypy.rpython.lltype import GcStruct, Signed, Array, Char, Ptr, malloc
 
-
 # utility conversion functions
 def to_rstr(s):
     p = malloc(STR, len(s))
@@ -78,13 +77,44 @@
     return os.dup(fd)
 ll_os_dup.suggested_primitive = True
 
+def ll_os_lseek(fd,pos,how):
+    return intmask(os.lseek(fd,pos,how))
+ll_os_lseek.suggested_primitive = True
+
+def ll_os_isatty(fd):
+    return os.isatty(fd)
+ll_os_isatty.suggested_primitive = True
+
+def ll_os_ftruncate(fd,len):
+    return os.ftruncate(fd,len)
+ll_os_ftruncate.suggested_primitive = True
+
+n = 10
+fieldnames = ['item%d' % i for i in range(n)]
+lltypes = [Signed]*n
+fields = tuple(zip(fieldnames, lltypes))    
+tup = malloc(GcStruct('tuple%d' % n, *fields))
+
+from pypy.rpython.rarithmetic import intmask
+
 def ll_os_fstat(fd):
+    
     stat = os.fstat(fd)
+    i = 0
     n = len(stat)
-    fieldnames = ['item%d' % i for i in range(n)]
-    lltypes = [Signed]*n
-    fields = tuple(zip(fieldnames, lltypes))    
-    tup = GcStruct('tuple%d' % n, fields)
-    #lowleveltype = Ptr(tup)
-    #p = malloc( tup )
-    return tup
\ No newline at end of file
+    tup.item0 = stat[0]
+    tup.item1 = intmask(stat[1])
+    tup.item2 = intmask(stat[2])
+    tup.item3 = intmask(stat[3])
+    tup.item4 = intmask(stat[4])
+    tup.item5 = intmask(stat[5])
+    tup.item6 = intmask(stat[6])
+    tup.item7 = intmask(stat[7])
+    tup.item8 = intmask(stat[8])
+    tup.item9 = intmask(stat[9])
+##    while i<n:
+##        itemname = 'item%d' % i
+##        setattr(tup,itemname,stat[i])
+##        i += 1
+    return tup
+ll_os_fstat.suggested_primitive = True
\ No newline at end of file



More information about the Pypy-commit mailing list