-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-89653: PEP 670: Convert unicodeobject.h macros to functions #91696
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
Conversation
Convert unicodeobject.h macros to static inline functions: * Reorder functions to declare functions before their first usage. * PyUnicode_READ_CHAR() and PyUnicode_MAX_CHAR_VALUE() now only call PyUnicode_KIND() once. * Simplify PyUnicode_GET_SIZE(). * PyUnicode_READ_CHAR() now uses PyUnicode_1BYTE_DATA(), PyUnicode_2BYTE_DATA() and PyUnicode_4BYTE_DATA(). * Remove redundant PyUnicode_Check() assertions. Static inline functions are wrapped into macros which casts pointer types (PyObject*, void*) to prevent introducing new compiler warnings when passing const pointers (ex: PyUnicode_WRITE). PyUnicode_KIND() return type is "unsigned int" rather than "enum PyUnicode_Kind" to prevent introducing new compiler warnings.
Changes since my #31221 POC:
I will re-do some on these changes (like deprecate functions) as separated PRs once this PR is merged. |
Ah, and I also updated comments :-) @erlend-aasland @gpshead: Would yo mind to review this PR? |
@erlend-aasland: Tell me if you prefer that I split this PR into smaller PRs. |
Oh. It seems like it's wrong. The following code emits a new compiler warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare].
|
I would prefer that, yes :) |
Here is a shorter PR: #91705 |
I splitted this PR into smaller PRs. |
Convert unicodeobject.h macros to static inline functions:
PyUnicode_KIND() once.
PyUnicode_2BYTE_DATA() and PyUnicode_4BYTE_DATA().
Static inline functions are wrapped into macros which casts pointer
types (PyObject*, void*) to prevent introducing new compiler warnings
when passing const pointers (ex: PyUnicode_WRITE).
PyUnicode_KIND() return type is "unsigned int" rather than "enum
PyUnicode_Kind" to prevent introducing new compiler warnings.