#345 Warning in swig generated files for lua

None
closed
None
1
2014-05-05
2013-12-12
Kris Lamb
No

warning: cast from 'void*' to 'long unsigned int' loses precision [-fpermissive]

Caused by
unsigned long userData = (unsigned long)lua_touserdata(L,1); / get the userdata address for later /

According to http://stackoverflow.com/questions/1640423/error-cast-from-void-to-int-loses-precision the fix is to use the intptr_t type.

See diff.

1 Attachments

Discussion

  • There's also a bug report on the same issue:
    http://sourceforge.net/p/swig/bugs/1356/

    On a 64-bit build (Windows & MinGW 64-bit), this is an error and breaks compilation.

    This patch fixes the error, but causes a new warning in the same function:
    warning: format '%lX' expects argument of type 'long unsigned int', but argument 5 has type 'intptr_t {aka long long int}' [-Wformat=]
    snprintf(output, 255, "<%s userdata: %lX>", className, userData);

    This is caused by 64-bit pointers.

     
  • Just after posting the above comment, I started browsing source code from SWIG's development version (3.0.1).

    SWIG_Lua_class_tostring seems to have been rewritten. It uses void* instead of unsigned long and lua_pushfstring() instead of snprintf().

    I tried the new version, and it fixes the issue! :)

     
  • William Fulton
    William Fulton
    2014-03-25

    • status: open --> closed
    • assigned_to: William Fulton
    • Group: -->