@@ -1087,19 +1087,8 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
1087
1087
The cache dict holds one reference to the link.
1088
1088
We created one other reference when the link was created.
1089
1089
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 ) {
1103
1092
/* An error arose while trying to remove the oldest key (the one
1104
1093
being evicted) from the cache. We restore the link to its
1105
1094
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
1110
1099
Py_DECREF (result );
1111
1100
return NULL ;
1112
1101
}
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
+ }
1113
1113
/* Keep a reference to the old key and old result to prevent their
1114
1114
ref counts from going to zero during the update. That will
1115
1115
prevent potentially arbitrary object clean-up code (i.e. __del__)
0 commit comments