things are fucky wucky
This commit is contained in:
+18
-6
@@ -7,6 +7,8 @@ void *dyn_array_create_func(dyn_array_create_func_args_t args) {
|
||||
.allocator=args.allocator,
|
||||
.itemsize=args.itemsize,
|
||||
.initial_capacity=args.initial_capacity,
|
||||
.file=args.file,
|
||||
.line=args.line
|
||||
}
|
||||
);
|
||||
if (bytes == NULL) {
|
||||
@@ -22,7 +24,7 @@ void *dyn_array_create_func(dyn_array_create_func_args_t args) {
|
||||
}
|
||||
|
||||
void *dyn_array_grow_func(void *this, size_t n_new_items, const char *file, int line) {
|
||||
void *bytes = dyn_array_grow_non_crashing_func(this, n_new_items);
|
||||
void *bytes = dyn_array_grow_non_crashing_func(this, n_new_items, file, line);
|
||||
if (bytes == NULL) {
|
||||
fprintf(
|
||||
stderr,
|
||||
@@ -35,9 +37,11 @@ void *dyn_array_grow_func(void *this, size_t n_new_items, const char *file, int
|
||||
}
|
||||
|
||||
void *dyn_array_create_non_crashing_func(dyn_array_create_non_crashing_func_args_t args) {
|
||||
dyn_array_header_t *header = allocator_alloc(
|
||||
dyn_array_header_t *header = allocator_alloc_func(
|
||||
args.allocator,
|
||||
sizeof(dyn_array_header_t) + args.itemsize * args.initial_capacity
|
||||
sizeof(dyn_array_header_t) + args.itemsize * args.initial_capacity,
|
||||
args.file,
|
||||
args.line
|
||||
);
|
||||
if (header == NULL) { return NULL; }
|
||||
header->size = 0;
|
||||
@@ -47,7 +51,7 @@ void *dyn_array_create_non_crashing_func(dyn_array_create_non_crashing_func_args
|
||||
return &header->bytes;
|
||||
}
|
||||
|
||||
void *dyn_array_grow_non_crashing_func(void *this, size_t n_new_items) {
|
||||
void *dyn_array_grow_non_crashing_func(void *this, size_t n_new_items, const char *file, int line) {
|
||||
dyn_array_header_t *header = PTR_FROM_FIELD_PTR(dyn_array_header_t, bytes, this);
|
||||
size_t new_size = header->size + n_new_items;
|
||||
|
||||
@@ -57,13 +61,16 @@ void *dyn_array_grow_non_crashing_func(void *this, size_t n_new_items) {
|
||||
cap_times_2 < new_size
|
||||
? new_size
|
||||
: cap_times_2;
|
||||
header = allocator_resize(
|
||||
header = allocator_resize_func(
|
||||
header->allocator,
|
||||
header,
|
||||
sizeof(dyn_array_header_t) + header->itemsize * new_capacity
|
||||
sizeof(dyn_array_header_t) + header->itemsize * new_capacity,
|
||||
file,
|
||||
line
|
||||
);
|
||||
if (header == NULL) { return NULL; }
|
||||
header->capacity = new_capacity;
|
||||
header->size = new_size;
|
||||
}
|
||||
return &header->bytes;
|
||||
}
|
||||
@@ -92,3 +99,8 @@ size_t dyn_array_capacity(void *this) {
|
||||
dyn_array_header_t *header = PTR_FROM_FIELD_PTR(dyn_array_header_t, bytes, this);
|
||||
return header->capacity;
|
||||
}
|
||||
|
||||
void dyn_array_destroy(void *this) {
|
||||
dyn_array_header_t *header = PTR_FROM_FIELD_PTR(dyn_array_header_t, bytes, this);
|
||||
allocator_free(header->allocator, header);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user