Commit a285484

kravantokh <kravantokh@noreply.codeberg.org>
2026-08-18 14:43:29
Change u8* to void* in signatures.
1 parent ae57894
Changed files (4)
memory/heap/heap_debug.h
@@ -77,8 +77,8 @@ static inline void _Heap_link_block( Heap *h, HeapEntry *e ) {
 	e->checksum = e->size ^ e->allowed_size ^ (usize)e->next ^ HEAP_XOR_KEY;
 }
 
-static inline usize Heap_get_asize( Heap *h, u8 *ptr ) {
-	HeapEntry *e = (HeapEntry*)( ptr - sizeof(HeapEntry) );
+static inline usize Heap_get_asize( Heap *h, void *ptr ) {
+	HeapEntry *e = (HeapEntry*)( (u8*)ptr - sizeof(HeapEntry) );
 	HeapEntry *prev = 0;
 	_Heap_check_entry( e );
 	_Heap_find_block( h, e, &prev );
@@ -103,7 +103,7 @@ Status Heap_destroy( Heap *h ) {
 	return S_SUCCESS;
 }
 
-Status Heap_alloc( Heap *h, usize amount, u8 **out ) {
+Status Heap_alloc( Heap *h, usize amount, void **out ) {
 	assert( h != 0 );
 	assert( amount > 0 ); /* If your code can try to allocate 0 amount of memory you should consider rewriting it (or getting some help) */
 
@@ -158,7 +158,7 @@ Status Heap_alloc( Heap *h, usize amount, u8 **out ) {
 	return S_SUCCESS;
 }
 
-Status Heap_free( Heap *h, u8 **ptr ) {
+Status Heap_free( Heap *h, void **ptr ) {
 	assert( h != 0 );
 	assert( ptr != 0 );
 
memory/heap/heap_release.h
@@ -13,7 +13,7 @@ STRUCT( Heap,
 	HeapEntry *freelist_data;
 );
 
-static inline usize Heap_get_asize( Heap *h, u8 *ptr ) {
+static inline usize Heap_get_asize( Heap *h, void *ptr ) {
 	(void)h;
 	return *((usize*)ptr - 1);
 }
@@ -34,7 +34,7 @@ Status Heap_destroy( Heap *h ) {
 	return S_SUCCESS;
 }
 
-Status Heap_alloc( Heap *h, usize amount, u8 **out ) {
+Status Heap_alloc( Heap *h, usize amount, void **out ) {
 	if( amount == 0 ) return S_FAILURE | ERR_INVALID_ARGUMENT | ERRSRC_ARG_2;
 
 	usize required_amount = usize_max(amount, sizeof(void*)); /* A pointer must fit into data, otherwise it can not be linked into the freelist when freed. */
@@ -70,7 +70,7 @@ Status Heap_alloc( Heap *h, usize amount, u8 **out ) {
 	return S_SUCCESS;
 }
 
-Status Heap_free( Heap *h, u8 **ptr ) {
+Status Heap_free( Heap *h, void **ptr ) {
 	if( h == 0 ) return S_FAILURE | ERR_INVALID_ARGUMENT | ERRSRC_ARG_1;
 	if( ptr == 0 ) return S_FAILURE | ERR_INVALID_ARGUMENT | ERRSRC_ARG_2;
 
memory/heap.h
@@ -16,10 +16,10 @@ typedef struct _Heap Heap;
 
 Status Heap_create( Heap *out, usize size ); /* size - size of underlying arena. The heap will hold less, due to bookkeeping overhead for allocations. */
 
-Status Heap_alloc( Heap *h, usize amount, u8 **out );
-Status Heap_free( Heap *h, u8 **ptr ); /* u8** cause it zeroes the pointer on success automatically. */
+Status Heap_alloc( Heap *h, usize amount, void **out );
+Status Heap_free( Heap *h, void **ptr ); /* u8** cause it zeroes the pointer on success automatically. */
 
-static inline usize Heap_get_asize( Heap *h, u8 *ptr );
+static inline usize Heap_get_asize( Heap *h, void *ptr );
 
 Status Heap_destroy( Heap *h );
 
testing/tests/013_heap.c
@@ -6,16 +6,16 @@ void entry(void) {
 
 	assert(S_OK( Heap_create( &h, KiB(8) ) ));
 
-	u8 *ptr1 = 0;
-	u8 *ptr2 = 0;
+	void *ptr1 = 0;
+	void *ptr2 = 0;
 	assert(S_OK( Heap_alloc( &h, 32, &ptr1 ) ));
 	assert(S_OK( Heap_alloc( &h, 32, &ptr2 ) ));
 
-	u8 *original_ptr1 = ptr1;
+	void *original_ptr1 = ptr1;
 
 	for( usize i = 0; i < 32; ++i ) {
-		ptr1[i] = 'h';
-		ptr2[i] = 'i';
+		((u8*)ptr1)[i] = 'h';
+		((u8*)ptr2)[i] = 'i';
 	}
 
 	assert(S_OK( Heap_free( &h, &ptr1 ) ));
@@ -24,7 +24,7 @@ void entry(void) {
 		assert(S_NOK( Heap_alloc( &h, 0, &ptr1 ) ));
 	#endif
 
-	u8 *ptr3 = 0;
+	void *ptr3 = 0;
 	assert(S_OK( Heap_alloc( &h, 32, &ptr3 ) ));
 
 	assert( ptr3 == original_ptr1 );