summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-04-16 23:49:32 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-04-16 23:49:32 (GMT)
commit0e59cc3fc347582d8625050de258a2dd6b87f978 (patch)
treea331216b541d0671cabc8328902e2f9c7487ce8e
parent9c0e94f95cb7c72da3554ead8b5b255455e6caae (diff)
downloadcpython-0e59cc3fc347582d8625050de258a2dd6b87f978.zip
cpython-0e59cc3fc347582d8625050de258a2dd6b87f978.tar.gz
cpython-0e59cc3fc347582d8625050de258a2dd6b87f978.tar.bz2
Issue #8393: subprocess accepts bytes, bytearray and str with surrogates for
the current working directory. Remove also a trailing space, and replace tabulation indentation by spaces.
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_posixsubprocess.c24
2 files changed, 23 insertions, 4 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 7e30651..a6e8586 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -315,6 +315,9 @@ C-API
Library
-------
+- Issue #8393: subprocess accepts bytes, bytearray and str with surrogates for
+ the current working directory.
+
- Issue #7606: XML-RPC traceback stored in X-traceback is now encoded to ASCII
using backslashreplace error handler
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index a6008ef..24a70bc 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -177,6 +177,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
int p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite;
int errpipe_read, errpipe_write, close_fds, restore_signals;
int call_setsid;
+ PyObject *cwd_obj, *cwd_obj2;
const char *cwd;
pid_t pid;
int need_to_reenable_gc = 0;
@@ -184,8 +185,9 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
Py_ssize_t arg_num;
if (!PyArg_ParseTuple(
- args, "OOOzOiiiiiiiiiiO:fork_exec",
- &process_args, &executable_list, &py_close_fds, &cwd, &env_list,
+ args, "OOOOOiiiiiiiiiiO:fork_exec",
+ &process_args, &executable_list, &py_close_fds,
+ &cwd_obj, &env_list,
&p2cread, &p2cwrite, &c2pread, &c2pwrite,
&errread, &errwrite, &errpipe_read, &errpipe_write,
&restore_signals, &call_setsid, &preexec_fn))
@@ -263,13 +265,25 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
preexec_fn_args_tuple = PyTuple_New(0);
if (!preexec_fn_args_tuple)
goto cleanup;
- _PyImport_AcquireLock();
+ _PyImport_AcquireLock();
+ }
+
+ if (cwd_obj != Py_None) {
+ if (PyUnicode_FSConverter(cwd_obj, &cwd_obj2) == 0)
+ goto cleanup;
+ if (PyBytes_Check(cwd_obj2))
+ cwd = PyBytes_AS_STRING(cwd_obj2);
+ else
+ cwd = PyByteArray_AS_STRING(cwd_obj2);
+ } else {
+ cwd = NULL;
+ cwd_obj2 = NULL;
}
pid = fork();
if (pid == 0) {
/* Child process */
- /*
+ /*
* Code from here to _exit() must only use async-signal-safe functions,
* listed at `man 7 signal` or
* http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html.
@@ -291,6 +305,8 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
_exit(255);
return NULL; /* Dead code to avoid a potential compiler warning. */
}
+ Py_XDECREF(cwd_obj2);
+
if (pid == -1) {
/* Capture the errno exception before errno can be clobbered. */
PyErr_SetFromErrno(PyExc_OSError);