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

bpo-39573: Convert Py_REFCNT and Py_SIZE to functions #20429

Merged
merged 2 commits into from May 27, 2020

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented May 26, 2020

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

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.
Copy link
Member

@corona10 corona10 left a comment

Objects/tupleobject.c:85:21: error: expression is not assignable
        Py_SIZE(op) = size;
        ~~~~~~~~~~~ ^

Copy link
Member

@corona10 corona10 left a comment

I left comment ;)

@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented May 26, 2020

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@vstinner
Copy link
Member Author

@vstinner vstinner commented May 26, 2020

Objects/tupleobject.c:85:21: error: expression is not assignable

Oh, Py_TRACE_REFS! Thanks for testing for me. It's now fixed.

Copy link
Member

@corona10 corona10 left a comment

lgtm

@vstinner
Copy link
Member Author

@vstinner vstinner commented May 26, 2020

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.

@vstinner
Copy link
Member Author

@vstinner vstinner commented May 27, 2020

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

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.

@vstinner vstinner merged commit fe2978b into python:master May 27, 2020
10 checks passed
@vstinner vstinner deleted the py_refnct_func branch May 27, 2020
tacaswell added a commit to tacaswell/numpy that referenced this issue May 29, 2020
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.
charris pushed a commit to charris/numpy that referenced this issue May 29, 2020
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.
vegerot pushed a commit to vegerot/cpython that referenced this issue Jun 10, 2020
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.
vegerot pushed a commit to vegerot/cpython that referenced this issue Jun 10, 2020
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.
gmelikov pushed a commit to gmelikov/cpython that referenced this issue Aug 22, 2020
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.
chrisburr pushed a commit to chrisburr/cpython that referenced this issue Dec 9, 2020
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.
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

4 participants