diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index fe7e6c2d735f52..480f4433b6a9f6 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -353,15 +353,10 @@ try_reuse_basic_ref(PyWeakReference *list, PyTypeObject *type, cand = proxy; } -#ifdef Py_GIL_DISABLED - if (cand != NULL && !_Py_TryIncref((PyObject *) cand)) { - cand = NULL; + if (cand != NULL && _Py_TryIncref((PyObject *) cand)) { + return cand; } -#else - Py_XINCREF(cand); -#endif - - return cand; + return NULL; } static int