#1356 Precision loss error in "SWIG_Lua_class_tostring"

John B

I am using TDM MinGW64 to build my engine and SWIG to assist in creating scripting bindings for it. When the scripting files are auto-generated there is a line in the method "SWIG_Lua_class_tostring" where SWIG attempts to convert the return value from the "lua_touserdata" method to an "unsigned long". On TDM MinGW this results in a compilation error.

Thus far I have been able to manually edit the generated files so it instead casts to "unsigned long long". However I have to do this every time my bindings are regenerated. SWIG should instead use a datatype that is guaranteed to be the same size of a pointer on the compiling platform. Ideally "uintptr_t" if it possible for SWIG to do so.


  • Sami Kankaristo

    Sami Kankaristo - 2014-01-29

    This is also affecting our builds with MinGW-w64 (https://sourceforge.net/projects/mingw-w64/).

    SWIG tries to cast a 64-bit pointer to a 32-bit (unsigned long) integer. Changing the cast to "unsigned long long" and the sprintf format from "%lX" to "%llX" fixes this.

    Not to criticize, but why is the pointer cast to an integer? You could use "%p" as the sprintf format, although it gives slightly different output.

  • William Fulton

    William Fulton - 2014-04-09

    Can you put a patch up on github: http://github.com/swig/swig. uintptr_t isn't in practice portable so I don't recommend using this. This problem might have gone away in the latest swig on github master, please check.

  • Sami Kankaristo

    Sami Kankaristo - 2014-04-11

    I can confirm that this is fixed in the new development version. The new version casts to void*, which is the correct size.

  • William Fulton

    William Fulton - 2014-04-15
    • status: open --> closed
    • Group: -->
  • William Fulton

    William Fulton - 2014-04-15

    Closing as reported fixed.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks