[Insight-developers] ambiguous else warnings from CableSwig generated python interface code

Wheeler, Frederick W (GE Global Research) wheeler at ge.com
Wed Feb 9 14:46:10 EST 2011


ITK list:

When compiling ITK with Python wrappers using gcc 4.5.1 and -Wall I get many (100s at least) warnings like this:

/projects/IUP3/wheeler/dev/itk_bld_gcc_rel/Wrapping/WrapITK/Libraries/IntensityFilters/itkInvertIntensityImageFilterPython.cpp:4186:10: warning: suggest explicit braces to avoid ambiguous ±else²

    ~PySequence_Cont()
    {
      if (_seq) Py_DECREF(_seq); //***** this is line 4186
    }

Another sample:

    PyObject_ptr(PyObject *obj, bool initial_ref = true) :_obj(obj)
    {
      if (initial_ref) Py_XINCREF(_obj); //***** warning emitted for this line also
    }

Py_DECREF is a macro from Python include file object.h that looks somethig like this:
  #define Py_DECREF() if(...) { statements ... } else statement
This is where the ambiguous else comes from, no {brackets} after the else.

If the above lines were changed like this, then I expect the warnings would cease.

    ~PySequence_Cont()
    {
      if (_seq) { Py_DECREF(_seq); }
    }

I've been trying to fix this but cannot figure out where this
generated code is emitted.  I suspect SWIG/Source/Modules/python.cxx,
but after much searching I cannot find where these warning-creating
statements are generated.  This seems like it should be an easy fix
and worth fixing.  If that is the case and someone can point me toward
the place where this code is created I'll produce and test a patch,
which may be quite trivial as I think only two pairs of brackets are
needed.


Generated lines like this also yield a warning: /projects/IUP3/wheeler/dev/itk_bld_gcc_rel/Wrapping/WrapITK/Libraries/UnaryPixelMath/itkExpNegativeImageFilterPython.cpp:2172:48: warning: deprecated conversion from string constant to ±char*²

 dict = PyObject_GetAttrString(inst, "__dict__");

But here I think the problem is PyObject_GetAttrString expects a char* for arg 2 in older versions of python (I'm using 2.4).  

Fred Wheeler



More information about the Insight-developers mailing list