Remove ERR_EXPLAIN macros and the scaffolding they needed.

This commit is contained in:
Marcel Admiraal 2019-11-11 10:38:15 +01:00
parent d18b2e599d
commit 83069a3c0f
6 changed files with 3 additions and 134 deletions

View file

@ -34,25 +34,8 @@
#include "core/ustring.h"
#include "os/os.h"
bool _err_error_exists = false;
static ErrorHandlerList *error_handler_list = NULL;
void _err_set_last_error(const char *p_err) {
OS::get_singleton()->set_last_error(p_err);
}
void _err_set_last_error(const String &p_err) {
_err_set_last_error(p_err.utf8().get_data());
}
void _err_clear_last_error() {
OS::get_singleton()->clear_last_error();
}
void add_error_handler(ErrorHandlerList *p_handler) {
_global_lock();
@ -86,27 +69,11 @@ void remove_error_handler(ErrorHandlerList *p_handler) {
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, ErrorHandlerType p_type) {
OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, _err_error_exists ? OS::get_singleton()->get_last_error() : "", (Logger::ErrorType)p_type);
_global_lock();
ErrorHandlerList *l = error_handler_list;
while (l) {
l->errfunc(l->userdata, p_function, p_file, p_line, p_error, _err_error_exists ? OS::get_singleton()->get_last_error() : "", p_type);
l = l->next;
}
_global_unlock();
if (_err_error_exists) {
OS::get_singleton()->clear_last_error();
_err_error_exists = false;
}
_err_print_error(p_function, p_file, p_line, p_error, "", p_type);
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, ErrorHandlerType p_type) {
_err_print_error(p_function, p_file, p_line, p_error.utf8().get_data(), p_type);
_err_print_error(p_function, p_file, p_line, p_error.utf8().get_data(), "", p_type);
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type) {

View file

@ -57,9 +57,6 @@ enum ErrorHandlerType {
class String;
typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
void _err_set_last_error(const char *p_err);
void _err_set_last_error(const String &p_err);
void _err_clear_last_error();
struct ErrorHandlerList {
@ -96,29 +93,6 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
/** An index has failed if m_index<0 or m_index >=m_size, the function exits */
extern bool _err_error_exists;
#ifdef DEBUG_ENABLED
/** Print a warning string.
*/
#define ERR_EXPLAINC(m_reason) \
{ \
_err_set_last_error(m_reason); \
_err_error_exists = true; \
}
#define ERR_EXPLAIN(m_string) \
{ \
_err_set_last_error(m_string); \
_err_error_exists = true; \
}
#else
#define ERR_EXPLAIN(m_text)
#define ERR_EXPLAINC(m_text)
#endif
#ifdef __GNUC__
//#define FUNCTION_STR __PRETTY_FUNCTION__ - too annoying
#define FUNCTION_STR __FUNCTION__
@ -145,7 +119,6 @@ extern bool _err_error_exists;
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return; \
} \
_err_error_exists = false; \
} while (0); // (*)
#define ERR_FAIL_INDEX_MSG(m_index, m_size, m_msg) \
@ -154,7 +127,6 @@ extern bool _err_error_exists;
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
return; \
} \
_err_error_exists = false; \
} while (0); // (*)
/** An index has failed if m_index<0 or m_index >=m_size, the function exits.
@ -168,7 +140,6 @@ extern bool _err_error_exists;
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} \
_err_error_exists = false; \
} while (0); // (*)
#define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
@ -177,7 +148,6 @@ extern bool _err_error_exists;
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
return m_retval; \
} \
_err_error_exists = false; \
} while (0); // (*)
/** An index has failed if m_index >=m_size, the function exits.
@ -191,7 +161,6 @@ extern bool _err_error_exists;
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} \
_err_error_exists = false; \
} while (0); // (*)
#define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
@ -200,7 +169,6 @@ extern bool _err_error_exists;
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
return m_retval; \
} \
_err_error_exists = false; \
} while (0); // (*)
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
@ -232,7 +200,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
return; \
} \
_err_error_exists = false; \
}
#define ERR_FAIL_NULL_MSG(m_param, m_msg) \
@ -241,7 +208,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null.", m_msg); \
return; \
} \
_err_error_exists = false; \
}
#define ERR_FAIL_NULL_V(m_param, m_retval) \
@ -250,7 +216,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
return m_retval; \
} \
_err_error_exists = false; \
}
#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
@ -259,7 +224,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null.", m_msg); \
return m_retval; \
} \
_err_error_exists = false; \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@ -272,7 +236,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true."); \
return; \
} \
_err_error_exists = false; \
}
#define ERR_FAIL_COND_MSG(m_cond, m_msg) \
@ -281,7 +244,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true.", m_msg); \
return; \
} \
_err_error_exists = false; \
}
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
@ -315,7 +277,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval)); \
return m_retval; \
} \
_err_error_exists = false; \
}
#define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
@ -324,7 +285,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval), m_msg); \
return m_retval; \
} \
_err_error_exists = false; \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@ -337,7 +297,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:"); \
continue; \
} \
_err_error_exists = false; \
}
#define ERR_CONTINUE_MSG(m_cond, m_msg) \
@ -346,7 +305,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:", m_msg); \
continue; \
} \
_err_error_exists = false; \
}
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
@ -359,7 +317,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
break; \
} \
_err_error_exists = false; \
}
#define ERR_BREAK_MSG(m_cond, m_msg) \
@ -368,7 +325,6 @@ extern bool _err_error_exists;
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:", m_msg); \
break; \
} \
_err_error_exists = false; \
}
/** Print an error string and return
@ -377,14 +333,12 @@ extern bool _err_error_exists;
#define ERR_FAIL() \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed."); \
_err_error_exists = false; \
return; \
}
#define ERR_FAIL_MSG(m_msg) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed.", m_msg); \
_err_error_exists = false; \
return; \
}
@ -394,14 +348,12 @@ extern bool _err_error_exists;
#define ERR_FAIL_V(m_value) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value)); \
_err_error_exists = false; \
return m_value; \
}
#define ERR_FAIL_V_MSG(m_value, m_msg) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value), m_msg); \
_err_error_exists = false; \
return m_value; \
}
@ -426,13 +378,11 @@ extern bool _err_error_exists;
#define ERR_PRINT(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
_err_error_exists = false; \
}
#define ERR_PRINTS(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
_err_error_exists = false; \
}
#define ERR_PRINT_ONCE(m_string) \
@ -440,7 +390,6 @@ extern bool _err_error_exists;
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
_err_error_exists = false; \
first_print = false; \
} \
}
@ -451,13 +400,11 @@ extern bool _err_error_exists;
#define WARN_PRINT(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
_err_error_exists = false; \
}
#define WARN_PRINTS(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
_err_error_exists = false; \
}
#define WARN_PRINT_ONCE(m_string) \
@ -465,7 +412,6 @@ extern bool _err_error_exists;
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
_err_error_exists = false; \
first_print = false; \
} \
}
@ -475,7 +421,6 @@ extern bool _err_error_exists;
static volatile bool warning_shown = false; \
if (!warning_shown) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future", ERR_HANDLER_WARNING); \
_err_error_exists = false; \
warning_shown = true; \
} \
}
@ -485,7 +430,6 @@ extern bool _err_error_exists;
static volatile bool warning_shown = false; \
if (!warning_shown) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future", m_msg, ERR_HANDLER_WARNING); \
_err_error_exists = false; \
warning_shown = true; \
} \
}

View file

@ -196,29 +196,6 @@ bool OS::is_stdout_verbose() const {
return _verbose_stdout;
}
void OS::set_last_error(const char *p_error) {
GLOBAL_LOCK_FUNCTION
if (p_error == NULL)
p_error = "Unknown Error";
if (last_error)
memfree(last_error);
last_error = NULL;
int len = 0;
while (p_error[len++])
;
last_error = (char *)memalloc(len);
for (int i = 0; i < len; i++)
last_error[i] = p_error[i];
}
const char *OS::get_last_error() const {
GLOBAL_LOCK_FUNCTION
return last_error ? last_error : "";
}
void OS::dump_memory_to_file(const char *p_file) {
//Memory::dump_static_mem_to_file(p_file);
@ -297,14 +274,6 @@ void OS::dump_resources_to_file(const char *p_file) {
ResourceCache::dump(p_file);
}
void OS::clear_last_error() {
GLOBAL_LOCK_FUNCTION
if (last_error)
memfree(last_error);
last_error = NULL;
}
void OS::set_no_window_mode(bool p_enable) {
_no_window = p_enable;
@ -764,7 +733,6 @@ OS::OS() {
void *volatile stack_bottom;
restart_on_exit = false;
last_error = NULL;
singleton = this;
_keep_screen_on = true; // set default value to true, because this had been true before godot 2.0.
low_processor_usage_mode = false;
@ -790,8 +758,6 @@ OS::OS() {
}
OS::~OS() {
if (last_error)
memfree(last_error);
memdelete(_logger);
singleton = NULL;
}

View file

@ -61,8 +61,6 @@ class OS {
bool _allow_layered;
bool _use_vsync;
char *last_error;
void *_stack_bottom;
CompositeLogger *_logger;
@ -155,10 +153,6 @@ public:
virtual void alert(const String &p_alert, const String &p_title = "ALERT!") = 0;
virtual String get_stdin_string(bool p_block = true) = 0;
virtual void set_last_error(const char *p_error);
virtual const char *get_last_error() const;
virtual void clear_last_error();
enum MouseMode {
MOUSE_MODE_VISIBLE,
MOUSE_MODE_HIDDEN,

View file

@ -2164,6 +2164,5 @@ void Main::cleanup() {
unregister_core_driver_types();
unregister_core_types();
OS::get_singleton()->clear_last_error();
OS::get_singleton()->finalize_core();
}

View file

@ -397,8 +397,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
OPCODE_BREAK; \
} else \
_err_error_exists = false; \
} \
}
#define CHECK_SPACE(m_space) \