PyOS_AfterFork_Child() uses PyStatus (GH-20596)

PyOS_AfterFork_Child() helper functions now return a PyStatus:
PyOS_AfterFork_Child() is now responsible to handle errors.

* Move _PySignal_AfterFork() to the internal C API
* Add #ifdef HAVE_FORK on _PyGILState_Reinit(), _PySignal_AfterFork()
  and _PyInterpreterState_DeleteExceptMain().
This commit is contained in:
Victor Stinner 2020-06-02 15:51:37 +02:00 committed by GitHub
parent 297257f7bc
commit 26881c8fae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 84 additions and 50 deletions

View file

@ -148,7 +148,7 @@ _PyImportZip_Init(PyThreadState *tstate)
in different threads to return with a partially loaded module.
These calls are serialized by the global interpreter lock. */
static PyThread_type_lock import_lock = 0;
static PyThread_type_lock import_lock = NULL;
static unsigned long import_lock_thread = PYTHREAD_INVALID_THREAD_ID;
static int import_lock_level = 0;
@ -171,7 +171,7 @@ _PyImport_AcquireLock(void)
!PyThread_acquire_lock(import_lock, 0))
{
PyThreadState *tstate = PyEval_SaveThread();
PyThread_acquire_lock(import_lock, 1);
PyThread_acquire_lock(import_lock, WAIT_LOCK);
PyEval_RestoreThread(tstate);
}
assert(import_lock_level == 0);
@ -197,19 +197,19 @@ _PyImport_ReleaseLock(void)
}
#ifdef HAVE_FORK
/* This function is called from PyOS_AfterFork_Child to ensure that newly
/* This function is called from PyOS_AfterFork_Child() to ensure that newly
created child processes do not share locks with the parent.
We now acquire the import lock around fork() calls but on some platforms
(Solaris 9 and earlier? see isue7242) that still left us with problems. */
void
PyStatus
_PyImport_ReInitLock(void)
{
if (import_lock != NULL) {
if (_PyThread_at_fork_reinit(&import_lock) < 0) {
_Py_FatalErrorFunc(__func__, "failed to create a new lock");
return _PyStatus_ERR("failed to create a new lock");
}
}
if (import_lock_level > 1) {
/* Forked as a side effect of import */
unsigned long me = PyThread_get_thread_ident();
@ -224,6 +224,7 @@ _PyImport_ReInitLock(void)
import_lock_thread = PYTHREAD_INVALID_THREAD_ID;
import_lock_level = 0;
}
return _PyStatus_OK();
}
#endif