mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 22:03:12 +00:00
Eliminate the job from block_t
This exists only to support the '--on-job-exit caller' feature. Just store the calling job ID directly in the parser's libdata.
This commit is contained in:
parent
6e0cf5db6f
commit
5158ee812b
4 changed files with 15 additions and 25 deletions
|
@ -93,19 +93,7 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig
|
||||||
job_id_t job_id = -1;
|
job_id_t job_id = -1;
|
||||||
|
|
||||||
if (is_subshell) {
|
if (is_subshell) {
|
||||||
size_t block_idx = 0;
|
job_id = parser.libdata().caller_job_id;
|
||||||
|
|
||||||
// Find the outermost substitution block.
|
|
||||||
for (block_idx = 0;; block_idx++) {
|
|
||||||
const block_t *b = parser.block_at_index(block_idx);
|
|
||||||
if (b == NULL || b->type() == SUBST) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go one step beyond that, to get to the caller.
|
|
||||||
const block_t *caller_block = parser.block_at_index(block_idx + 1);
|
|
||||||
if (caller_block != NULL && caller_block->job != NULL) {
|
|
||||||
job_id = caller_block->job->job_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (job_id == -1) {
|
if (job_id == -1) {
|
||||||
|
|
|
@ -1240,27 +1240,28 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
|
||||||
job->set_flag(job_flag_t::SKIP_NOTIFICATION,
|
job->set_flag(job_flag_t::SKIP_NOTIFICATION,
|
||||||
is_subshell || is_block || is_event || !shell_is_interactive());
|
is_subshell || is_block || is_event || !shell_is_interactive());
|
||||||
|
|
||||||
// Tell the current block what its job is. This has to happen before we populate it (#1394).
|
// We are about to populate a job. One possible argument to the job is a command substitution
|
||||||
parser->current_block()->job = job;
|
// which may be interested in the job that's populating it, via '--on-job-exit caller'. Record
|
||||||
|
// the job ID here.
|
||||||
|
auto &libdata = parser->libdata();
|
||||||
|
const auto saved_caller_jid = libdata.caller_job_id;
|
||||||
|
libdata.caller_job_id = job->job_id;
|
||||||
|
|
||||||
// Populate the job. This may fail for reasons like command_not_found. If this fails, an error
|
// Populate the job. This may fail for reasons like command_not_found. If this fails, an error
|
||||||
// will have been printed.
|
// will have been printed.
|
||||||
parse_execution_result_t pop_result =
|
parse_execution_result_t pop_result =
|
||||||
this->populate_job_from_job_node(job.get(), job_node, associated_block);
|
this->populate_job_from_job_node(job.get(), job_node, associated_block);
|
||||||
|
|
||||||
// Clean up the job on failure or cancellation.
|
assert(libdata.caller_job_id == job->job_id && "Caller job ID unexpectedly changed");
|
||||||
bool populated_job = (pop_result == parse_execution_success);
|
parser->libdata().caller_job_id = saved_caller_jid;
|
||||||
if (!populated_job || this->should_cancel_execution(associated_block)) {
|
|
||||||
assert(parser->current_block()->job == job);
|
|
||||||
parser->current_block()->job = NULL;
|
|
||||||
populated_job = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store time it took to 'parse' the command.
|
// Store time it took to 'parse' the command.
|
||||||
if (profile_item != NULL) {
|
if (profile_item != NULL) {
|
||||||
parse_time = get_time();
|
parse_time = get_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up the job on failure or cancellation.
|
||||||
|
bool populated_job = (pop_result == parse_execution_success);
|
||||||
if (populated_job) {
|
if (populated_job) {
|
||||||
// Success. Give the job to the parser - it will clean it up.
|
// Success. Give the job to the parser - it will clean it up.
|
||||||
parser->job_add(job);
|
parser->job_add(job);
|
||||||
|
|
|
@ -138,7 +138,6 @@ void parser_t::push_block_int(block_t *new_current) {
|
||||||
new_current->skip = false;
|
new_current->skip = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_current->job = nullptr;
|
|
||||||
new_current->loop_status = LOOP_NORMAL;
|
new_current->loop_status = LOOP_NORMAL;
|
||||||
|
|
||||||
// Push it onto our stack. This acquires ownership because of unique_ptr.
|
// Push it onto our stack. This acquires ownership because of unique_ptr.
|
||||||
|
|
|
@ -67,8 +67,6 @@ struct block_t {
|
||||||
bool skip{false};
|
bool skip{false};
|
||||||
/// Status for the current loop block. Can be any of the values from the loop_status enum.
|
/// Status for the current loop block. Can be any of the values from the loop_status enum.
|
||||||
enum loop_status_t loop_status { LOOP_NORMAL };
|
enum loop_status_t loop_status { LOOP_NORMAL };
|
||||||
/// The job that is currently evaluated in the specified block.
|
|
||||||
shared_ptr<job_t> job{};
|
|
||||||
/// Name of file that created this block. This string is intern'd.
|
/// Name of file that created this block. This string is intern'd.
|
||||||
const wchar_t *src_filename{nullptr};
|
const wchar_t *src_filename{nullptr};
|
||||||
/// Line number where this block was created.
|
/// Line number where this block was created.
|
||||||
|
@ -159,6 +157,10 @@ struct library_data_t {
|
||||||
|
|
||||||
/// Whether we are currently cleaning processes.
|
/// Whether we are currently cleaning processes.
|
||||||
bool is_cleaning_procs{false};
|
bool is_cleaning_procs{false};
|
||||||
|
|
||||||
|
/// The job id of the job being populated.
|
||||||
|
/// This supports the '--on-job-exit caller' feature.
|
||||||
|
job_id_t caller_job_id{-1};
|
||||||
};
|
};
|
||||||
|
|
||||||
class parser_t : public std::enable_shared_from_this<parser_t> {
|
class parser_t : public std::enable_shared_from_this<parser_t> {
|
||||||
|
|
Loading…
Reference in a new issue