Skip to content
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

gh-89653: PEP 670: Convert unicodeobject.h macros to functions #91705

Merged
merged 2 commits into from Apr 21, 2022

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Apr 19, 2022

Convert unicodeobject.h macros to static inline functions:

  • PyUnicode_CHECK_INTERNED()
  • PyUnicode_DATA(), _PyUnicode_COMPACT_DATA(),
    _PyUnicode_NONCOMPACT_DATA()
  • PyUnicode_GET_LENGTH()
  • PyUnicode_IS_ASCII()
  • PyUnicode_IS_COMPACT()
  • PyUnicode_IS_COMPACT_ASCII()
  • PyUnicode_IS_READY()

Reorder functions to declare functions before their first usage.

Static inline functions are wrapped into macros which casts
"PyObject*" with _PyObject_CAST() to prevent introducing new compiler
warnings when passing "const PyObject*".

@vstinner
Copy link
Member Author

vstinner commented Apr 19, 2022

@erlend-aasland: Ok, here is a shorter PR.

I left the PyUnicode_KIND() macro unchanged since converting it to a static inline function introduces new compiler warning if the return type is int, but also if the return type is unsigned int! The compiler doesn't emit warnings on the macro, only with a static inline function.

Convert unicodeobject.h macros to static inline functions:

* PyUnicode_CHECK_INTERNED()
* PyUnicode_DATA(), _PyUnicode_COMPACT_DATA(),
  _PyUnicode_NONCOMPACT_DATA()
* PyUnicode_GET_LENGTH()
* PyUnicode_IS_ASCII()
* PyUnicode_IS_COMPACT()
* PyUnicode_IS_COMPACT_ASCII()
* PyUnicode_IS_READY()

Reorder functions to declare functions before their first usage.

Static inline functions are wrapped into macros which casts
"PyObject*" with _PyObject_CAST() to prevent introducing new compiler
warnings when passing "const PyObject*".
Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Looks good! I left some small nitpick comments.

Include/cpython/unicodeobject.h Outdated Show resolved Hide resolved
Include/cpython/unicodeobject.h Outdated Show resolved Hide resolved
@vstinner vstinner merged commit 4e52c66 into python:main Apr 21, 2022
12 checks passed
@vstinner vstinner deleted the unicode_macros1 branch Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants