@@ -36,8 +36,8 @@ typedef struct {
36
36
PyObject * key ;
37
37
PyObject * file_repr ;
38
38
PyObject * weakreflist ;
39
- unsigned int num_transitions ;
40
- unsigned int num_ttinfos ;
39
+ size_t num_transitions ;
40
+ size_t num_ttinfos ;
41
41
int64_t * trans_list_utc ;
42
42
int64_t * trans_list_wall [2 ];
43
43
_ttinfo * * trans_ttinfos ; // References to the ttinfo for each transition
@@ -117,14 +117,14 @@ ts_to_local(size_t *trans_idx, int64_t *trans_utc, long *utcoff,
117
117
static int
118
118
parse_tz_str (PyObject * tz_str_obj , _tzrule * out );
119
119
120
- static ssize_t
120
+ static Py_ssize_t
121
121
parse_abbr (const char * const p , PyObject * * abbr );
122
- static ssize_t
122
+ static Py_ssize_t
123
123
parse_tz_delta (const char * const p , long * total_seconds );
124
- static ssize_t
124
+ static Py_ssize_t
125
125
parse_transition_time (const char * const p , int8_t * hour , int8_t * minute ,
126
126
int8_t * second );
127
- static ssize_t
127
+ static Py_ssize_t
128
128
parse_transition_rule (const char * const p , TransitionRuleType * * out );
129
129
130
130
static _ttinfo *
@@ -891,12 +891,12 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
891
891
892
892
// Load the relevant sizes
893
893
Py_ssize_t num_transitions = PyTuple_Size (trans_utc );
894
- if (num_transitions == -1 ) {
894
+ if (num_transitions < 0 ) {
895
895
goto error ;
896
896
}
897
897
898
898
Py_ssize_t num_ttinfos = PyTuple_Size (utcoff_list );
899
- if (num_ttinfos == -1 ) {
899
+ if (num_ttinfos < 0 ) {
900
900
goto error ;
901
901
}
902
902
@@ -908,7 +908,7 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
908
908
PyMem_Malloc (self -> num_transitions * sizeof (int64_t ));
909
909
trans_idx = PyMem_Malloc (self -> num_transitions * sizeof (Py_ssize_t ));
910
910
911
- for (Py_ssize_t i = 0 ; i < self -> num_transitions ; ++ i ) {
911
+ for (size_t i = 0 ; i < self -> num_transitions ; ++ i ) {
912
912
PyObject * num = PyTuple_GetItem (trans_utc , i );
913
913
if (num == NULL ) {
914
914
goto error ;
@@ -946,7 +946,7 @@ load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
946
946
if (utcoff == NULL || isdst == NULL ) {
947
947
goto error ;
948
948
}
949
- for (Py_ssize_t i = 0 ; i < self -> num_ttinfos ; ++ i ) {
949
+ for (size_t i = 0 ; i < self -> num_ttinfos ; ++ i ) {
950
950
PyObject * num = PyTuple_GetItem (utcoff_list , i );
951
951
if (num == NULL ) {
952
952
goto error ;
@@ -1468,7 +1468,7 @@ parse_tz_str(PyObject *tz_str_obj, _tzrule *out)
1468
1468
char * p = tz_str ;
1469
1469
1470
1470
// Read the `std` abbreviation, which must be at least 3 characters long.
1471
- ssize_t num_chars = parse_abbr (p , & std_abbr );
1471
+ Py_ssize_t num_chars = parse_abbr (p , & std_abbr );
1472
1472
if (num_chars < 1 ) {
1473
1473
PyErr_Format (PyExc_ValueError , "Invalid STD format in %R" , tz_str_obj );
1474
1474
goto error ;
@@ -1565,18 +1565,19 @@ parse_tz_str(PyObject *tz_str_obj, _tzrule *out)
1565
1565
return -1 ;
1566
1566
}
1567
1567
1568
- static ssize_t
1569
- parse_uint (const char * const p )
1568
+ static int
1569
+ parse_uint (const char * const p , uint8_t * value )
1570
1570
{
1571
1571
if (!isdigit (* p )) {
1572
1572
return -1 ;
1573
1573
}
1574
1574
1575
- return (* p ) - '0' ;
1575
+ * value = (* p ) - '0' ;
1576
+ return 0 ;
1576
1577
}
1577
1578
1578
1579
/* Parse the STD and DST abbreviations from a TZ string. */
1579
- static ssize_t
1580
+ static Py_ssize_t
1580
1581
parse_abbr (const char * const p , PyObject * * abbr )
1581
1582
{
1582
1583
const char * ptr = p ;
@@ -1629,7 +1630,7 @@ parse_abbr(const char *const p, PyObject **abbr)
1629
1630
}
1630
1631
1631
1632
/* Parse a UTC offset from a TZ str. */
1632
- static ssize_t
1633
+ static Py_ssize_t
1633
1634
parse_tz_delta (const char * const p , long * total_seconds )
1634
1635
{
1635
1636
// From the POSIX spec:
@@ -1712,7 +1713,7 @@ parse_tz_delta(const char *const p, long *total_seconds)
1712
1713
}
1713
1714
1714
1715
/* Parse the date portion of a transition rule. */
1715
- static ssize_t
1716
+ static Py_ssize_t
1716
1717
parse_transition_rule (const char * const p , TransitionRuleType * * out )
1717
1718
{
1718
1719
// The full transition rule indicates when to change back and forth between
@@ -1739,20 +1740,18 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
1739
1740
if (* ptr == 'M' ) {
1740
1741
uint8_t month , week , day ;
1741
1742
ptr ++ ;
1742
- ssize_t tmp = parse_uint (ptr );
1743
- if (tmp < 0 ) {
1743
+ if (parse_uint (ptr , & month )) {
1744
1744
return -1 ;
1745
1745
}
1746
- month = (uint8_t )tmp ;
1747
1746
ptr ++ ;
1748
1747
if (* ptr != '.' ) {
1749
- tmp = parse_uint ( ptr ) ;
1750
- if (tmp < 0 ) {
1748
+ uint8_t tmp ;
1749
+ if (parse_uint ( ptr , & tmp ) ) {
1751
1750
return -1 ;
1752
1751
}
1753
1752
1754
1753
month *= 10 ;
1755
- month += ( uint8_t ) tmp ;
1754
+ month += tmp ;
1756
1755
ptr ++ ;
1757
1756
}
1758
1757
@@ -1763,18 +1762,15 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
1763
1762
}
1764
1763
ptr ++ ;
1765
1764
1766
- tmp = parse_uint (ptr );
1767
- if (tmp < 0 ) {
1765
+ if (parse_uint (ptr , values [i ])) {
1768
1766
return -1 ;
1769
1767
}
1770
1768
ptr ++ ;
1771
-
1772
- * (values [i ]) = tmp ;
1773
1769
}
1774
1770
1775
1771
if (* ptr == '/' ) {
1776
1772
ptr ++ ;
1777
- ssize_t num_chars =
1773
+ Py_ssize_t num_chars =
1778
1774
parse_transition_time (ptr , & hour , & minute , & second );
1779
1775
if (num_chars < 0 ) {
1780
1776
return -1 ;
@@ -1816,7 +1812,7 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
1816
1812
1817
1813
if (* ptr == '/' ) {
1818
1814
ptr ++ ;
1819
- ssize_t num_chars =
1815
+ Py_ssize_t num_chars =
1820
1816
parse_transition_time (ptr , & hour , & minute , & second );
1821
1817
if (num_chars < 0 ) {
1822
1818
return -1 ;
@@ -1840,7 +1836,7 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
1840
1836
}
1841
1837
1842
1838
/* Parse the time portion of a transition rule (e.g. following an /) */
1843
- static ssize_t
1839
+ static Py_ssize_t
1844
1840
parse_transition_time (const char * const p , int8_t * hour , int8_t * minute ,
1845
1841
int8_t * second )
1846
1842
{
0 commit comments