make Fixnum::build_with harder to accidentally misuse

change trait bound order for better
This commit is contained in:
Bennet Bleßmann
2025-01-22 21:10:44 +01:00
committed by Mark Thom
parent 87ca083cfa
commit cbdd0fbf15
19 changed files with 422 additions and 223 deletions

View File

@@ -940,7 +940,7 @@ impl MachineState {
/*
if pstr_atom.len() > offset as usize {
self.heap.push(pstr_offset_as_cell!(h));
self.heap.push(fixnum_as_cell!(Fixnum::build_with(offset)));
self.heap.push(fixnum_as_cell!(Fixnum::build_with_unchecked(offset as i64)));
unify_fn!(*self, pstr_loc_as_cell!(h_len), a3);
} else {
@@ -973,13 +973,13 @@ impl MachineState {
if n == 1 {
self.unify_char(c, self.store(self.deref(self.registers[3])));
} else if n == 2 {
let offset = c.len_utf8() as i64;
let offset = c.len_utf8();
let h_len = self.heap.len();
if cstr_atom.len() > offset as usize {
if cstr_atom.len() > offset{
self.heap.push(atom_as_cstr_cell!(cstr_atom));
self.heap.push(pstr_offset_as_cell!(h_len));
self.heap.push(fixnum_as_cell!(Fixnum::build_with(offset)));
self.heap.push(fixnum_as_cell!(Fixnum::build_with_unchecked(offset as i64)));
unify_fn!(*self, pstr_loc_as_cell!(h_len+1), self.registers[3]);
} else {
@@ -1027,7 +1027,11 @@ impl MachineState {
if !self.fail {
let a3 = self.store(self.deref(self.registers[3]));
self.unify_fixnum(Fixnum::build_with(arity as i64), a3);
self.unify_fixnum(
/* FIXME this is not safe */
unsafe { Fixnum::build_with_unchecked(arity as i64) },
a3,
);
}
}