diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-01-12 02:00:42 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-01-12 02:00:42 (GMT) |
commit | 21e0da228d158ec248be5c7db274a7bc54a51307 (patch) | |
tree | 0982086d2e9631949626820ee61dac8d4b8482cb /Python/formatter_unicode.c | |
parent | 22ef4fa7e9805312c83b595b27218443c367dcd0 (diff) | |
download | cpython-21e0da228d158ec248be5c7db274a7bc54a51307.zip cpython-21e0da228d158ec248be5c7db274a7bc54a51307.tar.gz cpython-21e0da228d158ec248be5c7db274a7bc54a51307.tar.bz2 |
remove some usage of Py_UNICODE_TOUPPER/LOWER
Diffstat (limited to 'Python/formatter_unicode.c')
-rw-r--r-- | Python/formatter_unicode.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index ef01511..12b880d 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -561,13 +561,14 @@ fill_number(PyObject *out, Py_ssize_t pos, const NumberFieldWidths *spec, return -1; if (toupper) { Py_ssize_t t; - /* XXX if the upper-case prefix is wider than the target - buffer, the caller should have allocated a wider string, - but currently doesn't. */ - for (t = 0; t < spec->n_prefix; ++t) - PyUnicode_WRITE(kind, data, pos + t, - Py_UNICODE_TOUPPER( - PyUnicode_READ(kind, data, pos + t))); + for (t = 0; t < spec->n_prefix; t++) { + Py_UCS4 c = PyUnicode_READ(kind, data, pos + t); + if (c > 127) { + PyErr_SetString(PyExc_SystemError, "prefix not ASCII"); + return -1; + } + PyUnicode_WRITE(kind, data, pos + t, Py_TOUPPER(c)); + } } pos += spec->n_prefix; } @@ -607,10 +608,14 @@ fill_number(PyObject *out, Py_ssize_t pos, const NumberFieldWidths *spec, } if (toupper) { Py_ssize_t t; - for (t = 0; t < spec->n_grouped_digits; ++t) - PyUnicode_WRITE(kind, data, pos + t, - Py_UNICODE_TOUPPER( - PyUnicode_READ(kind, data, pos + t))); + for (t = 0; t < spec->n_grouped_digits; t++) { + Py_UCS4 c = PyUnicode_READ(kind, data, pos + t); + if (c > 127) { + PyErr_SetString(PyExc_SystemError, "non-ascii grouped digit"); + return -1; + } + PyUnicode_WRITE(kind, data, pos + t, Py_TOUPPER(c)); + } } pos += spec->n_grouped_digits; |