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
Compiler warnings in _PyObject_CallArg1() #73041
Comments
_PyObject_CallArg1() is the following macro: #define _PyObject_CallArg1(func, arg) \
_PyObject_FastCall((func), &(arg), 1) It works well in most cases, but my change 8f258245c391 or change b9c9691c72c5 added compiler warnings, because an argument which is not directly a PyObject* type is passed as "arg". I tried to cast in the caller: _PyObject_CallArg1(func, (PyObject*)arg), but sadly it doesn't work :-( I get a compiler error. Another option is to cast after "&" in the macro: #define _PyObject_CallArg1(func, arg) \
- _PyObject_FastCall((func), &(arg), 1)
+ _PyObject_FastCall((func), (PyObject **)&(arg), 1) This option may hide real bugs, so I dislike it. A better option is to stop using ugly C macros and use a modern static inline function: see attached static_inline.patch. This patch casts to PyObject* before calling _PyObject_CallArg1() to fix warnings. The question is if compilers are able to emit efficient code for static inline functions using "&" on an argument. I wrote the macro to implement the "&" optimization: convert a PyObject* to a stack of arguments: C array of PyObject* objects. |
New changeset 96245d4af0ca by Benjamin Peterson in branch 'default': |
It doesn't seem like the question is whether to use inline functions but whether to force all callers to cast. Your original code would work if you added all the casts in your static_inline.patch patch. |
(Sorry, I noticed and landed a fix before completely reading the issue.) |
I also think forcing callers to cast is fine. Most of our APIs require PyObject *. |
No problem, thanks for the fix Benjamin! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: