~emersion/mrsh

742831fac04c12f103245cc20bc6448666461863 — Simon Ser 2 months ago 41ead0f master
Replace assert(0) with abort()

This ensures functions reaching the asserts won't return, and avoids
issues with NDEBUG.
M arithm.c => arithm.c +1 -1
@@ 42,7 42,7 @@ void mrsh_arithm_expr_destroy(struct mrsh_arithm_expr *expr) {
		free(aa);
		return;
	}
	assert(false);
	abort();
}

struct mrsh_arithm_literal *mrsh_arithm_literal_create(long value) {

M ast.c => ast.c +22 -22
@@ 39,7 39,7 @@ void mrsh_node_destroy(struct mrsh_node *node) {
		mrsh_word_destroy(word);
		return;
	}
	assert(0);
	abort();
}

void mrsh_word_destroy(struct mrsh_word *word) {


@@ 79,7 79,7 @@ void mrsh_word_destroy(struct mrsh_word *word) {
		free(wl);
		return;
	}
	assert(false);
	abort();
}

void mrsh_io_redirect_destroy(struct mrsh_io_redirect *redir) {


@@ 205,7 205,7 @@ void mrsh_command_destroy(struct mrsh_command *cmd) {
		free(fd);
		return;
	}
	assert(0);
	abort();
}

void mrsh_and_or_list_destroy(struct mrsh_and_or_list *and_or_list) {


@@ 230,7 230,7 @@ void mrsh_and_or_list_destroy(struct mrsh_and_or_list *and_or_list) {
		free(binop);
		return;
	}
	assert(0);
	abort();
}

struct mrsh_command_list *mrsh_command_list_create(void) {


@@ 575,7 575,7 @@ void mrsh_node_for_each(struct mrsh_node *node,
			node_array_for_each(&pipeline->commands, iterator, user_data);
			return;
		}
		assert(false);
		abort();
	case MRSH_NODE_COMMAND:;
		struct mrsh_command *cmd = mrsh_node_get_command(node);
		switch (cmd->type) {


@@ 625,7 625,7 @@ void mrsh_node_for_each(struct mrsh_node *node,
			mrsh_node_for_each(&fn->body->node, iterator, user_data);
			return;
		}
		assert(false);
		abort();
	case MRSH_NODE_WORD:;
		struct mrsh_word *word = mrsh_node_get_word(node);
		switch (word->type) {


@@ 652,9 652,9 @@ void mrsh_node_for_each(struct mrsh_node *node,
			node_array_for_each(&wl->children, iterator, user_data);
			return;
		}
		assert(false);
		abort();
	}
	assert(false);
	abort();
}

static void position_next(struct mrsh_position *dst,


@@ 699,7 699,7 @@ void mrsh_word_range(struct mrsh_word *word, struct mrsh_position *begin,
		*end = wc->range.end;
		return;
	case MRSH_WORD_ARITHMETIC:
		assert(false); // TODO
		abort(); // TODO
	case MRSH_WORD_LIST:;
		struct mrsh_word_list *wl = mrsh_word_get_list(word);
		if (wl->children.len == 0) {


@@ 712,7 712,7 @@ void mrsh_word_range(struct mrsh_word *word, struct mrsh_position *begin,
		}
		return;
	}
	assert(false);
	abort();
}

void mrsh_command_range(struct mrsh_command *cmd, struct mrsh_position *begin,


@@ 801,7 801,7 @@ void mrsh_command_range(struct mrsh_command *cmd, struct mrsh_position *begin,
		*begin = fd->name_range.begin;
		mrsh_command_range(fd->body, NULL, end);
	}
	assert(false);
	abort();
}

static void buffer_append_str(struct mrsh_buffer *buf, const char *str) {


@@ 817,7 817,7 @@ static void word_str(const struct mrsh_word *word, struct mrsh_buffer *buf) {
	case MRSH_WORD_PARAMETER:
	case MRSH_WORD_COMMAND:
	case MRSH_WORD_ARITHMETIC:
		assert(false);
		abort();
	case MRSH_WORD_LIST:;
		const struct mrsh_word_list *wl = mrsh_word_get_list(word);
		for (size_t i = 0; i < wl->children.len; ++i) {


@@ 826,7 826,7 @@ static void word_str(const struct mrsh_word *word, struct mrsh_buffer *buf) {
		}
		return;
	}
	assert(false);
	abort();
}

char *mrsh_word_str(const struct mrsh_word *word) {


@@ 843,7 843,7 @@ static const char *binop_type_str(enum mrsh_binop_type t) {
	case MRSH_BINOP_OR:
		return "||";
	}
	assert(0);
	abort();
}

static void node_format(struct mrsh_node *node, struct mrsh_buffer *buf);


@@ 890,7 890,7 @@ static void node_format(struct mrsh_node *node, struct mrsh_buffer *buf) {
			node_array_format(&pipeline->commands, " | ", buf);
			return;
		}
		assert(false);
		abort();
	case MRSH_NODE_COMMAND:;
		struct mrsh_command *cmd = mrsh_node_get_command(node);
		switch (cmd->type) {


@@ 955,7 955,7 @@ static void node_format(struct mrsh_node *node, struct mrsh_buffer *buf) {
			// TODO: io-redirect
			return;
		}
		assert(false);
		abort();
	case MRSH_NODE_WORD:;
		// TODO: quoting
		struct mrsh_word *word = mrsh_node_get_word(node);


@@ 1001,9 1001,9 @@ static void node_format(struct mrsh_node *node, struct mrsh_buffer *buf) {
			}
			return;
		}
		assert(false);
		abort();
	}
	assert(false);
	abort();
}

char *mrsh_node_format(struct mrsh_node *node) {


@@ 1036,7 1036,7 @@ struct mrsh_node *mrsh_node_copy(const struct mrsh_node *node) {
		struct mrsh_word *word_copy = mrsh_word_copy(word);
		return &word_copy->node;
	}
	assert(0);
	abort();
}

struct mrsh_word *mrsh_word_copy(const struct mrsh_word *word) {


@@ 1079,7 1079,7 @@ struct mrsh_word *mrsh_word_copy(const struct mrsh_word *word) {
			mrsh_word_list_create(&children, wl->double_quoted);
		return &wl_copy->word;
	}
	assert(0);
	abort();
}

struct mrsh_io_redirect *mrsh_io_redirect_copy(


@@ 1250,7 1250,7 @@ struct mrsh_command *mrsh_command_copy(const struct mrsh_command *cmd) {
				mrsh_command_copy(fd->body), &io_redirects);
		return &fd_copy->command;
	}
	assert(0);
	abort();
}

struct mrsh_and_or_list *mrsh_and_or_list_copy(


@@ 1274,7 1274,7 @@ struct mrsh_and_or_list *mrsh_and_or_list_copy(
			mrsh_and_or_list_copy(binop->right));
		return &binop_copy->and_or_list;
	}
	assert(0);
	abort();
}

struct mrsh_command_list *mrsh_command_list_copy(

M ast_print.c => ast_print.c +3 -3
@@ 50,7 50,7 @@ static const char *word_parameter_op_str(enum mrsh_word_parameter_op op) {
	case MRSH_PARAM_DHASH:
		return "##";
	}
	assert(false);
	abort();
}

static void print_program(struct mrsh_program *prog, const char *prefix);


@@ 134,7 134,7 @@ static const char *io_redirect_op_str(enum mrsh_io_redirect_op op) {
	case MRSH_IO_DLESSDASH:
		return "<<-";
	}
	assert(false);
	abort();
}

static void print_word_array(struct mrsh_array *words, const char *prefix);


@@ 316,7 316,7 @@ static const char *loop_type_str(enum mrsh_loop_type type) {
	case MRSH_LOOP_WHILE:
		return "while";
	}
	assert(false);
	abort();
}

static void print_loop_clause(struct mrsh_loop_clause *lc, const char *prefix) {

M example/highlight.c => example/highlight.c +1 -1
@@ 118,7 118,7 @@ static void highlight_word(struct highlight_state *state,
		}
		break;
	case MRSH_WORD_ARITHMETIC:
		assert(false); // TODO
		abort(); // TODO
	case MRSH_WORD_LIST:;
		struct mrsh_word_list *wl = mrsh_word_get_list(word);
		if (wl->children.len == 0) {

M parser/program.c => parser/program.c +1 -1
@@ 1168,7 1168,7 @@ static bool is_word_quoted(struct mrsh_word *word) {
		}
		return false;
	default:
		assert(false);
		abort();
	}
}


M shell/arithm.c => shell/arithm.c +4 -4
@@ 99,7 99,7 @@ static bool run_arithm_binop(struct mrsh_state *state,
		*result = left || right;
		return true;
	}
	assert(false); // Unknown binary arithmetic operation
	abort(); // Unknown binary arithmetic operation
}

static bool run_arithm_unop(struct mrsh_state *state,


@@ 122,7 122,7 @@ static bool run_arithm_unop(struct mrsh_state *state,
		*result = !val;
		return true;
	}
	assert(false); // Unknown unary arithmetic operation
	abort(); // Unknown unary arithmetic operation
}

static bool run_arithm_cond(struct mrsh_state *state,


@@ 188,7 188,7 @@ static long run_arithm_assign_op(enum mrsh_arithm_assign_op op,
		*result = cur | val;
		return true;
	}
	assert(false);
	abort();
}

static bool run_arithm_assign(struct mrsh_state *state,


@@ 244,5 244,5 @@ bool mrsh_run_arithm_expr(struct mrsh_state *state,
			(struct mrsh_arithm_assign *)expr;
		return run_arithm_assign(state, assign, result);
	}
	assert(false);
	abort();
}

M shell/process.c => shell/process.c +2 -2
@@ 50,7 50,7 @@ int process_poll(struct mrsh_process *proc) {
	} else if (WIFSIGNALED(proc->stat)) {
		return 129; // POSIX requires >128
	} else {
		assert(false);
		abort();
	}
}



@@ 77,6 77,6 @@ void update_process(struct mrsh_state *state, pid_t pid, int stat) {
		proc->stopped = true;
		proc->signal = WSTOPSIG(stat);
	} else {
		assert(false);
		abort();
	}
}

M shell/task/task.c => shell/task/task.c +2 -2
@@ 281,7 281,7 @@ int run_command(struct mrsh_context *ctx, struct mrsh_command *cmd) {
			mrsh_command_get_function_definition(cmd);
		return run_function_definition(ctx, fnd);
	}
	assert(false);
	abort();
}

int run_and_or_list(struct mrsh_context *ctx, struct mrsh_and_or_list *and_or_list) {


@@ 306,7 306,7 @@ int run_and_or_list(struct mrsh_context *ctx, struct mrsh_and_or_list *and_or_li
		}
		return run_and_or_list(ctx, binop->right);
	}
	assert(false);
	abort();
}

/**

M shell/task/word.c => shell/task/word.c +4 -4
@@ 271,7 271,7 @@ static bool is_null_word(const struct mrsh_word *word) {
		}
		return true;
	default:
		assert(false);
		abort();
	}
}



@@ 338,7 338,7 @@ static int apply_parameter_cond_op(struct mrsh_context *ctx,
		mrsh_word_destroy(value);
		return 0;
	default:
		assert(false); // unreachable
		abort(); // unreachable
	}
}



@@ 456,7 456,7 @@ static int apply_parameter_str_op(struct mrsh_context *ctx,
		*result = &result_ws->word;
		return 0;
	default:
		assert(false);
		abort();
	}
}



@@ 661,7 661,7 @@ static int _run_word(struct mrsh_context *ctx, struct mrsh_word **word_ptr,

		return 0;
	}
	assert(false);
	abort();
}

int run_word(struct mrsh_context *ctx, struct mrsh_word **word_ptr) {

M shell/word.c => shell/word.c +3 -3
@@ 209,7 209,7 @@ static void _split_fields(struct split_fields_data *data,
		}
		break;
	default:
		assert(false);
		abort();
	}
}



@@ 290,7 290,7 @@ static bool needs_pathname_expansion(const struct mrsh_word *word) {
		}
		return false;
	default:
		assert(false);
		abort();
	}

}


@@ 319,7 319,7 @@ static void _word_to_pattern(struct mrsh_buffer *buf,
		}
		break;
	default:
		assert(false);
		abort();
	}
}