diff options
author | Victor Stinner <vstinner@python.org> | 2021-04-28 13:46:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-28 13:46:57 (GMT) |
commit | 77db337f1e69213e62ba79a797540cc4ac23492e (patch) | |
tree | 3c3807e1972611e7973abceca791498417d8834e /Python | |
parent | 7f7cfc41185b651be9cb4d2759c40c3abf738485 (diff) | |
download | cpython-77db337f1e69213e62ba79a797540cc4ac23492e.zip cpython-77db337f1e69213e62ba79a797540cc4ac23492e.tar.gz cpython-77db337f1e69213e62ba79a797540cc4ac23492e.tar.bz2 |
bpo-43962: Fix _PyInterpreterState_IDIncref() (GH-25683) (GH-25686)
_PyInterpreterState_IDIncref() now calls
_PyInterpreterState_IDInitref() and always increments id_refcount.
(cherry picked from commit 32c5a174445ec93747240cd8472012276ed27acf)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pystate.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index b1d0f1c..56c184e 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -473,24 +473,25 @@ _PyInterpreterState_IDInitref(PyInterpreterState *interp) } -void +int _PyInterpreterState_IDIncref(PyInterpreterState *interp) { - if (interp->id_mutex == NULL) { - return; + if (_PyInterpreterState_IDInitref(interp) < 0) { + return -1; } + PyThread_acquire_lock(interp->id_mutex, WAIT_LOCK); interp->id_refcount += 1; PyThread_release_lock(interp->id_mutex); + return 0; } void _PyInterpreterState_IDDecref(PyInterpreterState *interp) { - if (interp->id_mutex == NULL) { - return; - } + assert(interp->id_mutex != NULL); + struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate; PyThread_acquire_lock(interp->id_mutex, WAIT_LOCK); assert(interp->id_refcount != 0); |