@@ -115,19 +115,21 @@ is_sign_element(Py_UCS4 c)
115115}
116116
117117/* Locale type codes. LT_NO_LOCALE must be zero. */
118- #define LT_NO_LOCALE 0
119- #define LT_DEFAULT_LOCALE 1
120- #define LT_UNDERSCORE_LOCALE 2
121- #define LT_UNDER_FOUR_LOCALE 3
122- #define LT_CURRENT_LOCALE 4
118+ enum LocaleType {
119+ LT_NO_LOCALE = 0 ,
120+ LT_DEFAULT_LOCALE ,
121+ LT_UNDERSCORE_LOCALE ,
122+ LT_UNDER_FOUR_LOCALE ,
123+ LT_CURRENT_LOCALE
124+ };
123125
124126typedef struct {
125127 Py_UCS4 fill_char ;
126128 Py_UCS4 align ;
127129 int alternate ;
128130 Py_UCS4 sign ;
129131 Py_ssize_t width ;
130- int thousands_separators ;
132+ enum LocaleType thousands_separators ;
131133 Py_ssize_t precision ;
132134 Py_UCS4 type ;
133135} InternalFormatSpec ;
@@ -180,7 +182,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
180182 format -> alternate = 0 ;
181183 format -> sign = '\0' ;
182184 format -> width = -1 ;
183- format -> thousands_separators = 0 ;
185+ format -> thousands_separators = LT_NO_LOCALE ;
184186 format -> precision = -1 ;
185187 format -> type = default_type ;
186188
@@ -240,7 +242,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
240242 }
241243 /* Underscore signifies add thousands separators */
242244 if (end - pos && READ_spec (pos ) == '_' ) {
243- if (format -> thousands_separators != 0 ) {
245+ if (format -> thousands_separators != LT_NO_LOCALE ) {
244246 invalid_comma_and_underscore ();
245247 return 0 ;
246248 }
@@ -700,7 +702,7 @@ static const char no_grouping[1] = {CHAR_MAX};
700702 LT_CURRENT_LOCALE, a hard-coded locale if LT_DEFAULT_LOCALE or
701703 LT_UNDERSCORE_LOCALE/LT_UNDER_FOUR_LOCALE, or none if LT_NO_LOCALE. */
702704static int
703- get_locale_info (int type , LocaleInfo * locale_info )
705+ get_locale_info (enum LocaleType type , LocaleInfo * locale_info )
704706{
705707 switch (type ) {
706708 case LT_CURRENT_LOCALE : {
@@ -713,10 +715,8 @@ get_locale_info(int type, LocaleInfo *locale_info)
713715 locale_info -> thousands_sep = PyUnicode_DecodeLocale (
714716 locale_data -> thousands_sep ,
715717 NULL );
716- if (locale_info -> thousands_sep == NULL ) {
717- Py_DECREF (locale_info -> decimal_point );
718+ if (locale_info -> thousands_sep == NULL )
718719 return -1 ;
719- }
720720 locale_info -> grouping = locale_data -> grouping ;
721721 break ;
722722 }
@@ -726,11 +726,8 @@ get_locale_info(int type, LocaleInfo *locale_info)
726726 locale_info -> decimal_point = PyUnicode_FromOrdinal ('.' );
727727 locale_info -> thousands_sep = PyUnicode_FromOrdinal (
728728 type == LT_DEFAULT_LOCALE ? ',' : '_' );
729- if (!locale_info -> decimal_point || !locale_info -> thousands_sep ) {
730- Py_XDECREF (locale_info -> decimal_point );
731- Py_XDECREF (locale_info -> thousands_sep );
729+ if (!locale_info -> decimal_point || !locale_info -> thousands_sep )
732730 return -1 ;
733- }
734731 if (type != LT_UNDER_FOUR_LOCALE )
735732 locale_info -> grouping = "\3" ; /* Group every 3 characters. The
736733 (implicit) trailing 0 means repeat
@@ -741,15 +738,10 @@ get_locale_info(int type, LocaleInfo *locale_info)
741738 case LT_NO_LOCALE :
742739 locale_info -> decimal_point = PyUnicode_FromOrdinal ('.' );
743740 locale_info -> thousands_sep = PyUnicode_New (0 , 0 );
744- if (!locale_info -> decimal_point || !locale_info -> thousands_sep ) {
745- Py_XDECREF (locale_info -> decimal_point );
746- Py_XDECREF (locale_info -> thousands_sep );
741+ if (!locale_info -> decimal_point || !locale_info -> thousands_sep )
747742 return -1 ;
748- }
749743 locale_info -> grouping = no_grouping ;
750744 break ;
751- default :
752- assert (0 );
753745 }
754746 return 0 ;
755747}
0 commit comments