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 PyBytes macros to functions #91990

Merged
merged 1 commit into from
May 3, 2022
Merged

gh-89653: PEP 670: Convert PyBytes macros to functions #91990

merged 1 commit into from
May 3, 2022

Conversation

vstinner
Copy link
Member

Convert the following macros to static inline functions:

  • PyByteArray_AS_STRING()
  • PyByteArray_GET_SIZE()
  • PyBytes_AS_STRING()
  • PyBytes_GET_SIZE()

Limited C API version 3.11 no longer casts arguments.

Add _PyBytes_CAST() and _PyByteArray_CAST() macros.

@vstinner
Copy link
Member Author

cc @erlend-aasland

Comment on lines 17 to 19
#define _PyByteArray_CAST(op) \
(assert(PyByteArray_Check(op)), \
_Py_reinterpret_cast(PyByteArrayObject*, op))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not write this out in the static inline functions? Ditto for _PyBytes_CAST.

Copy link
Member Author

Choose a reason for hiding this comment

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

The purpose of this macro is to cast to PyByteArrayObject*. If it's converted to a function, what would be the argument type? How do you prevent introducing new compiler warnings?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, this is fine.

Include/cpython/bytearrayobject.h Outdated Show resolved Hide resolved
Convert the following macros to static inline functions:

* PyByteArray_AS_STRING()
* PyByteArray_GET_SIZE()
* PyBytes_AS_STRING()
* PyBytes_GET_SIZE()

Limited C API version 3.11 no longer casts arguments.

Add _PyBytes_CAST() and _PyByteArray_CAST() macros.
@vstinner
Copy link
Member Author

vstinner commented May 3, 2022

I rebased my PR to get the renamed _Py_CAST() macro. I addressed @erlend-aasland's review.

@vstinner vstinner merged commit 2eca5da into python:main May 3, 2022
@vstinner vstinner deleted the pybytes_func branch May 3, 2022 18:15
@vstinner
Copy link
Member Author

vstinner commented May 3, 2022

Thanks for the review @erlend-aasland.

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