You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
553 B

#include <stdlib.h>
#include <string.h>
#include "vector.h"
extern void panic(const char* string, ...) _rc_attr((noreturn));
_rc_attr((noinline, noreturn, cold)) static void _fail_vec_alloc(size_t cap)
{
panic("vec_alloc(): malloc() failed to allocate %d bytes (cap %d)", sizeof(vec_t) + (cap * sizeof(vec_elem_t)), cap);
}
_rc_alloc_fn vec_t* _rc_restrict vec_alloc(size_t cap)
{
vec_t* vec = malloc(sizeof(vec_t) + (cap * sizeof(vec_elem_t)));
if(!vec) _fail_vec_alloc(cap);
vec-> cap = cap;
vec-> scap = cap;
vec-> len = 0;
return vec;
}