-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
cast between incompatible function types reported by gcc 8 for swig & python #1259
Comments
Looks like we're currently deliberately defining these functions with the wrong signature when
But Python 2.3 changed that:
With typical calling conventions we get away with this (which is how it has gone unnoticed for so long) but it really should be fixed, and we're officially dropping support for such old Python versions in 4.0.0, so it looks like we just need to drop the Does this trigger with anything already in SWIG's testsuite? |
I've now installed GCC8 and the answer is yes - e.g. this results in many errors:
So no new testcases needed for this. |
I have also seen the following issue pop up on Archlinux (which uses gcc 8.1.0) but not on Fedora (which has gcc 8.1.1), so maybe that is a false positive:
Unfortunately that is not triggered by my reproducer but that is taken from a test pipeline of my project. The swig file looks like this: %module receiver
%include "stdint.i"
%include "carrays.i"
%include "cpointer.i"
%array_functions(uint8_t, byteArray);
%pointer_functions(double, doublep);
%{
#include <stdint.h>
int func(uint8_t *, size_t, uint8_t, size_t, const char *restrict, size_t, double *);
%}
int func(uint8_t *, size_t, uint8_t, size_t, const char *restrict, size_t, double *); (I have changed the function name & removed the parameter names since it is internal and I am embarrassed to have written that code) |
The |
Ah, I just checked the Fedora sources for swig and they already included that patch. That's why it's not showing up on Fedora but on Archlinux. Glad to hear that it's not an issue anymore. |
I'm seeing another warning from gcc-8 when wrapping
But then, vector<shared_ptr> seems to have some inherent problems anyhow (see for example #731 or #773), this may be (part of) the same problem...? |
@q-p Please don't tag new problems onto an existing issue - the only connection with the incompatible cast being tracked here is that GCC 8 warns about the two cases. Any fixes required will be entirely separate. However that warning should also already be fixed in git master (by #1027 and related earlier changes) - the only hit for |
(
Removed in 7d11c29. As for the actual topic of this issue, I've now pushed the clean up of the supported Python versions to git master. The warnings here still remain, but fixing them should be less painful now. |
The function cast thing is also something I looked at briefly. From my understanding (which could What happens is that python has a structure that has a function pointer and a flag. The function pointer is "generic" (as far as python is concerned). So, every function listed in this data structure must be of this type or the compiler will complain. But the pointer in the structure is designed to point at functions that take differing numbers of arguments. Which is why the cast is universally done in the first place. Later on, inside the guts of python, another cast is done using the flag that is also part of the data structure back to the (assuming the flag matches the real function type) correct function type. The whole thing is a little nauseating. But it is one way to work around limitations of C. Now gcc catches that the cast is bogus. It always was. But now the warning. But there is no way for swig or anyone else to fix this because it is how python (and other C based projects) are dealing with overloaded functions. I do remember seeing a patch for gcc itself to not issue this new warning for cases like python and other things that do this. So, this warning may just go away if the gcc developers decide the warning needs adjustment. Or python itself may have to undergo major surgery on this data structure. Which will pretty much break many python C modules along with swig. In my projects particular case, I just suppress this gcc warning and will wait for the dust to settle. My guess is that the new gcc warning will just go away with time as these sorts of casts seem rather common with C programs/libraries. |
In the cases I looked at, the type of the function actually changed during Python's 2.x history and we should be able to fix the (currently incorrect) function type we're defining. Those case are definitely worth fixing as they're technically undefined behaviour, and it'll be easier to do so now that we aren't trying to support all those old Python 2.x versions. It could well be that there are cases which are acting as you describe though. |
It seems we can fix this except when keyword argument support is enabled i.e. |
We got an error when building setools in meta-selinux: setools/policyrep/qpol_wrap.c:1819:23: error: cast between incompatible function types from 'PyObject * (*)(PyObject *)' {aka 'struct _object * (*)(struct _object *)'} to 'PyObject * (*)(PyObject *, PyObject *)' {aka 'struct _object * (*)(struct _object *, struct _object *)'} [-Werror=cast-function-type] {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, This is a swig issue. See: swig/swig#1259 Backport a patch from upstream to fix it. Signed-off-by: Yi Zhao <yi.zhao@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
We got an error when building setools in meta-selinux: setools/policyrep/qpol_wrap.c:1819:23: error: cast between incompatible function types from 'PyObject * (*)(PyObject *)' {aka 'struct _object * (*)(struct _object *)'} to 'PyObject * (*)(PyObject *, PyObject *)' {aka 'struct _object * (*)(struct _object *, struct _object *)'} [-Werror=cast-function-type] {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, This is a swig issue. See: swig/swig#1259 Backport a patch from upstream to fix it. Signed-off-by: Yi Zhao <yi.zhao@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Source: poky MR: 00000 Type: Integration Disposition: Merged from poky ChangeID: 2a040ba Description: We got an error when building setools in meta-selinux: setools/policyrep/qpol_wrap.c:1819:23: error: cast between incompatible function types from 'PyObject * (*)(PyObject *)' {aka 'struct _object * (*)(struct _object *)'} to 'PyObject * (*)(PyObject *, PyObject *)' {aka 'struct _object * (*)(struct _object *, struct _object *)'} [-Werror=cast-function-type] {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, This is a swig issue. See: swig/swig#1259 Backport a patch from upstream to fix it. (From OE-Core rev: f0f8ee668de34ad30ca16f5300966a3470018940) Signed-off-by: Yi Zhao <yi.zhao@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Jeremy Puhlman <jpuhlman@mvista.com>
Actually, GCC provides a way to suppress |
…on types We got an error when building setools in meta-selinux: setools/policyrep/qpol_wrap.c:1819:23: error: cast between incompatible function types from 'PyObject * (*)(PyObject *)' {aka 'struct _object * (*)(struct _object *)'} to 'PyObject * (*)(PyObject *, PyObject *)' {aka 'struct _object * (*)(struct _object *, struct _object *)'} [-Werror=cast-function-type] {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, This is a swig issue. See: swig/swig#1259 Backport a patch from upstream to fix it. (From OE-Core rev: f0f8ee668de34ad30ca16f5300966a3470018940) Signed-off-by: Yi Zhao <yi.zhao@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
…on types We got an error when building setools in meta-selinux: setools/policyrep/qpol_wrap.c:1819:23: error: cast between incompatible function types from 'PyObject * (*)(PyObject *)' {aka 'struct _object * (*)(struct _object *)'} to 'PyObject * (*)(PyObject *, PyObject *)' {aka 'struct _object * (*)(struct _object *, struct _object *)'} [-Werror=cast-function-type] {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, This is a swig issue. See: swig/swig#1259 Backport a patch from upstream to fix it. (From OE-Core rev: f0f8ee668de34ad30ca16f5300966a3470018940) Signed-off-by: Yi Zhao <yi.zhao@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Summary
swig with Python seems to produce C source code that triggers some of the new warnings provided by gcc 8.
Reproducer
I am running swig 3.0.12 & gcc 8.1.1 both from the Fedora 28 repositories. The same issue appears on Archlinux, too.
It can be reproduced with the following two files:
test.c:
and test.i:
Then running swig & gcc:
GCC complains about this part of the code:
Workaround
Ignore the warnings or make them non fatal by adding
-Wno-error=cast-function-type
to the compilation flags.The text was updated successfully, but these errors were encountered: