[Python-checkins] cpython: Close #24784: Fix compilation without thread support
victor.stinner
python-checkins at python.org
Sun Oct 11 03:54:57 EDT 2015
https://hg.python.org/cpython/rev/3ab4f23ab983
changeset: 98672:3ab4f23ab983
user: Victor Stinner <victor.stinner at gmail.com>
date: Sun Oct 11 09:54:42 2015 +0200
summary:
Close #24784: Fix compilation without thread support
Add "#ifdef WITH_THREAD" around cals to:
* PyGILState_Check()
* _PyImport_AcquireLock()
* _PyImport_ReleaseLock()
files:
Modules/_posixsubprocess.c | 12 ++++++++++--
Modules/socketmodule.c | 2 ++
Python/fileutils.c | 6 ++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -549,7 +549,9 @@
int need_to_reenable_gc = 0;
char *const *exec_array, *const *argv = NULL, *const *envp = NULL;
Py_ssize_t arg_num;
+#ifdef WITH_THREAD
int import_lock_held = 0;
+#endif
if (!PyArg_ParseTuple(
args, "OOpOOOiiiiiiiiiiO:fork_exec",
@@ -644,8 +646,10 @@
preexec_fn_args_tuple = PyTuple_New(0);
if (!preexec_fn_args_tuple)
goto cleanup;
+#ifdef WITH_THREAD
_PyImport_AcquireLock();
import_lock_held = 1;
+#endif
}
if (cwd_obj != Py_None) {
@@ -688,12 +692,14 @@
/* Capture the errno exception before errno can be clobbered. */
PyErr_SetFromErrno(PyExc_OSError);
}
- if (preexec_fn != Py_None &&
- _PyImport_ReleaseLock() < 0 && !PyErr_Occurred()) {
+#ifdef WITH_THREAD
+ if (preexec_fn != Py_None
+ && _PyImport_ReleaseLock() < 0 && !PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"not holding the import lock");
}
import_lock_held = 0;
+#endif
/* Parent process */
if (envp)
@@ -716,8 +722,10 @@
return PyLong_FromPid(pid);
cleanup:
+#ifdef WITH_THREAD
if (import_lock_held)
_PyImport_ReleaseLock();
+#endif
if (envp)
_Py_FreeCharPArray(envp);
if (argv)
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -719,8 +719,10 @@
int deadline_initialized = 0;
int res;
+#ifdef WITH_THREAD
/* sock_call() must be called with the GIL held. */
assert(PyGILState_Check());
+#endif
/* outer loop to retry select() when select() is interrupted by a signal
or to retry select()+sock_func() on false positive (see above) */
diff --git a/Python/fileutils.c b/Python/fileutils.c
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -986,8 +986,10 @@
int
_Py_open(const char *pathname, int flags)
{
+#ifdef WITH_THREAD
/* _Py_open() must be called with the GIL held. */
assert(PyGILState_Check());
+#endif
return _Py_open_impl(pathname, flags, 1);
}
@@ -1080,7 +1082,9 @@
wchar_t wmode[10];
int usize;
+#ifdef WITH_THREAD
assert(PyGILState_Check());
+#endif
if (!PyUnicode_Check(path)) {
PyErr_Format(PyExc_TypeError,
@@ -1108,7 +1112,9 @@
PyObject *bytes;
char *path_bytes;
+#ifdef WITH_THREAD
assert(PyGILState_Check());
+#endif
if (!PyUnicode_FSConverter(path, &bytes))
return NULL;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list