ares icon indicating copy to clipboard operation
ares copied to clipboard

Noun.data_pointer() doesn't do what you would expect for direct atoms

Open philipquirk opened this issue 8 months ago • 0 comments

data_pointer() isn't defined on DirectAtom but it is defined on Atom (and IndirectAtom). For indirect atoms it does what you would want. But for direct atoms it doesn't work. It does this:

Left(_direct) => (self as *const Atom) as *const u64,

If you have a cell where the tail is a direct atom, and you do this:

let atom = cell.tail()?;
let ptr = atom.data_pointer();

Then atom is the u64 of the direct atom now living in the stack of your function and data_pointer() gives you a pointer into your own stack. This is almost certainly not what anyone would want or what they would expect. If they want this behavior at all then they probably want a pointer to the tail element of the cell itself since this is where the direct atom actually lives.

So I propose removing data_pointer() from direct atom and either only implementing it on IndirectAtom or leaving it on Atom and panic!ing if its called on a direct atom.

philipquirk avatar Jun 19 '24 19:06 philipquirk