Kaydet (Commit) 995026a8 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

merge 3.5 (#28119)

...@@ -115,11 +115,13 @@ is_sign_element(Py_UCS4 c) ...@@ -115,11 +115,13 @@ is_sign_element(Py_UCS4 c)
} }
/* Locale type codes. LT_NO_LOCALE must be zero. */ /* Locale type codes. LT_NO_LOCALE must be zero. */
#define LT_NO_LOCALE 0 enum LocaleType {
#define LT_DEFAULT_LOCALE 1 LT_NO_LOCALE = 0,
#define LT_UNDERSCORE_LOCALE 2 LT_DEFAULT_LOCALE,
#define LT_UNDER_FOUR_LOCALE 3 LT_UNDERSCORE_LOCALE,
#define LT_CURRENT_LOCALE 4 LT_UNDER_FOUR_LOCALE,
LT_CURRENT_LOCALE
};
typedef struct { typedef struct {
Py_UCS4 fill_char; Py_UCS4 fill_char;
...@@ -127,7 +129,7 @@ typedef struct { ...@@ -127,7 +129,7 @@ typedef struct {
int alternate; int alternate;
Py_UCS4 sign; Py_UCS4 sign;
Py_ssize_t width; Py_ssize_t width;
int thousands_separators; enum LocaleType thousands_separators;
Py_ssize_t precision; Py_ssize_t precision;
Py_UCS4 type; Py_UCS4 type;
} InternalFormatSpec; } InternalFormatSpec;
...@@ -180,7 +182,7 @@ parse_internal_render_format_spec(PyObject *format_spec, ...@@ -180,7 +182,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
format->alternate = 0; format->alternate = 0;
format->sign = '\0'; format->sign = '\0';
format->width = -1; format->width = -1;
format->thousands_separators = 0; format->thousands_separators = LT_NO_LOCALE;
format->precision = -1; format->precision = -1;
format->type = default_type; format->type = default_type;
...@@ -240,7 +242,7 @@ parse_internal_render_format_spec(PyObject *format_spec, ...@@ -240,7 +242,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
} }
/* Underscore signifies add thousands separators */ /* Underscore signifies add thousands separators */
if (end-pos && READ_spec(pos) == '_') { if (end-pos && READ_spec(pos) == '_') {
if (format->thousands_separators != 0) { if (format->thousands_separators != LT_NO_LOCALE) {
invalid_comma_and_underscore(); invalid_comma_and_underscore();
return 0; return 0;
} }
...@@ -700,7 +702,7 @@ static const char no_grouping[1] = {CHAR_MAX}; ...@@ -700,7 +702,7 @@ static const char no_grouping[1] = {CHAR_MAX};
LT_CURRENT_LOCALE, a hard-coded locale if LT_DEFAULT_LOCALE or 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. */ LT_UNDERSCORE_LOCALE/LT_UNDER_FOUR_LOCALE, or none if LT_NO_LOCALE. */
static int static int
get_locale_info(int type, LocaleInfo *locale_info) get_locale_info(enum LocaleType type, LocaleInfo *locale_info)
{ {
switch (type) { switch (type) {
case LT_CURRENT_LOCALE: { case LT_CURRENT_LOCALE: {
...@@ -713,10 +715,8 @@ get_locale_info(int type, LocaleInfo *locale_info) ...@@ -713,10 +715,8 @@ get_locale_info(int type, LocaleInfo *locale_info)
locale_info->thousands_sep = PyUnicode_DecodeLocale( locale_info->thousands_sep = PyUnicode_DecodeLocale(
locale_data->thousands_sep, locale_data->thousands_sep,
NULL); NULL);
if (locale_info->thousands_sep == NULL) { if (locale_info->thousands_sep == NULL)
Py_DECREF(locale_info->decimal_point);
return -1; return -1;
}
locale_info->grouping = locale_data->grouping; locale_info->grouping = locale_data->grouping;
break; break;
} }
...@@ -726,11 +726,8 @@ get_locale_info(int type, LocaleInfo *locale_info) ...@@ -726,11 +726,8 @@ get_locale_info(int type, LocaleInfo *locale_info)
locale_info->decimal_point = PyUnicode_FromOrdinal('.'); locale_info->decimal_point = PyUnicode_FromOrdinal('.');
locale_info->thousands_sep = PyUnicode_FromOrdinal( locale_info->thousands_sep = PyUnicode_FromOrdinal(
type == LT_DEFAULT_LOCALE ? ',' : '_'); type == LT_DEFAULT_LOCALE ? ',' : '_');
if (!locale_info->decimal_point || !locale_info->thousands_sep) { if (!locale_info->decimal_point || !locale_info->thousands_sep)
Py_XDECREF(locale_info->decimal_point);
Py_XDECREF(locale_info->thousands_sep);
return -1; return -1;
}
if (type != LT_UNDER_FOUR_LOCALE) if (type != LT_UNDER_FOUR_LOCALE)
locale_info->grouping = "\3"; /* Group every 3 characters. The locale_info->grouping = "\3"; /* Group every 3 characters. The
(implicit) trailing 0 means repeat (implicit) trailing 0 means repeat
...@@ -741,15 +738,10 @@ get_locale_info(int type, LocaleInfo *locale_info) ...@@ -741,15 +738,10 @@ get_locale_info(int type, LocaleInfo *locale_info)
case LT_NO_LOCALE: case LT_NO_LOCALE:
locale_info->decimal_point = PyUnicode_FromOrdinal('.'); locale_info->decimal_point = PyUnicode_FromOrdinal('.');
locale_info->thousands_sep = PyUnicode_New(0, 0); locale_info->thousands_sep = PyUnicode_New(0, 0);
if (!locale_info->decimal_point || !locale_info->thousands_sep) { if (!locale_info->decimal_point || !locale_info->thousands_sep)
Py_XDECREF(locale_info->decimal_point);
Py_XDECREF(locale_info->thousands_sep);
return -1; return -1;
}
locale_info->grouping = no_grouping; locale_info->grouping = no_grouping;
break; break;
default:
assert(0);
} }
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment