[issue28855] Compiler warnings in _PyObject_CallArg1()
STINNER Victor
report at bugs.python.org
Thu Dec 1 19:38:43 EST 2016
New submission from STINNER Victor:
_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.
----------
files: static_inline.patch
keywords: patch
messages: 282212
nosy: benjamin.peterson, haypo, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Compiler warnings in _PyObject_CallArg1()
versions: Python 3.7
Added file: http://bugs.python.org/file45729/static_inline.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28855>
_______________________________________
More information about the Python-bugs-list
mailing list