[pypy-svn] r43648 - in pypy/branch/kill-ctypes/pypy/rpython/module: . test

fijal at codespeak.net fijal at codespeak.net
Fri May 25 20:51:10 CEST 2007


Author: fijal
Date: Fri May 25 20:51:09 2007
New Revision: 43648

Modified:
   pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py
   pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py
Log:
WHACK! Now execv has some saner implementation (but test has gone, since
it become identical to the one in translator/c :-/


Modified: pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py	(original)
+++ pypy/branch/kill-ctypes/pypy/rpython/module/ll_os.py	Fri May 25 20:51:09 2007
@@ -27,30 +27,25 @@
 import ctypes
 import pypy.rpython.rctypes.implementation
 from pypy.rpython.rctypes.tool.libc import libc
+from pypy.rpython.lltypesystem import rffi
+from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.rctypes.aerrno import geterrno
 
 if hasattr(os, 'execv'):
 
     if os.name == 'nt':
-        os_execv = libc._execv
+        name = '_execv'
     else:
-        os_execv = libc.execv
-    os_execv.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_char_p)]
-    os_execv.restype = ctypes.c_int
+        name = 'execv'
+    os_execv = rffi.llexternal(name, [lltype.Ptr(rffi.CCHARP),
+                               lltype.Ptr(rffi.CCHARPP)], lltype.Signed)
 
     def execv_lltypeimpl(path, args):
-        # XXX incredible code to work around rctypes limitations
-        length = len(args) + 1
-        num_bytes = ctypes.sizeof(ctypes.c_char_p) * length
-        buffer = ctypes.create_string_buffer(num_bytes)
-        array = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_char_p))
-        buffer_addr = ctypes.cast(buffer, ctypes.c_void_p).value
-        for num in range(len(args)):
-            adr1 = buffer_addr + ctypes.sizeof(ctypes.c_char_p) * num
-            ptr = ctypes.c_void_p(adr1)
-            arrayitem = ctypes.cast(ptr, ctypes.POINTER(ctypes.c_char_p))
-            arrayitem[0] = args[num]
-        os_execv(path, array)
+        l_path = rffi.str2charp(path)
+        l_args = rffi.liststr2charpp(args)
+        os_execv(l_path, l_args)
+        rffi.free_charpp(l_args)
+        lltype.free(l_path, flavor='raw')
         raise OSError(geterrno(), "execv failed")
 
     register_external(os.execv, [str, [str]], s_ImpossibleValue, llimpl=

Modified: pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py	(original)
+++ pypy/branch/kill-ctypes/pypy/rpython/module/test/test_ll_os.py	Fri May 25 20:51:09 2007
@@ -116,25 +116,6 @@
     compared_with.sort()
     assert result == compared_with
 
-if hasattr(os, 'execv'):
-    from pypy.rpython.extregistry import lookup
-    os_execv = lookup(os.execv).lltypeimpl
-    
-    def test_execv():
-        filename = str(udir.join('test_execv_ctypes.txt'))
-
-        progname = str(sys.executable)
-        l = ['', '']
-        l[0] = progname
-        l[1] = "-c"
-        l.append('open("%s","w").write("1")' % filename)
-        pid = os.fork()
-        if pid == 0:
-            os_execv(progname, l)
-        else:
-            os.waitpid(pid, 0)
-        assert open(filename).read() == "1"
-
 def test_dup():
     from pypy.rpython.extregistry import lookup
     os_dup = lookup(os.dup).lltypeimpl



More information about the Pypy-commit mailing list