-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C API: Add PyUnicode_EqualToUTF8() function #110289
Labels
Comments
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Oct 3, 2023
serhiy-storchaka
added a commit
to serhiy-storchaka/cpython
that referenced
this issue
Oct 3, 2023
serhiy-storchaka
added a commit
that referenced
this issue
Oct 11, 2023
…F8AndSize() functions (GH-110297)
Thanks! |
hauntsaninja
pushed a commit
to python/mypy
that referenced
this issue
Jul 7, 2024
Replace `_PyUnicode_EqualToASCIIString` with `PyUnicode_EqualToUTF8`. https://docs.python.org/dev/c-api/unicode.html#c.PyUnicode_EqualToUTF8 python/cpython#110289 Fixes ```cpp /home/runner/work/mypy/mypy/mypyc/lib-rt/getargs.c: In function ‘vgetargskeywords’: (diff) /home/runner/work/mypy/mypy/mypyc/lib-rt/pythonsupport.h:310:45: error: implicit declaration of function ‘_PyUnicode_EqualToASCIIString’; did you mean ‘CPyUnicode_EqualToASCIIString’? [-Werror=implicit-function-declaration] (diff) 310 | #define CPyUnicode_EqualToASCIIString(x, y) _PyUnicode_EqualToASCIIString(x, y) (diff) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (diff) /home/runner/work/mypy/mypy/mypyc/lib-rt/getargs.c:398:21: note: in expansion of macro ‘CPyUnicode_EqualToASCIIString’ (diff) 398 | if (CPyUnicode_EqualToASCIIString(key, kwlist[i])) { (diff) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (diff) ```
Glyphack
pushed a commit
to Glyphack/cpython
that referenced
this issue
Sep 2, 2024
…alToUTF8AndSize() functions (pythonGH-110297)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature or enhancement
There is public
PyUnicode_CompareWithASCIIString()
function. Despite it name, it compares Python string object with ISO-8859-1 encoded C string. it returns -1, 0 or 1 and never sets an error.There is private
_PyUnicode_EqualToASCIIString()
function. It only works with ASCII encoded C string and crashes in debug build it it is not ASCII. It returns 0 or 1 and never sets an error._PyUnicode_EqualToASCIIString()
is more efficient thanPyUnicode_CompareWithASCIIString()
, because if arguments are not equal it can simply return false instead of determining what is larger. It was the main reason of introducing it. It is also more convenient, because you do not need to add== 0
or!= 0
after the call (and if it is not added, it is difficult to read).I propose to add the latter function to the public C API, but also extend it to support UTF-8 encoded C strings. While most of use cases are ASCII-only, formally almost all C strings in the C API are UTF-8 encoded.
PyUnicode_FromString()
andPyUnicode_AsUTF8AndSize()
used to convert between Python and C strings use UTF-8 encoding.PyTypeObject.tp_name
,PyMethodDef.ml_name
,PyDescrObject.d_name
all are UTF-8 encoded.PyUnicode_CompareWithASCIIString()
cannot be used to compare Python string with such names.For PyASCIIObject objects the new function will be as fast as
_PyUnicode_EqualToASCIIString()
.Linked PRs
The text was updated successfully, but these errors were encountered: