static size_t
_bisect(const int64_t value, const int64_t *arr, size_t size);
-static void
+static int
eject_from_strong_cache(const PyTypeObject *const type, PyObject *key);
static void
clear_strong_cache(const PyTypeObject *const type);
}
PyObject *instance = zone_from_strong_cache(type, key);
- if (instance != NULL) {
+ if (instance != NULL || PyErr_Occurred()) {
return instance;
}
while ((item = PyIter_Next(iter))) {
// Remove from strong cache
- eject_from_strong_cache(type, item);
+ if (eject_from_strong_cache(type, item) < 0) {
+ Py_DECREF(item);
+ break;
+ }
// Remove from weak cache
PyObject *tmp = PyObject_CallMethodObjArgs(weak_cache, pop, item,
{
const StrongCacheNode *node = root;
while (node != NULL) {
- if (PyObject_RichCompareBool(key, node->key, Py_EQ)) {
+ int rv = PyObject_RichCompareBool(key, node->key, Py_EQ);
+ if (rv < 0) {
+ return NULL;
+ }
+ if (rv) {
return (StrongCacheNode *)node;
}
*
* This function is used to enable the per-key functionality in clear_cache.
*/
-static void
+static int
eject_from_strong_cache(const PyTypeObject *const type, PyObject *key)
{
if (type != &PyZoneInfo_ZoneInfoType) {
- return;
+ return 0;
}
StrongCacheNode *node = find_in_strong_cache(ZONEINFO_STRONG_CACHE, key);
strong_cache_node_free(node);
}
+ else if (PyErr_Occurred()) {
+ return -1;
+ }
+ return 0;
}
/* Moves a node to the front of the LRU cache.