Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Nov 18, 2020

This change partically reverts the
commit ad3252b.

Many third party C extension modules rely on the ability of using
Py_TYPE() to set an object type: "Py_TYPE(obj) = type;".

https://bugs.python.org/issue39573

Copy link
Contributor

Choose a reason for hiding this comment

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

Also this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't see any bug report about Py_REFCNT() becoming a static inline function, so I prefer to only change Py_TYPE() and Py_SIZE().

Setting manually the reference counter of an object is a very rare use case. I'm only aware of Cython doing that, and I already updated Cython to use Py_SET_REFCNT() internally.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note: I'm open to reverting Py_REFCNT() as well if the Py_REFCNT() change breaks too many third party Python projects.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I've made a mistake here and I've meant to point out Py_SIZE is not removed. See #23375

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh sorry, I misunderstood your comment! Thanks for the PR, it's already merged ;-)

This change partically reverts
commit ad3252b
and the commit fe2978b.

Many third party C extension modules rely on the ability of using
Py_TYPE() to set an object type: "Py_TYPE(obj) = type;" or to set an
object type using: "Py_SIZE(obj) = size;".
@vstinner vstinner changed the title bpo-39573: Convert Py_TYPE() back to a macro bpo-39573: Convert Py_TYPE() and Py_SIZE() back to macros Nov 18, 2020
@vstinner
Copy link
Member Author

I updated my PR to revret not only Py_TYPE(), but also Py_SIZE().

See discussion starting at https://bugs.python.org/issue39573#msg379675 for the rationale of revert these changes.

@vstinner vstinner merged commit 0e2ac21 into python:master Nov 18, 2020
@vstinner vstinner deleted the revert_py_type branch November 18, 2020 17:48
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
…3366)

This change partically reverts
commit ad3252b
and the commit fe2978b.

Many third party C extension modules rely on the ability of using
Py_TYPE() to set an object type: "Py_TYPE(obj) = type;" or to set an
object type using: "Py_SIZE(obj) = size;".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants