fix gen_refcount tests

This commit is contained in:
Brendan Hansknecht 2024-07-10 22:09:29 -07:00
parent ad76fa2a4e
commit a8bef30392
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
3 changed files with 34 additions and 3 deletions

View file

@ -310,7 +310,14 @@ where
RefCount::Deallocated
} else {
// Dereference the RC pointer and decode its value from the negative number format
let rc_encoded = read_i32(&inst.memory, rc_ptr);
let mut rc_encoded = read_i32(&inst.memory, rc_ptr);
if rc_encoded > 0 {
// We happen to be reading a list that is refcounted.
// This is the size on heap.
// Shift over 4 to and load the real RC.
rc_encoded = read_i32(&inst.memory, rc_ptr + 4);
}
if rc_encoded == 0 {
RefCount::Constant
} else {

View file

@ -53,9 +53,11 @@ size_t *alloc_ptr_to_rc_ptr(void *ptr, unsigned int alignment)
//--------------------------
size_t RC_LIST_INDICATOR = 1;
void *roc_alloc(size_t size, unsigned int alignment)
{
void *allocated = calloc(size, 1);
void *allocated = malloc(size);
if (rc_pointers)
{
@ -64,6 +66,7 @@ void *roc_alloc(size_t size, unsigned int alignment)
ASSERT(num_alloc <= rc_pointers_capacity, "Too many allocations %zd > %zd", num_alloc, rc_pointers_capacity);
size_t *rc_ptr = alloc_ptr_to_rc_ptr(allocated, alignment);
*rc_ptr = RC_LIST_INDICATOR;
rc_pointers->elements[rc_pointers->length] = rc_ptr;
rc_pointers->length++;
}