◐ Shell
reader mode source ↗
Skip to content

bpo-30459: Cast the result of PyList_SET_ITEM() to void#19975

Merged
vstinner merged 1 commit into
python:masterfrom
ZackerySpytz:bpo-30459-PyList_SET_ITEM
Dec 5, 2020
Merged

bpo-30459: Cast the result of PyList_SET_ITEM() to void#19975
vstinner merged 1 commit into
python:masterfrom
ZackerySpytz:bpo-30459-PyList_SET_ITEM

Conversation

@ZackerySpytz

@ZackerySpytz ZackerySpytz commented May 7, 2020

Copy link
Copy Markdown
Contributor

Do the same for PyTuple_SET_ITEM().

https://bugs.python.org/issue30459

Do the same for PyTuple_SET_ITEM().

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

The initial issue seems to show that PyList_SET_ITEM() result can be used, but also that it is used in practice:
https://bugs.python.org/issue30459#msg294362

So I would suggest to document in the C API changes, Porting to Python 3.9:
https://docs.python.org/dev/whatsnew/3.9.html#id2

@vstinner

vstinner commented May 7, 2020

Copy link
Copy Markdown
Member

By the way, I added Py_SET_REFCNT(), Py_SET_TYPE() and Py_SET_SIZE() in Python 3.9, but I left the related Py_REFCNT(), Py_TYPE() and Py_SIZE() unchanged. It remains possible to use them as l-value for example: Py_REFCNT(ob) = 1;.

I expect that few C extensions use Py_REFCNT(ob) = 1;, but maybe a few use Py_TYPE(op) = type;. For Py_SIZE(ob) = size;, Python 3.8 didn't provide any "abstract" setter function/macro, direct access to the member is also possible: ((PyVarObject*)ob)->ob_size = size;,

I chose to add new macros in Python 3.9, and maybe change the macros in Python 3.10. The change is part of a larger project:
https://github.com/vstinner/misc/blob/master/cpython/pep-opaque-c-api.rst

See bpo-39573.

@vstinner

vstinner commented Dec 4, 2020

Copy link
Copy Markdown
Member

No activity since May, I close the PR. I created PR #23645 which converts PyTuple_SET_ITEM() and PyList_SET_ITEM() to static inline functions.

@vstinner vstinner closed this Dec 4, 2020
@vstinner

vstinner commented Dec 5, 2020

Copy link
Copy Markdown
Member

Thanks @ZackerySpytz, I merged your PR. I wrote PR #23654 to modify also PyCell_SET().

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.

5 participants