Attempt replacement of memory allocation functions with primitive working alternatives

This commit is contained in:
Chris Young 2013-02-21 23:10:36 +00:00
parent 486593df35
commit 70df2d197d
2 changed files with 38 additions and 1 deletions

View File

@ -61,6 +61,7 @@ else
ifeq ($(SUBTARGET),os3)
LDFLAGS += -lpbl -liconv
else
CFLAGS += -DAMIGA_NETSURF_REPLACE_ALLOC
LDFLAGS += -lauto -lpbl -liconv
endif
endif
@ -80,7 +81,7 @@ S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c file.c \
sslcert.c gui_options.c print.c theme.c drag.c icon.c system_colour.c \
datatypes.c dt_picture.c dt_anim.c dt_sound.c plugin_hack.c \
stringview/stringview.c stringview/urlhistory.c \
agclass/amigaguide_class.c
agclass/amigaguide_class.c alloc.c
S_AMIGA := $(addprefix amiga/,$(S_AMIGA))
# This is the final source build list

36
amiga/alloc.c Executable file
View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <proto/exec.h>
#ifdef AMIGA_NETSURF_REPLACE_ALLOC
#define nsa_malloc malloc
#define nsa_calloc calloc
#define nsa_realloc realloc
#define nsa_free free
#endif
void nsa_free(void *p) {
if(p == NULL) return;
UBYTE *mem = p - 4;
FreeVec(mem);
}
void *nsa_malloc(size_t s) {
UBYTE *mem = AllocVec(s + 4, MEMF_PRIVATE);
*mem = s;
return mem + 4;
}
void *nsa_calloc(size_t nelem, size_t nsize) {
UBYTE *mem = AllocVec((nelem * nsize) + 4, MEMF_PRIVATE | MEMF_CLEAR);
*mem = (nelem * nsize);
return mem + 4;
}
void *nsa_realloc(void *p, size_t s) {
void *newptr;
ULONG old_size = *((UBYTE *)p - 4);
newptr = nsa_malloc(s);
memcpy(newptr, p, old_size);
nsa_free(p);
return newptr;
}