shithub: femtolisp

ref: d5ae75e18d3fd374910432809f062d5cfea5eb21
dir: /mem.c/

View raw version
#include "platform.h"

#define HAVE_MORECORE 1
#define MORECORE fl_sbrk
static void *fl_sbrk(intptr_t 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.inc"

void *
fl_malloc(size_t size)
{
	return dlmalloc(size);
}

void
fl_free(void *p)
{
	dlfree(p);
}

void *
fl_calloc(size_t n, size_t size)
{
	return dlcalloc(n, size);
}

void *
fl_realloc(void *p, size_t size)
{
	return dlrealloc(p, size);
}

char *
fl_strdup(const char *s)
{
	size_t sz = strlen(s)+1;
	char *p = dlmalloc(sz);
	memcpy(p, s, sz);
	return p;
}

#if defined(__macos__)
#include <Multiverse.h>
static void *
fl_sbrk(intptr_t 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 *
fl_sbrk(intptr_t increment)
{
	return sbrk(increment);
}
#endif