Browse Source

Return both resolved path and handle when we search the namespace

Sometimes, we need to construct another path to a child object after
finding something in the namespace, and so we need the full resolved name
instead of the handle to the object itself. We have this easily available
during the search, so we might as well provide it to the caller.
Isaac Woods 5 years ago
parent
commit
608c76c885
2 changed files with 18 additions and 16 deletions
  1. 15 12
      aml/src/namespace.rs
  2. 3 4
      aml/src/type2.rs

+ 15 - 12
aml/src/namespace.rs

@@ -97,9 +97,9 @@ impl Namespace {
     }
 
     /// Search for an object at the given path of the namespace, applying the search rules
-    /// described in §5.3 of the ACPI specification, if they are applicable. Returns the handle of
-    /// the first valid object, if found.
-    pub fn search(&self, path: &AmlName, starting_scope: &AmlName) -> Result<AmlHandle, AmlError> {
+    /// described in §5.3 of the ACPI specification, if they are applicable. Returns the resolved name, and the
+    /// handle of the first valid object, if found.
+    pub fn search(&self, path: &AmlName, starting_scope: &AmlName) -> Result<(AmlName, AmlHandle), AmlError> {
         if path.search_rules_apply() {
             /*
              * If search rules apply, we need to recursively look through the namespace. If the
@@ -110,8 +110,9 @@ impl Namespace {
             assert!(scope.is_absolute());
             loop {
                 // Search for the name at this namespace level. If we find it, we're done.
-                if let Some(handle) = self.name_map.get(&path.resolve(&scope)?) {
-                    return Ok(*handle);
+                let name = path.resolve(&scope)?;
+                if let Some(handle) = self.name_map.get(&name) {
+                    return Ok((name, *handle));
                 }
 
                 // If we don't find it, go up a level in the namespace and search for it there,
@@ -119,18 +120,20 @@ impl Namespace {
                 match scope.parent() {
                     Ok(parent) => scope = parent,
                     // If we still haven't found the value and have run out of parents, return `None`.
-                    Err(AmlError::RootHasNoParent) => {
-                        return Err(AmlError::ObjectDoesNotExist(path.as_string()))
-                    }
+                    Err(AmlError::RootHasNoParent) => return Err(AmlError::ObjectDoesNotExist(path.as_string())),
                     Err(err) => return Err(err),
                 }
             }
         } else {
             // If search rules don't apply, simply resolve it against the starting scope
-            self.name_map
-                .get(&path.resolve(starting_scope)?)
-                .map(|&handle| handle)
-                .ok_or(AmlError::ObjectDoesNotExist(path.as_string()))
+            let name = path.resolve(starting_scope)?;
+            Ok((
+                name,
+                self.name_map
+                    .get(&path.resolve(starting_scope)?)
+                    .map(|&handle| handle)
+                    .ok_or(AmlError::ObjectDoesNotExist(path.as_string()))?,
+            ))
         }
     }
 }

+ 3 - 4
aml/src/type2.rs

@@ -62,7 +62,7 @@ where
         |((), (value, target)), context| {
             match target {
                 Target::Name(ref path) => {
-                    let handle =
+                    let (_, handle) =
                         try_with_context!(context, context.namespace.search(path, &context.current_scope));
                     let desired_type = context.namespace.get(handle).unwrap().type_of();
                     let converted_object = try_with_context!(context, value.as_type(desired_type));
@@ -112,9 +112,8 @@ where
         "MethodInvocation",
         name_string()
             .map_with_context(move |name, context| {
-                let handle =
-                    try_with_context!(context, context.namespace.search(&name, &context.current_scope))
-                        .clone();
+                let (_, handle) =
+                    try_with_context!(context, context.namespace.search(&name, &context.current_scope)).clone();
                 (Ok(handle), context)
             })
             .feed(|handle| {