From b405b979ecba8197e5b5cb107cff212bea7ec984 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 27 May 2019 17:24:19 -0700 Subject: [PATCH] Eliminate the CHECK() macro This thing was pretty useless. --- src/builtin_functions.cpp | 2 +- src/builtin_read.cpp | 5 ++++- src/common.cpp | 4 +--- src/common.h | 11 ----------- src/complete.cpp | 2 +- src/event.cpp | 2 +- src/input.cpp | 8 ++------ src/parse_util.cpp | 11 ++++------- src/screen.cpp | 2 +- src/util.cpp | 3 +-- 10 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index 6b53c2b3c..1edd67c3b 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -126,7 +126,7 @@ static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(hi /// Return a definition of the specified function. Used by the functions builtin. static wcstring functions_def(const wcstring &name) { - CHECK(!name.empty(), L""); //!OCLINT(multiple unary operator) + assert(!name.empty() && "Empty name"); wcstring out; wcstring desc, def; function_get_desc(name, desc); diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 913293a15..1240b675c 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -274,7 +274,10 @@ static int read_in_chunks(int fd, wcstring &buff, bool split_null) { if (bytes_consumed < bytes_read) { // We found a splitter. The +1 because we need to treat the splitter as consumed, but // not append it to the string. - CHECK(lseek(fd, bytes_consumed - bytes_read + 1, SEEK_CUR) != -1, STATUS_CMD_ERROR) + if (lseek(fd, bytes_consumed - bytes_read + 1, SEEK_CUR) == -1) { + wperror(L"lseek"); + return STATUS_CMD_ERROR; + } finished = true; } else if (str.size() > read_byte_limit) { exit_res = STATUS_READ_TOO_MUCH; diff --git a/src/common.cpp b/src/common.cpp index efd2c19d0..8e1ad13ab 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -431,9 +431,7 @@ std::string wcs2string(const wcstring &input) { /// This function decodes illegal character sequences in a reversible way using the private use /// area. static char *wcs2str_internal(const wchar_t *in, char *out) { - CHECK(in, 0); - CHECK(out, 0); - + assert(in && out && "in and out must not be null"); size_t in_pos = 0; size_t out_pos = 0; mbstate_t state = {}; diff --git a/src/common.h b/src/common.h index 4a94a4aef..eadf02372 100644 --- a/src/common.h +++ b/src/common.h @@ -202,17 +202,6 @@ extern const wchar_t *program_name; /// Set to false if it's been determined we can't trust the last modified timestamp on the tty. extern const bool has_working_tty_timestamps; -/// This macro is used to check that an argument is true. It is a bit like a non-fatal form of -/// assert. Instead of exiting on failure, the current function is ended at once. The second -/// parameter is the return value of the current function on failure. -#define CHECK(arg, retval) \ - if (!(arg)) { \ - debug(0, "function %s called with false value for argument %s", __func__, #arg); \ - bugreport(); \ - show_stackframe(L'E'); \ - return retval; \ - } - // Pause for input, then exit the program. If supported, print a backtrace first. // The `return` will never be run but silences oclint warnings. Especially when this is called // from within a `switch` block. As of the time I'm writing this oclint doesn't recognize the diff --git a/src/complete.cpp b/src/complete.cpp index e45d0f4e9..bd0b4073f 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -438,7 +438,7 @@ void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option, complete_option_type_t option_type, completion_mode_t result_mode, const wchar_t *condition, const wchar_t *comp, const wchar_t *desc, complete_flags_t flags) { - CHECK(cmd, ); + assert(cmd && "Null command"); // option should be empty iff the option type is arguments only. assert(option.empty() == (option_type == option_type_args_only)); diff --git a/src/event.cpp b/src/event.cpp index 5d5d1e9fb..96e78d9ad 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -441,7 +441,7 @@ void event_print(io_streams_t &streams, maybe_t type_filter) { } void event_fire_generic(const wchar_t *name, const wcstring_list_t *args) { - CHECK(name, ); + assert(name && "Null name"); event_t ev(event_type_t::generic); ev.desc.str_param1 = name; diff --git a/src/input.cpp b/src/input.cpp index bbf990d4c..e9fb2b5cd 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -219,11 +219,7 @@ static void input_mapping_insert_sorted(const input_mapping_t &new_mapping, bool /// Adds an input mapping. void input_mapping_add(const wchar_t *sequence, const wchar_t *const *commands, size_t commands_len, const wchar_t *mode, const wchar_t *sets_mode, bool user) { - CHECK(sequence, ); - CHECK(commands, ); - CHECK(mode, ); - CHECK(sets_mode, ); - + assert(sequence && commands && mode && sets_mode && "Null parameter"); // Remove existing mappings with this sequence. const wcstring_list_t commands_vector(commands, commands + commands_len); @@ -663,7 +659,7 @@ static std::vector create_input_terminfo() { bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq) { ASSERT_IS_MAIN_THREAD(); assert(s_input_initialized); - CHECK(name, 0); + assert(name && "null name"); const char *res = 0; int err = ENOENT; diff --git a/src/parse_util.cpp b/src/parse_util.cpp index 8d3a987b7..7f5c14f05 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -112,7 +112,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin wchar_t *paran_begin = 0, *paran_end = 0; - CHECK(in, 0); + assert(in && "null parameter"); for (pos = const_cast(in); *pos; pos++) { if (prev != '\\') { @@ -236,10 +236,9 @@ int parse_util_locate_cmdsubst_range(const wcstring &str, size_t *inout_cursor_o void parse_util_cmdsubst_extent(const wchar_t *buff, size_t cursor_pos, const wchar_t **a, const wchar_t **b) { + assert(buff && "Null buffer"); const wchar_t *const cursor = buff + cursor_pos; - CHECK(buff, ); - const size_t bufflen = std::wcslen(buff); assert(cursor_pos <= bufflen); @@ -285,12 +284,11 @@ void parse_util_cmdsubst_extent(const wchar_t *buff, size_t cursor_pos, const wc /// Get the beginning and end of the job or process definition under the cursor. static void job_or_process_extent(const wchar_t *buff, size_t cursor_pos, const wchar_t **a, const wchar_t **b, int process) { + assert(buff && "Null buffer"); const wchar_t *begin, *end; wchar_t *buffcpy; int finished = 0; - CHECK(buff, ); - if (a) *a = 0; if (b) *b = 0; parse_util_cmdsubst_extent(buff, cursor_pos, &begin, &end); @@ -349,10 +347,9 @@ void parse_util_job_extent(const wchar_t *buff, size_t pos, const wchar_t **a, c void parse_util_token_extent(const wchar_t *buff, size_t cursor_pos, const wchar_t **tok_begin, const wchar_t **tok_end, const wchar_t **prev_begin, const wchar_t **prev_end) { + assert(buff && "Null buffer"); const wchar_t *a = NULL, *b = NULL, *pa = NULL, *pb = NULL; - CHECK(buff, ); - const wchar_t *cmdsubst_begin, *cmdsubst_end; parse_util_cmdsubst_extent(buff, cursor_pos, &cmdsubst_begin, &cmdsubst_end); diff --git a/src/screen.cpp b/src/screen.cpp index f653be3f8..cda851cad 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -1060,7 +1060,7 @@ void s_write(screen_t *s, const wcstring &left_prompt, const wcstring &right_pro s_save_status(s); } void s_reset(screen_t *s, screen_reset_mode_t mode) { - CHECK(s, ); + assert(s && "Null screen"); bool abandon_line = false, repaint_prompt = false, clear_to_eos = false; switch (mode) { diff --git a/src/util.cpp b/src/util.cpp index c3ce6b1a5..0b1080cbb 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -47,8 +47,7 @@ static int wcsfilecmp_leading_digits(const wchar_t **a, const wchar_t **b) { /// /// Returns: -1 if a < b, 0 if a == b, 1 if a > b. int wcsfilecmp(const wchar_t *a, const wchar_t *b) { - CHECK(a, 0); - CHECK(b, 0); + assert(a && b && "Null parameter"); const wchar_t *orig_a = a; const wchar_t *orig_b = b; int retval = 0; // assume the strings will be equal