Commit bc5b80ba authored by Victor Stinner's avatar Victor Stinner

Close #24784: Fix compilation without thread support

Add "#ifdef WITH_THREAD" around cals to:

* PyGILState_Check()
* _PyImport_AcquireLock()
* _PyImport_ReleaseLock()
parent b16e12aa
...@@ -549,7 +549,9 @@ subprocess_fork_exec(PyObject* self, PyObject *args) ...@@ -549,7 +549,9 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
int need_to_reenable_gc = 0; int need_to_reenable_gc = 0;
char *const *exec_array, *const *argv = NULL, *const *envp = NULL; char *const *exec_array, *const *argv = NULL, *const *envp = NULL;
Py_ssize_t arg_num; Py_ssize_t arg_num;
#ifdef WITH_THREAD
int import_lock_held = 0; int import_lock_held = 0;
#endif
if (!PyArg_ParseTuple( if (!PyArg_ParseTuple(
args, "OOpOOOiiiiiiiiiiO:fork_exec", args, "OOpOOOiiiiiiiiiiO:fork_exec",
...@@ -644,8 +646,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args) ...@@ -644,8 +646,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
preexec_fn_args_tuple = PyTuple_New(0); preexec_fn_args_tuple = PyTuple_New(0);
if (!preexec_fn_args_tuple) if (!preexec_fn_args_tuple)
goto cleanup; goto cleanup;
#ifdef WITH_THREAD
_PyImport_AcquireLock(); _PyImport_AcquireLock();
import_lock_held = 1; import_lock_held = 1;
#endif
} }
if (cwd_obj != Py_None) { if (cwd_obj != Py_None) {
...@@ -688,12 +692,14 @@ subprocess_fork_exec(PyObject* self, PyObject *args) ...@@ -688,12 +692,14 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
/* Capture the errno exception before errno can be clobbered. */ /* Capture the errno exception before errno can be clobbered. */
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);
} }
if (preexec_fn != Py_None && #ifdef WITH_THREAD
_PyImport_ReleaseLock() < 0 && !PyErr_Occurred()) { if (preexec_fn != Py_None
&& _PyImport_ReleaseLock() < 0 && !PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
"not holding the import lock"); "not holding the import lock");
} }
import_lock_held = 0; import_lock_held = 0;
#endif
/* Parent process */ /* Parent process */
if (envp) if (envp)
...@@ -716,8 +722,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args) ...@@ -716,8 +722,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
return PyLong_FromPid(pid); return PyLong_FromPid(pid);
cleanup: cleanup:
#ifdef WITH_THREAD
if (import_lock_held) if (import_lock_held)
_PyImport_ReleaseLock(); _PyImport_ReleaseLock();
#endif
if (envp) if (envp)
_Py_FreeCharPArray(envp); _Py_FreeCharPArray(envp);
if (argv) if (argv)
......
...@@ -719,8 +719,10 @@ sock_call_ex(PySocketSockObject *s, ...@@ -719,8 +719,10 @@ sock_call_ex(PySocketSockObject *s,
int deadline_initialized = 0; int deadline_initialized = 0;
int res; int res;
#ifdef WITH_THREAD
/* sock_call() must be called with the GIL held. */ /* sock_call() must be called with the GIL held. */
assert(PyGILState_Check()); assert(PyGILState_Check());
#endif
/* outer loop to retry select() when select() is interrupted by a signal /* outer loop to retry select() when select() is interrupted by a signal
or to retry select()+sock_func() on false positive (see above) */ or to retry select()+sock_func() on false positive (see above) */
......
...@@ -986,8 +986,10 @@ _Py_open_impl(const char *pathname, int flags, int gil_held) ...@@ -986,8 +986,10 @@ _Py_open_impl(const char *pathname, int flags, int gil_held)
int int
_Py_open(const char *pathname, int flags) _Py_open(const char *pathname, int flags)
{ {
#ifdef WITH_THREAD
/* _Py_open() must be called with the GIL held. */ /* _Py_open() must be called with the GIL held. */
assert(PyGILState_Check()); assert(PyGILState_Check());
#endif
return _Py_open_impl(pathname, flags, 1); return _Py_open_impl(pathname, flags, 1);
} }
...@@ -1080,7 +1082,9 @@ _Py_fopen_obj(PyObject *path, const char *mode) ...@@ -1080,7 +1082,9 @@ _Py_fopen_obj(PyObject *path, const char *mode)
wchar_t wmode[10]; wchar_t wmode[10];
int usize; int usize;
#ifdef WITH_THREAD
assert(PyGILState_Check()); assert(PyGILState_Check());
#endif
if (!PyUnicode_Check(path)) { if (!PyUnicode_Check(path)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
...@@ -1108,7 +1112,9 @@ _Py_fopen_obj(PyObject *path, const char *mode) ...@@ -1108,7 +1112,9 @@ _Py_fopen_obj(PyObject *path, const char *mode)
PyObject *bytes; PyObject *bytes;
char *path_bytes; char *path_bytes;
#ifdef WITH_THREAD
assert(PyGILState_Check()); assert(PyGILState_Check());
#endif
if (!PyUnicode_FSConverter(path, &bytes)) if (!PyUnicode_FSConverter(path, &bytes))
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment