diff options
author | Georg Brandl <georg@python.org> | 2007-08-30 18:29:48 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-08-30 18:29:48 (GMT) |
commit | f4780d03d540ebc4bc5eec6754d23bb00b2329c8 (patch) | |
tree | 2d7673b402ec9181dea1a50408d5b226dfa35e02 | |
parent | 47cc2a00a14bdddcbb0653e33542f7eb2637ef0d (diff) | |
download | cpython-f4780d03d540ebc4bc5eec6754d23bb00b2329c8.zip cpython-f4780d03d540ebc4bc5eec6754d23bb00b2329c8.tar.gz cpython-f4780d03d540ebc4bc5eec6754d23bb00b2329c8.tar.bz2 |
Fix #1753395.
-rw-r--r-- | Objects/typeobject.c | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 9bd9202..0cc63fc 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1561,28 +1561,16 @@ static PyGetSetDef subtype_getsets_weakref_only[] = { static int valid_identifier(PyObject *s) { - Py_UNICODE *p; - Py_ssize_t i, n; - if (!PyUnicode_Check(s)) { PyErr_Format(PyExc_TypeError, "__slots__ items must be strings, not '%.200s'", Py_Type(s)->tp_name); return 0; } - p = PyUnicode_AS_UNICODE(s); - n = PyUnicode_GET_SIZE(s); - /* We must reject an empty name. As a hack, we bump the - length to 1 so that the loop will balk on the trailing \0. */ - if (n == 0) - n = 1; - for (i = 0; i < n; i++, p++) { - if (*p > 127 || - (!(i == 0 ? isalpha(*p) : isalnum(*p)) && *p != '_')) { - PyErr_SetString(PyExc_TypeError, - "__slots__ must be identifiers"); - return 0; - } + if (!PyUnicode_IsIdentifier(s)) { + PyErr_SetString(PyExc_TypeError, + "__slots__ must be identifiers"); + return 0; } return 1; } |