[pypy-svn] r45732 - in pypy/branch/pypy-more-rtti-inprogress: rpython rpython/module translator/c translator/c/src translator/c/test

arigo at codespeak.net arigo at codespeak.net
Thu Aug 16 16:46:49 CEST 2007


Author: arigo
Date: Thu Aug 16 16:46:47 2007
New Revision: 45732

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
   pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py
Log:
os.spawnv()... with a new test which I cannot run on Linux, so well, untested


Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py	Thu Aug 16 16:46:47 2007
@@ -149,13 +149,7 @@
     return SomeString(can_be_None=True)
 
 # external function declarations
-posix = __import__(os.name)
 declare(os._exit    , noneannotation, 'll_os/_exit')
-if hasattr(os, 'spawnv'):
-    declare(os.spawnv,    int,            'll_os/spawnv')
-#if hasattr(os, 'execv'):
-#    declare(os.execv, noneannotation, 'll_os/execv')
-#    declare(os.execve, noneannotation, 'll_os/execve')
 
 declare(os.path.exists, bool        , 'll_os_path/exists')
 declare(os.path.isdir, bool         , 'll_os_path/isdir')

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	Thu Aug 16 16:46:47 2007
@@ -17,6 +17,7 @@
 from pypy.rpython.lltypesystem import rffi
 from pypy.rpython.lltypesystem.rffi import platform
 from pypy.rpython.lltypesystem import lltype
+posix = __import__(os.name)
 
 class RegisterOs(BaseLazyRegistering):
     UNISTD_INCL = ['unistd.h', 'sys/types.h']
@@ -54,6 +55,27 @@
             self.register(os.execv, [str, [str]], s_ImpossibleValue, llimpl=
                           execv_lltypeimpl, export_name="ll_os.ll_os_execv")
 
+    if hasattr(posix, 'spawnv'):
+        @registering(os.spawnv)
+        def register_os_spawnv(self):
+            os_spawnv = rffi.llexternal('spawnv',
+                                        [rffi.INT, rffi.CCHARP, rffi.CCHARPP],
+                                        rffi.INT)
+
+            def spawnv_lltypeimpl(mode, path, args):
+                mode = rffi.cast(rffi.INT, mode)
+                l_path = rffi.str2charp(path)
+                l_args = rffi.liststr2charpp(args)
+                childpid = os_spawnv(mode, l_path, l_args)
+                rffi.free_charpp(l_args)
+                rffi.free_charp(l_path)
+                if childpid == -1:
+                    raise OSError(rffi.get_errno(), "os_spawnv failed")
+                return rffi.cast(lltype.Signed, childpid)
+
+            self.register(os.spawnv, [int, str, [str]], int, llimpl=
+                          spawnv_lltypeimpl, export_name="ll_os.ll_os_spawnv")
+
     @registering(os.dup)
     def register_os_dup(self):
         os_dup = rffi.llexternal('dup', [rffi.INT], rffi.INT)
@@ -931,10 +953,6 @@
     # XXX deprecated style, this is all waiting to be converted to rffi
     __metaclass__ = ClassMethods
 
-    def ll_os_spawnv(cls, mode, path, args):
-        return os.spawnv(mode, path, args)
-    ll_os_spawnv.suggested_primitive = True
-
     def ll_os__exit(cls, status):
         os._exit(status)
     ll_os__exit.suggested_primitive = True

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py	Thu Aug 16 16:46:47 2007
@@ -20,7 +20,6 @@
 # references to functions, so we cannot insert classmethods here.
 
 EXTERNALS = {
-    impl.ll_os_spawnv.im_func:  'LL_os_spawnv',
     impl.ll_os__exit.im_func:   'LL_os__exit',
     ll_time.ll_time_clock: 'LL_time_clock',
     ll_time.ll_time_sleep: 'LL_time_sleep',

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h	Thu Aug 16 16:46:47 2007
@@ -27,9 +27,6 @@
 
 /* prototypes */
 
-#if defined(HAVE_SPAWNV) && defined(HAVE_RPY_LIST_OF_STRING) /* argh */
-long LL_os_spawnv(int mode, RPyString *path, RPyListOfString *args);
-#endif
 void LL_os__exit(long status);
 
 static int geterrno(void)    /* XXX only for rpython.rctypes, kill me */
@@ -44,33 +41,6 @@
 
 #include "ll_osdefs.h"
 
-/*
-  The following code is only generated if spawnv exists and
-  if RPyListOfString exists. The latter is a bit tricky:
-  The RPyListOfString is necessary to correctly declare this function.
-  For this to work, the test code must be properly written in a way
-  that RPyListOfString is really annotated as such.
-  Please see the test in test_extfunc.py - creating the correct
-  argument string type is not obvious and error prone.
- */
-#if defined(HAVE_SPAWNV) && defined(HAVE_RPY_LIST_OF_STRING)
-long LL_os_spawnv(int mode, RPyString *path, RPyListOfString *args) {
-	int pid, i, nargs = args->l_length;
-	char **slist = malloc((nargs+1) * sizeof(char*));
-	pid = -1;
-	if (slist) {
-		for (i=0; i<nargs; i++)
-			slist[i] = RPyString_AsString(args->l_items->items[i]);
-		slist[nargs] = NULL;
-		pid = spawnv(mode, RPyString_AsString(path), slist);
-		free(slist);
-	}
-	if (pid == -1)
-		RPYTHON_RAISE_OSERROR(errno);
-	return pid;
-}
-#endif
-
 void LL_os__exit(long status) {
 	_exit((int)status);
 }

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py	Thu Aug 16 16:46:47 2007
@@ -870,6 +870,18 @@
         func()
         assert open(filename).read() == "42"
 
+if hasattr(posix, 'spawnv'):
+    def test_spawnv():
+        filename = str(udir.join('test_spawnv.txt'))
+        progname = str(sys.executable)
+        def does_stuff():
+            l = [progname, '-c', 'open("%s","w").write("2")' % filename]
+            pid = os.spawnv(os.P_NOWAIT, progname, l)
+            os.waitpid(pid, 0)
+        func = compile(does_stuff, [])
+        func()
+        assert open(filename).read() == "2"
+
 def test_utime():
     # XXX utimes & float support
     path = str(udir.ensure("test_utime.txt"))



More information about the Pypy-commit mailing list