summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2015-12-05 02:03:42 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2015-12-05 02:03:42 (GMT)
commit6a77c2d978277fc9597baaa6ff612666332bfdca (patch)
tree7b3501d6c3ca0f34d9c076828aa29184f2e89d98 /Modules
parentccddbb186bcaec77f52a8c37d8b3f56de4b871dd (diff)
parentafdd51343cafbc02443fa6f7a2166af951a67c64 (diff)
downloadcpython-6a77c2d978277fc9597baaa6ff612666332bfdca.zip
cpython-6a77c2d978277fc9597baaa6ff612666332bfdca.tar.gz
cpython-6a77c2d978277fc9597baaa6ff612666332bfdca.tar.bz2
Issue #25764: Merge subprocess fix from 3.4 into 3.5
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_posixsubprocess.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index 2cdc381..8bedab5 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -47,17 +47,25 @@
#define POSIX_CALL(call) do { if ((call) == -1) goto error; } while (0)
-/* Given the gc module call gc.enable() and return 0 on success. */
+/* If gc was disabled, call gc.enable(). Return 0 on success. */
static int
-_enable_gc(PyObject *gc_module)
+_enable_gc(int need_to_reenable_gc, PyObject *gc_module)
{
PyObject *result;
_Py_IDENTIFIER(enable);
+ PyObject *exctype, *val, *tb;
- result = _PyObject_CallMethodId(gc_module, &PyId_enable, NULL);
- if (result == NULL)
- return 1;
- Py_DECREF(result);
+ if (need_to_reenable_gc) {
+ PyErr_Fetch(&exctype, &val, &tb);
+ result = _PyObject_CallMethodId(gc_module, &PyId_enable, NULL);
+ if (exctype != NULL) {
+ PyErr_Restore(exctype, val, tb);
+ }
+ if (result == NULL) {
+ return 1;
+ }
+ Py_DECREF(result);
+ }
return 0;
}
@@ -698,6 +706,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
&& _PyImport_ReleaseLock() < 0 && !PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"not holding the import lock");
+ pid = -1;
}
import_lock_held = 0;
#endif
@@ -710,9 +719,8 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
_Py_FreeCharPArray(exec_array);
/* Reenable gc in the parent process (or if fork failed). */
- if (need_to_reenable_gc && _enable_gc(gc_module)) {
- Py_XDECREF(gc_module);
- return NULL;
+ if (_enable_gc(need_to_reenable_gc, gc_module)) {
+ pid = -1;
}
Py_XDECREF(preexec_fn_args_tuple);
Py_XDECREF(gc_module);
@@ -736,14 +744,7 @@ cleanup:
Py_XDECREF(converted_args);
Py_XDECREF(fast_args);
Py_XDECREF(preexec_fn_args_tuple);
-
- /* Reenable gc if it was disabled. */
- if (need_to_reenable_gc) {
- PyObject *exctype, *val, *tb;
- PyErr_Fetch(&exctype, &val, &tb);
- _enable_gc(gc_module);
- PyErr_Restore(exctype, val, tb);
- }
+ _enable_gc(need_to_reenable_gc, gc_module);
Py_XDECREF(gc_module);
return NULL;
}