diff options
author | David Robillard <d@drobilla.net> | 2016-03-16 16:21:20 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 16:27:02 -0500 |
commit | 84bab08585dec858807a6130bd2d71f304b889f0 (patch) | |
tree | ea78338414095c2c871944a0135028e1399b12fe /src/stack.h | |
parent | caa74939cba8b1cd357e553efca9bec5074b1c53 (diff) | |
download | serd-84bab08585dec858807a6130bd2d71f304b889f0.tar.gz serd-84bab08585dec858807a6130bd2d71f304b889f0.tar.bz2 serd-84bab08585dec858807a6130bd2d71f304b889f0.zip |
Use char* for strings in public API
The constant casting just makes user code a mess, for no benefit.
Diffstat (limited to 'src/stack.h')
-rw-r--r-- | src/stack.h | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/stack.h b/src/stack.h index d118430a..7cd40a2f 100644 --- a/src/stack.h +++ b/src/stack.h @@ -15,9 +15,9 @@ /** A dynamic stack in memory. */ typedef struct { - uint8_t* buf; ///< Stack memory - size_t buf_size; ///< Allocated size of buf (>= size) - size_t size; ///< Conceptual size of stack in buf + char* buf; ///< Stack memory + size_t buf_size; ///< Allocated size of buf (>= size) + size_t size; ///< Conceptual size of stack in buf } SerdStack; /** An offset to start the stack at. Note 0 is reserved for NULL. */ @@ -27,7 +27,7 @@ static inline SerdStack serd_stack_new(size_t size) { SerdStack stack; - stack.buf = (uint8_t*)calloc(size, 1); + stack.buf = (char*)calloc(size, 1); stack.buf_size = size; stack.size = SERD_STACK_BOTTOM; return stack; @@ -54,12 +54,10 @@ serd_stack_push(SerdStack* stack, size_t n_bytes) const size_t new_size = stack->size + n_bytes; if (stack->buf_size < new_size) { stack->buf_size += (stack->buf_size >> 1); // *= 1.5 - stack->buf = (uint8_t*)realloc(stack->buf, stack->buf_size); + stack->buf = (char*)realloc(stack->buf, stack->buf_size); } - - uint8_t* const ret = (stack->buf + stack->size); - - stack->size = new_size; + char* const ret = (stack->buf + stack->size); + stack->size = new_size; return ret; } @@ -83,8 +81,7 @@ serd_stack_push_aligned(SerdStack* stack, size_t n_bytes, size_t align) } // Set top of stack to pad count so we can properly pop later - assert(pad < UINT8_MAX); - stack->buf[stack->size - 1] = (uint8_t)pad; + stack->buf[stack->size - 1] = (char)pad; // Push requested space at aligned location return serd_stack_push(stack, n_bytes); @@ -97,7 +94,7 @@ serd_stack_pop_aligned(SerdStack* stack, size_t n_bytes) serd_stack_pop(stack, n_bytes); // Get amount of padding from top of stack - const uint8_t pad = stack->buf[stack->size - 1]; + const uint8_t pad = (uint8_t)stack->buf[stack->size - 1]; // Pop padding and pad count serd_stack_pop(stack, pad + 1U); |