Lua: Multiple GCC warnings and errors in luarun.swg using SWIG 3.0.0 #157

Closed
SebDyn opened this Issue Apr 9, 2014 · 6 comments

Comments

Projects
None yet
4 participants

SebDyn commented Apr 9, 2014

Dear SWIG community:

I use GCC 4.8 with SWIG 3.0.0 and Lua.

The compiler g++ is run with -Wall -Werror .

When compiling the generated wrapper code, the compiler complains on several issues:

  • unused variable 'begin' [-Wunused-variable] -> This appears multiple times in the line

        int begin = lua_gettop(L);
    

    I found a workaround adding

        if (begin==0){;}
    

    to the same line to luaswig.swg using 'sed'. One can not replace the line by

        lua_gettop(L);
    

    since in some C++ functions, the variable begin is indeed used.

  • Unused parameter 'swig_type' in luaswig.swg, line:

        SWIGINTERN int SWIG_Lua_iterate_bases(lua_State L, swig_type_info * swig_type, int first_arg, swig_lua_base_iterator_func func, int const ret)
    

    Here I tried to resolve the problem by commenting out swig_type, but at another point in my project I enhance the SWIG-Lua bindings using

        #include "luarun.swg"
    

    in a C++ source file. If I remove swig_type from the parameter list, the compiler complains that it needs the parameter at that point.

  • warning: unused parameter 'first_arg' [-Wunused-parameter]
    in

    SWIGINTERN int  SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int first_arg, int *ret)
    
  • In the wrapper code, I have multiple compiler warnings

        XYZ defined, but not used (-Werror=unused-variable)
    

    XYZ are entries like swig_string_constants and swig_string_Sf_SwigStatic_meta (with a class string being wrapped), swig_SwigModule_meta

  • There is even a compile error of a wrong cast. Here you need to replace

    (unsigned long)lua_touserdata(L,1)
    

    by

    reinterpret_cast<size_t>(lua_touserdata(L,1))
    

To ensure quality control, I can not switch off -Wall -Werror in my project. Until SWIG 2.0.11 I was able to use a sequence of sed commands to find work arounds. But in this case, I would be very grateful if some of the SWIG developers could fix this issue.

Best regards
Sebastian

Member

ojwb commented Apr 9, 2014

The final issue looks like it was already fixed in f2c410a.

The best option for the rest would be for you to put together a patch (and verify it actually fixes the warnings you're seeing) and submit a pull request. See the SWIGUNUSED and SWIGUNUSEDPARM(p) macros.

Contributor

v-for-vandal commented Apr 14, 2014

@ojwb @SebDyn Should I tackle this one ?

Member

ojwb commented Apr 15, 2014

@v-for-vandal It wouldn't be bad if somebody did - avoiding warnings from the generated code is something we aim for, though it can be difficult to achieve in some cases.

It is certainly more convenient to be able to compile generated code and non-generated code with the same compiler flags, and the generated wrapper can also include code the user wrote in the interface file - warning on issues in that can be helpful.

SebDyn commented May 28, 2014

Hi,
I just checked out SWIG 3.0.1 today. I must thank all volunteers for their effort in improving these things. There is one warning left in the generated wrapper code:

In function 'void SWIG_Lua_class_register_instance(lua_State*, swig_lua_class*)':
warning: unused variable 'new_metatable_index' [-Wunused-variable]
Member

ojwb commented May 28, 2014

Looks like William introduced that in 3191473 after the previous fixes. Fixed in 703862d. Thanks for reporting.

ojwb closed this May 28, 2014

Owner

wsfulton commented May 28, 2014

@ojwb, thanks for fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment