diff --git a/src/builtin_bg.cpp b/src/builtin_bg.cpp index 0b3b146b1..cf645a508 100644 --- a/src/builtin_bg.cpp +++ b/src/builtin_bg.cpp @@ -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); diff --git a/src/builtin_fg.cpp b/src/builtin_fg.cpp index 628e76470..3dfdc2141 100644 --- a/src/builtin_fg.cpp +++ b/src/builtin_fg.cpp @@ -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; diff --git a/src/builtin_jobs.cpp b/src/builtin_jobs.cpp index fe82b7704..254e40667 100644 --- a/src/builtin_jobs.cpp +++ b/src/builtin_jobs.cpp @@ -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()) { diff --git a/src/event.cpp b/src/event.cpp index e20d4567e..4dd17567a 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -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()); diff --git a/src/event.h b/src/event.h index 13a6dd677..b9f13f1f9 100644 --- a/src/event.h +++ b/src/event.h @@ -118,7 +118,7 @@ void event_enqueue_signal(int signal); void event_print(io_streams_t &streams, maybe_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, diff --git a/src/parser.cpp b/src/parser.cpp index 425ce3106..84601264e 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -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. // diff --git a/src/proc.cpp b/src/proc.cpp index 1da651a4c..bc3169553 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -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) { diff --git a/src/proc.h b/src/proc.h index aea7220f7..b18ac5d52 100644 --- a/src/proc.h +++ b/src/proc.h @@ -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.