]> git.lizzy.rs Git - rust.git/commitdiff
Move functions to eval libc constants to helpers
authorChristian Poveda <christianpoveda@protonmail.com>
Fri, 11 Oct 2019 06:53:31 +0000 (01:53 -0500)
committerChristian Poveda <christianpoveda@protonmail.com>
Fri, 11 Oct 2019 06:53:31 +0000 (01:53 -0500)
src/helpers.rs
src/shims/foreign_items.rs

index 3bee028c5eb7a7148620869755f8838107c66465..39c7af94e0ae7227b385134b7090377ffbc91994 100644 (file)
@@ -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<Tag>> {
+        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())
+    }
 }
index 9cd84d0b887ee4943cf5cdb025a73ed750c42d85..00160156312a8dfa06ef7c6726287874222d050a 100644 (file)
@@ -981,17 +981,6 @@ fn eval_path_scalar(
         return Ok(None);
     }
 
-    fn eval_libc(&mut self, name: &str) -> InterpResult<'tcx, Scalar<Tag>> {
-        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<Tag>) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
         let tcx = &{ this.tcx.tcx };