summaryrefslogtreecommitdiff
path: root/src/script/common
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2020-10-31 18:19:23 +0000
committerGitHub <noreply@github.com>2020-10-31 18:19:23 +0000
commit89dd05fdf35ce465fcc2b3588337f79f818a78aa (patch)
tree8cd34c9435fd0feca4d35184649bc002cc53d260 /src/script/common
parent2dff3dd03f7ba25f3fab7c360759ddbf93615668 (diff)
downloadminetest-89dd05fdf35ce465fcc2b3588337f79f818a78aa.tar.gz
minetest-89dd05fdf35ce465fcc2b3588337f79f818a78aa.tar.bz2
minetest-89dd05fdf35ce465fcc2b3588337f79f818a78aa.zip
Fix segfault in deprecation logging due to tail call, log by default (#10174)
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_internal.cpp20
-rw-r--r--src/script/common/c_internal.h20
2 files changed, 32 insertions, 8 deletions
diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp
index 6df1f8b7b..ad5f836c5 100644
--- a/src/script/common/c_internal.cpp
+++ b/src/script/common/c_internal.cpp
@@ -155,24 +155,28 @@ static void script_log(lua_State *L, const std::string &message,
infostream << script_get_backtrace(L) << std::endl;
}
-void log_deprecated(lua_State *L, const std::string &message, int stack_depth)
+DeprecatedHandlingMode get_deprecated_handling_mode()
{
static thread_local bool configured = false;
- static thread_local bool do_log = false;
- static thread_local bool do_error = false;
+ static thread_local DeprecatedHandlingMode ret = DeprecatedHandlingMode::Ignore;
// Only read settings on first call
if (!configured) {
std::string value = g_settings->get("deprecated_lua_api_handling");
if (value == "log") {
- do_log = true;
+ ret = DeprecatedHandlingMode::Log;
} else if (value == "error") {
- do_log = true;
- do_error = true;
+ ret = DeprecatedHandlingMode::Error;
}
configured = true;
}
- if (do_log)
- script_log(L, message, warningstream, do_error, stack_depth);
+ return ret;
+}
+
+void log_deprecated(lua_State *L, const std::string &message, int stack_depth)
+{
+ DeprecatedHandlingMode mode = get_deprecated_handling_mode();
+ if (mode != DeprecatedHandlingMode::Ignore)
+ script_log(L, message, warningstream, mode == DeprecatedHandlingMode::Error, stack_depth);
}
diff --git a/src/script/common/c_internal.h b/src/script/common/c_internal.h
index 442546332..452c2dd5e 100644
--- a/src/script/common/c_internal.h
+++ b/src/script/common/c_internal.h
@@ -114,5 +114,25 @@ void script_error(lua_State *L, int pcall_result, const char *mod, const char *f
void script_run_callbacks_f(lua_State *L, int nargs,
RunCallbacksMode mode, const char *fxn);
+enum class DeprecatedHandlingMode {
+ Ignore,
+ Log,
+ Error
+};
+
+/**
+ * Reads `deprecated_lua_api_handling` in settings, returns cached value.
+ *
+ * @return DeprecatedHandlingMode
+ */
+DeprecatedHandlingMode get_deprecated_handling_mode();
+
+/**
+ * Handles a deprecation warning based on user settings
+ *
+ * @param L Lua State
+ * @param message The deprecation method
+ * @param stack_depth How far on the stack to the first user function (ie: not builtin or core)
+ */
void log_deprecated(lua_State *L, const std::string &message,
int stack_depth=1);