From: Christian Poveda Date: Fri, 11 Oct 2019 06:53:31 +0000 (-0500) Subject: Move functions to eval libc constants to helpers X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=c8df0171e84deb4563f30f9f1c3cf61e859315fb;p=rust.git Move functions to eval libc constants to helpers --- diff --git a/src/helpers.rs b/src/helpers.rs index 3bee028c5eb..39c7af94e0a 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -291,4 +291,15 @@ fn visit_primitive(&mut self, _v: MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx> } } } + /// Helper function to get a `libc` constant as a `Scalar`. + fn eval_libc(&mut self, name: &str) -> InterpResult<'tcx, Scalar> { + self.eval_context_mut() + .eval_path_scalar(&["libc", name])? + .ok_or_else(|| err_unsup_format!("Path libc::{} cannot be resolved.", name).into()) + .and_then(|scalar| scalar.not_undef()) + } + /// Helper function to get a `libc` constant as an `i32`. + fn eval_libc_i32(&mut self, name: &str) -> InterpResult<'tcx, i32> { + self.eval_libc(name).and_then(|scalar| scalar.to_i32()) + } } diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 9cd84d0b887..00160156312 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -981,17 +981,6 @@ fn eval_path_scalar( return Ok(None); } - fn eval_libc(&mut self, name: &str) -> InterpResult<'tcx, Scalar> { - self.eval_context_mut() - .eval_path_scalar(&["libc", name])? - .ok_or_else(|| err_unsup_format!("Path libc::{} cannot be resolved.", name).into()) - .and_then(|scalar| scalar.not_undef()) - } - - fn eval_libc_i32(&mut self, name: &str) -> InterpResult<'tcx, i32> { - self.eval_libc(name).and_then(|scalar| scalar.to_i32()) - } - fn set_last_error(&mut self, scalar: Scalar) -> InterpResult<'tcx> { let this = self.eval_context_mut(); let tcx = &{ this.tcx.tcx };