Skip to content

Conversation

vstinner
Copy link
Member

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

@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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left some small nitpick comments.

@vstinner vstinner merged commit 4e52c66 into python:main Apr 21, 2022
@vstinner vstinner deleted the unicode_macros1 branch April 21, 2022 00:51
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.

3 participants