[pypy-commit] pypy more-rposix: Port os.spawn* functions.

amauryfa noreply at buildbot.pypy.org
Wed Nov 5 20:04:43 CET 2014


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: more-rposix
Changeset: r74349:3ad549fc500c
Date: 2014-11-05 20:03 +0100
http://bitbucket.org/pypy/pypy/changeset/3ad549fc500c/

Log:	Port os.spawn* functions.

	Untested, need to kick a win32 buildbot.

diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -295,9 +295,10 @@
     """Decorator that causes RPython to replace the function passed as parameter
     with the function being defined."""
     def wrap(func):
-        @register_flow_sc(replaced_function)
-        def sc_redirected_function(ctx, *args_w):
-            return ctx.appcall(func, *args_w)
+        if replaced_function is not None:
+            @register_flow_sc(replaced_function)
+            def sc_redirected_function(ctx, *args_w):
+                return ctx.appcall(func, *args_w)
         if sandboxed_name:
             func._sandbox_external_name = sandboxed_name
         return func
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -153,6 +153,12 @@
 c_execve = external('execve',
                     [rffi.CCHARP, rffi.CCHARPP, rffi.CCHARPP], rffi.INT)
 # Win32 specific functions
+c_spawnv = external('spawnv',
+                    [rffi.INT, rffi.CCHARP, rffi.CCHARPP], rffi.INT)
+c_spawnve = external('spawnve',
+                    [rffi.INT, rffi.CCHARP, rffi.CCHARPP, rffi.CCHARP],
+                     rffi.INT)
+# Win32 Unicode functions
 c_wopen = external(UNDERSCORE_ON_WIN32 + 'wopen',
                    [rffi.CWCHARP, rffi.INT, rffi.MODE_T], rffi.INT)
 
@@ -352,7 +358,34 @@
     l_env = rffi.ll_liststr2charpp(envstrs)
     c_execve(path, l_args, l_env)
 
-    
     rffi.free_charpp(l_env)
     rffi.free_charpp(l_args)
     raise OSError(get_errno(), "execve failed")
+
+ at register_replacement_for(getattr(os, 'spawnv', None),
+                          sandboxed_name='ll_os.ll_os_spawnv')
+def spawnv(mode, path, args):
+    rstring.check_str0(path)
+    l_args = rffi.ll_liststr2charpp(args)
+    childpid = c_spawnv(mode, path, l_args)
+    rffi.free_charpp(l_args)
+    if childpid < 0:
+        raise OSError(get_errno(), "os_spawnv failed")
+    return intmask(childpid)
+
+ at register_replacement_for(getattr(os, 'spawnve', None),
+                          sandboxed_name='ll_os.ll_os_spawnve')
+def spawnve(mode, path, args, env):
+    envstrs = []
+    for item in env.iteritems():
+        envstrs.append("%s=%s" % item)
+    rstring.check_str0(path)
+    l_args = rffi.ll_liststr2charpp(args)
+    l_env = rffi.ll_liststr2charpp(envstrs)
+    childpid = c_spawnve(mode, path, l_args, l_env)
+    rffi.free_charpp(l_env)
+    rffi.free_charpp(l_args)
+    if childpid == -1:
+        raise OSError(rposix.get_errno(), "os_spawnve failed")
+    return intmask(childpid)
+


More information about the pypy-commit mailing list