-
Notifications
You must be signed in to change notification settings - Fork 171
WIP: fix longjump leaks #6871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
WIP: fix longjump leaks #6871
Conversation
This is the recommended way to use lua with c++. It uses exceptions instead of longjump, which will fix several memory leaks. There are still problems: - unused headers in src/scripting/lua.h - compiler warnings about header files from src/third_party/eris/
…RFACE_SYSTEM_INCLUDE_DIRECTORIES Mark eris headers as system headers, because warnings of those are normally ignored by compilers. trying to follow https://stackoverflow.com/questions/56707123/how-to-suppress-clang-warnings-in-third-party-library-header-file-in-cmakelists But I seem to not understand it.
This works, but there are many source files. It is a workaround only anyway.
Compile works. But of course this is not a good solution. The good thing is that many memory leaks do not show up no more.
|
Mirrored on Codeberg as #CB5230. |
|
As expected GitHub has complained about the headers. I ignored it on my machine. So no proof (here) that many leaks are fixed. How shall the two points (in TODO) be fixed? As the label says: HELP WANTED about "properly exclude compiler warnings about header files from ..."
|
| luna_impl | ||
| PROPERTIES | ||
| COMPILE_OPTIONS -Wno-old-style-cast # TODO(somebody): remove this and ignore for header only | ||
| ) # because code/src/third_party/eris/lua.h and third_party/eris/luaconf.h cast integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Listing all files like this gets much too many files. Maybe half of the project. So only a minor advantage over disabling generally, but much more work.
TODO remove
| base_exceptions | ||
| third_party_eris | ||
| ) | ||
| set_target_properties(scripting_base PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ../third_party/eris/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I either do not find out how to set this path correctly, or it does not work for this case.
I tried:
- path relative to CMakeLists.txt (as here)
- path relative to main source
- absolute path to header file dir
- absolute path to header file dir in build
| set_source_files_properties(${ERIS_SRC} ${ERIS_H} | ||
| DIRECTORY . .. | ||
| PROPERTIES COMPILE_OPTIONS -Wno-old-style-cast | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setting COMPILE_OPTIONS for the header files has probably no effect. (Would it work for pre-compiled headers?)
Removing this file does not result in an error.
| set_source_files_properties(${ERIS_SRC} PROPERTIES LANGUAGE CXX) | ||
| set_source_files_properties(${ERIS_SRC} ${ERIS_H} | ||
| DIRECTORY . .. | ||
| PROPERTIES COMPILE_OPTIONS -Wno-old-style-cast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compile option -Wno-old-style-cast is not supported on windows msvc:
https://github.com/widelands/widelands/actions/runs/17128350443/job/48587469069?pr=6871#step:8:158
|
from run testsuite / testsuite (Debug, ubuntu-24.04, clang-18) You may compare to https://github.com/widelands/widelands/actions/runs/17051950618?pr=6851#summary-48341685572 There 39 origins, here 14 origins There, for the first reported test (test/maps/lua_testsuite.wmf/scripting/test_lua_in_game.lua) here ... created with utils/test/memory_leak_summary_from_gh_log.py from #6851 memory leaksTip To find the full traceback, go to the log and copy the line from the traceback here in the log's search field. ==34935==ERROR: LeakSanitizer: detected memory leakstriggered by test test/maps/lua_testsuite.wmf/scripting/test_lua_in_game.lua Details
4 leaks==35229==ERROR: LeakSanitizer: detected memory leakstriggered by test test/maps/plain.wmf/scripting/test_text_renderer_does_not_crash.lua Details
16 leaks==35829==ERROR: LeakSanitizer: detected memory leakstriggered by test test/templates/test_fortified_village-artifacts.lua Details
1 leaks==35904==ERROR: LeakSanitizer: detected memory leakstriggered by test test/templates/test_trading_outpost-collectors.lua Details
5 leaks==35958==ERROR: LeakSanitizer: detected memory leakstriggered by test test/maps/lua_testsuite.wmf/scripting/editor_test_lua_in_editor.lua Details
2 leaksmemory leaks by originfrom 14 origins
|
|
looking at the remaining origin lines, I am positive that those will be closed by the other pull requests fixing memory leaks. |
|
I might not be easy available when it is time to finish this pr. Feel free to take over. |
|
Instead of ignoring warnings of a header file, a patch similar to this one might be easiest: diff --git a/src/third_party/eris/luaconf.h b/src/third_party/eris/luaconf.h
index 9ecf49777d..c7078a98d4 100644
--- a/src/third_party/eris/luaconf.h
+++ b/src/third_party/eris/luaconf.h
@@ -751,8 +751,12 @@
#if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE
#define LUAL_BUFFERSIZE 8192
#else
+#ifdef __cplusplus
+#define LUAL_BUFFERSIZE (static_cast<int>(0x80 * sizeof(void*) * sizeof(lua_Integer)))
+#else
#define LUAL_BUFFERSIZE ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))
#endif
+#endif
/* }================================================================== */
`` |
Type of Change
Bugfix
Issue(s) Closed
Fixes #6808 fixes #6809 fixes #6810 fixes #6811 fixes #6812 fixes #6812 fixes #6813 fixes #6814 fixes #6815 fixes #6816 fixes #6817 fixes #6818 fixes #6820 fixes #6821 fixes #6822 fixes #6828 fixes #6829 fixes #6838
To Reproduce
see reported memory leak from a recent test run, like https://github.com/widelands/widelands/actions/runs/17108726999/job/48524654051#step:9:1417
New Behavior
Now there are much fewer memory leaks because lua does not use longjump.
(see summary of leaks below in comment)
How it Works
The code for eris+lua is compiled with c++. Now lua throws an exception on error instead of doing longjump (and catches the exception). So stack is unwound and variables get deleted properly (including calling the destructor).
Possible Regressions
Additional context
As expected GitHub complained about the headers. I ignored it on my machine. So no proof that many leaks are fixed.
How shall the two following points be fixed? As the label says: HELP WANTED
TODO