diff options
author | Tor Andersson <tor@ghostscript.com> | 2009-03-11 22:02:49 +0100 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2009-03-11 22:02:49 +0100 |
commit | 9f6a77c2d17128a44bf2fc9fead449a05354def5 (patch) | |
tree | 905d3c56580a906b77b1ca2660cb6f3fd123b945 /fitz/base_memory.c | |
parent | 31733cfd3ba1a920542da3792f2591cf7ba5f62a (diff) | |
download | mupdf-9f6a77c2d17128a44bf2fc9fead449a05354def5.tar.xz |
Rename and prune some files and functions.
Diffstat (limited to 'fitz/base_memory.c')
-rw-r--r-- | fitz/base_memory.c | 66 |
1 files changed, 13 insertions, 53 deletions
diff --git a/fitz/base_memory.c b/fitz/base_memory.c index cd6de8cb..21effdc1 100644 --- a/fitz/base_memory.c +++ b/fitz/base_memory.c @@ -1,71 +1,31 @@ #include "fitz_base.h" -/* Make this thread local storage if you wish. */ - -static void *stdmalloc(fz_memorycontext *mem, int n) -{ - return malloc(n); -} - -static void *stdrealloc(fz_memorycontext *mem, void *p, int n) -{ - return realloc(p, n); -} - -static void stdfree(fz_memorycontext *mem, void *p) -{ - free(p); -} - -static fz_memorycontext defmem = { stdmalloc, stdrealloc, stdfree }; -static fz_memorycontext *curmem = &defmem; - -fz_memorycontext * -fz_currentmemorycontext() -{ - return curmem; -} - -void -fz_setmemorycontext(fz_memorycontext *mem) -{ - curmem = mem; -} - -void * -fz_malloc(int n) +void * fz_malloc(int n) { - fz_memorycontext *mem = fz_currentmemorycontext(); - void *p = mem->malloc(mem, n); + void *p = malloc(n); if (!p) - fz_warn("cannot malloc %d bytes", n); + fz_throw("cannot malloc %d bytes", n); return p; } -void * -fz_realloc(void *p, int n) +void * fz_realloc(void *p, int n) { - fz_memorycontext *mem = fz_currentmemorycontext(); - void *np = mem->realloc(mem, p, n); + void *np = realloc(p, n); if (np == nil) - fz_warn("cannot realloc %d bytes", n); + fz_throw("cannot realloc %d bytes", n); return np; } -void -fz_free(void *p) +void fz_free(void *p) { - fz_memorycontext *mem = fz_currentmemorycontext(); - mem->free(mem, p); + free(p); } -char * -fz_strdup(char *s) +char * fz_strdup(char *s) { - int len = strlen(s); - char *ns = fz_malloc(len + 1); - if (ns) - strcpy(ns, s); - return ns; + char *ns = strdup(s); + if (!ns) + fz_throw("cannot strdup %d bytes", strlen(s) + 1); + return ns; } |