Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/aml/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl Object {

/// Replace this object's contents with that of a `new` object, applying implicit casting rules
/// as needed. This follows the NT interpreter's creative interpretation of implicit casts, which is
/// effectively a byte-wise transmutation.
/// effectively a byte-wise transmutation. A buffer keeps its length, unless it's empty.
pub fn replace_with_implicit_casting(&mut self, new: Object) -> Result<(), AmlError> {
let new_bytes = match new {
Object::Integer(value) => &value.to_le_bytes(),
Expand All @@ -401,7 +401,12 @@ impl Object {
*value = String::from_utf8_lossy(new_bytes).split('\0').next().unwrap().to_string();
}
Object::Buffer(value) => {
*value = new_bytes.to_vec();
if value.is_empty() {
value.resize(new_bytes.len(), 0);
}
let n = usize::min(new_bytes.len(), value.len());
value[..n].copy_from_slice(&new_bytes[..n]);
value[n..].fill(0);
}
_ => return Err(AmlError::InvalidImplicitCast { from: self.typ(), to: new.typ() }),
}
Expand Down
16 changes: 16 additions & 0 deletions tests/store.asl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ DefinitionBlock ("", "DSDT", 2, "RSACPI", "TESTTABL", 0xF0F0F0F0)
}
}

Method (T10) {
Name(BUF, Buffer (4) { 0xff, 0xff, 0xff, 0xff })
BUF = Buffer () { 1, 2 }
CHEK(BUF, Buffer () { 1, 2, 0, 0 })
BUF = Buffer () { 1, 2, 3, 4, 5, 6 }
CHEK(BUF, Buffer () { 1, 2, 3, 4 })
}

Method (T11) {
Name(BUF, Buffer (0) {})
BUF = Buffer () { 1, 2 }
CHEK(BUF, Buffer () { 1, 2 })
}

Method (MAIN, 0, NotSerialized) {
T1()
T2()
Expand All @@ -196,6 +210,8 @@ DefinitionBlock ("", "DSDT", 2, "RSACPI", "TESTTABL", 0xF0F0F0F0)
U4() // references-8
U5() // references-9
U6() // references-10
T10()
T11()

Return (FCNT)
}
Expand Down
Loading