Control: tags 897857 + patch
Control: tags 897857 + pending
Dear maintainer,
I've prepared an NMU for swig (versioned as 3.0.12-1.2) and uploaded it.
NMU diff is attached.
Cheers,
Olly
diff -Nru swig-3.0.12/debian/changelog swig-3.0.12/debian/changelog
--- swig-3.0.12/debian/changelog 2018-06-18 00:25:41.000000000 +1200
+++ swig-3.0.12/debian/changelog 2018-08-10 12:48:36.000000000 +1200
@@ -1,3 +1,15 @@
+swig (3.0.12-1.2) unstable; urgency=medium
+
+ * Non-maintainer upload.
+ * python-fix-function-cast-warnings.patch: Fix GCC8 warnings in generated
+ Python code. (Closes: #897857)
+ * python-fix-gcc8-strncpy-warning.patch: Fix more GCC8 warnings in generated
+ Python code.
+ * fix-gcc8-memset-warnings.patch: Fix GCC8 warnings in generated code for
+ various languages.
+
+ -- Olly Betts <[email protected]> Fri, 10 Aug 2018 12:48:36 +1200
+
swig (3.0.12-1.1) unstable; urgency=medium
* Non-maintainer upload.
diff -Nru swig-3.0.12/debian/patches/fix-gcc8-memset-warnings.patch swig-3.0.12/debian/patches/fix-gcc8-memset-warnings.patch
--- swig-3.0.12/debian/patches/fix-gcc8-memset-warnings.patch 1970-01-01 12:00:00.000000000 +1200
+++ swig-3.0.12/debian/patches/fix-gcc8-memset-warnings.patch 2018-08-10 12:48:36.000000000 +1200
@@ -0,0 +1,212 @@
+Description: Fix new GCC8 warnings in generated code
+ Backported from upstream git master based on the following ranges of commits:
+ git diff 74345c92^..b229d92f
+ git diff dd26e8a0^..a67eff0a
+ git diff ef1351c7..7ac21f37
+Author: Mike Romberg <[email protected]>
+Origin: upstream
+Last-Updated: 2018-08-10
+
+--- a/Lib/python/pycontainer.swg
++++ b/Lib/python/pycontainer.swg
+@@ -434,8 +434,8 @@
+ {
+ swig::SwigVar_PyObject item = PySequence_GetItem(_seq, _index);
+ try {
+- return swig::as<T>(item, true);
+- } catch (std::exception& e) {
++ return swig::as<T>(item);
++ } catch (const std::invalid_argument& e) {
+ char msg[1024];
+ sprintf(msg, "in sequence element %d ", (int)_index);
+ if (!PyErr_Occurred()) {
+--- a/Lib/python/pystdcommon.swg
++++ b/Lib/python/pystdcommon.swg
+@@ -107,14 +107,14 @@
+
+ template <class Type>
+ struct traits_as<Type, value_category> {
+- static Type as(PyObject *obj, bool throw_error) {
++ static Type as(PyObject *obj) {
+ Type v;
+ int res = asval(obj, &v);
+ if (!obj || !SWIG_IsOK(res)) {
+ if (!PyErr_Occurred()) {
+ ::%type_error(swig::type_name<Type>());
+ }
+- if (throw_error) throw std::invalid_argument("bad type");
++ throw std::invalid_argument("bad type");
+ }
+ return v;
+ }
+@@ -122,7 +122,7 @@
+
+ template <class Type>
+ struct traits_as<Type, pointer_category> {
+- static Type as(PyObject *obj, bool throw_error) {
++ static Type as(PyObject *obj) {
+ Type *v = 0;
+ int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
+ if (SWIG_IsOK(res) && v) {
+@@ -134,21 +134,17 @@
+ return *v;
+ }
+ } else {
+- // Uninitialized return value, no Type() constructor required.
+- static Type *v_def = (Type*) malloc(sizeof(Type));
+ if (!PyErr_Occurred()) {
+ %type_error(swig::type_name<Type>());
+ }
+- if (throw_error) throw std::invalid_argument("bad type");
+- memset(v_def,0,sizeof(Type));
+- return *v_def;
++ throw std::invalid_argument("bad type");
+ }
+ }
+ };
+
+ template <class Type>
+ struct traits_as<Type*, pointer_category> {
+- static Type* as(PyObject *obj, bool throw_error) {
++ static Type* as(PyObject *obj) {
+ Type *v = 0;
+ int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
+ if (SWIG_IsOK(res)) {
+@@ -157,15 +153,14 @@
+ if (!PyErr_Occurred()) {
+ %type_error(swig::type_name<Type>());
+ }
+- if (throw_error) throw std::invalid_argument("bad type");
+- return 0;
++ throw std::invalid_argument("bad type");
+ }
+ }
+ };
+
+ template <class Type>
+- inline Type as(PyObject *obj, bool te = false) {
+- return traits_as<Type, typename traits<Type>::category>::as(obj, te);
++ inline Type as(PyObject *obj) {
++ return traits_as<Type, typename traits<Type>::category>::as(obj);
+ }
+
+ template <class Type>
+--- a/Lib/ruby/rubycontainer.swg
++++ b/Lib/ruby/rubycontainer.swg
+@@ -183,8 +183,8 @@
+ {
+ VALUE item = rb_ary_entry(_seq, _index );
+ try {
+- return swig::as<T>(item, true);
+- } catch (std::exception& e) {
++ return swig::as<T>(item);
++ } catch (const std::invalid_argument& e) {
+ char msg[1024];
+ sprintf(msg, "in sequence element %d ", _index);
+ VALUE lastErr = rb_gv_get("$!");
+@@ -926,7 +926,7 @@
+ VALUE elem = argv[0];
+ int idx = 0;
+ try {
+- Sequence::value_type val = swig::as<Sequence::value_type>( elem, true );
++ Sequence::value_type val = swig::as<Sequence::value_type>( elem );
+ if ( i >= len ) {
+ $self->resize(i-1, val);
+ return $self;
+@@ -943,7 +943,7 @@
+ }
+
+ }
+- catch( std::invalid_argument )
++ catch( const std::invalid_argument & )
+ {
+ rb_raise( rb_eArgError, "%s",
+ Ruby_Format_TypeError( "",
+@@ -967,10 +967,10 @@
+ Sequence::iterator start = $self->begin();
+ VALUE elem = argv[idx];
+ try {
+- Sequence::value_type val = swig::as<Sequence::value_type>( elem, true );
++ Sequence::value_type val = swig::as<Sequence::value_type>( elem );
+ $self->insert( start, val );
+ }
+- catch( std::invalid_argument )
++ catch( const std::invalid_argument & )
+ {
+ rb_raise( rb_eArgError, "%s",
+ Ruby_Format_TypeError( "",
+--- a/Lib/ruby/rubystdcommon.swg
++++ b/Lib/ruby/rubystdcommon.swg
+@@ -114,15 +114,15 @@
+
+ template <class Type>
+ struct traits_as<Type, value_category> {
+- static Type as(VALUE obj, bool throw_error) {
++ static Type as(VALUE obj) {
+ Type v;
+ int res = asval(obj, &v);
+ if (!obj || !SWIG_IsOK(res)) {
+- if (throw_error) throw std::invalid_argument("bad type");
+ VALUE lastErr = rb_gv_get("$!");
+ if (lastErr == Qnil) {
+ %type_error(swig::type_name<Type>());
+ }
++ throw std::invalid_argument("bad type");
+ }
+ return v;
+ }
+@@ -130,7 +130,7 @@
+
+ template <class Type>
+ struct traits_as<Type, pointer_category> {
+- static Type as(VALUE obj, bool throw_error) {
++ static Type as(VALUE obj) {
+ Type *v = 0;
+ int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
+ if (SWIG_IsOK(res) && v) {
+@@ -142,40 +142,35 @@
+ return *v;
+ }
+ } else {
+- // Uninitialized return value, no Type() constructor required.
+- if (throw_error) throw std::invalid_argument("bad type");
+ VALUE lastErr = rb_gv_get("$!");
+ if (lastErr == Qnil) {
+ %type_error(swig::type_name<Type>());
+ }
+- static Type *v_def = (Type*) malloc(sizeof(Type));
+- memset(v_def,0,sizeof(Type));
+- return *v_def;
++ throw std::invalid_argument("bad type");
+ }
+ }
+ };
+
+ template <class Type>
+ struct traits_as<Type*, pointer_category> {
+- static Type* as(VALUE obj, bool throw_error) {
++ static Type* as(VALUE obj) {
+ Type *v = 0;
+ int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
+ if (SWIG_IsOK(res)) {
+ return v;
+ } else {
+- if (throw_error) throw std::invalid_argument("bad type");
+ VALUE lastErr = rb_gv_get("$!");
+ if (lastErr == Qnil) {
+ %type_error(swig::type_name<Type>());
+ }
+- return 0;
++ throw std::invalid_argument("bad type");
+ }
+ }
+ };
+
+ template <class Type>
+- inline Type as(VALUE obj, bool te = false) {
+- return traits_as< Type, typename traits< Type >::category >::as(obj, te);
++ inline Type as(VALUE obj) {
++ return traits_as< Type, typename traits< Type >::category >::as(obj);
+ }
+
+ template <class Type>
diff -Nru swig-3.0.12/debian/patches/python-fix-function-cast-warnings.patch swig-3.0.12/debian/patches/python-fix-function-cast-warnings.patch
--- swig-3.0.12/debian/patches/python-fix-function-cast-warnings.patch 1970-01-01 12:00:00.000000000 +1200
+++ swig-3.0.12/debian/patches/python-fix-function-cast-warnings.patch 2018-08-10 11:29:30.000000000 +1200
@@ -0,0 +1,174 @@
+Description: [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).
+Author: Olly Betts <[email protected]>
+Bug-Debian: https://bugs.debian.org/897857
+Bug: https://github.com/swig/swig/issues/1259
+Origin: upstream
+Forwarded: https://github.com/swig/swig/commit/7f9883011029674553a2a4b623d459f02b512458
+Last-Updated: 2018-08-10
+
+--- a/Lib/python/pyinit.swg
++++ b/Lib/python/pyinit.swg
+@@ -368,8 +368,8 @@
+ (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL
+ };
+ static SwigPyGetSet thisown_getset_closure = {
+- (PyCFunction) SwigPyObject_own,
+- (PyCFunction) SwigPyObject_own
++ SwigPyObject_own,
++ SwigPyObject_own
+ };
+ static PyGetSetDef thisown_getset_def = {
+ (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure
+--- a/Lib/python/pyrun.swg
++++ b/Lib/python/pyrun.swg
+@@ -465,6 +465,14 @@
+ return repr;
+ }
+
++/* We need a version taking two PyObject* parameters so it's a valid
++ * PyCFunction to use in swigobject_methods[]. */
++SWIGRUNTIME PyObject *
++SwigPyObject_repr2(PyObject *v, PyObject *SWIGUNUSEDPARM(args))
++{
++ return SwigPyObject_repr((SwigPyObject*)v);
++}
++
+ SWIGRUNTIME int
+ SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w)
+ {
+@@ -594,11 +602,7 @@
+ }
+
+ SWIGRUNTIME PyObject*
+-#ifdef METH_NOARGS
+-SwigPyObject_next(PyObject* v)
+-#else
+ SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
+-#endif
+ {
+ SwigPyObject *sobj = (SwigPyObject *) v;
+ if (sobj->next) {
+@@ -633,6 +637,20 @@
+ return SWIG_Py_Void();
+ }
+
++#ifdef METH_NOARGS
++static PyObject*
++SwigPyObject_disown2(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
++{
++ return SwigPyObject_disown(v);
++}
++
++static PyObject*
++SwigPyObject_acquire2(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
++{
++ return SwigPyObject_acquire(v);
++}
++#endif
++
+ SWIGINTERN PyObject*
+ SwigPyObject_own(PyObject *v, PyObject *args)
+ {
+@@ -673,12 +691,12 @@
+ #ifdef METH_O
+ static PyMethodDef
+ swigobject_methods[] = {
+- {(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"},
+- {(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"acquires ownership of the pointer"},
++ {(char *)"disown", (PyCFunction)SwigPyObject_disown2, METH_NOARGS, (char *)"releases ownership of the pointer"},
++ {(char *)"acquire", (PyCFunction)SwigPyObject_acquire2,METH_NOARGS, (char *)"acquires ownership of the pointer"},
+ {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"},
+ {(char *)"append", (PyCFunction)SwigPyObject_append, METH_O, (char *)"appends another 'this' object"},
+ {(char *)"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, (char *)"returns the next 'this' object"},
+- {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, (char *)"returns object representation"},
++ {(char *)"__repr__",(PyCFunction)SwigPyObject_repr2, METH_NOARGS, (char *)"returns object representation"},
+ {0, 0, 0, 0}
+ };
+ #else
+@@ -689,7 +707,7 @@
+ {(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"},
+ {(char *)"append", (PyCFunction)SwigPyObject_append, METH_VARARGS, (char *)"appends another 'this' object"},
+ {(char *)"next", (PyCFunction)SwigPyObject_next, METH_VARARGS, (char *)"returns the next 'this' object"},
+- {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_VARARGS, (char *)"returns object representation"},
++ {(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_VARARGS, (char *)"returns object representation"},
+ {0, 0, 0, 0}
+ };
+ #endif
+--- a/Source/Modules/python.cxx
++++ b/Source/Modules/python.cxx
+@@ -1109,7 +1109,7 @@
+ * ------------------------------------------------------------ */
+ int add_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);
+ return 0;
+ }
+@@ -2479,17 +2479,17 @@
+ if (!kw) {
+ if (n && funpack) {
+ 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) {
+- Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, ", name, function);
++ Printf(methods, "\t { \"%s\", %s, METH_O, ", name, function);
+ } else {
+- Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function);
++ Printf(methods, "\t { \"%s\", %s, METH_VARARGS, ", name, function);
+ }
+ } else {
+- Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function);
++ Printf(methods, "\t { \"%s\", %s, METH_VARARGS, ", name, function);
+ }
+ } 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) {
+@@ -3857,7 +3857,7 @@
+ if (shadow) {
+ if (builtin) {
+ 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);
+ } else {
+ String *symname = Getattr(n, "sym:name");
+@@ -4694,13 +4694,13 @@
+ int argcount = Getattr(n, "python:argcount") ? atoi(Char(Getattr(n, "python:argcount"))) : 2;
+ String *ds = have_docstring(n) ? cdocstring(n, AUTODOC_FUNC) : NewString("");
+ 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) {
+- 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) {
+- 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 {
+- 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(wname);
+@@ -4801,10 +4801,10 @@
+ Append(pyflags, "METH_VARARGS");
+ if (have_docstring(n)) {
+ 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);
+ } 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(wname);
diff -Nru swig-3.0.12/debian/patches/python-fix-gcc8-strncpy-warning.patch swig-3.0.12/debian/patches/python-fix-gcc8-strncpy-warning.patch
--- swig-3.0.12/debian/patches/python-fix-gcc8-strncpy-warning.patch 1970-01-01 12:00:00.000000000 +1200
+++ swig-3.0.12/debian/patches/python-fix-gcc8-strncpy-warning.patch 2018-08-10 11:57:37.000000000 +1200
@@ -0,0 +1,28 @@
+Description: Fix issue reported for SWIG_Python_FixMethods
+ "buffer_size: Calling strncpy with a source string whose length
+ (10 chars) is greater than or equal to the size argument (10)
+ will fail to null-terminate buff."
+ .
+ The issue is only reported for the "swig_ptr: " line, but for
+ consistency we replace both occurrences of strncpy with memcpy.
+Author: Mark Dufour <[email protected]>
+Origin: upstream
+Forwarded: https://github.com/swig/swig/commit/9825fcbab5c4ddd867432f9922bebfbec7b78af0
+Last-Updated: 2018-08-10
+
+diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg
+index 2cc58284..fe45ac94 100644
+--- a/Lib/python/pyinit.swg
++++ b/Lib/python/pyinit.swg
+@@ -306,9 +306,9 @@ SWIG_Python_FixMethods(PyMethodDef *methods,
+ char *ndoc = (char*)malloc(ldoc + lptr + 10);
+ if (ndoc) {
+ char *buff = ndoc;
+- strncpy(buff, methods[i].ml_doc, ldoc);
++ memcpy(buff, methods[i].ml_doc, ldoc);
+ buff += ldoc;
+- strncpy(buff, "swig_ptr: ", 10);
++ memcpy(buff, "swig_ptr: ", 10);
+ buff += 10;
+ SWIG_PackVoidPtr(buff, ptr, ty->name, lptr);
+ methods[i].ml_doc = ndoc;
diff -Nru swig-3.0.12/debian/patches/series swig-3.0.12/debian/patches/series
--- swig-3.0.12/debian/patches/series 2018-06-18 00:13:21.000000000 +1200
+++ swig-3.0.12/debian/patches/series 2018-08-10 12:35:46.000000000 +1200
@@ -1,2 +1,5 @@
ccache-rename.diff
octave4.4.patch
+python-fix-function-cast-warnings.patch
+python-fix-gcc8-strncpy-warning.patch
+fix-gcc8-memset-warnings.patch