@@ -163,7 +163,7 @@ is_leap_year(int year);
163163static size_t
164164_bisect (const int64_t value , const int64_t * arr , size_t size );
165165
166- static void
166+ static int
167167eject_from_strong_cache (const PyTypeObject * const type , PyObject * key );
168168static void
169169clear_strong_cache (const PyTypeObject * const type );
@@ -265,7 +265,7 @@ zoneinfo_new(PyTypeObject *type, PyObject *args, PyObject *kw)
265265 }
266266
267267 PyObject * instance = zone_from_strong_cache (type , key );
268- if (instance != NULL ) {
268+ if (instance != NULL || PyErr_Occurred () ) {
269269 return instance ;
270270 }
271271
@@ -428,7 +428,10 @@ zoneinfo_clear_cache(PyObject *cls, PyObject *args, PyObject *kwargs)
428428
429429 while ((item = PyIter_Next (iter ))) {
430430 // Remove from strong cache
431- eject_from_strong_cache (type , item );
431+ if (eject_from_strong_cache (type , item ) < 0 ) {
432+ Py_DECREF (item );
433+ break ;
434+ }
432435
433436 // Remove from weak cache
434437 PyObject * tmp = PyObject_CallMethodObjArgs (weak_cache , pop , item ,
@@ -2347,7 +2350,11 @@ find_in_strong_cache(const StrongCacheNode *const root, PyObject *const key)
23472350{
23482351 const StrongCacheNode * node = root ;
23492352 while (node != NULL ) {
2350- if (PyObject_RichCompareBool (key , node -> key , Py_EQ )) {
2353+ int rv = PyObject_RichCompareBool (key , node -> key , Py_EQ );
2354+ if (rv < 0 ) {
2355+ return NULL ;
2356+ }
2357+ if (rv ) {
23512358 return (StrongCacheNode * )node ;
23522359 }
23532360
@@ -2361,11 +2368,11 @@ find_in_strong_cache(const StrongCacheNode *const root, PyObject *const key)
23612368 *
23622369 * This function is used to enable the per-key functionality in clear_cache.
23632370 */
2364- static void
2371+ static int
23652372eject_from_strong_cache (const PyTypeObject * const type , PyObject * key )
23662373{
23672374 if (type != & PyZoneInfo_ZoneInfoType ) {
2368- return ;
2375+ return 0 ;
23692376 }
23702377
23712378 StrongCacheNode * node = find_in_strong_cache (ZONEINFO_STRONG_CACHE , key );
@@ -2374,6 +2381,10 @@ eject_from_strong_cache(const PyTypeObject *const type, PyObject *key)
23742381
23752382 strong_cache_node_free (node );
23762383 }
2384+ else if (PyErr_Occurred ()) {
2385+ return -1 ;
2386+ }
2387+ return 0 ;
23772388}
23782389
23792390/* Moves a node to the front of the LRU cache.
0 commit comments