summaryrefslogtreecommitdiffstats
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2011-09-28 05:41:54 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2011-09-28 05:41:54 (GMT)
commitd63a3b8beb4a0841cb59fb3515347ccaab34b733 (patch)
tree3b4e3cc63151c5a5a910c3550a190aefaea96ad4 /Python/_warnings.c
parent48d49497c50e79d14e9df9527d766ca3a0a38be5 (diff)
downloadcpython-d63a3b8beb4a0841cb59fb3515347ccaab34b733.zip
cpython-d63a3b8beb4a0841cb59fb3515347ccaab34b733.tar.gz
cpython-d63a3b8beb4a0841cb59fb3515347ccaab34b733.tar.bz2
Implement PEP 393.
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c16
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;
}