Mercurial > cpython-lru_cache-weakref
diff Objects/codeobject.c @ 72475:8beaa9a37387
Implement PEP 393.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Wed, 28 Sep 2011 07:41:54 +0200 |
| parents | d0b0fcbb40db |
| children | 5aaf83414ae7 |
line wrap: on
line diff
--- a/Objects/codeobject.c Tue Sep 27 20:52:04 2011 -0500 +++ b/Objects/codeobject.c Wed Sep 28 07:41:54 2011 +0200 @@ -8,19 +8,24 @@ /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */ static int -all_name_chars(Py_UNICODE *s) +all_name_chars(PyObject *o) { static char ok_name_char[256]; static unsigned char *name_chars = (unsigned char *)NAME_CHARS; + PyUnicodeObject *u = (PyUnicodeObject *)o; + const unsigned char *s; + + if (!PyUnicode_Check(o) || PyUnicode_READY(u) == -1 || + PyUnicode_MAX_CHAR_VALUE(u) >= 128) + return 0; if (ok_name_char[*name_chars] == 0) { unsigned char *p; for (p = name_chars; *p; p++) ok_name_char[*p] = 1; } + s = PyUnicode_1BYTE_DATA(u); while (*s) { - if (*s >= 128) - return 0; if (ok_name_char[*s++] == 0) return 0; } @@ -77,9 +82,7 @@ /* Intern selected string constants */ for (i = PyTuple_GET_SIZE(consts); --i >= 0; ) { PyObject *v = PyTuple_GetItem(consts, i); - if (!PyUnicode_Check(v)) - continue; - if (!all_name_chars(PyUnicode_AS_UNICODE(v))) + if (!all_name_chars(v)) continue; PyUnicode_InternInPlace(&PyTuple_GET_ITEM(consts, i)); }
