[Python] Fix new GCC8 warnings in generated code

Avoid casts between incompatible function types where possible (when
keyword args are in use, it is not possible to avoid such warnings as
they are inherent in the design of Python's C API in that particular
case).  Fixes #1259.
This commit is contained in:
Olly Betts 2018-06-11 15:51:53 +12:00
commit 7f98830110
4 changed files with 36 additions and 21 deletions

View file

@ -7,6 +7,13 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress) Version 4.0.0 (in progress)
=========================== ===========================
2018-06-11: olly
[Python] Fix new GCC8 warnings in generated code by avoiding casts
between incompatible function types where possible (when keyword
args are in use, it is not possible to avoid such warnings as they
are inherent in the design of Python's C API in that particular
case). Fixes #1259.
2018-06-08: philippkraft 2018-06-08: philippkraft
[Python] Stop exposing <CLASS>_swigregister to Python. It's not [Python] Stop exposing <CLASS>_swigregister to Python. It's not
useful for user Python code to call this, and it just clutters the useful for user Python code to call this, and it just clutters the

View file

@ -347,8 +347,8 @@ SWIG_init(void) {
(char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL
}; };
static SwigPyGetSet thisown_getset_closure = { static SwigPyGetSet thisown_getset_closure = {
(PyCFunction) SwigPyObject_own, SwigPyObject_own,
(PyCFunction) SwigPyObject_own SwigPyObject_own
}; };
static PyGetSetDef thisown_getset_def = { static PyGetSetDef thisown_getset_def = {
(char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure

View file

@ -445,6 +445,14 @@ SwigPyObject_repr(SwigPyObject *v)
return repr; return repr;
} }
/* We need a version taking two PyObject* parameters so it's a valid
* PyCFunction to use in swigobject_methods[]. */
static PyObject *
SwigPyObject_repr2(PyObject *v, PyObject *SWIGUNUSEDPARM(args))
{
return SwigPyObject_repr((SwigPyObject*)v);
}
SWIGRUNTIME int SWIGRUNTIME int
SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w) SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w)
{ {
@ -621,12 +629,12 @@ SwigPyObject_own(PyObject *v, PyObject *args)
static PyMethodDef static PyMethodDef
swigobject_methods[] = { swigobject_methods[] = {
{"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, "releases ownership of the pointer"}, {"disown", SwigPyObject_disown, METH_NOARGS, "releases ownership of the pointer"},
{"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, "acquires ownership of the pointer"}, {"acquire", SwigPyObject_acquire, METH_NOARGS, "acquires ownership of the pointer"},
{"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, "returns/sets ownership of the pointer"}, {"own", SwigPyObject_own, METH_VARARGS, "returns/sets ownership of the pointer"},
{"append", (PyCFunction)SwigPyObject_append, METH_O, "appends another 'this' object"}, {"append", SwigPyObject_append, METH_O, "appends another 'this' object"},
{"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, "returns the next 'this' object"}, {"next", SwigPyObject_next, METH_NOARGS, "returns the next 'this' object"},
{"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, "returns object representation"}, {"__repr__",SwigPyObject_repr2, METH_NOARGS, "returns object representation"},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };

View file

@ -1090,7 +1090,7 @@ public:
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
int add_pyinstancemethod_new() { int add_pyinstancemethod_new() {
String *name = NewString("SWIG_PyInstanceMethod_New"); String *name = NewString("SWIG_PyInstanceMethod_New");
Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, NULL},\n", name, name); Printf(methods, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
Delete(name); Delete(name);
return 0; return 0;
} }
@ -2507,17 +2507,17 @@ public:
if (!kw) { if (!kw) {
if (n && funpack) { if (n && funpack) {
if (num_required == 0 && num_arguments == 0) { if (num_required == 0 && num_arguments == 0) {
Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_NOARGS, ", name, function); Printf(methods, "\t { \"%s\", %s, METH_NOARGS, ", name, function);
} else if (num_required == 1 && num_arguments == 1) { } else if (num_required == 1 && num_arguments == 1) {
Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, ", name, function); Printf(methods, "\t { \"%s\", %s, METH_O, ", name, function);
} else { } else {
Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); Printf(methods, "\t { \"%s\", %s, METH_VARARGS, ", name, function);
} }
} else { } else {
Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); Printf(methods, "\t { \"%s\", %s, METH_VARARGS, ", name, function);
} }
} else { } else {
Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); Printf(methods, "\t { \"%s\", (PyCFunction)%s, METH_VARARGS|METH_KEYWORDS, ", name, function);
} }
if (!n) { if (!n) {
@ -3898,7 +3898,7 @@ public:
if (shadow) { if (shadow) {
if (builtin) { if (builtin) {
String *rname = SwigType_namestr(real_classname); String *rname = SwigType_namestr(real_classname);
Printf(builtin_methods, " { \"__disown__\", (PyCFunction) Swig::Director::swig_pyobj_disown< %s >, METH_NOARGS, \"\" },\n", rname); Printf(builtin_methods, " { \"__disown__\", Swig::Director::swig_pyobj_disown< %s >, METH_NOARGS, \"\" },\n", rname);
Delete(rname); Delete(rname);
} else { } else {
String *symname = Getattr(n, "sym:name"); String *symname = Getattr(n, "sym:name");
@ -4738,13 +4738,13 @@ public:
int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2; int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2;
String *ds = have_docstring(n) ? cdocstring(n, AUTODOC_METHOD) : NewString(""); String *ds = have_docstring(n) ? cdocstring(n, AUTODOC_METHOD) : NewString("");
if (check_kwargs(n)) { if (check_kwargs(n)) {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS|METH_KEYWORDS, (char *) \"%s\" },\n", symname, wname, ds); Printf(builtin_methods, " { \"%s\", (PyCFunction)%s, METH_VARARGS|METH_KEYWORDS, \"%s\" },\n", symname, wname, ds);
} else if (argcount == 0) { } else if (argcount == 0) {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_NOARGS, (char *) \"%s\" },\n", symname, wname, ds); Printf(builtin_methods, " { \"%s\", %s, METH_NOARGS, \"%s\" },\n", symname, wname, ds);
} else if (argcount == 1) { } else if (argcount == 1) {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_O, (char *) \"%s\" },\n", symname, wname, ds); Printf(builtin_methods, " { \"%s\", %s, METH_O, \"%s\" },\n", symname, wname, ds);
} else { } else {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, METH_VARARGS, (char *) \"%s\" },\n", symname, wname, ds); Printf(builtin_methods, " { \"%s\", %s, METH_VARARGS, \"%s\" },\n", symname, wname, ds);
} }
Delete(fullname); Delete(fullname);
Delete(wname); Delete(wname);
@ -4845,10 +4845,10 @@ public:
Append(pyflags, "METH_VARARGS"); Append(pyflags, "METH_VARARGS");
if (have_docstring(n)) { if (have_docstring(n)) {
String *ds = cdocstring(n, AUTODOC_STATICFUNC); String *ds = cdocstring(n, AUTODOC_STATICFUNC);
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, (char *) \"%s\" },\n", symname, wname, pyflags, ds); Printf(builtin_methods, " { \"%s\", (PyCFunction)%s, %s, \"%s\" },\n", symname, wname, pyflags, ds);
Delete(ds); Delete(ds);
} else { } else {
Printf(builtin_methods, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", symname, wname, pyflags); Printf(builtin_methods, " { \"%s\", (PyCFunction)%s, %s, \"\" },\n", symname, wname, pyflags);
} }
Delete(fullname); Delete(fullname);
Delete(wname); Delete(wname);