Skip to content
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

Many -Werror=cast-function-type with GCC 8 #2

Closed
fishilico opened this issue Jul 14, 2018 · 2 comments
Closed

Many -Werror=cast-function-type with GCC 8 #2

fishilico opened this issue Jul 14, 2018 · 2 comments

Comments

@fishilico
Copy link
Member

The code generated by Cython heavily uses function casts between function types which have incompatible signatures. GCC 8.1.1 (on Arch Linux) does not like this and reports many Werror=cast-function-type errors:

setools/policyrep/libpolicyrep.c:8874:108: error: cast between incompatible function types from ‘PyObject * (*)(PyObject *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Werror=cast-function-type]
 static PyMethodDef __pyx_mdef_7setools_9policyrep_12libpolicyrep_10PolicyEnum_3__format__ = {"__format__", (PyCFunction)__pyx_pw_7setools_9policyrep_12libpolicyrep_10PolicyEnum_3__format__, METH_VARARGS|METH_KEYWORDS, 0};
                                                                                                            ^
setools/policyrep/libpolicyrep.c:9084:100: error: cast between incompatible function types from ‘PyObject * (*)(PyObject *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Werror=cast-function-type]
 static PyMethodDef __pyx_mdef_7setools_9policyrep_12libpolicyrep_10PolicyEnum_5__eq__ = {"__eq__", (PyCFunction)__pyx_pw_7setools_9policyrep_12libpolicyrep_10PolicyEnum_5__eq__, METH_VARARGS|METH_KEYWORDS, 0};
                                                                                                    ^
setools/policyrep/libpolicyrep.c:9500:100: error: cast between incompatible function types from ‘PyObject * (*)(PyObject *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Werror=cast-function-type]
 static PyMethodDef __pyx_mdef_7setools_9policyrep_12libpolicyrep_10PolicyEnum_9lookup = {"lookup", (PyCFunction)__pyx_pw_7setools_9policyrep_12libpolicyrep_10PolicyEnum_9lookup, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7setools_9policyrep_12libpolicyrep_10PolicyEnum_8lookup};
                                                                                                    ^
...

Have you already encountered this issue?

As -Wcast-function-type does not exist in previous GCC releases, adding it to the set of disabled warnings in setup.py will break building with older compilers.
In order to silence the warning, I can think of two possible ways:

  • either by adding code in setup.py which tries running $CC -Wcast-function-type on a dummy C file and adds -Wno-cast-function-type to the compiler flags if this succeeds,
  • or by adding a pragma which disables the warning flag for GCC versions which support it, in the Cython file (if adding inline C code at the beginning of the file is possible).

What do you think about these options?

@pebenito
Copy link
Member

I've only got gcc 7.3 right now, and I added -Wno-cast-function-type locally, and it didn't complain.

@fishilico
Copy link
Member Author

Indeed. It seems that gcc never warns for unknown warning which are disabled, even in old versions like 4.9.2:

$ gcc --version
gcc (Debian 4.9.2-10+deb8u1) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ echo 'int main(){return 0;}' > test.c
$ gcc -Wcast-function-type test.c
gcc: error: unrecognized command line option ‘-Wcast-function-type’
$ gcc -Wno-cast-function-type test.c
$

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants