Your message dated Wed, 14 Feb 2024 17:04:38 +1300
with message-id <zcw71isbvz3sm...@survex.com>
and subject line Re: Bug#650246: swig: compile warnings in C++ wrappers for
Python
has caused the Debian Bug report #650246,
regarding swig: compile warnings in C++ wrappers for Python
to be marked as done.
This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.
(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact ow...@bugs.debian.org
immediately.)
--
650246: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=650246
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems
--- Begin Message ---
Package: swig
Version: 1.3.31-1
Severity: wishlist
Hi,
Compiling swig wrappers with my usual list of warnings enabled makes a
bit of noise that should be fairly easy to fix. Changing the C casts
that remove constness from (char*)X to const_cast<char*>(X) should
silence most of them. The 'format not a string literal and no format
arguments' ones mean something like printf(string_variable) should be
replaced with printf("%s", string_variable) instead. The rest should
be fairly self evident on their own.
I haven't provided a patch, since there are surely more of these
for the wrapper types I haven't tried and in library functions I haven't
used, but the build logs for a simple 'hello_world()' interface are
included below to indicate the first few.
It would be nice to not have to disable some useful warnings to build
this code, and the format string warnings may have real implications.
Cheers,
Ron
swig -perl -c++ -o perl-foo_wrap.cpp foo.i
g++ -c -MMD -fPIC -I./include -I/usr/lib/perl/5.8/CORE -pipe -O2 -Wall -W
-Wpointer-arith -Wcast-qual -Wcast-align -Wformat=2 -Wno-format-nonliteral
-Wfloat-equal -Woverloaded-virtual -o perl-foo_wrap.o perl-foo_wrap.cpp
perl-foo_wrap.cpp: In function ‘swig_cast_info* SWIG_TypeProxyCheck(const
char*, swig_type_info*)’:
perl-foo_wrap.cpp:1067: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
perl-foo_wrap.cpp: In function ‘void SWIG_Perl_MakePtr(SV*, void*,
swig_type_info*, int)’:
perl-foo_wrap.cpp:1161: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
perl-foo_wrap.cpp:1179: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
perl-foo_wrap.cpp: In function ‘void boot_foo(PerlInterpreter*, CV*)’:
perl-foo_wrap.cpp:1777: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
perl-foo_wrap.cpp:1777: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
perl-foo_wrap.cpp:1783: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
perl-foo_wrap.cpp:1789: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
perl-foo_wrap.cpp:1795: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
perl-foo_wrap.cpp:1770: warning: unused variable ‘items’
g++ -shared -o perl/foo.so foo.o perl-foo_wrap.o
swig -python -c++ -o python-foo_wrap.cpp foo.i
g++ -c -MMD -fPIC -I./include -I/usr/include/python2.4 -pipe -O2 -Wall -W
-Wpointer-arith -Wcast-qual -Wcast-align -Wformat=2 -Wno-format-nonliteral
-Wfloat-equal -Woverloaded-virtual -o python-foo_wrap.o python-foo_wrap.cpp
python-foo_wrap.cpp: In function ‘void SWIG_Python_AddErrorMsg(const char*)’:
python-foo_wrap.cpp:870: warning: format not a string literal and no format
arguments
python-foo_wrap.cpp: In function ‘void SWIG_Python_SetErrorMsg(PyObject*, const
char*)’:
python-foo_wrap.cpp:1048: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘void SWIG_Python_SetConstant(PyObject*, const
char*, PyObject*)’:
python-foo_wrap.cpp:1058: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘PySwigClientData*
PySwigClientData_New(PyObject*)’:
python-foo_wrap.cpp:1265: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1277: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘PyObject* PySwigObject_own(PyObject*,
PyObject*)’:
python-foo_wrap.cpp:1523: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: At global scope:
python-foo_wrap.cpp:1554: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1554: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1555: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1555: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1556: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1556: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1557: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1557: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1558: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1558: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1559: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:1559: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘PyTypeObject* _PySwigObject_type()’:
python-foo_wrap.cpp:1625: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘PyTypeObject* _PySwigPacked_type()’:
python-foo_wrap.cpp:1792: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘void SWIG_Python_SetSwigThis(PyObject*,
PyObject*)’:
python-foo_wrap.cpp:2178: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘PyObject*
SWIG_Python_InitShadowInstance(PyObject*)’:
python-foo_wrap.cpp:2187: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘swig_module_info* SWIG_Python_GetModule()’:
python-foo_wrap.cpp:2244: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:2245: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘void
SWIG_Python_SetModule(swig_module_info*)’:
python-foo_wrap.cpp:2307: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp:2311: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘const char* PySwigObject_GetDesc(PyObject*)’:
python-foo_wrap.cpp:2396: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘PyObject* _wrap_hello_perl(PyObject*,
PyObject*)’:
python-foo_wrap.cpp:2568: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: At global scope:
python-foo_wrap.cpp:2578: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘PyTypeObject* swig_varlink_type()’:
python-foo_wrap.cpp:2942: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
python-foo_wrap.cpp: In function ‘void init_foo()’:
python-foo_wrap.cpp:3108: warning: cast from type ‘const char*’ to type ‘char*’
casts away constness
g++ -shared -o python/_foo.so foo.o python-foo_wrap.o
--- End Message ---
--- Begin Message ---
Control: fixed -1 swig/4.2.0-1
On Tue, Nov 29, 2011 at 06:38:06PM +1300, Olly Betts wrote:
> On Mon, Nov 28, 2011 at 08:33:57PM +1300, Olly Betts wrote:
> > On Thu, Aug 09, 2007 at 02:04:12AM +0930, Ron wrote:
> > > Compiling swig wrappers with my usual list of warnings enabled makes a
> > > bit of noise that should be fairly easy to fix. Changing the C casts
> > > that remove constness from (char*)X to const_cast<char*>(X) should
> > > silence most of them. The 'format not a string literal and no format
> > > arguments' ones mean something like printf(string_variable) should be
> > > replaced with printf("%s", string_variable) instead.
> >
> > I've already fixed the format string warnings upstream (back in 2008):
> >
> > https://sourceforge.net/tracker/?func=detail&atid=101645&aid=1882220&group_id=1645
> >
> > There are still some cast and unused parameter warnings though.
>
> As with Perl, several of the casts aren't required and can just be removed;
> some can also be made conditional on the Python version. I've fixed the easy
> ones upstream in r12852 (which should be in 2.0.5 when it is released), though
> a few cast warnings still remain.
These are all fixed by SWIG 4.2.0 - I tested with the "class" example:
$ make -C Examples/python/class CXXFLAGS='-O2 -Wall -W -Wpointer-arith
-Wcast-qual -Wcast-align -Wformat=2 -Wno-format-nonliteral -Wfloat-equal
-Woverloaded-virtual' SWIGEXE=/usr/bin/swig SWIG_LIB_DIR=`swig -swiglib`
make: Entering directory '/home/olly/git/swig/Examples/python/class'
make -f ../../Makefile SRCDIR='' CXXSRCS='example.cxx' \
SWIG_LIB_DIR='/usr/share/swig4.0' SWIGEXE='/usr/bin/swig' \
TARGET='example' INTERFACE='example.i' python_cpp
make[1]: Entering directory '/home/olly/git/swig/Examples/python/class'
env SWIG_LIB=/usr/share/swig4.0 /usr/bin/swig -python -c++ -o
example_wrap.cxx example.i
g++ -c -fpic -I. -O2 -Wall -W -Wpointer-arith -Wcast-qual -Wcast-align
-Wformat=2 -Wno-format-nonliteral -Wfloat-equal -Woverloaded-virtual
example_wrap.cxx example.cxx -I/usr/include/python3.11
-I/usr/include/python3.11
g++ -shared -O2 -Wall -W -Wpointer-arith -Wcast-qual -Wcast-align -Wformat=2
-Wno-format-nonliteral -Wfloat-equal -Woverloaded-virtual example.o
example_wrap.o -o _example.so
make[1]: Leaving directory '/home/olly/git/swig/Examples/python/class'
make -f ../../Makefile SRCDIR='' python_run
make[1]: Entering directory '/home/olly/git/swig/Examples/python/class'
pycodestyle --ignore=E252,E30,E402,E501,E731,W291,W391 runme.py
env PYTHONPATH=$PWD python3 runme.py
Creating some objects:
Created circle <example.Circle; proxy of <Swig Object of type 'Circle *' at
0x7f9edc5ab6f0> >
Created square <example.Square; proxy of <Swig Object of type 'Square *' at
0x7f9edc5ab8a0> >
A total of 2 shapes were created
Here is their current position:
Circle = (20.000000, 30.000000)
Square = (-10.000000, 5.000000)
Here are some properties of the shapes:
<example.Circle; proxy of <Swig Object of type 'Circle *' at
0x7f9edc5ab6f0> >
area = 314.1592653589793
perimeter = 62.83185307179586
<example.Square; proxy of <Swig Object of type 'Square *' at
0x7f9edc5ab8a0> >
area = 100.0
perimeter = 40.0
Guess I'll clean up now
0 shapes remain
Goodbye
make[1]: Leaving directory '/home/olly/git/swig/Examples/python/class'
make: Leaving directory '/home/olly/git/swig/Examples/python/class'
Cheers,
Olly
--- End Message ---