Author: Amaury Forgeot d'Arc <[email protected]>
Branch: more-rposix
Changeset: r74347:e010a14828c5
Date: 2014-11-05 19:24 +0100
http://bitbucket.org/pypy/pypy/changeset/e010a14828c5/

Log:    Port os.execv and os.execve

diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -149,6 +149,9 @@
 c_dup2 = external(UNDERSCORE_ON_WIN32 + 'dup2', [rffi.INT, rffi.INT], rffi.INT)
 c_open = external(UNDERSCORE_ON_WIN32 + 'open',
                   [rffi.CCHARP, rffi.INT, rffi.MODE_T], rffi.INT)
+c_execv = external('execv', [rffi.CCHARP, rffi.CCHARPP], rffi.INT)
+c_execve = external('execve',
+                    [rffi.CCHARP, rffi.CCHARPP, rffi.CCHARPP], rffi.INT)
 # Win32 specific functions
 c_wopen = external(UNDERSCORE_ON_WIN32 + 'wopen',
                    [rffi.CWCHARP, rffi.INT, rffi.MODE_T], rffi.INT)
@@ -325,3 +328,31 @@
         raise OSError(get_errno(), "open failed")
     return intmask(fd)
         
+@register_replacement_for(getattr(os, 'execv', None),
+                          sandboxed_name='ll_os.ll_os_execv')
+def execv(path, args):
+    rstring.check_str0(path)
+    # This list conversion already takes care of NUL bytes.
+    l_args = rffi.ll_liststr2charpp(args)
+    c_execv(path, l_args)
+    rffi.free_charpp(l_args)
+    raise OSError(get_errno(), "execv failed")
+
+@register_replacement_for(getattr(os, 'execve', None),
+                          sandboxed_name='ll_os.ll_os_execve')
+def execve(path, args, env):
+    envstrs = []
+    for item in env.iteritems():
+        envstr = "%s=%s" % item
+        envstrs.append(envstr)
+
+    rstring.check_str0(path)
+    # This list conversion already takes care of NUL bytes.
+    l_args = rffi.ll_liststr2charpp(args)
+    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")
diff --git a/rpython/rtyper/module/ll_os.py b/rpython/rtyper/module/ll_os.py
--- a/rpython/rtyper/module/ll_os.py
+++ b/rpython/rtyper/module/ll_os.py
@@ -247,53 +247,6 @@
         return extdef([int], int, llimpl=c_func_llimpl,
                       export_name='ll_os.ll_os_' + name)
 
-    @registering_if(os, 'execv')
-    def register_os_execv(self):
-        os_execv = self.llexternal(
-            'execv',
-            [rffi.CCHARP, rffi.CCHARPP], rffi.INT)
-
-        def execv_llimpl(path, args):
-            l_args = rffi.ll_liststr2charpp(args)
-            os_execv(path, l_args)
-            rffi.free_charpp(l_args)
-            raise OSError(rposix.get_errno(), "execv failed")
-
-        return extdef([str0, [str0]], s_ImpossibleValue, llimpl=execv_llimpl,
-                      export_name="ll_os.ll_os_execv")
-
-
-    @registering_if(os, 'execve')
-    def register_os_execve(self):
-        os_execve = self.llexternal(
-            'execve',
-            [rffi.CCHARP, rffi.CCHARPP, rffi.CCHARPP], rffi.INT)
-
-        def execve_llimpl(path, args, env):
-            # XXX Check path, args, env for \0 and raise TypeErrors as
-            # appropriate
-            envstrs = []
-            for item in env.iteritems():
-                envstr = "%s=%s" % item
-                envstrs.append(envstr)
-
-            l_args = rffi.ll_liststr2charpp(args)
-            l_env = rffi.ll_liststr2charpp(envstrs)
-            os_execve(path, l_args, l_env)
-
-            # XXX untested
-            rffi.free_charpp(l_env)
-            rffi.free_charpp(l_args)
-
-            raise OSError(rposix.get_errno(), "execve failed")
-
-        return extdef(
-            [str0, [str0], {str0: str0}],
-            s_ImpossibleValue,
-            llimpl=execve_llimpl,
-            export_name="ll_os.ll_os_execve")
-
-
     @registering_if(posix, 'spawnv')
     def register_os_spawnv(self):
         os_spawnv = self.llexternal('spawnv',
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to