Remove WS_DISABLE_ASSERT

Assertions can be enabled/disabled using WS_DISABLE_DEBUG. The extra
granularity afforded by WS_DISABLE_ASSERT seems unnecessary.
This commit is contained in:
João Valverde 2023-01-12 00:30:50 +00:00
parent 640c44f24e
commit 25d4a099f7
7 changed files with 12 additions and 29 deletions

View File

@ -457,7 +457,6 @@ set_property(DIRECTORY
PROPERTY COMPILE_DEFINITIONS
"G_DISABLE_DEPRECATED"
"G_DISABLE_SINGLE_INCLUDES"
$<$<OR:$<NOT:$<BOOL:${ENABLE_ASSERT}>>,$<CONFIG:Release>>:WS_DISABLE_ASSERT>
$<$<OR:$<NOT:$<BOOL:${ENABLE_DEBUG}>>,$<CONFIG:Release>>:WS_DISABLE_DEBUG>
$<$<OR:$<BOOL:${ENABLE_DEBUG_MBS}>,$<CONFIG:Debug>>:WS_DEBUG_UTF_8>
)

View File

@ -53,7 +53,6 @@ option(BUILD_fuzzshark "Build fuzzshark" OFF)
option(ENABLE_WERROR "Treat warnings as errors" ON)
option(ENABLE_DEBUG "Enable debug code" ON)
option(ENABLE_ASSERT "Enable assertions" ON)
option(ENABLE_DEBUG_MBS "Enable extra debug checks for detecting invalid multibyte (UTF-8) strings" OFF)
option(ENABLE_DEBUG_A2W "Enable line directive from .cnf file" OFF)

View File

@ -569,8 +569,8 @@ used for that purpose.
Use assertions to catch logic errors in your program. A failed assertion
indicates a bug in the code. Use ws_assert() instead of g_assert() to
test a logic condition. Note that ws_assert() will be removed with
WS_DISABLE_ASSERT. Therefore assertions should not have any side-effects,
test a logic condition. Note that ws_assert() can be removed at compile
time. Therefore assertions should not have any side-effects,
otherwise the program may behave inconsistently.
Use ws_assert_not_reached() instead of g_assert_not_reached() for

View File

@ -213,12 +213,6 @@ get_compiled_version_info(gather_feature_func gather_compile)
g_string_append(str, ", debug build (");
#endif
#ifdef WS_DISABLE_ASSERT
g_string_append(str, "-assert");
#else
g_string_append(str, "+assert");
#endif
#ifdef WS_DEBUG_UTF_8
g_string_append(str, " +utf8");
#else

View File

@ -15,11 +15,11 @@
#include <glib.h>
#ifdef WS_DISABLE_ASSERT
#ifdef WS_DISABLE_DEBUG
#define ASSERT(...) (void)0
#else
#define ASSERT(...) g_assert(__VA_ARGS__)
#endif /* WS_DISABLE_ASSERT */
#endif /* WS_DISABLE_DEBUG */
#endif /* __WMEM_INT_H__ */

View File

@ -16,7 +16,7 @@
#include <string.h>
#include <wsutil/wslog.h>
#ifdef WS_DISABLE_ASSERT
#ifdef WS_DISABLE_DEBUG
#define _ASSERT_ENABLED false
#else
#define _ASSERT_ENABLED true
@ -27,9 +27,9 @@ extern "C" {
#endif /* __cplusplus */
/*
* We don't want to execute the expression with WS_DISABLE_ASSERT because
* We don't want to execute the expression with WS_DISABLE_DEBUG because
* it might be time and space costly and the goal here is to optimize for
* WS_DISABLE_ASSERT. However removing it completely is not good enough
* WS_DISABLE_DEBUG. However removing it completely is not good enough
* because it might generate many unused variable warnings. So we use
* if (false) and let the compiler optimize away the dead execution branch.
*/
@ -40,7 +40,7 @@ extern "C" {
} while (0)
/*
* ws_abort_if_fail() is not conditional on WS_DISABLE_ASSERT.
* ws_abort_if_fail() is not conditional on WS_DISABLE_DEBUG.
* Usually used to appease a static analyzer.
*/
#define ws_abort_if_fail(expr) \
@ -48,7 +48,7 @@ extern "C" {
/*
* ws_assert() cannot produce side effects, otherwise code will
* behave differently because of WS_DISABLE_ASSERT, and probably introduce
* behave differently because of WS_DISABLE_DEBUG, and probably introduce
* some difficult to track bugs.
*/
#define ws_assert(expr) \
@ -70,7 +70,7 @@ extern "C" {
} while (0)
/*
* We don't want to disable ws_assert_not_reached() with WS_DISABLE_ASSERT.
* We don't want to disable ws_assert_not_reached() with WS_DISABLE_DEBUG.
* That would blast compiler warnings everywhere for no benefit, not
* even a miniscule performance gain. Reaching this function is always
* a programming error and will unconditionally abort execution.

View File

@ -10,18 +10,14 @@
#include "config.h"
/* Because ws_assert() dependes on ws_error() we do not use it
* here and fall back on assert() instead. */
#if defined(WS_DISABLE_ASSERT) && !defined(NDEBUG)
#define NDEBUG
#endif
#include "wslog.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
/* Because ws_assert() dependes on ws_error() we do not use it
* here and fall back on assert() instead. */
#include <assert.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@ -40,12 +36,7 @@
#include "console_win32.h"
#endif
#ifndef WS_DISABLE_ASSERT
#define ASSERT(expr) assert(expr)
#else
#define ASSERT(expr) (void)(expr);
#endif
/* Runtime log level. */
#define ENV_VAR_LEVEL "WIRESHARK_LOG_LEVEL"