Eliminate the CHECK() macro
This thing was pretty useless.
This commit is contained in:
parent
8c76bb49a4
commit
b405b979ec
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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 = {};
|
||||
|
11
src/common.h
11
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
|
||||
|
@ -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));
|
||||
|
||||
|
@ -441,7 +441,7 @@ void event_print(io_streams_t &streams, maybe_t<event_type_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;
|
||||
|
@ -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<terminfo_mapping_t> 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;
|
||||
|
@ -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<wchar_t *>(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);
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user