Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92f0113

Browse files
committed
Close #24784: Fix compilation without thread support
Add "#ifdef WITH_THREAD" around cals to: * PyGILState_Check() * _PyImport_AcquireLock() * _PyImport_ReleaseLock()
1 parent 647dac9 commit 92f0113

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

Modules/_posixsubprocess.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,9 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
549549
int need_to_reenable_gc = 0;
550550
char *const *exec_array, *const *argv = NULL, *const *envp = NULL;
551551
Py_ssize_t arg_num;
552+
#ifdef WITH_THREAD
552553
int import_lock_held = 0;
554+
#endif
553555

554556
if (!PyArg_ParseTuple(
555557
args, "OOpOOOiiiiiiiiiiO:fork_exec",
@@ -644,8 +646,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
644646
preexec_fn_args_tuple = PyTuple_New(0);
645647
if (!preexec_fn_args_tuple)
646648
goto cleanup;
649+
#ifdef WITH_THREAD
647650
_PyImport_AcquireLock();
648651
import_lock_held = 1;
652+
#endif
649653
}
650654

651655
if (cwd_obj != Py_None) {
@@ -688,12 +692,14 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
688692
/* Capture the errno exception before errno can be clobbered. */
689693
PyErr_SetFromErrno(PyExc_OSError);
690694
}
691-
if (preexec_fn != Py_None &&
692-
_PyImport_ReleaseLock() < 0 && !PyErr_Occurred()) {
695+
#ifdef WITH_THREAD
696+
if (preexec_fn != Py_None
697+
&& _PyImport_ReleaseLock() < 0 && !PyErr_Occurred()) {
693698
PyErr_SetString(PyExc_RuntimeError,
694699
"not holding the import lock");
695700
}
696701
import_lock_held = 0;
702+
#endif
697703

698704
/* Parent process */
699705
if (envp)
@@ -716,8 +722,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
716722
return PyLong_FromPid(pid);
717723

718724
cleanup:
725+
#ifdef WITH_THREAD
719726
if (import_lock_held)
720727
_PyImport_ReleaseLock();
728+
#endif
721729
if (envp)
722730
_Py_FreeCharPArray(envp);
723731
if (argv)

Modules/socketmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,10 @@ sock_call_ex(PySocketSockObject *s,
719719
int deadline_initialized = 0;
720720
int res;
721721

722+
#ifdef WITH_THREAD
722723
/* sock_call() must be called with the GIL held. */
723724
assert(PyGILState_Check());
725+
#endif
724726

725727
/* outer loop to retry select() when select() is interrupted by a signal
726728
or to retry select()+sock_func() on false positive (see above) */

Python/fileutils.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,10 @@ _Py_open_impl(const char *pathname, int flags, int gil_held)
986986
int
987987
_Py_open(const char *pathname, int flags)
988988
{
989+
#ifdef WITH_THREAD
989990
/* _Py_open() must be called with the GIL held. */
990991
assert(PyGILState_Check());
992+
#endif
991993
return _Py_open_impl(pathname, flags, 1);
992994
}
993995

@@ -1080,7 +1082,9 @@ _Py_fopen_obj(PyObject *path, const char *mode)
10801082
wchar_t wmode[10];
10811083
int usize;
10821084

1085+
#ifdef WITH_THREAD
10831086
assert(PyGILState_Check());
1087+
#endif
10841088

10851089
if (!PyUnicode_Check(path)) {
10861090
PyErr_Format(PyExc_TypeError,
@@ -1108,7 +1112,9 @@ _Py_fopen_obj(PyObject *path, const char *mode)
11081112
PyObject *bytes;
11091113
char *path_bytes;
11101114

1115+
#ifdef WITH_THREAD
11111116
assert(PyGILState_Check());
1117+
#endif
11121118

11131119
if (!PyUnicode_FSConverter(path, &bytes))
11141120
return NULL;

0 commit comments

Comments
 (0)