mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-07-01 16:31:16 -03:00
Switch job handling to use shared pointers instead of raw pointers
Clarifies memory management around allocation of job_ts
This commit is contained in:
@@ -523,17 +523,18 @@ wcstring parser_t::current_line() {
|
||||
return line_info;
|
||||
}
|
||||
|
||||
void parser_t::job_add(job_t *job) {
|
||||
void parser_t::job_add(shared_ptr<job_t> job) {
|
||||
assert(job != NULL);
|
||||
assert(! job->processes.empty());
|
||||
this->my_job_list.push_front(job);
|
||||
this->my_job_list.push_front(std::move(job));
|
||||
}
|
||||
|
||||
bool parser_t::job_remove(job_t *job) {
|
||||
job_list_t::iterator iter = std::find(my_job_list.begin(), my_job_list.end(), job);
|
||||
if (iter != my_job_list.end()) {
|
||||
my_job_list.erase(iter);
|
||||
return true;
|
||||
for (auto iter = my_job_list.begin(); iter != my_job_list.end(); ++iter) {
|
||||
if (iter->get() == job) {
|
||||
my_job_list.erase(iter);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
debug(1, _(L"Job inconsistency"));
|
||||
@@ -542,7 +543,12 @@ bool parser_t::job_remove(job_t *job) {
|
||||
}
|
||||
|
||||
void parser_t::job_promote(job_t *job) {
|
||||
job_list_t::iterator loc = std::find(my_job_list.begin(), my_job_list.end(), job);
|
||||
job_list_t::iterator loc;
|
||||
for (loc = my_job_list.begin(); loc != my_job_list.end(); ++loc) {
|
||||
if (loc->get() == job) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(loc != my_job_list.end());
|
||||
|
||||
// Move the job to the beginning.
|
||||
@@ -550,10 +556,8 @@ void parser_t::job_promote(job_t *job) {
|
||||
}
|
||||
|
||||
job_t *parser_t::job_get(job_id_t id) {
|
||||
job_iterator_t jobs(my_job_list);
|
||||
job_t *job;
|
||||
while ((job = jobs.next())) {
|
||||
if (id <= 0 || job->job_id == id) return job;
|
||||
for (const auto &job : my_job_list) {
|
||||
if (id <= 0 || job->job_id == id) return job.get();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user