@@ -164,7 +164,7 @@ is_leap_year(int year);
164
164
static size_t
165
165
_bisect (const int64_t value , const int64_t * arr , size_t size );
166
166
167
- static void
167
+ static int
168
168
eject_from_strong_cache (const PyTypeObject * const type , PyObject * key );
169
169
static void
170
170
clear_strong_cache (const PyTypeObject * const type );
@@ -266,7 +266,7 @@ zoneinfo_new(PyTypeObject *type, PyObject *args, PyObject *kw)
266
266
}
267
267
268
268
PyObject * instance = zone_from_strong_cache (type , key );
269
- if (instance != NULL ) {
269
+ if (instance != NULL || PyErr_Occurred () ) {
270
270
return instance ;
271
271
}
272
272
@@ -429,7 +429,10 @@ zoneinfo_clear_cache(PyObject *cls, PyObject *args, PyObject *kwargs)
429
429
430
430
while ((item = PyIter_Next (iter ))) {
431
431
// Remove from strong cache
432
- eject_from_strong_cache (type , item );
432
+ if (eject_from_strong_cache (type , item ) < 0 ) {
433
+ Py_DECREF (item );
434
+ break ;
435
+ }
433
436
434
437
// Remove from weak cache
435
438
PyObject * tmp = PyObject_CallMethodObjArgs (weak_cache , pop , item ,
@@ -2342,7 +2345,11 @@ find_in_strong_cache(const StrongCacheNode *const root, PyObject *const key)
2342
2345
{
2343
2346
const StrongCacheNode * node = root ;
2344
2347
while (node != NULL ) {
2345
- if (PyObject_RichCompareBool (key , node -> key , Py_EQ )) {
2348
+ int rv = PyObject_RichCompareBool (key , node -> key , Py_EQ );
2349
+ if (rv < 0 ) {
2350
+ return NULL ;
2351
+ }
2352
+ if (rv ) {
2346
2353
return (StrongCacheNode * )node ;
2347
2354
}
2348
2355
@@ -2356,11 +2363,11 @@ find_in_strong_cache(const StrongCacheNode *const root, PyObject *const key)
2356
2363
*
2357
2364
* This function is used to enable the per-key functionality in clear_cache.
2358
2365
*/
2359
- static void
2366
+ static int
2360
2367
eject_from_strong_cache (const PyTypeObject * const type , PyObject * key )
2361
2368
{
2362
2369
if (type != & PyZoneInfo_ZoneInfoType ) {
2363
- return ;
2370
+ return 0 ;
2364
2371
}
2365
2372
2366
2373
StrongCacheNode * node = find_in_strong_cache (ZONEINFO_STRONG_CACHE , key );
@@ -2369,6 +2376,10 @@ eject_from_strong_cache(const PyTypeObject *const type, PyObject *key)
2369
2376
2370
2377
strong_cache_node_free (node );
2371
2378
}
2379
+ else if (PyErr_Occurred ()) {
2380
+ return -1 ;
2381
+ }
2382
+ return 0 ;
2372
2383
}
2373
2384
2374
2385
/* Moves a node to the front of the LRU cache.
0 commit comments