summaryrefslogtreecommitdiff
path: root/fitz/base_memory.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2005-03-30 10:45:21 +0200
committerTor Andersson <tor@ghostscript.com>2005-03-30 10:45:21 +0200
commit5f4d61903ee8fc514ed7e23eac4d5ac6409ff760 (patch)
treea824aa883d9d5df072c17ec0a2ac4a2b5074c2c0 /fitz/base_memory.c
parentee154f16bd09a43359967f7e7b86c3677c09461d (diff)
downloadmupdf-5f4d61903ee8fc514ed7e23eac4d5ac6409ff760.tar.xz
rename and shuffle -- part 2
Diffstat (limited to 'fitz/base_memory.c')
-rw-r--r--fitz/base_memory.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/fitz/base_memory.c b/fitz/base_memory.c
new file mode 100644
index 00000000..2c2f8e0d
--- /dev/null
+++ b/fitz/base_memory.c
@@ -0,0 +1,81 @@
+#include <fitz.h>
+
+/* Make this thread local storage if you wish. */
+
+static void *stdmalloc(fz_memorycontext *mem, int n)
+{
+#if 0
+ void *p = malloc(n);
+ if (!p)
+ fprintf(stderr, "failed to malloc %d bytes\n", n);
+ return p;
+#else
+ return malloc(n);
+#endif
+}
+
+static void *stdrealloc(fz_memorycontext *mem, void *p, int n)
+{
+#if 0
+ void *np = realloc(p, n);
+ if (np == nil)
+ fprintf(stderr, "realloc failed %d nytes", n);
+ else if (np == p)
+ fprintf(stderr, "realloc kept %d\n", n);
+ else
+ fprintf(stderr, "realloc moved %d\n", n);
+ return np;
+#else
+ return realloc(p, n);
+#endif
+}
+
+static void stdfree(fz_memorycontext *mem, void *p)
+{
+ free(p);
+}
+
+static fz_memorycontext defmem = { stdmalloc, stdrealloc, stdfree };
+static fz_memorycontext *curmem = &defmem;
+
+fz_error fz_koutofmem = {
+ -1,
+ {"out of memory"},
+ {"<malloc>"},
+ {"memory.c"},
+ 0
+};
+
+fz_memorycontext *
+fz_currentmemorycontext()
+{
+ return curmem;
+}
+
+void
+fz_setmemorycontext(fz_memorycontext *mem)
+{
+ curmem = mem;
+}
+
+void *
+fz_malloc(int n)
+{
+ fz_memorycontext *mem = fz_currentmemorycontext();
+ return mem->malloc(mem, n);
+}
+
+void *
+fz_realloc(void *p, int n)
+{
+ fz_memorycontext *mem = fz_currentmemorycontext();
+ return mem->realloc(mem, p, n);
+}
+
+void
+fz_free(void *p)
+{
+ fz_memorycontext *mem = fz_currentmemorycontext();
+ mem->free(mem, p);
+}
+