Closed osa1 closed 3 years ago
I also don't see where we initialize the BigInt
object header here. BigInt::from_payload
does not do it: https://github.com/dfinity/motoko/blob/34a740618f099e6ca81eb6f7ea8170b2084cabf2/rts/motoko-rts/src/types.rs#L325-L327
False alarm. The allocation is done in mp_init
, which calls mp_alloc
, which allocates on the heap with the BigInt tag.
I guess I didn't expect mp_init
to allocate, I'd expect mp to allocate lazily (e.g. in mp_set_u32
when needed).
Relevant code: https://github.com/dfinity/motoko/blob/34a740618f099e6ca81eb6f7ea8170b2084cabf2/rts/motoko-rts/src/bigint.rs#L150-L168
persist_bigint
takes stack-allocatedmp_int
struct. It's supposed to move the struct to the heap (as documented) but it returns a pointer to the stack instead.