Skip to content

Ensure that Locals passed to Methods are preserved - #335

Open
martin-hughes wants to merge 1 commit into
rust-osdev:mainfrom
martin-hughes:i313-store-refs
Open

Ensure that Locals passed to Methods are preserved#335
martin-hughes wants to merge 1 commit into
rust-osdev:mainfrom
martin-hughes:i313-store-refs

Conversation

@martin-hughes

Copy link
Copy Markdown
Contributor

Since both Locals and Args are stored as references internally, a plain unwrap_reference was causing Locals that got passed to methods to be treated as though they had been passed by reference, instead of by value.

This corrects that logic, and also takes into account the strange behaviour of the Windows NT interpreter - it treats strings passed via Locals into methods as always passed by reference, and never by value.

Fixes #313

Since both Locals and Args are stored as references internally, a plain
`unwrap_reference` was causing Locals that got passed to methods to be
treated as though they had been passed by reference, instead of by
value.

This corrects that logic, and also takes into account the strange
behaviour of the Windows NT interpreter - it treats strings passed via
Locals into methods as *always* passed by reference, and never by value.
Comment thread src/aml/object.rs
/// Returns a tuple containing:
/// - The object that should be modified
/// - A boolean indicating whether an implicit cast should occur before the store
pub fn unwrap_ref_for_store(self) -> Result<(WrappedObject, bool), AmlError> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pulled this function out of do_store for a few reasons:

  1. It makes it way easier to test in unit tests
  2. I think it looks nicer sitting next to the other unwrap functions, since it matches a large part of their functionality
  3. It doesn't need to access any Interpreter fields, nor protect any invariants - so it's worth moving out of that Impl.

Counter argument could be that it's explicitly "for stores" rather than generic object behaviour. I'm sympathetic to that... but look at my shiny unit tests 😉

Comment thread src/aml/object.rs
// return that instead (a bit like a normal `unwrap_reference`)
//
// See issue 313 and the `store.asl` tests for more details.
let mut found_arg_to_local: Option<Result<(WrappedObject, bool), AmlError>> = None;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does pollute the loop a bit. In my first draft I had a straightforward unwrap_reference and a string type check that returned before the loop. But I wasn't a fan of potentially unwrapping twice. Could change it back if you prefer - my way could be a premature optimisation.

Comment thread tests/store.asl

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unchanged (except possibly in the comments) from the file I sent you by PM.

@martin-hughes
martin-hughes marked this pull request as ready for review September 4, 2026 19:32
@martin-hughes

Copy link
Copy Markdown
Contributor Author

@IsaacWoods would you mind taking a look? I'm pretty confident that the logic is correct, but you might be able to think of more edge cases than I can.

(Also any other interested party feel free to chip in!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passing Local to Method allows it to be overwritten

1 participant