From d15e475440d8ce51b668494d8fbbac7e40fe334b Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 16 Sep 2023 21:51:05 +0200 Subject: [PATCH] event: reduce lock scope to allow re-locking in event handler The following "Port execution" commit will use RefCell for the wait handle store. If we hold a borrow while we are running an event (which may run script code) there will be a borrowing conflict. Avoid this by returning the borrow earlier. --- fish-rust/src/builtins/function.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fish-rust/src/builtins/function.rs b/fish-rust/src/builtins/function.rs index c3b05e9b2..1b0eb536e 100644 --- a/fish-rust/src/builtins/function.rs +++ b/fish-rust/src/builtins/function.rs @@ -356,16 +356,14 @@ pub fn function( for ed in &opts.events { match *ed { EventDescription::ProcessExit { pid } if pid != event::ANY_PID => { - if let Some(status) = parser - .get_wait_handles() - .get_by_pid(pid) - .and_then(|wh| wh.status()) - { + let wh = parser.get_wait_handles().get_by_pid(pid); + if let Some(status) = wh.and_then(|wh| wh.status()) { event::fire(parser, event::Event::process_exit(pid, status)); } } EventDescription::JobExit { pid, .. } if pid != event::ANY_PID => { - if let Some(wh) = parser.get_wait_handles().get_by_pid(pid) { + let wh = parser.get_wait_handles().get_by_pid(pid); + if let Some(wh) = wh { if wh.is_completed() { event::fire(parser, event::Event::job_exit(pid, wh.internal_job_id)); }