-
-
Notifications
You must be signed in to change notification settings - Fork 446
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
Leak a little less memory with dynamic allocations in Lua #5508
Conversation
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.
clang-tidy made some suggestions
@@ -69,14 +69,33 @@ StackIdx push(lua_State *L, const bool &b); | |||
StackIdx push(lua_State *L, const int &b); | |||
StackIdx push(lua_State *L, const api::CompletionEvent &ev); | |||
|
|||
struct PeekResult { | |||
bool ok = true; | |||
std::vector<QString> errorReason = {}; |
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.
warning: initializer for member 'errorReason' is redundant [readability-redundant-member-init]
std::vector<QString> errorReason = {}; | |
std::vector<QString> errorReason; |
3e9e61f
to
d97b720
Compare
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.
clang-tidy made some suggestions
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.
clang-tidy made some suggestions
src/util/drop.hpp
Outdated
* Helps you avoid accidentally dropping a pointer not the object behind it. | ||
*/ | ||
template <typename T> | ||
inline void drop(T * /*var*/) = delete; |
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.
warning: function 'drop' has inline specifier but is implicitly inlined [readability-redundant-inline-specifier]
inline void drop(T * /*var*/) = delete; | |
void drop(T * /*var*/) = delete; |
You're invoking undefined behavior in many cases by using Speaking of exceptions... why not use them? At that point, it's probably best to use some bindings library (most (if not all) support incremental adoption). sol2 has a built-in trampoline. LuaBridge3 doesn't seem to have anything like it. There are probably others with support for that. I tried to convert the channel-api to use sol2 in https://github.com/Nerixyz/chatterino2/tree/experiment/sol3 (Nerixyz@45b7c0a) which has, despite adding adaptions for Qt types, more deletions than additions. |
Actually lua has an exception backend which could be used if we compiled it as c++ instead of c. This would then call destructors i think? |
I took a look at the sol this. And not having to do the SharedUserData is appealing but I'm not sure that it's appealing enough to rip everything out and convert it to sol. |
This PR ensures that any potentially large objects will get deallocated on error instead of getting forgotten and leaked.
This would have leaked memory:
Now it doesn't leak this memory.