The new roots callback mechanism makes it possible to traverse the gc objects on the stack without needing the stack to be an gc object. This also uncovered a nasty bug in apfl_stack_pop where we passed in a wrong mem pointer into apfl_resizable_splice. We should probably find a way to make the apfl_resizable_* functions a bit safer, the need for casting stuff to void** easily hides errors.
81 lines
1.6 KiB
C
81 lines
1.6 KiB
C
#ifndef APFL_RESIZABLE
|
|
#define APFL_RESIZABLE 1
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "apfl.h"
|
|
|
|
// TODO: Find a way to make these functions safer. These functions require
|
|
// casting things to void** which hides useful compiler warnings. Also needing
|
|
// to pass in the correct elem_size is error prone.
|
|
|
|
#define APFL_RESIZABLE_TRAIT(T, N) \
|
|
T* N; \
|
|
size_t len; \
|
|
size_t cap;
|
|
|
|
#define APFL_RESIZABLE_ARGS(S, N) (void **)(&(S).N), &(S).len, &(S).cap
|
|
|
|
void apfl_resizable_init(void **mem, size_t *len, size_t *cap);
|
|
|
|
bool apfl_resizable_resize(
|
|
struct apfl_allocator,
|
|
size_t elem_size,
|
|
void **mem,
|
|
size_t *len,
|
|
size_t *cap,
|
|
size_t newlen
|
|
);
|
|
|
|
bool apfl_resizable_ensure_cap(
|
|
struct apfl_allocator,
|
|
size_t elem_size,
|
|
void **mem,
|
|
size_t *cap,
|
|
size_t want_cap
|
|
);
|
|
|
|
bool apfl_resizable_ensure_cap_for_more_elements(
|
|
struct apfl_allocator,
|
|
size_t elem_size,
|
|
void **mem,
|
|
size_t len,
|
|
size_t *cap,
|
|
size_t more_elements
|
|
);
|
|
|
|
bool apfl_resizable_check_cut_args(size_t len, size_t cut_start, size_t cut_len);
|
|
|
|
bool apfl_resizable_cut_without_resize(
|
|
size_t elem_size,
|
|
void **mem,
|
|
size_t *len,
|
|
size_t cut_start,
|
|
size_t cut_len
|
|
);
|
|
|
|
bool apfl_resizable_splice(
|
|
struct apfl_allocator,
|
|
size_t elem_size,
|
|
void **mem,
|
|
size_t *len,
|
|
size_t *cap,
|
|
size_t start,
|
|
size_t cut_len,
|
|
const void *other_mem,
|
|
size_t other_len
|
|
);
|
|
|
|
bool apfl_resizable_append(
|
|
struct apfl_allocator,
|
|
size_t elem_size,
|
|
void **mem,
|
|
size_t *len,
|
|
size_t *cap,
|
|
const void *other_mem,
|
|
size_t other_len
|
|
);
|
|
|
|
|
|
#endif
|