Commits

Armin Rigo committed 7e5b04e

Test and fix for CPython's issue952953.

Comments (0)

Files changed (2)

pypy/module/posix/interp_posix.py

         path: path of executable file
         args: iterable of strings
     """
-    command = fsencode_w(space, w_command)
-    try:
-        args_w = space.unpackiterable(w_args)
-        if len(args_w) < 1:
-            w_msg = space.wrap("execv() must have at least one argument")
-            raise OperationError(space.w_ValueError, w_msg)
-        args = [fsencode_w(space, w_arg) for w_arg in args_w]
-    except OperationError, e:
-        if not e.match(space, space.w_TypeError):
-            raise
-        msg = "execv() arg 2 must be an iterable of strings"
-        raise OperationError(space.w_TypeError, space.wrap(str(msg)))
-    try:
-        os.execv(command, args)
-    except OSError, e:
-        raise wrap_oserror(space, e)
+    execve(space, w_command, w_args, None)
 
 def _env2interp(space, w_env):
     env = {}
         env: dictionary of strings mapping to strings
     """
     command = fsencode_w(space, w_command)
-    args = [fsencode_w(space, w_arg) for w_arg in space.unpackiterable(w_args)]
-    env = _env2interp(space, w_env)
     try:
-        os.execve(command, args, env)
-    except OSError, e:
-        raise wrap_oserror(space, e)
+        args_w = space.unpackiterable(w_args)
+        if len(args_w) < 1:
+            w_msg = space.wrap("execv() must have at least one argument")
+            raise OperationError(space.w_ValueError, w_msg)
+        args = [fsencode_w(space, w_arg) for w_arg in args_w]
+    except OperationError, e:
+        if not e.match(space, space.w_TypeError):
+            raise
+        msg = "execv() arg 2 must be an iterable of strings"
+        raise OperationError(space.w_TypeError, space.wrap(str(msg)))
+    #
+    if w_env is None:    # when called via execv() above
+        try:
+            os.execv(command, args)
+        except OSError, e:
+            raise wrap_oserror(space, e)
+    else:
+        env = _env2interp(space, w_env)
+        try:
+            os.execve(command, args, env)
+        except OSError, e:
+            raise wrap_oserror(space, e)
 
 @unwrap_spec(mode=int, path='str0')
 def spawnv(space, mode, path, w_args):

pypy/module/posix/test/test_posix2.py

         def test_execv_no_args(self):
             os = self.posix
             raises(ValueError, os.execv, "notepad", [])
+            raises(ValueError, os.execve, "notepad", [], {})
 
         def test_execv_raising2(self):
             os = self.posix