Commit f33385f5 authored by stijn's avatar stijn
Browse files

gc: Use byte* pointers instead of void* for pointer arithmetic

void* is of unknown size
parent 8340c483
...@@ -120,7 +120,7 @@ void gc_init(void *start, void *end) { ...@@ -120,7 +120,7 @@ void gc_init(void *start, void *end) {
// F = A * BLOCKS_PER_ATB / BLOCKS_PER_FTB // F = A * BLOCKS_PER_ATB / BLOCKS_PER_FTB
// P = A * BLOCKS_PER_ATB * BYTES_PER_BLOCK // P = A * BLOCKS_PER_ATB * BYTES_PER_BLOCK
// => T = A * (1 + BLOCKS_PER_ATB / BLOCKS_PER_FTB + BLOCKS_PER_ATB * BYTES_PER_BLOCK) // => T = A * (1 + BLOCKS_PER_ATB / BLOCKS_PER_FTB + BLOCKS_PER_ATB * BYTES_PER_BLOCK)
machine_uint_t total_byte_len = end - start; machine_uint_t total_byte_len = (byte*)end - (byte*)start;
#if MICROPY_ENABLE_FINALISER #if MICROPY_ENABLE_FINALISER
gc_alloc_table_byte_len = total_byte_len * BITS_PER_BYTE / (BITS_PER_BYTE + BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK); gc_alloc_table_byte_len = total_byte_len * BITS_PER_BYTE / (BITS_PER_BYTE + BITS_PER_BYTE * BLOCKS_PER_ATB / BLOCKS_PER_FTB + BITS_PER_BYTE * BLOCKS_PER_ATB * BYTES_PER_BLOCK);
#else #else
...@@ -136,8 +136,8 @@ void gc_init(void *start, void *end) { ...@@ -136,8 +136,8 @@ void gc_init(void *start, void *end) {
#endif #endif
machine_uint_t gc_pool_block_len = gc_alloc_table_byte_len * BLOCKS_PER_ATB; machine_uint_t gc_pool_block_len = gc_alloc_table_byte_len * BLOCKS_PER_ATB;
gc_pool_start = end - gc_pool_block_len * BYTES_PER_BLOCK; gc_pool_start = (machine_uint_t*)((byte*)end - gc_pool_block_len * BYTES_PER_BLOCK);
gc_pool_end = end; gc_pool_end = (machine_uint_t*)end;
// clear ATBs // clear ATBs
memset(gc_alloc_table_start, 0, gc_alloc_table_byte_len); memset(gc_alloc_table_start, 0, gc_alloc_table_byte_len);
...@@ -400,7 +400,7 @@ found: ...@@ -400,7 +400,7 @@ found:
} }
// get pointer to first block // get pointer to first block
void *ret_ptr = (void*)(gc_pool_start + start_block * WORDS_PER_BLOCK); byte *ret_ptr = (byte*)(gc_pool_start + start_block * WORDS_PER_BLOCK);
// zero out the additional bytes of the newly allocated blocks // zero out the additional bytes of the newly allocated blocks
// This is needed because the blocks may have previously held pointers // This is needed because the blocks may have previously held pointers
...@@ -571,7 +571,7 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) { ...@@ -571,7 +571,7 @@ void *gc_realloc(void *ptr_in, machine_uint_t n_bytes) {
} }
// zero out the additional bytes of the newly allocated blocks (see comment above in gc_alloc) // zero out the additional bytes of the newly allocated blocks (see comment above in gc_alloc)
memset(ptr_in + n_bytes, 0, new_blocks * BYTES_PER_BLOCK - n_bytes); memset((byte*)ptr_in + n_bytes, 0, new_blocks * BYTES_PER_BLOCK - n_bytes);
return ptr_in; return ptr_in;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment