From 40fbb328150d853d0d7a83ce447c3f008de38822 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sun, 16 Jun 2024 22:20:07 +0300 Subject: Start integrating pds, fix warnings and add new test build object --- src/pds.h | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'src/pds.h') diff --git a/src/pds.h b/src/pds.h index e0b9df2..0c10158 100644 --- a/src/pds.h +++ b/src/pds.h @@ -31,7 +31,6 @@ extern "C" uint64_t cap; uint64_t size; uint64_t stride; - void* data; } pstack; /* Exported API */ @@ -47,17 +46,17 @@ extern "C" PDSDEF void* _pstack_push(void* list, const void* value_ptr); #ifndef pstack_push -#define pstack_push(list, val) \ - do { \ - typeof(val) tmp = val; \ - list = _pstack_push(list, &tmp); \ +#define pstack_push(list, val) \ + do { \ + typeof(val) tmp = val; \ + list = _pstack_push(list, &tmp); \ } while (0); #endif - - PDSDEF uint64_t pstack_capacity(void* list); - PDSDEF uint64_t pstack_size(void* list); - PDSDEF uint64_t pstack_stride(void* list); - PDSDEF void pstack_length_set(void* list, uint64_t value); + PDSDEF int pstack_pop(const void* list, void* dest); + PDSDEF uint64_t pstack_capacity(const void* list); + PDSDEF uint64_t pstack_size(const void* list); + PDSDEF uint64_t pstack_stride(const void* list); + PDSDEF void pstack_size_set(const void* list, uint64_t value); PDSDEF void pstack_destroy(void* list); PDSDEF void* pstack_resize(void* list); @@ -103,13 +102,12 @@ _pstack_create(uint64_t length, uint64_t stride) list->cap = length; list->size = 0; list->stride = stride; - list->data = NULL; return (void*)((uint8_t*)list + header_size); } PDSDEF uint64_t -pstack_capacity(void* list) +pstack_capacity(const void* list) { uint64_t header_size = sizeof(pstack); pstack* header = (pstack*)((uint8_t*)list - header_size); @@ -117,7 +115,7 @@ pstack_capacity(void* list) } PDSDEF uint64_t -pstack_size(void* list) +pstack_size(const void* list) { uint64_t header_size = sizeof(pstack); pstack* header = (pstack*)((uint8_t*)list - header_size); @@ -125,7 +123,7 @@ pstack_size(void* list) } PDSDEF uint64_t -pstack_stride(void* list) +pstack_stride(const void* list) { uint64_t header_size = sizeof(pstack); pstack* header = (pstack*)((uint8_t*)list - header_size); @@ -133,7 +131,7 @@ pstack_stride(void* list) } PDSDEF void -pstack_length_set(void* list, uint64_t value) +pstack_size_set(const void* list, uint64_t value) { uint64_t header_size = sizeof(pstack); pstack* header = (pstack*)((uint8_t*)list - header_size); @@ -186,12 +184,12 @@ _pstack_push(void* list, const void* value_ptr) uint64_t addr = (uint64_t)list; addr += (header->size * header->stride); memcpy((void*)addr, value_ptr, header->stride); - pstack_length_set(list, header->size + 1); + pstack_size_set(list, header->size + 1); return list; } PDSDEF int -pstack_pop(void* list, void* dest) +pstack_pop(const void* list, void* dest) { uint64_t size = pstack_size(list); uint64_t stride = pstack_stride(list); @@ -203,7 +201,7 @@ pstack_pop(void* list, void* dest) uint64_t addr = (uint64_t)list; addr += ((size - 1) * stride); memcpy(dest, (void*)addr, stride); - pstack_length_set(list, size - 1); + pstack_size_set(list, size - 1); return 0; } -- cgit v1.2.3