summaryrefslogtreecommitdiffstats
path: root/src/pds.h
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2024-06-16 22:20:07 +0300
committergramanas <anastasis.gramm2@gmail.com>2024-06-16 22:20:07 +0300
commit40fbb328150d853d0d7a83ce447c3f008de38822 (patch)
tree2a41218d92e94c360692ef39162ff2d5348c0e3a /src/pds.h
parentfb9a5b153f16d8c8fe961b6af0f54a7178e032a6 (diff)
downloadcgame-40fbb328150d853d0d7a83ce447c3f008de38822.tar.gz
cgame-40fbb328150d853d0d7a83ce447c3f008de38822.tar.bz2
cgame-40fbb328150d853d0d7a83ce447c3f008de38822.zip
Start integrating pds, fix warnings and add new test build object
Diffstat (limited to 'src/pds.h')
-rw-r--r--src/pds.h34
1 files changed, 16 insertions, 18 deletions
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;
}