gh-89653: PEP 670: Convert unicodeobject.h macros to functions by vstinner · Pull Request #91696 · python/cpython · GitHub
Skip to content

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

Closed
vstinner wants to merge 1 commit intopython:mainfrom
vstinner:unicode_static_inline2
Closed

gh-89653: PEP 670: Convert unicodeobject.h macros to functions#91696
vstinner wants to merge 1 commit intopython:mainfrom
vstinner:unicode_static_inline2

Conversation

@vstinner
Copy link
Copy Markdown
Member

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.

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.
@vstinner
Copy link
Copy Markdown
Member Author

@vstinner
Copy link
Copy Markdown
Member Author

Ah, and I also updated comments :-)

@erlend-aasland @gpshead: Would yo mind to review this PR?

@vstinner
Copy link
Copy Markdown
Member Author

@erlend-aasland: Tell me if you prefer that I split this PR into smaller PRs.

@vstinner
Copy link
Copy Markdown
Member Author

The following functions return type is now unsigned int instead of int: PyUnicode_IS_COMPACT(), PyUnicode_CHECK_INTERNED(), PyUnicode_IS_READY(), PyUnicode_IS_ASCII(). Previously, the macros just exposed structure members of type unsigned int.

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].

    int skind = PyUnicode_KIND(self);
    ...
    int rkind = skind;
    ...
    assert(PyUnicode_KIND(u) == rkind);

@erlend-aasland
Copy link
Copy Markdown
Contributor

@erlend-aasland: Tell me if you prefer that I split this PR into smaller PRs.

I would prefer that, yes :)

@vstinner
Copy link
Copy Markdown
Member Author

I would prefer that, yes :)

Here is a shorter PR: #91705

@vstinner
Copy link
Copy Markdown
Member Author

@vstinner vstinner closed this Apr 21, 2022
@vstinner vstinner deleted the unicode_static_inline2 branch April 21, 2022 21:01
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