From 4411903cca01933cc98ac903b3864768b6136024 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 24 Dec 2019 00:22:32 +0100 Subject: [PATCH] Add a scheme for registering and obtaining errors even without access to an `InterpCx` --- src/diagnostics.rs | 17 +++++++++++++++++ src/lib.rs | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 30be49ff770..2431d9230f3 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -60,3 +60,20 @@ pub fn report_err<'tcx, 'mir>( // Let the reported error determine the return code. return None; } + +use std::cell::RefCell; +thread_local! { + static ECX: RefCell>> = RefCell::new(Vec::new()); +} + +pub fn register_err(e: InterpErrorInfo<'static>) { + ECX.with(|ecx| ecx.borrow_mut().push(e)); +} + +pub fn process_errors(mut f: impl FnMut(InterpErrorInfo<'static>)) { + ECX.with(|ecx| { + for e in ecx.borrow_mut().drain(..) { + f(e); + } + }); +} diff --git a/src/lib.rs b/src/lib.rs index b5925bb26c8..bf6b111754d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ pub use crate::shims::time::EvalContextExt as TimeEvalContextExt; pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData}; pub use crate::shims::EvalContextExt as ShimsEvalContextExt; -pub use crate::diagnostics::report_err; +pub use crate::diagnostics::{process_errors, register_err, report_err}; pub use crate::eval::{create_ecx, eval_main, MiriConfig, TerminationInfo}; pub use crate::helpers::EvalContextExt as HelpersEvalContextExt; pub use crate::machine::{