[Python-checkins] cpython (merge 3.6 -> default): Issue #28701: Replace PyUnicode_CompareWithASCIIString with
serhiy.storchaka
python-checkins at python.org
Wed Nov 16 03:20:17 EST 2016
https://hg.python.org/cpython/rev/6f0f77333da5
changeset: 105148:6f0f77333da5
parent: 105145:da59b7084dbe
parent: 105147:72d07d13869a
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed Nov 16 10:19:57 2016 +0200
summary:
Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
The latter function is more readable, faster and doesn't raise exceptions.
files:
Doc/c-api/unicode.rst | 6 +++
Include/unicodeobject.h | 11 ++++++
Modules/_decimal/_decimal.c | 14 +++---
Modules/_elementtree.c | 6 +-
Modules/_io/textio.c | 2 +-
Modules/_io/winconsoleio.c | 6 +-
Modules/_lsprof.c | 2 +-
Modules/_pickle.c | 2 +-
Modules/_sqlite/connection.c | 2 +-
Modules/_testcapimodule.c | 2 +-
Modules/pyexpat.c | 43 +++++++++++------------
Objects/longobject.c | 8 ++--
Objects/moduleobject.c | 2 +-
Objects/typeobject.c | 4 +-
Objects/unicodeobject.c | 35 +++++++++++++++++++
Python/_warnings.c | 14 +++---
Python/ast.c | 8 ++--
Python/compile.c | 10 ++--
Python/future.c | 2 +-
Python/getargs.c | 2 +-
Python/import.c | 20 +++-------
Python/symtable.c | 4 +-
22 files changed, 125 insertions(+), 80 deletions(-)
diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst
--- a/Doc/c-api/unicode.rst
+++ b/Doc/c-api/unicode.rst
@@ -1643,6 +1643,9 @@
Compare two strings and return ``-1``, ``0``, ``1`` for less than, equal, and greater than,
respectively.
+ This function returns ``-1`` upon failure, so one should call
+ :c:func:`PyErr_Occurred` to check for errors.
+
.. c:function:: int PyUnicode_CompareWithASCIIString(PyObject *uni, const char *string)
@@ -1651,6 +1654,9 @@
ASCII-encoded strings, but the function interprets the input string as
ISO-8859-1 if it contains non-ASCII characters.
+ This function returns ``-1`` upon failure, so one should call
+ :c:func:`PyErr_Occurred` to check for errors.
+
.. c:function:: PyObject* PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -2048,6 +2048,17 @@
const char *right /* ASCII-encoded string */
);
+#ifndef Py_LIMITED_API
+/* Test whether a unicode is equal to ASCII string. Return 1 if true,
+ 0 otherwise. Return 0 if any argument contains non-ASCII characters.
+ Any error occurs inside will be cleared before return. */
+
+PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString(
+ PyObject *left,
+ const char *right /* ASCII-encoded string */
+ );
+#endif
+
/* Rich compare two strings and return one of the following:
- NULL in case an exception was raised
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -1118,12 +1118,12 @@
PyObject *retval;
if (PyUnicode_Check(name)) {
- if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "traps")) {
retval = ((PyDecContextObject *)self)->traps;
Py_INCREF(retval);
return retval;
}
- if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "flags")) {
retval = ((PyDecContextObject *)self)->flags;
Py_INCREF(retval);
return retval;
@@ -1143,10 +1143,10 @@
}
if (PyUnicode_Check(name)) {
- if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "traps")) {
return context_settraps_dict(self, value);
}
- if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "flags")) {
return context_setstatus_dict(self, value);
}
}
@@ -2449,14 +2449,14 @@
tmp = PyTuple_GET_ITEM(dectuple, 2);
if (PyUnicode_Check(tmp)) {
/* special */
- if (PyUnicode_CompareWithASCIIString(tmp, "F") == 0) {
+ if (_PyUnicode_EqualToASCIIString(tmp, "F")) {
strcat(sign_special, "Inf");
is_infinite = 1;
}
- else if (PyUnicode_CompareWithASCIIString(tmp, "n") == 0) {
+ else if (_PyUnicode_EqualToASCIIString(tmp, "n")) {
strcat(sign_special, "NaN");
}
- else if (PyUnicode_CompareWithASCIIString(tmp, "N") == 0) {
+ else if (_PyUnicode_EqualToASCIIString(tmp, "N")) {
strcat(sign_special, "sNaN");
}
else {
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -3661,11 +3661,11 @@
{
if (PyUnicode_Check(nameobj)) {
PyObject* res;
- if (PyUnicode_CompareWithASCIIString(nameobj, "entity") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "entity"))
res = self->entity;
- else if (PyUnicode_CompareWithASCIIString(nameobj, "target") == 0)
+ else if (_PyUnicode_EqualToASCIIString(nameobj, "target"))
res = self->target;
- else if (PyUnicode_CompareWithASCIIString(nameobj, "version") == 0) {
+ else if (_PyUnicode_EqualToASCIIString(nameobj, "version")) {
return PyUnicode_FromFormat(
"Expat %d.%d.%d", XML_MAJOR_VERSION,
XML_MINOR_VERSION, XML_MICRO_VERSION);
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1023,7 +1023,7 @@
else if (PyUnicode_Check(res)) {
const encodefuncentry *e = encodefuncs;
while (e->name != NULL) {
- if (!PyUnicode_CompareWithASCIIString(res, e->name)) {
+ if (_PyUnicode_EqualToASCIIString(res, e->name)) {
self->encodefunc = e->encodefunc;
break;
}
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -93,11 +93,11 @@
}
char m = '\0';
- if (PyUnicode_CompareWithASCIIString(decoded_upper, "CONIN$") == 0) {
+ if (_PyUnicode_EqualToASCIIString(decoded_upper, "CONIN$")) {
m = 'r';
- } else if (PyUnicode_CompareWithASCIIString(decoded_upper, "CONOUT$") == 0) {
+ } else if (_PyUnicode_EqualToASCIIString(decoded_upper, "CONOUT$")) {
m = 'w';
- } else if (PyUnicode_CompareWithASCIIString(decoded_upper, "CON") == 0) {
+ } else if (_PyUnicode_EqualToASCIIString(decoded_upper, "CON")) {
m = 'x';
}
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -181,7 +181,7 @@
}
}
if (modname != NULL) {
- if (PyUnicode_CompareWithASCIIString(modname, "builtins") != 0) {
+ if (!_PyUnicode_EqualToASCIIString(modname, "builtins")) {
PyObject *result;
result = PyUnicode_FromFormat("<%U.%s>", modname,
fn->m_ml->ml_name);
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -1687,7 +1687,7 @@
while (PyDict_Next(modules_dict, &i, &module_name, &module)) {
PyObject *candidate;
if (PyUnicode_Check(module_name) &&
- !PyUnicode_CompareWithASCIIString(module_name, "__main__"))
+ _PyUnicode_EqualToASCIIString(module_name, "__main__"))
continue;
if (module == Py_None)
continue;
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -1191,7 +1191,7 @@
return -1;
}
for (candidate = begin_statements; *candidate; candidate++) {
- if (!PyUnicode_CompareWithASCIIString(uppercase_level, *candidate + 6))
+ if (_PyUnicode_EqualToASCIIString(uppercase_level, *candidate + 6))
break;
}
Py_DECREF(uppercase_level);
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2325,7 +2325,7 @@
result = PyUnicode_FromFormat(FORMAT, (TYPE)1); \
if (result == NULL) \
return NULL; \
- if (PyUnicode_CompareWithASCIIString(result, "1")) { \
+ if (!_PyUnicode_EqualToASCIIString(result, "1")) { \
msg = FORMAT " failed at 1"; \
goto Fail; \
} \
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1244,8 +1244,7 @@
{
int i;
for (i = 0; handler_info[i].name != NULL; i++) {
- if (PyUnicode_CompareWithASCIIString(
- name, handler_info[i].name) == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, handler_info[i].name)) {
return i;
}
}
@@ -1283,45 +1282,45 @@
first_char = PyUnicode_READ_CHAR(nameobj, 0);
if (first_char == 'E') {
- if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorCode") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorCode"))
return PyLong_FromLong((long)
XML_GetErrorCode(self->itself));
- if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorLineNumber") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorLineNumber"))
return PyLong_FromLong((long)
XML_GetErrorLineNumber(self->itself));
- if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorColumnNumber") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorColumnNumber"))
return PyLong_FromLong((long)
XML_GetErrorColumnNumber(self->itself));
- if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorByteIndex") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorByteIndex"))
return PyLong_FromLong((long)
XML_GetErrorByteIndex(self->itself));
}
if (first_char == 'C') {
- if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentLineNumber") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "CurrentLineNumber"))
return PyLong_FromLong((long)
XML_GetCurrentLineNumber(self->itself));
- if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentColumnNumber") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "CurrentColumnNumber"))
return PyLong_FromLong((long)
XML_GetCurrentColumnNumber(self->itself));
- if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentByteIndex") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "CurrentByteIndex"))
return PyLong_FromLong((long)
XML_GetCurrentByteIndex(self->itself));
}
if (first_char == 'b') {
- if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_size") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "buffer_size"))
return PyLong_FromLong((long) self->buffer_size);
- if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_text") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "buffer_text"))
return get_pybool(self->buffer != NULL);
- if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_used") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "buffer_used"))
return PyLong_FromLong((long) self->buffer_used);
}
- if (PyUnicode_CompareWithASCIIString(nameobj, "namespace_prefixes") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "namespace_prefixes"))
return get_pybool(self->ns_prefixes);
- if (PyUnicode_CompareWithASCIIString(nameobj, "ordered_attributes") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "ordered_attributes"))
return get_pybool(self->ordered_attributes);
- if (PyUnicode_CompareWithASCIIString(nameobj, "specified_attributes") == 0)
+ if (_PyUnicode_EqualToASCIIString(nameobj, "specified_attributes"))
return get_pybool((long) self->specified_attributes);
- if (PyUnicode_CompareWithASCIIString(nameobj, "intern") == 0) {
+ if (_PyUnicode_EqualToASCIIString(nameobj, "intern")) {
if (self->intern == NULL) {
Py_INCREF(Py_None);
return Py_None;
@@ -1383,7 +1382,7 @@
PyErr_SetString(PyExc_RuntimeError, "Cannot delete attribute");
return -1;
}
- if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "buffer_text")) {
int b = PyObject_IsTrue(v);
if (b < 0)
return -1;
@@ -1405,7 +1404,7 @@
}
return 0;
}
- if (PyUnicode_CompareWithASCIIString(name, "namespace_prefixes") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "namespace_prefixes")) {
int b = PyObject_IsTrue(v);
if (b < 0)
return -1;
@@ -1413,14 +1412,14 @@
XML_SetReturnNSTriplet(self->itself, self->ns_prefixes);
return 0;
}
- if (PyUnicode_CompareWithASCIIString(name, "ordered_attributes") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "ordered_attributes")) {
int b = PyObject_IsTrue(v);
if (b < 0)
return -1;
self->ordered_attributes = b;
return 0;
}
- if (PyUnicode_CompareWithASCIIString(name, "specified_attributes") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "specified_attributes")) {
int b = PyObject_IsTrue(v);
if (b < 0)
return -1;
@@ -1428,7 +1427,7 @@
return 0;
}
- if (PyUnicode_CompareWithASCIIString(name, "buffer_size") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "buffer_size")) {
long new_buffer_size;
if (!PyLong_Check(v)) {
PyErr_SetString(PyExc_TypeError, "buffer_size must be an integer");
@@ -1474,7 +1473,7 @@
return 0;
}
- if (PyUnicode_CompareWithASCIIString(name, "CharacterDataHandler") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "CharacterDataHandler")) {
/* If we're changing the character data handler, flush all
* cached data with the old handler. Not sure there's a
* "right" thing to do, though, but this probably won't
diff --git a/Objects/longobject.c b/Objects/longobject.c
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -5166,9 +5166,9 @@
return NULL;
}
- if (!PyUnicode_CompareWithASCIIString(byteorder_str, "little"))
+ if (_PyUnicode_EqualToASCIIString(byteorder_str, "little"))
little_endian = 1;
- else if (!PyUnicode_CompareWithASCIIString(byteorder_str, "big"))
+ else if (_PyUnicode_EqualToASCIIString(byteorder_str, "big"))
little_endian = 0;
else {
PyErr_SetString(PyExc_ValueError,
@@ -5249,9 +5249,9 @@
return NULL;
}
- if (!PyUnicode_CompareWithASCIIString(byteorder_str, "little"))
+ if (_PyUnicode_EqualToASCIIString(byteorder_str, "little"))
little_endian = 1;
- else if (!PyUnicode_CompareWithASCIIString(byteorder_str, "big"))
+ else if (_PyUnicode_EqualToASCIIString(byteorder_str, "big"))
little_endian = 0;
else {
PyErr_SetString(PyExc_ValueError,
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -586,7 +586,7 @@
while (PyDict_Next(d, &pos, &key, &value)) {
if (value != Py_None && PyUnicode_Check(key)) {
if (PyUnicode_READ_CHAR(key, 0) != '_' ||
- PyUnicode_CompareWithASCIIString(key, "__builtins__") != 0)
+ !_PyUnicode_EqualToASCIIString(key, "__builtins__"))
{
if (Py_VerboseFlag > 1) {
const char *s = _PyUnicode_AsString(key);
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2412,7 +2412,7 @@
}
add_dict++;
}
- if (PyUnicode_CompareWithASCIIString(tmp, "__weakref__") == 0) {
+ if (_PyUnicode_EqualToASCIIString(tmp, "__weakref__")) {
if (!may_add_weak || add_weak) {
PyErr_SetString(PyExc_TypeError,
"__weakref__ slot disallowed: "
@@ -2436,7 +2436,7 @@
if ((add_dict &&
_PyUnicode_CompareWithId(tmp, &PyId___dict__) == 0) ||
(add_weak &&
- PyUnicode_CompareWithASCIIString(tmp, "__weakref__") == 0))
+ _PyUnicode_EqualToASCIIString(tmp, "__weakref__")))
continue;
tmp =_Py_Mangle(name, tmp);
if (!tmp) {
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -11048,6 +11048,41 @@
}
}
+static int
+non_ready_unicode_equal_to_ascii_string(PyObject *unicode, const char *str)
+{
+ size_t i, len;
+ const wchar_t *p;
+ len = (size_t)_PyUnicode_WSTR_LENGTH(unicode);
+ if (strlen(str) != len)
+ return 0;
+ p = _PyUnicode_WSTR(unicode);
+ assert(p);
+ for (i = 0; i < len; i++) {
+ unsigned char c = (unsigned char)str[i];
+ if (c > 128 || p[i] != (wchar_t)c)
+ return 0;
+ }
+ return 1;
+}
+
+int
+_PyUnicode_EqualToASCIIString(PyObject *unicode, const char *str)
+{
+ size_t len;
+ assert(_PyUnicode_CHECK(unicode));
+ if (PyUnicode_READY(unicode) == -1) {
+ /* Memory error or bad data */
+ PyErr_Clear();
+ return non_ready_unicode_equal_to_ascii_string(unicode, str);
+ }
+ if (!PyUnicode_IS_ASCII(unicode))
+ return 0;
+ len = (size_t)PyUnicode_GET_LENGTH(unicode);
+ return strlen(str) == len &&
+ memcmp(PyUnicode_1BYTE_DATA(unicode), str, len) == 0;
+}
+
#define TEST_COND(cond) \
((cond) ? Py_True : Py_False)
diff --git a/Python/_warnings.c b/Python/_warnings.c
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -503,7 +503,7 @@
if (action == NULL)
goto cleanup;
- if (PyUnicode_CompareWithASCIIString(action, "error") == 0) {
+ if (_PyUnicode_EqualToASCIIString(action, "error")) {
PyErr_SetObject(category, message);
goto cleanup;
}
@@ -511,13 +511,13 @@
/* Store in the registry that we've been here, *except* when the action
is "always". */
rc = 0;
- if (PyUnicode_CompareWithASCIIString(action, "always") != 0) {
+ if (!_PyUnicode_EqualToASCIIString(action, "always")) {
if (registry != NULL && registry != Py_None &&
PyDict_SetItem(registry, key, Py_True) < 0)
goto cleanup;
- else if (PyUnicode_CompareWithASCIIString(action, "ignore") == 0)
+ else if (_PyUnicode_EqualToASCIIString(action, "ignore"))
goto return_none;
- else if (PyUnicode_CompareWithASCIIString(action, "once") == 0) {
+ else if (_PyUnicode_EqualToASCIIString(action, "once")) {
if (registry == NULL || registry == Py_None) {
registry = get_once_registry();
if (registry == NULL)
@@ -526,12 +526,12 @@
/* _once_registry[(text, category)] = 1 */
rc = update_registry(registry, text, category, 0);
}
- else if (PyUnicode_CompareWithASCIIString(action, "module") == 0) {
+ else if (_PyUnicode_EqualToASCIIString(action, "module")) {
/* registry[(text, category, 0)] = 1 */
if (registry != NULL && registry != Py_None)
rc = update_registry(registry, text, category, 0);
}
- else if (PyUnicode_CompareWithASCIIString(action, "default") != 0) {
+ else if (!_PyUnicode_EqualToASCIIString(action, "default")) {
PyErr_Format(PyExc_RuntimeError,
"Unrecognized action (%R) in warnings.filters:\n %R",
action, item);
@@ -715,7 +715,7 @@
}
else {
*filename = NULL;
- if (*module != Py_None && PyUnicode_CompareWithASCIIString(*module, "__main__") == 0) {
+ if (*module != Py_None && _PyUnicode_EqualToASCIIString(*module, "__main__")) {
PyObject *argv = _PySys_GetObjectId(&PyId_argv);
/* PyList_Check() is needed because sys.argv is set to None during
Python finalization */
diff --git a/Python/ast.c b/Python/ast.c
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -934,12 +934,12 @@
int full_checks)
{
assert(PyUnicode_Check(name));
- if (PyUnicode_CompareWithASCIIString(name, "__debug__") == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, "__debug__")) {
ast_error(c, n, "assignment to keyword");
return 1;
}
- if (PyUnicode_CompareWithASCIIString(name, "async") == 0 ||
- PyUnicode_CompareWithASCIIString(name, "await") == 0)
+ if (_PyUnicode_EqualToASCIIString(name, "async") ||
+ _PyUnicode_EqualToASCIIString(name, "await"))
{
PyObject *message = PyUnicode_FromString(
"'async' and 'await' will become reserved keywords"
@@ -963,7 +963,7 @@
if (full_checks) {
const char * const *p;
for (p = FORBIDDEN; *p; p++) {
- if (PyUnicode_CompareWithASCIIString(name, *p) == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, *p)) {
ast_error(c, n, "assignment to keyword");
return 1;
}
diff --git a/Python/compile.c b/Python/compile.c
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1522,7 +1522,7 @@
{
int scope;
if (c->u->u_scope_type == COMPILER_SCOPE_CLASS &&
- !PyUnicode_CompareWithASCIIString(name, "__class__"))
+ _PyUnicode_EqualToASCIIString(name, "__class__"))
return CELL;
scope = PyST_GetScope(c->u->u_ste, name);
if (scope == 0) {
@@ -2688,7 +2688,7 @@
}
if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module &&
- !PyUnicode_CompareWithASCIIString(s->v.ImportFrom.module, "__future__")) {
+ _PyUnicode_EqualToASCIIString(s->v.ImportFrom.module, "__future__")) {
Py_DECREF(level);
Py_DECREF(names);
return compiler_error(c, "from __future__ imports must occur "
@@ -3027,9 +3027,9 @@
if (!mangled)
return 0;
- assert(PyUnicode_CompareWithASCIIString(name, "None") &&
- PyUnicode_CompareWithASCIIString(name, "True") &&
- PyUnicode_CompareWithASCIIString(name, "False"));
+ assert(!_PyUnicode_EqualToASCIIString(name, "None") &&
+ !_PyUnicode_EqualToASCIIString(name, "True") &&
+ !_PyUnicode_EqualToASCIIString(name, "False"));
op = 0;
optype = OP_NAME;
diff --git a/Python/future.c b/Python/future.c
--- a/Python/future.c
+++ b/Python/future.c
@@ -102,7 +102,7 @@
if (s->kind == ImportFrom_kind) {
identifier modname = s->v.ImportFrom.module;
if (modname &&
- !PyUnicode_CompareWithASCIIString(modname, "__future__")) {
+ _PyUnicode_EqualToASCIIString(modname, "__future__")) {
if (done) {
PyErr_SetString(PyExc_SyntaxError,
ERR_LATE_FUTURE);
diff --git a/Python/getargs.c b/Python/getargs.c
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -1808,7 +1808,7 @@
return cleanreturn(0, &freelist);
}
for (i = 0; i < len; i++) {
- if (*kwlist[i] && !PyUnicode_CompareWithASCIIString(key, kwlist[i])) {
+ if (*kwlist[i] && _PyUnicode_EqualToASCIIString(key, kwlist[i])) {
match = 1;
break;
}
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -936,10 +936,9 @@
static int
is_builtin(PyObject *name)
{
- int i, cmp;
+ int i;
for (i = 0; PyImport_Inittab[i].name != NULL; i++) {
- cmp = PyUnicode_CompareWithASCIIString(name, PyImport_Inittab[i].name);
- if (cmp == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, PyImport_Inittab[i].name)) {
if (PyImport_Inittab[i].initfunc == NULL)
return -1;
else
@@ -1059,7 +1058,7 @@
for (p = PyImport_Inittab; p->name != NULL; p++) {
PyModuleDef *def;
- if (PyUnicode_CompareWithASCIIString(name, p->name) == 0) {
+ if (_PyUnicode_EqualToASCIIString(name, p->name)) {
if (p->initfunc == NULL) {
/* Cannot re-init internal module ("sys" or "builtins") */
mod = PyImport_AddModule(namestr);
@@ -1109,7 +1108,7 @@
for (p = PyImport_FrozenModules; ; p++) {
if (p->name == NULL)
return NULL;
- if (PyUnicode_CompareWithASCIIString(name, p->name) == 0)
+ if (_PyUnicode_EqualToASCIIString(name, p->name))
break;
}
return p;
@@ -1310,12 +1309,8 @@
int now_in_importlib;
assert(PyTraceBack_Check(tb));
- now_in_importlib = (PyUnicode_CompareWithASCIIString(
- code->co_filename,
- importlib_filename) == 0) ||
- (PyUnicode_CompareWithASCIIString(
- code->co_filename,
- external_filename) == 0);
+ now_in_importlib = _PyUnicode_EqualToASCIIString(code->co_filename, importlib_filename) ||
+ _PyUnicode_EqualToASCIIString(code->co_filename, external_filename);
if (now_in_importlib && !in_importlib) {
/* This is the link to this chunk of importlib tracebacks */
outer_link = prev_link;
@@ -1324,8 +1319,7 @@
if (in_importlib &&
(always_trim ||
- PyUnicode_CompareWithASCIIString(code->co_name,
- remove_frames) == 0)) {
+ _PyUnicode_EqualToASCIIString(code->co_name, remove_frames))) {
Py_XINCREF(next);
Py_XSETREF(*outer_link, next);
prev_link = outer_link;
diff --git a/Python/symtable.c b/Python/symtable.c
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -1503,7 +1503,7 @@
/* Special-case super: it counts as a use of __class__ */
if (e->v.Name.ctx == Load &&
st->st_cur->ste_type == FunctionBlock &&
- !PyUnicode_CompareWithASCIIString(e->v.Name.id, "super")) {
+ _PyUnicode_EqualToASCIIString(e->v.Name.id, "super")) {
if (!GET_IDENTIFIER(__class__) ||
!symtable_add_def(st, __class__, USE))
VISIT_QUIT(st, 0);
@@ -1652,7 +1652,7 @@
store_name = name;
Py_INCREF(store_name);
}
- if (PyUnicode_CompareWithASCIIString(name, "*")) {
+ if (!_PyUnicode_EqualToASCIIString(name, "*")) {
int r = symtable_add_def(st, store_name, DEF_IMPORT);
Py_DECREF(store_name);
return r;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list