[Python-checkins] cpython (merge 3.5 -> 3.6): merge 3.5 (#28119)

benjamin.peterson python-checkins at python.org
Wed Sep 14 01:47:08 EDT 2016


https://hg.python.org/cpython/rev/5ab61df1ca96
changeset:   103785:5ab61df1ca96
branch:      3.6
parent:      103773:9e8e15993aae
parent:      103784:a27cb132e140
user:        Benjamin Peterson <benjamin at python.org>
date:        Tue Sep 13 22:46:15 2016 -0700
summary:
  merge 3.5 (#28119)

files:
  Python/formatter_unicode.c |  36 ++++++++++---------------
  1 files changed, 14 insertions(+), 22 deletions(-)


diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -115,11 +115,13 @@
 }
 
 /* Locale type codes. LT_NO_LOCALE must be zero. */
-#define LT_NO_LOCALE 0
-#define LT_DEFAULT_LOCALE 1
-#define LT_UNDERSCORE_LOCALE 2
-#define LT_UNDER_FOUR_LOCALE 3
-#define LT_CURRENT_LOCALE 4
+enum LocaleType {
+    LT_NO_LOCALE = 0,
+    LT_DEFAULT_LOCALE,
+    LT_UNDERSCORE_LOCALE,
+    LT_UNDER_FOUR_LOCALE,
+    LT_CURRENT_LOCALE
+};
 
 typedef struct {
     Py_UCS4 fill_char;
@@ -127,7 +129,7 @@
     int alternate;
     Py_UCS4 sign;
     Py_ssize_t width;
-    int thousands_separators;
+    enum LocaleType thousands_separators;
     Py_ssize_t precision;
     Py_UCS4 type;
 } InternalFormatSpec;
@@ -180,7 +182,7 @@
     format->alternate = 0;
     format->sign = '\0';
     format->width = -1;
-    format->thousands_separators = 0;
+    format->thousands_separators = LT_NO_LOCALE;
     format->precision = -1;
     format->type = default_type;
 
@@ -240,7 +242,7 @@
     }
     /* Underscore signifies add thousands separators */
     if (end-pos && READ_spec(pos) == '_') {
-        if (format->thousands_separators != 0) {
+        if (format->thousands_separators != LT_NO_LOCALE) {
             invalid_comma_and_underscore();
             return 0;
         }
@@ -700,7 +702,7 @@
    LT_CURRENT_LOCALE, a hard-coded locale if LT_DEFAULT_LOCALE or
    LT_UNDERSCORE_LOCALE/LT_UNDER_FOUR_LOCALE, or none if LT_NO_LOCALE. */
 static int
-get_locale_info(int type, LocaleInfo *locale_info)
+get_locale_info(enum LocaleType type, LocaleInfo *locale_info)
 {
     switch (type) {
     case LT_CURRENT_LOCALE: {
@@ -713,10 +715,8 @@
         locale_info->thousands_sep = PyUnicode_DecodeLocale(
                                          locale_data->thousands_sep,
                                          NULL);
-        if (locale_info->thousands_sep == NULL) {
-            Py_DECREF(locale_info->decimal_point);
+        if (locale_info->thousands_sep == NULL)
             return -1;
-        }
         locale_info->grouping = locale_data->grouping;
         break;
     }
@@ -726,11 +726,8 @@
         locale_info->decimal_point = PyUnicode_FromOrdinal('.');
         locale_info->thousands_sep = PyUnicode_FromOrdinal(
             type == LT_DEFAULT_LOCALE ? ',' : '_');
-        if (!locale_info->decimal_point || !locale_info->thousands_sep) {
-            Py_XDECREF(locale_info->decimal_point);
-            Py_XDECREF(locale_info->thousands_sep);
+        if (!locale_info->decimal_point || !locale_info->thousands_sep)
             return -1;
-        }
         if (type != LT_UNDER_FOUR_LOCALE)
             locale_info->grouping = "\3"; /* Group every 3 characters.  The
                                          (implicit) trailing 0 means repeat
@@ -741,15 +738,10 @@
     case LT_NO_LOCALE:
         locale_info->decimal_point = PyUnicode_FromOrdinal('.');
         locale_info->thousands_sep = PyUnicode_New(0, 0);
-        if (!locale_info->decimal_point || !locale_info->thousands_sep) {
-            Py_XDECREF(locale_info->decimal_point);
-            Py_XDECREF(locale_info->thousands_sep);
+        if (!locale_info->decimal_point || !locale_info->thousands_sep)
             return -1;
-        }
         locale_info->grouping = no_grouping;
         break;
-    default:
-        assert(0);
     }
     return 0;
 }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list