mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Eliminate more calls to principal_parser()
Require a parser to get a job from its pgid.
This commit is contained in:
parent
d957f6b302
commit
f1f97b6476
8 changed files with 13 additions and 21 deletions
|
@ -90,7 +90,7 @@ int builtin_bg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||
// Background all existing jobs that match the pids.
|
||||
// Non-existent jobs aren't an error, but information about them is useful.
|
||||
for (auto p : pids) {
|
||||
if (job_t *j = job_t::from_pid(p)) {
|
||||
if (job_t *j = parser.job_get_from_pid(p)) {
|
||||
retval |= send_to_bg(parser, streams, j);
|
||||
} else {
|
||||
streams.err.append_format(_(L"%ls: Could not find job '%d'\n"), cmd, p);
|
||||
|
|
|
@ -56,7 +56,7 @@ int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||
bool found_job = false;
|
||||
int pid = fish_wcstoi(argv[optind]);
|
||||
if (errno == 0 && pid > 0) {
|
||||
found_job = (job_t::from_pid(pid) != nullptr);
|
||||
found_job = (parser.job_get_from_pid(pid) != nullptr);
|
||||
}
|
||||
|
||||
if (found_job) {
|
||||
|
@ -73,7 +73,7 @@ int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||
streams.err.append_format(BUILTIN_ERR_NOT_NUMBER, cmd, argv[optind]);
|
||||
builtin_print_error_trailer(parser, streams.err, cmd);
|
||||
} else {
|
||||
job = job_t::from_pid(pid);
|
||||
job = parser.job_get_from_pid(pid);
|
||||
if (!job || !job->is_constructed() || job->is_completed()) {
|
||||
streams.err.append_format(_(L"%ls: No suitable job: %d\n"), cmd, pid);
|
||||
job = nullptr;
|
||||
|
|
|
@ -203,7 +203,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||
argv[i]);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
j = job_t::from_pid(pid);
|
||||
j = parser.job_get_from_pid(pid);
|
||||
}
|
||||
|
||||
if (j && !j->is_completed() && j->is_constructed()) {
|
||||
|
|
|
@ -138,7 +138,7 @@ static int event_is_blocked(parser_t &parser, const event_t &e) {
|
|||
return event_block_list_blocks_type(parser.global_event_blocks);
|
||||
}
|
||||
|
||||
wcstring event_get_desc(const event_t &evt) {
|
||||
wcstring event_get_desc(const parser_t &parser, const event_t &evt) {
|
||||
const event_description_t &ed = evt.desc;
|
||||
switch (ed.type) {
|
||||
case event_type_t::signal: {
|
||||
|
@ -155,7 +155,7 @@ wcstring event_get_desc(const event_t &evt) {
|
|||
return format_string(_(L"exit handler for process %d"), ed.param1.pid);
|
||||
} else {
|
||||
// In events, PGIDs are stored as negative PIDs
|
||||
job_t *j = job_t::from_pid(-ed.param1.pid);
|
||||
job_t *j = parser.job_get_from_pid(-ed.param1.pid);
|
||||
if (j) {
|
||||
return format_string(_(L"exit handler for job %d, '%ls'"), j->job_id(),
|
||||
j->command_wcstr());
|
||||
|
|
|
@ -118,7 +118,7 @@ void event_enqueue_signal(int signal);
|
|||
void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter);
|
||||
|
||||
/// Returns a string describing the specified event.
|
||||
wcstring event_get_desc(const event_t &e);
|
||||
wcstring event_get_desc(const parser_t &parser, const event_t &e);
|
||||
|
||||
/// Fire a generic event with the specified name.
|
||||
void event_fire_generic(parser_t &parser, const wchar_t *name,
|
||||
|
|
|
@ -340,8 +340,8 @@ operation_context_t parser_t::context() {
|
|||
}
|
||||
|
||||
/// Append stack trace info for the block \p b to \p trace.
|
||||
static void append_block_description_to_stack_trace(const block_t &b, wcstring &trace,
|
||||
const environment_t &vars) {
|
||||
static void append_block_description_to_stack_trace(const parser_t &parser, const block_t &b,
|
||||
wcstring &trace) {
|
||||
bool print_call_site = false;
|
||||
switch (b.type()) {
|
||||
case block_type_t::function_call:
|
||||
|
@ -375,13 +375,13 @@ static void append_block_description_to_stack_trace(const block_t &b, wcstring &
|
|||
case block_type_t::source: {
|
||||
const wchar_t *source_dest = b.sourced_file;
|
||||
append_format(trace, _(L"from sourcing file %ls\n"),
|
||||
user_presentable_path(source_dest, vars).c_str());
|
||||
user_presentable_path(source_dest, parser.vars()).c_str());
|
||||
print_call_site = true;
|
||||
break;
|
||||
}
|
||||
case block_type_t::event: {
|
||||
assert(b.event && "Should have an event");
|
||||
wcstring description = event_get_desc(*b.event);
|
||||
wcstring description = event_get_desc(parser, *b.event);
|
||||
append_format(trace, _(L"in event handler: %ls\n"), description.c_str());
|
||||
print_call_site = true;
|
||||
break;
|
||||
|
@ -403,7 +403,7 @@ static void append_block_description_to_stack_trace(const block_t &b, wcstring &
|
|||
const wchar_t *file = b.src_filename;
|
||||
if (file) {
|
||||
append_format(trace, _(L"\tcalled on line %d of file %ls\n"), b.src_lineno,
|
||||
user_presentable_path(file, vars).c_str());
|
||||
user_presentable_path(file, parser.vars()).c_str());
|
||||
} else if (is_within_fish_initialization()) {
|
||||
append_format(trace, _(L"\tcalled during startup\n"));
|
||||
}
|
||||
|
@ -413,7 +413,7 @@ static void append_block_description_to_stack_trace(const block_t &b, wcstring &
|
|||
wcstring parser_t::stack_trace() const {
|
||||
wcstring trace;
|
||||
for (const auto &b : blocks()) {
|
||||
append_block_description_to_stack_trace(b, trace, vars());
|
||||
append_block_description_to_stack_trace(*this, b, trace);
|
||||
|
||||
// Stop at event handler. No reason to believe that any other code is relevant.
|
||||
//
|
||||
|
|
|
@ -123,11 +123,6 @@ job_t *job_t::from_job_id(job_id_t id) {
|
|||
return parser_t::principal_parser().job_get(id);
|
||||
}
|
||||
|
||||
job_t *job_t::from_pid(pid_t pid) {
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
return parser_t::principal_parser().job_get_from_pid(pid);
|
||||
}
|
||||
|
||||
/// Return true if all processes in the job have stopped or completed.
|
||||
bool job_t::is_stopped() const {
|
||||
for (const process_ptr_t &p : processes) {
|
||||
|
|
|
@ -517,9 +517,6 @@ class job_t {
|
|||
/// Return the job instance matching this unique job id.
|
||||
/// If id is 0 or less, return the last job used.
|
||||
static job_t *from_job_id(job_id_t id);
|
||||
|
||||
/// Return the job containing the process identified by the unique pid provided.
|
||||
static job_t *from_pid(pid_t pid);
|
||||
};
|
||||
|
||||
/// Whether this shell is attached to the keyboard at all.
|
||||
|
|
Loading…
Reference in a new issue