make self.s_offset use bytes in case of HeapPtr::PStr in UnifyVoid (#2897)

This commit is contained in:
Mark Thom
2025-04-21 20:25:50 -07:00
committed by Mark Thom
parent 41b90c6e46
commit 39ea2d5899

View File

@@ -3072,9 +3072,19 @@ impl Machine {
}
&Instruction::UnifyVoid(n) => {
match self.machine_st.mode {
MachineMode::Read => {
self.machine_st.s_offset += n;
}
MachineMode::Read => match &self.machine_st.s {
HeapPtr::HeapCell(_) => self.machine_st.s_offset += n,
&HeapPtr::PStr(pstr_loc) => {
debug_assert!(n <= 2);
let mut char_iter = self.machine_st.heap.char_iter(pstr_loc);
// this only matters in the case that n == 1, but the case
// analysis isn't worth doing since the effect is benign if n ==
// 2
self.machine_st.s_offset +=
char_iter.next().unwrap().len_utf8();
}
},
MachineMode::Write => {
let h = self.machine_st.heap.cell_len();