diff options
Diffstat (limited to 'src/pds.h')
-rw-r--r-- | src/pds.h | 34 |
1 files changed, 16 insertions, 18 deletions
@@ -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; } |