ref: a2b9a02e2dd89643fa1f1ed368679a7a924e05f2
dir: /mem.c/
#include "platform.h" #if defined(MEM_NEED_ALIGNED) void * fl_malloc(size_t sz) { uint8_t *p = malloc(sz+1+7); assert(p != nil); uint8_t *a = (uint8_t*)(((uintptr_t)p+1+7) & ~(uintptr_t)7); a[-1] = a-p; return a; } void * fl_calloc(size_t n, size_t esz) { size_t sz = n*esz; assert(sz >= esz); uint8_t *p = fl_malloc(sz); memset(p, 0, sz); return p; } void * fl_realloc(void *a_, size_t sz) { uint8_t *a = a_; assert(((uintptr_t)a & 7) == 0); uint8_t *p = a != nil ? a - a[-1] : nil; p = realloc(p, sz+1+7); assert(p != nil); a = (uint8_t*)(((uintptr_t)p+1+7) & ~(uintptr_t)7); a[-1] = a-p; return a; } void fl_free(void *a_) { uint8_t *a = a_; if(a == nil) return; assert(((uintptr_t)a & 7) == 0); uint8_t *p = a - a[-1]; free(p); } char * fl_strdup(const char *s) { size_t sz = strlen(s)+1; char *p = fl_malloc(sz); memcpy(p, s, sz); return p; } #endif