-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
bpo-39573: Convert Py_REFCNT and Py_SIZE to functions #20429
Conversation
Convert Py_REFCNT() and Py_SIZE() macros to static inline functions. They cannot be used as l-value anymore: use Py_SET_REFCNT() and Py_SET_SIZE() to set an object reference count and size. Replace &Py_SIZE(self) with &((PyVarObject*)self)->ob_size in arraymodule.c. This change is backward incompatible on purpose, to prepare the C API for an opaque PyObject structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Objects/tupleobject.c:85:21: error: expression is not assignable
Py_SIZE(op) = size;
~~~~~~~~~~~ ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left comment ;)
When you're done making the requested changes, leave the comment: |
Oh, Py_TRACE_REFS! Thanks for testing for me. It's now fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This PR breaks Cython. I proposed cython/cython#3639 to use Py_SET_SIZE(): PR for the Cython master branch (then I will have to backport it to the 0.29.x branch). Maybe we should wait for a new Cython release compatible with this PR, before merging this PR. |
My fix landed in 0.29.x and master branches of Cython, great! I asked cython/cython#3639 (comment) if a Cython 0.29.20 version will be released with the fix. In the meanwhile, I think that it's fine to break Cython for a few days/weeks since we are at the beginning of the Python 3.10 dev cycle. So I merge my PR to be able to move on other C API issues. |
In python/cpython#20290 CPython changed `Py_TYPE` from a macro to an inline function. This requires a code change to us `Py_SET_TYPE` instead when using `Py_TYPE()` as a lvalue in c code. In python/cpython#20429 CPython changed `Py_SIZE` from a macro to an inline function. This requires a code change to us `Py_SET_SIZE` instead of using `Py_SIZE` as a lvalue in c code.
In python/cpython#20290 CPython changed `Py_TYPE` from a macro to an inline function. This requires a code change to us `Py_SET_TYPE` instead when using `Py_TYPE()` as a lvalue in c code. In python/cpython#20429 CPython changed `Py_SIZE` from a macro to an inline function. This requires a code change to us `Py_SET_SIZE` instead of using `Py_SIZE` as a lvalue in c code.
In python/cpython#20290 CPython changed `Py_TYPE` from a macro to an inline function. This requires a code change to us `Py_SET_TYPE` instead when using `Py_TYPE()` as a lvalue in c code. In python/cpython#20429 CPython changed `Py_SIZE` from a macro to an inline function. This requires a code change to us `Py_SET_SIZE` instead of using `Py_SIZE` as a lvalue in c code.
In python/cpython#20290 CPython changed `Py_TYPE` from a macro to an inline function. This requires a code change to us `Py_SET_TYPE` instead when using `Py_TYPE()` as a lvalue in c code. In python/cpython#20429 CPython changed `Py_SIZE` from a macro to an inline function. This requires a code change to us `Py_SET_SIZE` instead of using `Py_SIZE` as a lvalue in c code.
Convert Py_REFCNT() and Py_SIZE() macros to static inline functions.
They cannot be used as l-value anymore: use Py_SET_REFCNT() and
Py_SET_SIZE() to set an object reference count and size.
Replace &Py_SIZE(self) with &((PyVarObject*)self)->ob_size
in arraymodule.c.
This change is backward incompatible on purpose, to prepare the C API
for a fully opaque PyObject structure.
https://bugs.python.org/issue39573