GeezerVison is showing github.com — Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicod… · Maddie-Code-Collab/cpython@3b73ea1
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Doc/c-api/unicode.rst +6Lines changed: 6 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1643,6 +1643,9 @@ They all return *NULL* or ``-1`` if an exception occurs. | 1643 | 1643 | Compare two strings and return ``-1``, ``0``, ``1`` for less than, equal, and greater than, | 1644 | 1644 | respectively. | 1645 | 1645 |
| | 1646 | + This function returns ``-1`` upon failure, so one should call | | 1647 | + :c:func:`PyErr_Occurred` to check for errors. | | 1648 | +
| 1646 | 1649 |
| 1647 | 1650 | .. c:function:: int PyUnicode_CompareWithASCIIString(PyObject *uni, const char *string) | 1648 | 1651 |
| @@ -1651,6 +1654,9 @@ They all return *NULL* or ``-1`` if an exception occurs. | 1651 | 1654 | ASCII-encoded strings, but the function interprets the input string as | 1652 | 1655 | ISO-8859-1 if it contains non-ASCII characters. | 1653 | 1656 |
| | 1657 | + This function returns ``-1`` upon failure, so one should call | | 1658 | + :c:func:`PyErr_Occurred` to check for errors. | | 1659 | +
| 1654 | 1660 |
| 1655 | 1661 | .. c:function:: PyObject* PyUnicode_RichCompare(PyObject *left, PyObject *right, int op) | 1656 | 1662 |
| |
Collapse file Copy file name to clipboardExpand all lines: Include/unicodeobject.h +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2048,6 +2048,17 @@ PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString( | 2048 | 2048 | const char *right /* ASCII-encoded string */ | 2049 | 2049 | ); | 2050 | 2050 |
| | 2051 | +#ifndef Py_LIMITED_API | | 2052 | +/* Test whether a unicode is equal to ASCII string. Return 1 if true, | | 2053 | + 0 otherwise. Return 0 if any argument contains non-ASCII characters. | | 2054 | + Any error occurs inside will be cleared before return. */ | | 2055 | + | | 2056 | +PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString( | | 2057 | + PyObject *left, | | 2058 | + const char *right /* ASCII-encoded string */ | | 2059 | + ); | | 2060 | +#endif | | 2061 | + | 2051 | 2062 | /* Rich compare two strings and return one of the following: | 2052 | 2063 |
| 2053 | 2064 | - NULL in case an exception was raised | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_decimal/_decimal.c +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1118,12 +1118,12 @@ context_getattr(PyObject *self, PyObject *name) | 1118 | 1118 | PyObject *retval; | 1119 | 1119 |
| 1120 | 1120 | if (PyUnicode_Check(name)) { | 1121 | | - if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) { | | 1121 | + if (_PyUnicode_EqualToASCIIString(name, "traps")) { | 1122 | 1122 | retval = ((PyDecContextObject *)self)->traps; | 1123 | 1123 | Py_INCREF(retval); | 1124 | 1124 | return retval; | 1125 | 1125 | } | 1126 | | - if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) { | | 1126 | + if (_PyUnicode_EqualToASCIIString(name, "flags")) { | 1127 | 1127 | retval = ((PyDecContextObject *)self)->flags; | 1128 | 1128 | Py_INCREF(retval); | 1129 | 1129 | return retval; | @@ -1143,10 +1143,10 @@ context_setattr(PyObject *self, PyObject *name, PyObject *value) | 1143 | 1143 | } | 1144 | 1144 |
| 1145 | 1145 | if (PyUnicode_Check(name)) { | 1146 | | - if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) { | | 1146 | + if (_PyUnicode_EqualToASCIIString(name, "traps")) { | 1147 | 1147 | return context_settraps_dict(self, value); | 1148 | 1148 | } | 1149 | | - if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) { | | 1149 | + if (_PyUnicode_EqualToASCIIString(name, "flags")) { | 1150 | 1150 | return context_setstatus_dict(self, value); | 1151 | 1151 | } | 1152 | 1152 | } | @@ -2449,14 +2449,14 @@ dectuple_as_str(PyObject *dectuple) | 2449 | 2449 | tmp = PyTuple_GET_ITEM(dectuple, 2); | 2450 | 2450 | if (PyUnicode_Check(tmp)) { | 2451 | 2451 | /* special */ | 2452 | | - if (PyUnicode_CompareWithASCIIString(tmp, "F") == 0) { | | 2452 | + if (_PyUnicode_EqualToASCIIString(tmp, "F")) { | 2453 | 2453 | strcat(sign_special, "Inf"); | 2454 | 2454 | is_infinite = 1; | 2455 | 2455 | } | 2456 | | - else if (PyUnicode_CompareWithASCIIString(tmp, "n") == 0) { | | 2456 | + else if (_PyUnicode_EqualToASCIIString(tmp, "n")) { | 2457 | 2457 | strcat(sign_special, "NaN"); | 2458 | 2458 | } | 2459 | | - else if (PyUnicode_CompareWithASCIIString(tmp, "N") == 0) { | | 2459 | + else if (_PyUnicode_EqualToASCIIString(tmp, "N")) { | 2460 | 2460 | strcat(sign_special, "sNaN"); | 2461 | 2461 | } | 2462 | 2462 | else { | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_elementtree.c +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3661,11 +3661,11 @@ xmlparser_getattro(XMLParserObject* self, PyObject* nameobj) | 3661 | 3661 | { | 3662 | 3662 | if (PyUnicode_Check(nameobj)) { | 3663 | 3663 | PyObject* res; | 3664 | | - if (PyUnicode_CompareWithASCIIString(nameobj, "entity") == 0) | | 3664 | + if (_PyUnicode_EqualToASCIIString(nameobj, "entity")) | 3665 | 3665 | res = self->entity; | 3666 | | - else if (PyUnicode_CompareWithASCIIString(nameobj, "target") == 0) | | 3666 | + else if (_PyUnicode_EqualToASCIIString(nameobj, "target")) | 3667 | 3667 | res = self->target; | 3668 | | - else if (PyUnicode_CompareWithASCIIString(nameobj, "version") == 0) { | | 3668 | + else if (_PyUnicode_EqualToASCIIString(nameobj, "version")) { | 3669 | 3669 | return PyUnicode_FromFormat( | 3670 | 3670 | "Expat %d.%d.%d", XML_MAJOR_VERSION, | 3671 | 3671 | XML_MINOR_VERSION, XML_MICRO_VERSION); | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_io/textio.c +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1023,7 +1023,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, | 1023 | 1023 | else if (PyUnicode_Check(res)) { | 1024 | 1024 | const encodefuncentry *e = encodefuncs; | 1025 | 1025 | while (e->name != NULL) { | 1026 | | - if (!PyUnicode_CompareWithASCIIString(res, e->name)) { | | 1026 | + if (_PyUnicode_EqualToASCIIString(res, e->name)) { | 1027 | 1027 | self->encodefunc = e->encodefunc; | 1028 | 1028 | break; | 1029 | 1029 | } | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_io/winconsoleio.c +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,11 +93,11 @@ char _PyIO_get_console_type(PyObject *path_or_fd) { | 93 | 93 | } | 94 | 94 |
| 95 | 95 | char m = '\0'; | 96 | | - if (PyUnicode_CompareWithASCIIString(decoded_upper, "CONIN$") == 0) { | | 96 | + if (_PyUnicode_EqualToASCIIString(decoded_upper, "CONIN$")) { | 97 | 97 | m = 'r'; | 98 | | - } else if (PyUnicode_CompareWithASCIIString(decoded_upper, "CONOUT$") == 0) { | | 98 | + } else if (_PyUnicode_EqualToASCIIString(decoded_upper, "CONOUT$")) { | 99 | 99 | m = 'w'; | 100 | | - } else if (PyUnicode_CompareWithASCIIString(decoded_upper, "CON") == 0) { | | 100 | + } else if (_PyUnicode_EqualToASCIIString(decoded_upper, "CON")) { | 101 | 101 | m = 'x'; | 102 | 102 | } | 103 | 103 |
| |
Collapse file Copy file name to clipboardExpand all lines: Modules/_lsprof.c +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -181,7 +181,7 @@ normalizeUserObj(PyObject *obj) | 181 | 181 | } | 182 | 182 | } | 183 | 183 | if (modname != NULL) { | 184 | | - if (PyUnicode_CompareWithASCIIString(modname, "builtins") != 0) { | | 184 | + if (!_PyUnicode_EqualToASCIIString(modname, "builtins")) { | 185 | 185 | PyObject *result; | 186 | 186 | result = PyUnicode_FromFormat("<%U.%s>", modname, | 187 | 187 | fn->m_ml->ml_name); | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_pickle.c +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1687,7 +1687,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) | 1687 | 1687 | while (PyDict_Next(modules_dict, &i, &module_name, &module)) { | 1688 | 1688 | PyObject *candidate; | 1689 | 1689 | if (PyUnicode_Check(module_name) && | 1690 | | - !PyUnicode_CompareWithASCIIString(module_name, "__main__")) | | 1690 | + _PyUnicode_EqualToASCIIString(module_name, "__main__")) | 1691 | 1691 | continue; | 1692 | 1692 | if (module == Py_None) | 1693 | 1693 | continue; | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_sqlite/connection.c +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1191,7 +1191,7 @@ static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, Py | 1191 | 1191 | return -1; | 1192 | 1192 | } | 1193 | 1193 | for (candidate = begin_statements; *candidate; candidate++) { | 1194 | | - if (!PyUnicode_CompareWithASCIIString(uppercase_level, *candidate + 6)) | | 1194 | + if (_PyUnicode_EqualToASCIIString(uppercase_level, *candidate + 6)) | 1195 | 1195 | break; | 1196 | 1196 | } | 1197 | 1197 | Py_DECREF(uppercase_level); | |
Collapse file Copy file name to clipboardExpand all lines: Modules/_testcapimodule.c +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2329,7 +2329,7 @@ test_string_from_format(PyObject *self, PyObject *args) | 2329 | 2329 | result = PyUnicode_FromFormat(FORMAT, (TYPE)1); \ | 2330 | 2330 | if (result == NULL) \ | 2331 | 2331 | return NULL; \ | 2332 | | - if (PyUnicode_CompareWithASCIIString(result, "1")) { \ | | 2332 | + if (!_PyUnicode_EqualToASCIIString(result, "1")) { \ | 2333 | 2333 | msg = FORMAT " failed at 1"; \ | 2334 | 2334 | goto Fail; \ | 2335 | 2335 | } \ | |
|