Lua unit tests crash on win32/VS2008 build

Bug #590472 reported by Jari Hautio
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Fix Released
Undecided
Jari Hautio

Bug Description

Running Lua unit tests ts.wmf crashes in Flag tests when built with Visual Studio 2008 (Win32).
Seems like Luna implementation has problems with virtual base classes and multiple inheritance.

Related branches

Jari Hautio (jarih)
Changed in widelands:
assignee: nobody → Jari Hautio (jarih)
status: New → In Progress
Revision history for this message
Jari Hautio (jarih) wrote :

I created a unit test using boost unit test framework to isolate the problem (in lp:~jarih/widelands/fix-lua-msvc) and interestingly, also GCC build will crash in the unit test. Same fix applied to both platforms.

Revision history for this message
Jari Hautio (jarih) wrote :

Method dispatching started to work, but properties still need some work.

Revision history for this message
SirVer (sirver) wrote :

jari, I have deep respect for the work you put into this. There is quite a lot of magic in my Lua wrappings and I assume it is hard to get those bugs vanquished. Keep up the good work!

Revision history for this message
Jari Hautio (jarih) wrote :

Also properties are now fixed in the branch. Unit tests pass under windows and linux.

When considering merging to trunk, biggest issue is unit test support as it propably clashes with spice-up-cmake branch.

Revision history for this message
SirVer (sirver) wrote :

There is currently no need to rush the merge. Have you managed to solve all problems now? Can you enlighten me how you did this?

Revision history for this message
Jari Hautio (jarih) wrote :

All problems are solved. both multiple inheritance and virtual bnase classes are now supported on linux/gcc and windows/msvc. Basic principle in the fixes was to ensure that whenever something is reinterpred_cast:ed to void* and stored to lua tables, it's always casted to exactly same type when it's casted back from void*.

Fix contained three parts.

First issue was that when LuaInterface_Impl* is stored to lua registry, it must be casted first to LuaInterface*. This is already in trunk, as it's very simple fix and practically required for launching widelands.exe with msvc2008.

Second issue was to fix method dispatching to retrive method pointer using correct type and was easily fixed by additional template parameter for parent type in m_method_dispatch.

Last part was to fix properties and this required more work as it did not employ dispatching. Therefore I implemented dispatching system for it. Intead of storing lightuserdata with pointer to property structure to metatable, metatable now contains a table with lightuserdata for getter and setter as well as cfunction for dispatching the property. Templated dispatching function stores type information for parent type so that when property is accessed, types are same is when it was stored.

I tried to reuse m_method_dispatch for also properties, but I could not figure out how to use cclosure correctly. So I opted for more straightforward version. m_property_disptach is practically a copy of m_method_dispatch with different place to get member function pointer. If you can come up with cleaner solution to pass getter/setter to dispatching function, then by all means have a try. Unit tests should validate that everything works.

Additionally I implemented unit test support to better debug the problems. There were some tricks needed to prevent linking with widelands main.cc or SDL_main:
 - WL_MAIN_SRCS contained main.cc due to greedy globbing. This was fixed by removing main.cc after globbing.
 - SDL_LIBRARY contained SDL_main.lib, which had to be removed before adding SDL libraries to test executable.

Revision history for this message
SirVer (sirver) wrote :

Excellent work. I will have a look over your code as soon as I can (which might not be too soon :( ). I suggest merging this back to trunk now as it is a very important fix. Feel free to do this at any time.

Changed in widelands:
milestone: none → build16-rc1
Jari Hautio (jarih)
Changed in widelands:
status: In Progress → Invalid
status: Invalid → Incomplete
status: Incomplete → Fix Committed
Revision history for this message
SirVer (sirver) wrote :

Released in build16-rc1

Changed in widelands:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.