Issue 31013: gcc7 throws warning when pymem.h development header is used (original) (raw)

Created on 2017-07-24 14:15 by Gabriel Somlo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Python-2.7.13-pymem-gcc7.patch Gabriel Somlo,2017-07-24 14:15 patch to fix gcc7 warnings when calling PyMem_MALLOC macros
netnsmodule.c Gabriel Somlo,2017-07-24 14:19 file showing warning emitted with -Wall (error -Werror)
foo.c Gabriel Somlo,2017-07-24 14:36
Messages (6)
msg298973 - (view) Author: Gabriel Somlo (Gabriel Somlo) * Date: 2017-07-24 14:15
C programs using PyMem_MALLOC in pymem.h generate a warning when -Wint-in-bool-context is enabled (typically through -Wall). In places where -Werror is enabled (such as RPM build), this causes the build to fail with an error that looks like: ... In file included from /usr/include/python2.7/Python.h:78:0, from netnsmodule.c:16: netnsmodule.c: In function 'netns_nsexecvp': /usr/include/python2.7/pymem.h:97:30: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] ( (type *) PyMem_MALLOC((n) * sizeof(type)) ) ) ^ /usr/include/python2.7/pymem.h:75:15: note: in definition of macro 'PyMem_MALLOC' : malloc((n) ? (n) : 1)) ^ netnsmodule.c:61:10: note: in expansion of macro 'PyMem_NEW' argv = PyMem_NEW(char *, argc + 1); ^~~~~~~~~ cc1: all warnings being treated as errors error: command 'gcc' failed with exit status 1 ... I'm attaching a patch that fixes the issue, please consider applying! Thanks, --Gabriel
msg298974 - (view) Author: Gabriel Somlo (Gabriel Somlo) * Date: 2017-07-24 14:19
This attachment illustrates how the problem is triggered. The file is part of the CORE network emulator (github.com/coreemu/core). Compile with "gcc -Wall -I/usr/include/python2.7 -c netnsmodule.c".
msg298975 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-24 14:25
> /usr/include/python2.7/pymem.h:97:30: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] I don't understand this error. I would be curious to see the output of the preprocessor. Try maybe to use gcc -E?
msg298977 - (view) Author: Gabriel Somlo (Gabriel Somlo) * Date: 2017-07-24 14:36
output of "gcc -E -Wall -I/usr/include/python2.7 -c netnsmodule.c > foo.c" I think gcc7 is a bit more paranoid about whether some expression evaluating to an int can/should in itself be used as a Boolean (i.e., without being compared to 0).
msg298978 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-24 14:42
> malloc(((argc + 1) * sizeof(char *)) ? ((argc + 1) * sizeof(char *)) : 1)) ) ); Ah ok, the "(n)?" expression is "((argc + 1) * sizeof(char *)) ? " and yes it contains "*".
msg313057 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2018-02-28 11:56
This is a duplicate of https://bugs.python.org/issue31474 which was fixed in https://github.com/python/cpython/pull/3581 It should be included in the next Python 2.7.x release.
History
Date User Action Args
2022-04-11 14:58:49 admin set github: 75196
2018-02-28 17:55:45 ned.deily set status: open -> closedsuperseder: [2.7] Fix -Wnonnull and -Wint-in-bool-context warningsresolution: duplicatestage: resolved
2018-02-28 11:56:28 petr.viktorin set nosy: + petr.viktorinmessages: +
2017-07-24 16:17:25 cstratak set nosy: + cstratak
2017-07-24 14:42:29 vstinner set messages: +
2017-07-24 14:36:47 Gabriel Somlo set files: + foo.cmessages: +
2017-07-24 14:25:29 vstinner set messages: +
2017-07-24 14:23:52 vstinner set nosy: + vstinner
2017-07-24 14:19:05 Gabriel Somlo set files: + netnsmodule.cmessages: +
2017-07-24 14:15:36 Gabriel Somlo create