@@ -272,6 +272,7 @@ zoneinfo_new_instance(zoneinfo_state *state, PyTypeObject *type, PyObject *key)
272272
273273 goto cleanup ;
274274error :
275+ assert (PyErr_Occurred ());
275276 Py_CLEAR (self );
276277cleanup :
277278 if (file_obj != NULL ) {
@@ -458,6 +459,7 @@ zoneinfo_ZoneInfo_from_file_impl(PyTypeObject *type, PyTypeObject *cls,
458459 return (PyObject * )self ;
459460
460461error :
462+ assert (PyErr_Occurred ());
461463 Py_XDECREF (file_repr );
462464 Py_XDECREF (self );
463465 return NULL ;
@@ -1043,10 +1045,12 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
10431045 self -> trans_list_utc =
10441046 PyMem_Malloc (self -> num_transitions * sizeof (int64_t ));
10451047 if (self -> trans_list_utc == NULL ) {
1048+ PyErr_NoMemory ();
10461049 goto error ;
10471050 }
10481051 trans_idx = PyMem_Malloc (self -> num_transitions * sizeof (Py_ssize_t ));
10491052 if (trans_idx == NULL ) {
1053+ PyErr_NoMemory ();
10501054 goto error ;
10511055 }
10521056
@@ -1086,6 +1090,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
10861090 isdst = PyMem_Malloc (self -> num_ttinfos * sizeof (unsigned char ));
10871091
10881092 if (utcoff == NULL || isdst == NULL ) {
1093+ PyErr_NoMemory ();
10891094 goto error ;
10901095 }
10911096 for (size_t i = 0 ; i < self -> num_ttinfos ; ++ i ) {
@@ -1115,6 +1120,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
11151120
11161121 dstoff = PyMem_Calloc (self -> num_ttinfos , sizeof (long ));
11171122 if (dstoff == NULL ) {
1123+ PyErr_NoMemory ();
11181124 goto error ;
11191125 }
11201126
@@ -1131,6 +1137,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
11311137 // Build _ttinfo objects from utcoff, dstoff and abbr
11321138 self -> _ttinfos = PyMem_Malloc (self -> num_ttinfos * sizeof (_ttinfo ));
11331139 if (self -> _ttinfos == NULL ) {
1140+ PyErr_NoMemory ();
11341141 goto error ;
11351142 }
11361143 for (size_t i = 0 ; i < self -> num_ttinfos ; ++ i ) {
@@ -1151,6 +1158,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
11511158 self -> trans_ttinfos =
11521159 PyMem_Calloc (self -> num_transitions , sizeof (_ttinfo * ));
11531160 if (self -> trans_ttinfos == NULL ) {
1161+ PyErr_NoMemory ();
11541162 goto error ;
11551163 }
11561164 for (size_t i = 0 ; i < self -> num_transitions ; ++ i ) {
@@ -1669,9 +1677,11 @@ parse_tz_str(zoneinfo_state *state, PyObject *tz_str_obj, _tzrule *out)
16691677 p ++ ;
16701678
16711679 if (parse_transition_rule (& p , transitions [i ])) {
1672- PyErr_Format (PyExc_ValueError ,
1673- "Malformed transition rule in TZ string: %R" ,
1674- tz_str_obj );
1680+ if (!PyErr_ExceptionMatches (PyExc_MemoryError )) {
1681+ PyErr_Format (PyExc_ValueError ,
1682+ "Malformed transition rule in TZ string: %R" ,
1683+ tz_str_obj );
1684+ }
16751685 goto error ;
16761686 }
16771687 }
@@ -1871,6 +1881,7 @@ parse_transition_rule(const char **p, TransitionRuleType **out)
18711881
18721882 CalendarRule * rv = PyMem_Calloc (1 , sizeof (CalendarRule ));
18731883 if (rv == NULL ) {
1884+ PyErr_NoMemory ();
18741885 return -1 ;
18751886 }
18761887
@@ -1902,6 +1913,7 @@ parse_transition_rule(const char **p, TransitionRuleType **out)
19021913
19031914 DayRule * rv = PyMem_Calloc (1 , sizeof (DayRule ));
19041915 if (rv == NULL ) {
1916+ PyErr_NoMemory ();
19051917 return -1 ;
19061918 }
19071919
@@ -2135,6 +2147,7 @@ ts_to_local(size_t *trans_idx, int64_t *trans_utc, long *utcoff,
21352147 for (size_t i = 0 ; i < 2 ; ++ i ) {
21362148 trans_local [i ] = PyMem_Malloc (num_transitions * sizeof (int64_t ));
21372149 if (trans_local [i ] == NULL ) {
2150+ PyErr_NoMemory ();
21382151 return -1 ;
21392152 }
21402153
0 commit comments