[pypy-svn] r36568 - in pypy/dist/pypy: module/posix rpython/module translator/c/test

arigo at codespeak.net arigo at codespeak.net
Fri Jan 12 14:01:33 CET 2007


Author: arigo
Date: Fri Jan 12 14:01:30 2007
New Revision: 36568

Modified:
   pypy/dist/pypy/module/posix/__init__.py
   pypy/dist/pypy/rpython/module/ll_os.py
   pypy/dist/pypy/translator/c/test/test_extfunc.py
Log:
Whack at the ctypes implementation of execv() until rctypes is happy with it.
Skip execve.


Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py	(original)
+++ pypy/dist/pypy/module/posix/__init__.py	Fri Jan 12 14:01:30 2007
@@ -74,7 +74,7 @@
         interpleveldefs['waitpid'] = 'interp_posix.waitpid'
     if hasattr(os, 'execv'):
         interpleveldefs['execv'] = 'interp_posix.execv'
-    if hasattr(os, 'execve'):
+    if hasattr(os, 'execve')   and 0:     # XXX XXX in-progress
         interpleveldefs['execve'] = 'interp_posix.execve'
     #if hasattr(ctypes_posix, 'uname'):
     #    interpleveldefs['uname'] = 'interp_posix.uname'

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 Jan 12 14:01:30 2007
@@ -41,12 +41,19 @@
         signature_result = s_ImpossibleValue
 
         def lltypeimpl(path, args):
-            typ = ctypes.c_char_p * (len(args) + 1)
-            array = typ()
+            # 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)):
-                array[num] = args[num]
+                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)
-            raise OSError(geterrno())
+            raise OSError(geterrno(), "execv failed")
 
 class BaseOS:
     __metaclass__ = ClassMethods

Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py	Fri Jan 12 14:01:30 2007
@@ -731,6 +731,7 @@
         py.test.raises(OSError, "func()")
 
     def test_execve():
+        import py; py.test.skip("in-progress")
         filename = str(udir.join('test_execve.txt'))
         def does_stuff():
             progname = str(sys.executable)



More information about the Pypy-commit mailing list