diff options
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r-- | Python/_warnings.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index f8a7175..2bcca91 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -498,17 +498,19 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, *filename = PyDict_GetItemString(globals, "__file__"); if (*filename != NULL && PyUnicode_Check(*filename)) { Py_ssize_t len = PyUnicode_GetSize(*filename); - Py_UNICODE *unicode = PyUnicode_AS_UNICODE(*filename); + int kind = PyUnicode_KIND(*filename); + void *data = PyUnicode_DATA(*filename); /* if filename.lower().endswith((".pyc", ".pyo")): */ if (len >= 4 && - unicode[len-4] == '.' && - Py_UNICODE_TOLOWER(unicode[len-3]) == 'p' && - Py_UNICODE_TOLOWER(unicode[len-2]) == 'y' && - (Py_UNICODE_TOLOWER(unicode[len-1]) == 'c' || - Py_UNICODE_TOLOWER(unicode[len-1]) == 'o')) + PyUnicode_READ(kind, data, len-4) == '.' && + Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-3)) == 'p' && + Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-2)) == 'y' && + (Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-1)) == 'c' || + Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-1)) == 'o')) { - *filename = PyUnicode_FromUnicode(unicode, len-1); + *filename = PyUnicode_Substring(*filename, 0, + PyUnicode_GET_LENGTH(*filename)-1); if (*filename == NULL) goto handle_error; } |