Issue 28855: Compiler warnings in _PyObject_CallArg1() (original) (raw)
_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.