Add do..while(0) wrappers to macros without one.

- Add do..while(0) wrapper to ERR_FAIL_NULL macros.
- Add do..while(0) wrapper to ERR_FAIL_COND macros.
- Add do..while(0) wrapper to ERR_CONTINUE macros.
- Add do..while(0) wrapper to ERR_BREAK macros.
- Add do..while(0) wrapper to CRASH_COND macros.
- Add do..while(0) wrapper to ERR_FAIL macros.
- Add do..while(0) wrapper to ERR_PRINT macros.
- Add do..while(0) wrapper to WARN_PRINT macros.
- Add do..while(0) wrapper to WARN_DEPRECATED macros.
- Add do..while(0) wrapper to CRASH_NOW macros.
This commit is contained in:
Marcel Admiraal 2019-11-07 10:37:44 +01:00
parent f0db13502a
commit 6d69cd40bd
10 changed files with 88 additions and 88 deletions

View file

@ -230,38 +230,38 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
// The current function returns.
#define ERR_FAIL_NULL(m_param) \
{ \
do { \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
return; \
} \
}
} while (0)
#define ERR_FAIL_NULL_MSG(m_param, m_msg) \
{ \
do { \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", DEBUG_STR(m_msg)); \
return; \
} \
}
} while (0)
// The current function returns m_retval.
#define ERR_FAIL_NULL_V(m_param, m_retval) \
{ \
do { \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
return m_retval; \
} \
}
} while (0)
#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
{ \
do { \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", DEBUG_STR(m_msg)); \
return m_retval; \
} \
}
} while (0)
// Error condition macros.
// Ensures that `m_cond` is not true.
@ -269,193 +269,193 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
// The current function returns.
#define ERR_FAIL_COND(m_cond) \
{ \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true."); \
return; \
} \
}
} while (0)
#define ERR_FAIL_COND_MSG(m_cond, m_msg) \
{ \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true.", DEBUG_STR(m_msg)); \
return; \
} \
}
} while (0)
// The current function returns m_retval.
#define ERR_FAIL_COND_V(m_cond, m_retval) \
{ \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. returned: " _STR(m_retval)); \
return m_retval; \
} \
}
} while (0)
#define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
{ \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. returned: " _STR(m_retval), DEBUG_STR(m_msg)); \
return m_retval; \
} \
}
} while (0)
// The current loop continues.
#define ERR_CONTINUE(m_cond) \
{ \
if (unlikely(m_cond)) { \
#define ERR_CONTINUE(m_cond) \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing."); \
continue; \
} \
}
continue; \
} \
} while (0)
#define ERR_CONTINUE_MSG(m_cond, m_msg) \
{ \
if (unlikely(m_cond)) { \
#define ERR_CONTINUE_MSG(m_cond, m_msg) \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing.", DEBUG_STR(m_msg)); \
continue; \
} \
}
continue; \
} \
} while (0)
// The current loop breaks.
#define ERR_BREAK(m_cond) \
{ \
if (unlikely(m_cond)) { \
#define ERR_BREAK(m_cond) \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking."); \
break; \
} \
}
break; \
} \
} while (0)
#define ERR_BREAK_MSG(m_cond, m_msg) \
{ \
if (unlikely(m_cond)) { \
#define ERR_BREAK_MSG(m_cond, m_msg) \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking.", DEBUG_STR(m_msg)); \
break; \
} \
}
break; \
} \
} while (0)
// Only use CRASH macros if there is no sensible fallback, that is, the error is unrecoverable.
#define CRASH_COND(m_cond) \
{ \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true."); \
GENERATE_TRAP(); \
} \
}
} while (0)
#define CRASH_COND_MSG(m_cond, m_msg) \
{ \
do { \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true.", DEBUG_STR(m_msg)); \
GENERATE_TRAP(); \
} \
}
} while (0)
// Generic error macros.
// The current function returns.
#define ERR_FAIL() \
{ \
do { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed."); \
return; \
}
} while (0)
#define ERR_FAIL_MSG(m_msg) \
{ \
do { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed.", DEBUG_STR(m_msg)); \
return; \
}
} while (0)
// The current function returns m_retval.
#define ERR_FAIL_V(m_retval) \
{ \
do { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value)); \
return m_retval; \
}
} while (0)
#define ERR_FAIL_V_MSG(m_value, m_msg) \
{ \
do { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value), DEBUG_STR(m_msg)); \
return m_value; \
}
} while (0)
// Print error message macros.
#define ERR_PRINT(m_msg) \
{ \
do { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, DEBUG_STR(m_msg)); \
}
} while (0)
// Only prints the error message once.
#define ERR_PRINT_ONCE(m_msg) \
{ \
do { \
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, DEBUG_STR(m_msg)); \
first_print = false; \
} \
}
} while (0)
// Print warning message macros.
// To warn about deprecated usage, use `WARN_DEPRECATED` or `WARN_DEPRECATED_MSG` instead.
#define WARN_PRINT(m_msg) \
{ \
do { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, DEBUG_STR(m_msg), ERR_HANDLER_WARNING); \
}
} while (0)
// Only prints the warning message once.
#define WARN_PRINT_ONCE(m_msg) \
{ \
do { \
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, DEBUG_STR(m_msg), ERR_HANDLER_WARNING); \
first_print = false; \
} \
}
} while (0)
// Print deprecated warning message macros.
// Only prints the warning message once.
#define WARN_DEPRECATED \
{ \
static volatile bool warning_shown = false; \
if (!warning_shown) { \
#define WARN_DEPRECATED \
do { \
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); \
warning_shown = true; \
} \
}
warning_shown = true; \
} \
} while (0)
#define WARN_DEPRECATED_MSG(m_msg) \
{ \
static volatile bool warning_shown = false; \
if (!warning_shown) { \
#define WARN_DEPRECATED_MSG(m_msg) \
do { \
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.", DEBUG_STR(m_msg), ERR_HANDLER_WARNING); \
warning_shown = true; \
} \
}
warning_shown = true; \
} \
} while (0)
// Only use CRASH macros if there is no sensible fallback, that is, the error is unrecoverable.
#define CRASH_NOW() \
{ \
do { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method/Function Failed."); \
GENERATE_TRAP(); \
}
} while (0)
#define CRASH_NOW_MSG(m_msg) \
{ \
do { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method/Function Failed.", DEBUG_STR(m_msg)); \
GENERATE_TRAP(); \
}
} while (0)
#endif

View file

@ -341,7 +341,7 @@ static int _bsp_create_node(const Face3 *p_faces, const Vector<int> &p_indices,
ERR_FAIL_COND_V(p_nodes.size() == BSP_Tree::MAX_NODES, -1);
// should not reach here
ERR_FAIL_COND_V(p_indices.size() == 0, -1)
ERR_FAIL_COND_V(p_indices.size() == 0, -1);
int ic = p_indices.size();
const int *indices = p_indices.ptr();

View file

@ -63,7 +63,7 @@ void EditorVCSInterface::_bind_methods() {
bool EditorVCSInterface::_initialize(String p_project_root_path) {
WARN_PRINT("Selected VCS addon does not implement an initialization function. This warning will be suppressed.")
WARN_PRINT("Selected VCS addon does not implement an initialization function. This warning will be suppressed.");
return true;
}

View file

@ -233,7 +233,7 @@ Error EditorSceneImporterGLTF::_parse_scenes(GLTFState &state) {
if (state.json.has("scene")) {
loaded_scene = state.json["scene"];
} else {
WARN_PRINT("The load-time scene is not defined in the glTF2 file. Picking the first scene.")
WARN_PRINT("The load-time scene is not defined in the glTF2 file. Picking the first scene.");
}
if (scenes.size()) {

View file

@ -203,7 +203,7 @@ void VersionControlEditorPlugin::_refresh_stage_area() {
}
} else {
WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu.")
WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu.");
}
}

View file

@ -389,7 +389,7 @@ EditorSceneImporterAssimp::_generate_scene(const String &p_path, aiScene *scene,
Spatial *parent_node = parent_lookup->value();
ERR_FAIL_COND_V_MSG(parent_node == NULL, state.root,
"Parent node invalid even though lookup successful, out of ram?")
"Parent node invalid even though lookup successful, out of ram?");
if (spatial != state.root) {
parent_node->add_child(spatial);

View file

@ -167,7 +167,7 @@ bool AreaBullet::is_monitoring() const {
}
void AreaBullet::main_shape_changed() {
CRASH_COND(!get_main_shape())
CRASH_COND(!get_main_shape());
btGhost->setCollisionShape(get_main_shape());
}

View file

@ -320,7 +320,7 @@ void RigidBodyBullet::destroy_kinematic_utilities() {
}
void RigidBodyBullet::main_shape_changed() {
CRASH_COND(!get_main_shape())
CRASH_COND(!get_main_shape());
btBody->setCollisionShape(get_main_shape());
set_continuous_collision_detection(is_continuous_collision_detection_enabled()); // Reset
}

View file

@ -1845,7 +1845,7 @@ bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_che
void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
ERR_FAIL_COND(p_event.is_null())
ERR_FAIL_COND(p_event.is_null());
//?
/*

View file

@ -2374,13 +2374,13 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String
if (tex3d.is_null()) {
f->close();
memdelete(f);
ERR_FAIL_COND_V(tex3d.is_null(), RES())
ERR_FAIL_COND_V(tex3d.is_null(), RES());
}
} else if (header[0] == 'G' && header[1] == 'D' && header[2] == 'A' && header[3] == 'T') {
if (texarr.is_null()) {
f->close();
memdelete(f);
ERR_FAIL_COND_V(texarr.is_null(), RES())
ERR_FAIL_COND_V(texarr.is_null(), RES());
}
} else {