summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorCraig Robbins <kde.psych@gmail.com>2015-03-06 20:21:51 +1000
committerCraig Robbins <kde.psych@gmail.com>2015-03-07 22:41:47 +1000
commitced6d20295a8263757d57c02a07ffcb66688a163 (patch)
treea44527357c1ffccb88bf479686735aef168d15c1 /src/script
parenta603a767877b94b4d3bc4d3de8d762fbc56a583d (diff)
downloadminetest-ced6d20295a8263757d57c02a07ffcb66688a163.tar.gz
minetest-ced6d20295a8263757d57c02a07ffcb66688a163.tar.bz2
minetest-ced6d20295a8263757d57c02a07ffcb66688a163.zip
For usages of assert() that are meant to persist in Release builds (when NDEBUG is defined), replace those usages with persistent alternatives
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_internal.cpp6
-rw-r--r--src/script/cpp_api/s_async.cpp4
-rw-r--r--src/script/cpp_api/s_base.cpp2
-rw-r--r--src/script/lua_api/l_env.cpp6
-rw-r--r--src/script/lua_api/l_mainmenu.cpp28
5 files changed, 22 insertions, 24 deletions
diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp
index f811dd5d3..61248534c 100644
--- a/src/script/common/c_internal.cpp
+++ b/src/script/common/c_internal.cpp
@@ -87,7 +87,7 @@ void script_error(lua_State *L)
// computed depending on mode
void script_run_callbacks(lua_State *L, int nargs, RunCallbacksMode mode)
{
- assert(lua_gettop(L) >= nargs + 1);
+ FATAL_ERROR_IF(lua_gettop(L) < nargs + 1, "Not enough arguments");
// Insert error handler
lua_pushcfunction(L, script_error_handler);
@@ -136,9 +136,7 @@ void log_deprecated(lua_State *L, std::string message)
if (L != NULL) {
script_error(L);
} else {
- /* As of april 2014 assert is not optimized to nop in release builds
- * therefore this is correct. */
- assert("Can't do a scripterror for this deprecated message, so exit completely!");
+ FATAL_ERROR("Can't do a scripterror for this deprecated message, so exit completely!");
}
}
diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp
index de1ebc07b..eb1a2923a 100644
--- a/src/script/cpp_api/s_async.cpp
+++ b/src/script/cpp_api/s_async.cpp
@@ -155,7 +155,7 @@ void AsyncEngine::step(lua_State *L, int errorhandler)
lua_getfield(L, -1, "async_event_handler");
if (lua_isnil(L, -1)) {
- assert("Async event handler does not exist!" == 0);
+ FATAL_ERROR("Async event handler does not exist!");
}
luaL_checktype(L, -1, LUA_TFUNCTION);
@@ -237,7 +237,7 @@ AsyncWorkerThread::AsyncWorkerThread(AsyncEngine* jobDispatcher,
/******************************************************************************/
AsyncWorkerThread::~AsyncWorkerThread()
{
- assert(IsRunning() == false);
+ sanity_check(IsRunning() == false);
}
/******************************************************************************/
diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp
index 1f96373dc..71473d215 100644
--- a/src/script/cpp_api/s_base.cpp
+++ b/src/script/cpp_api/s_base.cpp
@@ -72,7 +72,7 @@ ScriptApiBase::ScriptApiBase()
#endif
m_luastack = luaL_newstate();
- assert(m_luastack);
+ FATAL_ERROR_IF(!m_luastack, "luaL_newstate() failed");
luaL_openlibs(m_luastack);
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 1f1d8bffa..840c34595 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -49,7 +49,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
scriptIface->realityCheck();
lua_State *L = scriptIface->getStack();
- assert(lua_checkstack(L, 20));
+ sanity_check(lua_checkstack(L, 20));
StackUnroller stack_unroller(L);
lua_pushcfunction(L, script_error_handler);
@@ -65,7 +65,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
lua_pushnumber(L, m_id);
lua_gettable(L, -2);
if(lua_isnil(L, -1))
- assert(0);
+ FATAL_ERROR("");
lua_remove(L, -2); // Remove registered_abms
// Call action
@@ -459,7 +459,7 @@ int ModApiEnvMod::l_set_timeofday(lua_State *L)
// Do it
float timeofday_f = luaL_checknumber(L, 1);
- assert(timeofday_f >= 0.0 && timeofday_f <= 1.0);
+ sanity_check(timeofday_f >= 0.0 && timeofday_f <= 1.0);
int timeofday_mh = (int)(timeofday_f * 24000.0);
// This should be set directly in the environment but currently
// such changes aren't immediately sent to the clients, so call
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 2bed2a255..e6fcdcf83 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -90,7 +90,7 @@ int ModApiMainMenu::getBoolData(lua_State *L, std::string name,bool& valid)
int ModApiMainMenu::l_update_formspec(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
if (engine->m_startgame)
return 0;
@@ -109,7 +109,7 @@ int ModApiMainMenu::l_update_formspec(lua_State *L)
int ModApiMainMenu::l_start(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
//update c++ gamedata from lua table
@@ -134,7 +134,7 @@ int ModApiMainMenu::l_start(lua_State *L)
int ModApiMainMenu::l_close(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
engine->m_kill = true;
return 0;
@@ -144,7 +144,7 @@ int ModApiMainMenu::l_close(lua_State *L)
int ModApiMainMenu::l_set_background(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
std::string backgroundlevel(luaL_checkstring(L, 1));
std::string texturename(luaL_checkstring(L, 2));
@@ -189,7 +189,7 @@ int ModApiMainMenu::l_set_background(lua_State *L)
int ModApiMainMenu::l_set_clouds(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
bool value = lua_toboolean(L,1);
@@ -209,7 +209,7 @@ int ModApiMainMenu::l_get_textlist_index(lua_State *L)
int ModApiMainMenu::l_get_table_index(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
std::wstring tablename(narrow_to_wide(luaL_checkstring(L, 1)));
GUITable *table = engine->m_menu->getTable(tablename);
@@ -617,7 +617,7 @@ int ModApiMainMenu::l_delete_favorite(lua_State *L)
int ModApiMainMenu::l_show_keys_menu(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
GUIKeyChangeMenu *kmenu
= new GUIKeyChangeMenu( engine->m_device->getGUIEnvironment(),
@@ -692,7 +692,7 @@ int ModApiMainMenu::l_delete_world(lua_State *L)
int ModApiMainMenu::l_set_topleft_text(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
std::string text = "";
@@ -843,7 +843,7 @@ int ModApiMainMenu::l_copy_dir(lua_State *L)
int ModApiMainMenu::l_extract_zip(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);(engine != 0);
const char *zipfile = luaL_checkstring(L, 1);
const char *destination = luaL_checkstring(L, 2);
@@ -860,7 +860,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
return 1;
}
- assert(fs->getFileArchiveCount() > 0);
+ sanity_check(fs->getFileArchiveCount() > 0);
/**********************************************************************/
/* WARNING this is not threadsafe!! */
@@ -931,7 +931,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
int ModApiMainMenu::l_get_mainmenu_path(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
lua_pushstring(L,engine->getScriptDir().c_str());
return 1;
@@ -963,7 +963,7 @@ bool ModApiMainMenu::isMinetestPath(std::string path)
int ModApiMainMenu::l_show_file_open_dialog(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
- assert(engine != 0);
+ sanity_check(engine != NULL);
const char *formname= luaL_checkstring(L, 1);
const char *title = luaL_checkstring(L, 2);
@@ -1118,8 +1118,8 @@ int ModApiMainMenu::l_do_async_callback(lua_State *L)
const char* serialized_param_raw = luaL_checklstring(L, 2, &param_length);
- assert(serialized_func_raw != NULL);
- assert(serialized_param_raw != NULL);
+ sanity_check(serialized_func_raw != NULL);
+ sanity_check(serialized_param_raw != NULL);
std::string serialized_func = std::string(serialized_func_raw, func_length);
std::string serialized_param = std::string(serialized_param_raw, param_length);