summaryrefslogtreecommitdiff
path: root/fitz/base_context.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-09-21 00:11:22 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-09-21 00:11:22 +0200
commit69ed4a8f4dbfac7f2f1de925e34807e4fee3b27c (patch)
treeb7f82296a259d360ce90f0826e475321d630a222 /fitz/base_context.c
parent99ba154018b7c4a2c47b4c7e721ffe6d9164f9f3 (diff)
downloadmupdf-69ed4a8f4dbfac7f2f1de925e34807e4fee3b27c.tar.xz
Don't thread ctx through safe fz_obj functions.
Diffstat (limited to 'fitz/base_context.c')
-rw-r--r--fitz/base_context.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/fitz/base_context.c b/fitz/base_context.c
new file mode 100644
index 00000000..db702e8e
--- /dev/null
+++ b/fitz/base_context.c
@@ -0,0 +1,61 @@
+#include "fitz.h"
+
+static fz_obj *
+fz_resolve_indirect_null(fz_obj *ref)
+{
+ return ref;
+}
+
+fz_obj *(*fz_resolve_indirect)(fz_obj*) = fz_resolve_indirect_null;
+
+void
+fz_free_context(fz_context *ctx)
+{
+ assert(ctx != NULL);
+
+ /* Other finalisation calls go here (in reverse order) */
+
+ if (ctx->error)
+ {
+ assert(ctx->error->top == -1);
+ ctx->alloc->free(ctx->alloc->opaque, ctx->error);
+ }
+
+ /* Free the context itself */
+ ctx->alloc->free(ctx->alloc->opaque, ctx);
+
+ /* We do NOT free the allocator! */
+}
+
+fz_context *
+fz_new_context(fz_alloc_context *alloc)
+{
+ fz_context *ctx;
+
+ assert(alloc != NULL);
+ ctx = alloc->malloc(alloc->opaque, sizeof(fz_context));
+ if (ctx == NULL)
+ return NULL;
+ ctx->alloc = alloc;
+
+ ctx->error = alloc->malloc(alloc->opaque, sizeof(fz_error_context));
+ if (!ctx->error)
+ goto cleanup;
+ ctx->error->top = -1;
+ ctx->error->message[0] = 0;
+
+ /* New initialisation calls for context entries go here */
+
+ return ctx;
+
+cleanup:
+ fprintf(stderr, "cannot create context\n");
+ fz_free_context(ctx);
+ return NULL;
+}
+
+fz_context *
+fz_clone_context(fz_context *ctx)
+{
+ return fz_new_context(ctx->alloc);
+}