@@ -1087,19 +1087,8 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
10871087 The cache dict holds one reference to the link.
10881088 We created one other reference when the link was created.
10891089 The linked list only has borrowed references. */
1090- (void )_PyDict_Pop_KnownHash ((PyDictObject * )self -> cache , link -> key ,
1091- link -> hash , Py_None , & popresult );
1092- if (popresult == Py_None ) {
1093- /* Getting here means that the user function call or another
1094- thread has already removed the old key from the dictionary.
1095- This link is now an orphan. Since we don't want to leave the
1096- cache in an inconsistent state, we don't restore the link. */
1097- Py_DECREF (popresult );
1098- Py_DECREF (link );
1099- Py_DECREF (key );
1100- return result ;
1101- }
1102- if (popresult == NULL ) {
1090+ if (_PyDict_Pop_KnownHash ((PyDictObject * )self -> cache , link -> key ,
1091+ link -> hash , Py_None , & popresult ) < 0 ) {
11031092 /* An error arose while trying to remove the oldest key (the one
11041093 being evicted) from the cache. We restore the link to its
11051094 original position as the oldest link. Then we allow the
@@ -1110,6 +1099,17 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
11101099 Py_DECREF (result );
11111100 return NULL ;
11121101 }
1102+
1103+ if (popresult == Py_None ) {
1104+ /* Getting here means that the user function call or another
1105+ thread has already removed the old key from the dictionary.
1106+ This link is now an orphan. Since we don't want to leave the
1107+ cache in an inconsistent state, we don't restore the link. */
1108+ Py_DECREF (popresult );
1109+ Py_DECREF (link );
1110+ Py_DECREF (key );
1111+ return result ;
1112+ }
11131113 /* Keep a reference to the old key and old result to prevent their
11141114 ref counts from going to zero during the update. That will
11151115 prevent potentially arbitrary object clean-up code (i.e. __del__)
0 commit comments