Mercurial > cpython-lru_cache-weakref
diff Python/formatter_unicode.c @ 74341:c2153ce1b5dd
remove some usage of Py_UNICODE_TOUPPER/LOWER
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Wed, 11 Jan 2012 21:00:42 -0500 |
| parents | 405f65676010 |
| children | 5c33ebb50702 |
line wrap: on
line diff
--- a/Python/formatter_unicode.c Wed Jan 11 18:17:40 2012 -0500 +++ b/Python/formatter_unicode.c Wed Jan 11 21:00:42 2012 -0500 @@ -561,13 +561,14 @@ 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 @@ } 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;
