aboutsummaryrefslogtreecommitdiffstats
path: root/src/stack.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-03-16 16:21:20 -0400
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit085e63e53502adfc16c3830ed6b0b941314b8f8a (patch)
tree509a1b7b5ee85e9e6d3a409e25029f9062fe29fb /src/stack.h
parent9e5fa742b6ef66a546c0a77c14f834f2268c5f71 (diff)
downloadserd-085e63e53502adfc16c3830ed6b0b941314b8f8a.tar.gz
serd-085e63e53502adfc16c3830ed6b0b941314b8f8a.tar.bz2
serd-085e63e53502adfc16c3830ed6b0b941314b8f8a.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.h13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/stack.h b/src/stack.h
index 9c1d075a..8943370c 100644
--- a/src/stack.h
+++ b/src/stack.h
@@ -28,7 +28,7 @@
/** A dynamic stack in memory. */
typedef struct {
- uint8_t* buf; ///< Stack memory
+ char* buf; ///< Stack memory
size_t buf_size; ///< Allocated size of buf (>= size)
size_t size; ///< Conceptual size of stack in buf
} SerdStack;
@@ -40,7 +40,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;
@@ -67,9 +67,9 @@ 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);
+ char* const ret = (stack->buf + stack->size);
stack->size = new_size;
return ret;
}
@@ -94,8 +94,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);
@@ -108,7 +107,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);