ref: 12c9d2fc728b51aa1eb9a70d0d331eb9464912d9
dir: /src/mem.c/
#if defined(__macos__)
#include <MacMemory.h>
#endif
#include "platform.h"
#define HAVE_MORECORE 1
#define MORECORE sl_sbrk
static void *sl_sbrk(intptr increment);
#define MORECORE_CONTIGUOUS 0
#define MORECORE_CANNOT_TRIM 1
#define NO_SEGMENT_TRAVERSAL 1
#define USE_BUILTIN_FFS 1
#define MALLOC_ALIGNMENT 8
#define USE_LOCKS 0
#define USE_DL_PREFIX 1
#define LACKS_SYS_PARAM_H
#define LACKS_FCNTL_H
#define LACKS_TIME_H
#define LACKS_SYS_TYPES_H
#define HAVE_MMAP 0
#define HAVE_MREMAP 0
#define NO_MALLINFO 1
#define NO_MALLOC_STATS 1
#define DEFAULT_GRANULARITY 64
#define malloc_getpagesize 4096
#include "dlmalloc.h"
void *
sl_malloc(usize size)
{
return dlmalloc(size);
}
void
sl_free(void *p)
{
dlfree(p);
}
void *
sl_calloc(usize n, usize size)
{
return dlcalloc(n, size);
}
void *
sl_realloc(void *p, usize size)
{
return dlrealloc(p, size);
}
char *
sl_strdup(const char *s)
{
usize sz = strlen(s)+1;
char *p = dlmalloc(sz);
memcpy(p, s, sz);
return p;
}
#if defined(__macos__)
static void *
sl_sbrk(intptr increment)
{
static char *e = nil;
if(increment == 0)
return e;
if(increment < 0)
return MFAIL;
increment = (increment + malloc_getpagesize-1) & ~(malloc_getpagesize-1);
char *p = NewPtr(increment);
e = p + increment;
return p;
}
#else
static void *
sl_sbrk(intptr increment)
{
return sbrk(increment);
}
#endif