Issue #28701: _PyUnicode_EqualToASCIIId and _PyUnicode_EqualToASCIISt… · python/cpython@a83a6a3 (original) (raw)
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2038,7 +2038,7 @@ PyAPI_FUNC(int) PyUnicode_Compare( | ||
2038 | 2038 | |
2039 | 2039 | #ifndef Py_LIMITED_API |
2040 | 2040 | /* Test whether a unicode is equal to ASCII identifier. Return 1 if true, |
2041 | - 0 otherwise. Return 0 if any argument contains non-ASCII characters. | |
2041 | + 0 otherwise. The right argument must be ASCII identifier. | |
2042 | 2042 | Any error occurs inside will be cleared before return. */ |
2043 | 2043 | |
2044 | 2044 | PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId( |
@@ -2060,7 +2060,7 @@ PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString( | ||
2060 | 2060 | |
2061 | 2061 | #ifndef Py_LIMITED_API |
2062 | 2062 | /* Test whether a unicode is equal to ASCII string. Return 1 if true, |
2063 | - 0 otherwise. Return 0 if any argument contains non-ASCII characters. | |
2063 | + 0 otherwise. The right argument must be ASCII-encoded string. | |
2064 | 2064 | Any error occurs inside will be cleared before return. */ |
2065 | 2065 | |
2066 | 2066 | PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -11081,6 +11081,12 @@ _PyUnicode_EqualToASCIIString(PyObject *unicode, const char *str) | ||
11081 | 11081 | { |
11082 | 11082 | size_t len; |
11083 | 11083 | assert(_PyUnicode_CHECK(unicode)); |
11084 | +assert(str); | |
11085 | +#ifndef NDEBUG | |
11086 | +for (const char *p = str; *p; p++) { | |
11087 | +assert((unsigned char)*p < 128); | |
11088 | + } | |
11089 | +#endif | |
11084 | 11090 | if (PyUnicode_READY(unicode) == -1) { |
11085 | 11091 | /* Memory error or bad data */ |
11086 | 11092 | PyErr_Clear(); |
@@ -11101,6 +11107,11 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right) | ||
11101 | 11107 | |
11102 | 11108 | assert(_PyUnicode_CHECK(left)); |
11103 | 11109 | assert(right->string); |
11110 | +#ifndef NDEBUG | |
11111 | +for (const char *p = right->string; *p; p++) { | |
11112 | +assert((unsigned char)*p < 128); | |
11113 | + } | |
11114 | +#endif | |
11104 | 11115 | |
11105 | 11116 | if (PyUnicode_READY(left) == -1) { |
11106 | 11117 | /* memory error or bad data */ |