-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
bpo-30459: Cast the result of PyList_SET_ITEM() to void #19975
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
Conversation
Do the same for PyTuple_SET_ITEM().
@@ -34,7 +34,7 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out); | |||
#define _PyList_CAST(op) (assert(PyList_Check(op)), (PyListObject *)(op)) | |||
|
|||
#define PyList_GET_ITEM(op, i) (_PyList_CAST(op)->ob_item[i]) | |||
#define PyList_SET_ITEM(op, i, v) (_PyList_CAST(op)->ob_item[i] = (v)) | |||
#define PyList_SET_ITEM(op, i, v) ((void)(_PyList_CAST(op)->ob_item[i] = (v))) |
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.
If a change is made, I would prefer to convert this macro to a static inline function. You need to keep a macro for _PyList_CAST(). For example, declare the static inline function with name _PyList_SET_ITEM(). See Py_INCREF() for another example. Also, while we are here, I would prefer to use better name than "i" and "v". For example: PyList_SET_ITEM(list, index, value).
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.
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
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: I expect that few C extensions use 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: See bpo-39573. |
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. |
Thanks @ZackerySpytz, I merged your PR. I wrote PR #23654 to modify also PyCell_SET(). |
Do the same for PyTuple_SET_ITEM().
Do the same for PyTuple_SET_ITEM().
https://bugs.python.org/issue30459