summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-01-18 15:49:09 +0000
committerRobin Watts <robin.watts@artifex.com>2012-01-19 12:40:24 +0000
commit40f4ed22806b88ba0e26c458915d4695f1f7c201 (patch)
treebacdebee1932d294f8233a8fb14cb86383e5f107
parent2c836b57d5295b47655988cf8deaffda731e1c3c (diff)
downloadmupdf-40f4ed22806b88ba0e26c458915d4695f1f7c201.tar.xz
Multi-threading support for MuPDF
When we moved over to a context based system, we laid the foundation for a thread-safe mupdf. This commit should complete that process. Firstly, fz_clone_context is properly implemented so that it makes a new context, but shares certain sections (currently just the allocator, and the store). Secondly, we add locking (to parts of the code that have previously just had placeholder LOCK/UNLOCK comments). Functions to lock and unlock a mutex are added to the allocator structure; omit these (as is the case today) and no multithreading is (safely) possible. The context will refuse to clone if these are not provided. Finally we flesh out the LOCK/UNLOCK comments to be real calls of the functions - unfortunately this requires us to plumb fz_context into the fz_keep_storable function (and all the fz_keep_xxx functions that call it). This is the largest section of the patch. No changes expected to any test files.
-rw-r--r--draw/draw_glyph.c4
-rw-r--r--fitz/base_context.c49
-rw-r--r--fitz/base_memory.c12
-rw-r--r--fitz/dev_list.c10
-rw-r--r--fitz/fitz.h25
-rw-r--r--fitz/res_colorspace.c6
-rw-r--r--fitz/res_pixmap.c6
-rw-r--r--fitz/res_shade.c4
-rw-r--r--fitz/res_store.c57
-rw-r--r--pdf/mupdf.h10
-rw-r--r--pdf/pdf_cmap.c6
-rw-r--r--pdf/pdf_colorspace.c2
-rw-r--r--pdf/pdf_font.c4
-rw-r--r--pdf/pdf_function.c4
-rw-r--r--pdf/pdf_interpret.c48
-rw-r--r--pdf/pdf_pattern.c4
-rw-r--r--pdf/pdf_xobject.c4
-rw-r--r--scripts/cmapdump.c7
18 files changed, 168 insertions, 94 deletions
diff --git a/draw/draw_glyph.c b/draw/draw_glyph.c
index ebda003e..1edcef4a 100644
--- a/draw/draw_glyph.c
+++ b/draw/draw_glyph.c
@@ -115,7 +115,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_color
val = fz_hash_find(cache->hash, &key);
if (val)
- return fz_keep_pixmap(val);
+ return fz_keep_pixmap(ctx, val);
ctm.e = floorf(ctm.e) + key.e / 256.0f;
ctm.f = floorf(ctm.f) + key.f / 256.0f;
@@ -144,7 +144,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_color
{
fz_hash_insert(cache->hash, &key, val);
fz_keep_font(key.font);
- val = fz_keep_pixmap(val);
+ val = fz_keep_pixmap(ctx, val);
}
fz_catch(ctx)
{
diff --git a/fitz/base_context.c b/fitz/base_context.c
index 8991a565..68dba187 100644
--- a/fitz/base_context.c
+++ b/fitz/base_context.c
@@ -36,14 +36,14 @@ fz_free_context(fz_context *ctx)
ctx->alloc->free(ctx->alloc->user, ctx);
}
-fz_context *
-fz_new_context(fz_alloc_context *alloc, unsigned int max_store)
+/* Allocate new context structure, and initialise allocator, and sections
+ * that aren't shared between contexts.
+ */
+static fz_context *
+new_context_phase1(fz_alloc_context *alloc)
{
fz_context *ctx;
- if (!alloc)
- alloc = &fz_alloc_default;
-
ctx = alloc->malloc(alloc->user, sizeof(fz_context));
if (!ctx)
return NULL;
@@ -69,7 +69,6 @@ fz_new_context(fz_alloc_context *alloc, unsigned int max_store)
{
fz_new_font_context(ctx);
fz_new_aa_context(ctx);
- fz_new_store_context(ctx, max_store);
}
fz_catch(ctx)
{
@@ -79,14 +78,46 @@ fz_new_context(fz_alloc_context *alloc, unsigned int max_store)
return ctx;
cleanup:
- fprintf(stderr, "cannot create context\n");
+ fprintf(stderr, "cannot create context (phase 1)\n");
fz_free_context(ctx);
return NULL;
}
fz_context *
+fz_new_context(fz_alloc_context *alloc, unsigned int max_store)
+{
+ fz_context *ctx;
+
+ if (!alloc)
+ alloc = &fz_alloc_default;
+
+ ctx = new_context_phase1(alloc);
+
+ /* Now initialise sections that are shared */
+ fz_try(ctx)
+ {
+ fz_new_store_context(ctx, max_store);
+ }
+ fz_catch(ctx)
+ {
+ fprintf(stderr, "cannot create context (phase 2)\n");
+ fz_free_context(ctx);
+ return NULL;
+ }
+ return ctx;
+}
+
+fz_context *
fz_clone_context(fz_context *ctx)
{
- /* FIXME: Should be sharing store */
- return fz_new_context(ctx->alloc, 256<<20);
+ fz_context *new_ctx;
+
+ /* We cannot safely clone the context without having locking/
+ * unlocking functions. */
+ if (ctx == NULL || ctx->alloc == NULL || ctx->alloc->lock == NULL || ctx->alloc->unlock == NULL)
+ return NULL;
+
+ new_ctx = new_context_phase1(ctx->alloc);
+ new_ctx->store = fz_store_keep(ctx);
+ return ctx;
}
diff --git a/fitz/base_memory.c b/fitz/base_memory.c
index 0b043a32..c9b94f1e 100644
--- a/fitz/base_memory.c
+++ b/fitz/base_memory.c
@@ -6,13 +6,13 @@ do_scavenging_malloc(fz_context *ctx, unsigned int size)
void *p;
int phase = 0;
- /* LOCK */
+ fz_lock(ctx);
do {
p = ctx->alloc->malloc(ctx->alloc->user, size);
if (p != NULL)
return p;
} while (fz_store_scavenge(ctx, size, &phase));
- /* UNLOCK */
+ fz_unlock(ctx);
return NULL;
}
@@ -23,13 +23,13 @@ do_scavenging_realloc(fz_context *ctx, void *p, unsigned int size)
void *q;
int phase = 0;
- /* LOCK */
+ fz_lock(ctx);
do {
q = ctx->alloc->realloc(ctx->alloc->user, p, size);
if (q != NULL)
return q;
} while (fz_store_scavenge(ctx, size, &phase));
- /* UNLOCK */
+ fz_unlock(ctx);
return NULL;
}
@@ -171,9 +171,9 @@ fz_resize_array_no_throw(fz_context *ctx, void *p, unsigned int count, unsigned
void
fz_free(fz_context *ctx, void *p)
{
- /* LOCK */
+ fz_lock(ctx);
ctx->alloc->free(ctx->alloc->user, p);
- /* UNLOCK */
+ fz_unlock(ctx);
}
char *
diff --git a/fitz/dev_list.c b/fitz/dev_list.c
index 0c273c57..7f36ce88 100644
--- a/fitz/dev_list.c
+++ b/fitz/dev_list.c
@@ -80,7 +80,7 @@ fz_new_display_node(fz_context *ctx, fz_display_command cmd, fz_matrix ctm,
node->ctm = ctm;
if (colorspace)
{
- node->colorspace = fz_keep_colorspace(colorspace);
+ node->colorspace = fz_keep_colorspace(ctx, colorspace);
if (color)
{
for (i = 0; i < node->colorspace->n; i++)
@@ -430,7 +430,7 @@ fz_list_fill_shade(fz_device *dev, fz_shade *shade, fz_matrix ctm, float alpha)
fz_context *ctx = dev->ctx;
node = fz_new_display_node(ctx, FZ_CMD_FILL_SHADE, ctm, NULL, NULL, alpha);
node->rect = fz_bound_shade(shade, ctm);
- node->item.shade = fz_keep_shade(shade);
+ node->item.shade = fz_keep_shade(ctx, shade);
fz_append_display_node(dev->user, node);
}
@@ -440,7 +440,7 @@ fz_list_fill_image(fz_device *dev, fz_pixmap *image, fz_matrix ctm, float alpha)
fz_display_node *node;
node = fz_new_display_node(dev->ctx, FZ_CMD_FILL_IMAGE, ctm, NULL, NULL, alpha);
node->rect = fz_transform_rect(ctm, fz_unit_rect);
- node->item.image = fz_keep_pixmap(image);
+ node->item.image = fz_keep_pixmap(dev->ctx, image);
fz_append_display_node(dev->user, node);
}
@@ -451,7 +451,7 @@ fz_list_fill_image_mask(fz_device *dev, fz_pixmap *image, fz_matrix ctm,
fz_display_node *node;
node = fz_new_display_node(dev->ctx, FZ_CMD_FILL_IMAGE_MASK, ctm, colorspace, color, alpha);
node->rect = fz_transform_rect(ctm, fz_unit_rect);
- node->item.image = fz_keep_pixmap(image);
+ node->item.image = fz_keep_pixmap(dev->ctx, image);
fz_append_display_node(dev->user, node);
}
@@ -463,7 +463,7 @@ fz_list_clip_image_mask(fz_device *dev, fz_pixmap *image, fz_rect *rect, fz_matr
node->rect = fz_transform_rect(ctm, fz_unit_rect);
if (rect)
node->rect = fz_intersect_rect(node->rect, *rect);
- node->item.image = fz_keep_pixmap(image);
+ node->item.image = fz_keep_pixmap(dev->ctx, image);
fz_append_display_node(dev->user, node);
}
diff --git a/fitz/fitz.h b/fitz/fitz.h
index ccfa0bd6..3971f24c 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -120,6 +120,8 @@ struct fz_alloc_context_s
void *(*malloc)(void *, unsigned int);
void *(*realloc)(void *, void *, unsigned int);
void (*free)(void *, void *);
+ void (*lock)(void *);
+ void (*unlock)(void *);
};
/* Default allocator */
@@ -376,6 +378,20 @@ void fz_free_context(fz_context *ctx);
void fz_new_aa_context(fz_context *ctx);
void fz_free_aa_context(fz_context *ctx);
+static inline void
+fz_lock(fz_context *ctx)
+{
+ if (ctx->alloc->lock)
+ ctx->alloc->lock(ctx->alloc->user);
+}
+
+static inline void
+fz_unlock(fz_context *ctx)
+{
+ if (ctx->alloc->unlock)
+ ctx->alloc->unlock(ctx->alloc->user);
+}
+
/*
* Basic runtime and utility functions
*/
@@ -737,9 +753,10 @@ enum {
void fz_new_store_context(fz_context *ctx, unsigned int max);
void fz_free_store_context(fz_context *ctx);
+fz_store *fz_store_keep(fz_context *ctx);
void fz_debug_store(fz_context *ctx);
-void *fz_keep_storable(fz_storable *);
+void *fz_keep_storable(fz_context *, fz_storable *);
void fz_drop_storable(fz_context *, fz_storable *);
void fz_store_item(fz_context *ctx, fz_obj *key, void *val, unsigned int itemsize);
@@ -921,7 +938,7 @@ fz_pixmap *fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, i
fz_pixmap *fz_new_pixmap_with_rect(fz_context *ctx, fz_colorspace *, fz_bbox bbox);
fz_pixmap *fz_new_pixmap_with_rect_and_data(fz_context *ctx, fz_colorspace *, fz_bbox bbox, unsigned char *samples);
fz_pixmap *fz_new_pixmap(fz_context *ctx, fz_colorspace *, int w, int h);
-fz_pixmap *fz_keep_pixmap(fz_pixmap *pix);
+fz_pixmap *fz_keep_pixmap(fz_context *ctx, fz_pixmap *pix);
void fz_drop_pixmap(fz_context *ctx, fz_pixmap *pix);
void fz_free_pixmap_imp(fz_context *ctx, fz_storable *pix);
void fz_clear_pixmap(fz_pixmap *pix);
@@ -1009,7 +1026,7 @@ struct fz_colorspace_s
};
fz_colorspace *fz_new_colorspace(fz_context *ctx, char *name, int n);
-fz_colorspace *fz_keep_colorspace(fz_colorspace *colorspace);
+fz_colorspace *fz_keep_colorspace(fz_context *ctx, fz_colorspace *colorspace);
void fz_drop_colorspace(fz_context *ctx, fz_colorspace *colorspace);
void fz_free_colorspace_imp(fz_context *ctx, fz_storable *colorspace);
@@ -1250,7 +1267,7 @@ struct fz_shade_s
float *mesh; /* [x y 0], [x y r], [x y t] or [x y c1 ... cn] */
};
-fz_shade *fz_keep_shade(fz_shade *shade);
+fz_shade *fz_keep_shade(fz_context *ctx, fz_shade *shade);
void fz_drop_shade(fz_context *ctx, fz_shade *shade);
void fz_free_shade_imp(fz_context *ctx, fz_storable *shade);
void fz_debug_shade(fz_shade *shade);
diff --git a/fitz/res_colorspace.c b/fitz/res_colorspace.c
index 8c95f6a4..1fdc8c4a 100644
--- a/fitz/res_colorspace.c
+++ b/fitz/res_colorspace.c
@@ -28,9 +28,9 @@ fz_new_colorspace(fz_context *ctx, char *name, int n)
}
fz_colorspace *
-fz_keep_colorspace(fz_colorspace *cs)
+fz_keep_colorspace(fz_context *ctx, fz_colorspace *cs)
{
- return (fz_colorspace *)fz_keep_storable(&cs->storable);
+ return (fz_colorspace *)fz_keep_storable(ctx, &cs->storable);
}
void
@@ -507,7 +507,7 @@ fz_convert_pixmap(fz_context *ctx, fz_pixmap *sp, fz_pixmap *dp)
assert(ss && ds);
if (sp->mask)
- dp->mask = fz_keep_pixmap(sp->mask);
+ dp->mask = fz_keep_pixmap(ctx, sp->mask);
dp->interpolate = sp->interpolate;
if (ss == fz_device_gray)
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c
index 008781b4..1998c7fc 100644
--- a/fitz/res_pixmap.c
+++ b/fitz/res_pixmap.c
@@ -1,9 +1,9 @@
#include "fitz.h"
fz_pixmap *
-fz_keep_pixmap(fz_pixmap *pix)
+fz_keep_pixmap(fz_context *ctx, fz_pixmap *pix)
{
- return (fz_pixmap *)fz_keep_storable(&pix->storable);
+ return (fz_pixmap *)fz_keep_storable(ctx, &pix->storable);
}
void
@@ -46,7 +46,7 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h
if (colorspace)
{
- pix->colorspace = fz_keep_colorspace(colorspace);
+ pix->colorspace = fz_keep_colorspace(ctx, colorspace);
pix->n = 1 + colorspace->n;
}
diff --git a/fitz/res_shade.c b/fitz/res_shade.c
index 0be4ba7c..34fba64d 100644
--- a/fitz/res_shade.c
+++ b/fitz/res_shade.c
@@ -1,9 +1,9 @@
#include "fitz.h"
fz_shade *
-fz_keep_shade(fz_shade *shade)
+fz_keep_shade(fz_context *ctx, fz_shade *shade)
{
- return (fz_shade *)fz_keep_storable(&shade->storable);
+ return (fz_shade *)fz_keep_storable(ctx, &shade->storable);
}
void
diff --git a/fitz/res_store.c b/fitz/res_store.c
index dc9b14a2..93d48272 100644
--- a/fitz/res_store.c
+++ b/fitz/res_store.c
@@ -20,6 +20,8 @@ struct refkey
struct fz_store_s
{
+ int refs;
+
/* Every item in the store is kept in a doubly linked list, ordered
* by usage (so LRU entries are at the end). */
fz_item *head;
@@ -48,6 +50,7 @@ fz_new_store_context(fz_context *ctx, unsigned int max)
fz_free(ctx, store);
fz_rethrow(ctx);
}
+ store->refs = 1;
store->head = NULL;
store->tail = NULL;
store->size = 0;
@@ -56,14 +59,14 @@ fz_new_store_context(fz_context *ctx, unsigned int max)
}
void *
-fz_keep_storable(fz_storable *s)
+fz_keep_storable(fz_context *ctx, fz_storable *s)
{
if (s == NULL)
return NULL;
- /* LOCK */
+ fz_lock(ctx);
if (s->refs > 0)
s->refs++;
- /* UNLOCK */
+ fz_unlock(ctx);
return s;
}
@@ -72,7 +75,7 @@ fz_drop_storable(fz_context *ctx, fz_storable *s)
{
if (s == NULL)
return;
- /* LOCK */
+ fz_lock(ctx);
if (s->refs < 0)
{
/* It's a static object. Dropping does nothing. */
@@ -86,7 +89,7 @@ fz_drop_storable(fz_context *ctx, fz_storable *s)
* itself without any operations on the fz_store. */
s->free(ctx, s);
}
- /* UNLOCK */
+ fz_unlock(ctx);
}
static void
@@ -189,12 +192,12 @@ fz_store_item(fz_context *ctx, fz_obj *key, void *val_, unsigned int itemsize)
return;
}
- /* LOCK */
+ fz_lock(ctx);
size = store->size + itemsize;
if (store->max != FZ_STORE_UNLIMITED && size > store->max && ensure_space(ctx, size - store->max))
{
fz_free(ctx, item);
- /* UNLOCK */
+ fz_unlock(ctx);
return;
}
store->size += itemsize;
@@ -218,7 +221,7 @@ fz_store_item(fz_context *ctx, fz_obj *key, void *val_, unsigned int itemsize)
fz_catch(ctx)
{
fz_free(ctx, item);
- /* UNLOCK */
+ fz_unlock(ctx);
return;
}
}
@@ -233,7 +236,7 @@ fz_store_item(fz_context *ctx, fz_obj *key, void *val_, unsigned int itemsize)
store->tail = item;
store->head = item;
item->prev = NULL;
- /* UNLOCK */
+ fz_unlock(ctx);
}
void *
@@ -249,7 +252,7 @@ fz_find_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key)
if (!key)
return NULL;
- /* LOCK */
+ fz_lock(ctx);
if (fz_is_indirect(key))
{
/* We can find objects keyed on indirected objects quickly */
@@ -290,10 +293,10 @@ fz_find_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key)
/* And bump the refcount before returning */
if (item->val->refs > 0)
item->val->refs++;
- /* UNLOCK */
+ fz_unlock(ctx);
return (void *)item->val;
}
- /* UNLOCK */
+ fz_unlock(ctx);
return NULL;
}
@@ -305,7 +308,7 @@ fz_remove_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key)
fz_item *item;
fz_store *store = ctx->store;
- /* LOCK */
+ fz_lock(ctx);
if (fz_is_indirect(key))
{
/* We can find objects keyed on indirect objects quickly */
@@ -338,7 +341,7 @@ fz_remove_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key)
fz_drop_obj(item->key);
fz_free(ctx, item);
}
- /* UNLOCK */
+ fz_unlock(ctx);
}
void
@@ -350,21 +353,39 @@ fz_empty_store(fz_context *ctx)
if (store == NULL)
return;
- /* LOCK */
+ fz_lock(ctx);
/* Run through all the items in the store */
for (item = store->head; item; item = next)
{
next = item->next;
evict(ctx, item);
}
- /* UNLOCK */
+ fz_unlock(ctx);
+}
+
+fz_store *
+fz_store_keep(fz_context *ctx)
+{
+ if (ctx == NULL || ctx->store == NULL)
+ return NULL;
+ fz_lock(ctx);
+ ctx->store->refs++;
+ fz_unlock(ctx);
+ return ctx->store;
}
void
fz_free_store_context(fz_context *ctx)
{
+ int refs;
if (ctx == NULL || ctx->store == NULL)
return;
+ fz_lock(ctx);
+ refs = --ctx->store->refs;
+ fz_unlock(ctx);
+ if (refs != 0)
+ return;
+
fz_empty_store(ctx);
fz_free_hash(ctx->store->hash);
fz_free(ctx, ctx->store);
@@ -379,7 +400,7 @@ fz_debug_store(fz_context *ctx)
printf("-- resource store contents --\n");
- /* LOCK */
+ fz_lock(ctx);
for (item = store->head; item; item = item->next)
{
printf("store[*][refs=%d][size=%d] ", item->val->refs, item->size);
@@ -390,7 +411,7 @@ fz_debug_store(fz_context *ctx)
fz_debug_obj(item->key);
printf(" = %p\n", item->val);
}
- /* UNLOCK */
+ fz_unlock(ctx);
}
static int
diff --git a/pdf/mupdf.h b/pdf/mupdf.h
index 0e21f930..b1b2a7e1 100644
--- a/pdf/mupdf.h
+++ b/pdf/mupdf.h
@@ -159,7 +159,7 @@ typedef struct pdf_function_s pdf_function;
pdf_function *pdf_load_function(pdf_xref *xref, fz_obj *ref);
void pdf_eval_function(fz_context *ctx, pdf_function *func, float *in, int inlen, float *out, int outlen);
-pdf_function *pdf_keep_function(pdf_function *func);
+pdf_function *pdf_keep_function(fz_context *ctx, pdf_function *func);
void pdf_drop_function(fz_context *ctx, pdf_function *func);
unsigned int pdf_function_size(pdf_function *func);
@@ -191,7 +191,7 @@ struct pdf_pattern_s
};
pdf_pattern *pdf_load_pattern(pdf_xref *xref, fz_obj *obj);
-pdf_pattern *pdf_keep_pattern(pdf_pattern *pat);
+pdf_pattern *pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat);
void pdf_drop_pattern(fz_context *ctx, pdf_pattern *pat);
/*
@@ -215,7 +215,7 @@ struct pdf_xobject_s
};
pdf_xobject *pdf_load_xobject(pdf_xref *xref, fz_obj *obj);
-pdf_xobject *pdf_keep_xobject(pdf_xobject *xobj);
+pdf_xobject *pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj);
void pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj);
/*
@@ -263,7 +263,7 @@ struct pdf_cmap_s
};
pdf_cmap *pdf_new_cmap(fz_context *ctx);
-pdf_cmap *pdf_keep_cmap(pdf_cmap *cmap);
+pdf_cmap *pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap);
void pdf_drop_cmap(fz_context *ctx, pdf_cmap *cmap);
void pdf_free_cmap_imp(fz_context *ctx, fz_storable *cmap);
unsigned int pdf_cmap_size(pdf_cmap *cmap);
@@ -401,7 +401,7 @@ pdf_font_desc *pdf_load_type3_font(pdf_xref *xref, fz_obj *rdb, fz_obj *obj);
pdf_font_desc *pdf_load_font(pdf_xref *xref, fz_obj *rdb, fz_obj *obj);
pdf_font_desc *pdf_new_font_desc(fz_context *ctx);
-pdf_font_desc *pdf_keep_font(pdf_font_desc *fontdesc);
+pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc);
void pdf_drop_font(fz_context *ctx, pdf_font_desc *font);
void pdf_debug_font(pdf_font_desc *fontdesc);
diff --git a/pdf/pdf_cmap.c b/pdf/pdf_cmap.c
index bb1c1ea0..4430979c 100644
--- a/pdf/pdf_cmap.c
+++ b/pdf/pdf_cmap.c
@@ -68,9 +68,9 @@ pdf_new_cmap(fz_context *ctx)
/* Could be a macro for speed */
pdf_cmap *
-pdf_keep_cmap(pdf_cmap *cmap)
+pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap)
{
- return (pdf_cmap *)fz_keep_storable(&cmap->storable);
+ return (pdf_cmap *)fz_keep_storable(ctx, &cmap->storable);
}
/* Could be a macro for speed */
@@ -87,7 +87,7 @@ pdf_set_usecmap(fz_context *ctx, pdf_cmap *cmap, pdf_cmap *usecmap)
if (cmap->usecmap)
pdf_drop_cmap(ctx, cmap->usecmap);
- cmap->usecmap = pdf_keep_cmap(usecmap);
+ cmap->usecmap = pdf_keep_cmap(ctx, usecmap);
if (cmap->codespace_len == 0)
{
diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c
index b2f42b8f..b7f9f131 100644
--- a/pdf/pdf_colorspace.c
+++ b/pdf/pdf_colorspace.c
@@ -211,7 +211,7 @@ pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src)
}
if (src->mask)
- dst->mask = fz_keep_pixmap(src->mask);
+ dst->mask = fz_keep_pixmap(ctx, src->mask);
dst->interpolate = src->interpolate;
return dst;
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index d0a7241d..b6c59153 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -304,9 +304,9 @@ pdf_load_embedded_font(pdf_font_desc *fontdesc, pdf_xref *xref, fz_obj *stmref)
*/
pdf_font_desc *
-pdf_keep_font(pdf_font_desc *fontdesc)
+pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc)
{
- return (pdf_font_desc *)fz_keep_storable(&fontdesc->storable);
+ return (pdf_font_desc *)fz_keep_storable(ctx, &fontdesc->storable);
}
void
diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c
index 5cc4524e..61682ac2 100644
--- a/pdf/pdf_function.c
+++ b/pdf/pdf_function.c
@@ -1295,9 +1295,9 @@ eval_stitching_func(fz_context *ctx, pdf_function *func, float in, float *out)
*/
pdf_function *
-pdf_keep_function(pdf_function *func)
+pdf_keep_function(fz_context *ctx, pdf_function *func)
{
- return (pdf_function *)fz_keep_storable(&func->storable);
+ return (pdf_function *)fz_keep_storable(ctx, &func->storable);
}
void
diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c
index 7bb2da9c..d42684c0 100644
--- a/pdf/pdf_interpret.c
+++ b/pdf/pdf_interpret.c
@@ -867,14 +867,14 @@ pdf_init_gstate(pdf_gstate *gs, fz_matrix ctm)
memset(gs->stroke_state.dash_list, 0, sizeof(gs->stroke_state.dash_list));
gs->stroke.kind = PDF_MAT_COLOR;
- gs->stroke.colorspace = fz_keep_colorspace(fz_device_gray);
+ gs->stroke.colorspace = fz_device_gray; /* No fz_keep_colorspace as static */
gs->stroke.v[0] = 0;
gs->stroke.pattern = NULL;
gs->stroke.shade = NULL;
gs->stroke.alpha = 1;
gs->fill.kind = PDF_MAT_COLOR;
- gs->fill.colorspace = fz_keep_colorspace(fz_device_gray);
+ gs->fill.colorspace = fz_device_gray; /* No fz_keep_colorspace as static */
gs->fill.v[0] = 0;
gs->fill.pattern = NULL;
gs->fill.shade = NULL;
@@ -896,14 +896,14 @@ pdf_init_gstate(pdf_gstate *gs, fz_matrix ctm)
}
static pdf_material *
-pdf_keep_material(pdf_material *mat)
+pdf_keep_material(fz_context *ctx, pdf_material *mat)
{
if (mat->colorspace)
- fz_keep_colorspace(mat->colorspace);
+ fz_keep_colorspace(ctx, mat->colorspace);
if (mat->pattern)
- pdf_keep_pattern(mat->pattern);
+ pdf_keep_pattern(ctx, mat->pattern);
if (mat->shade)
- fz_keep_shade(mat->shade);
+ fz_keep_shade(ctx, mat->shade);
return mat;
}
@@ -920,19 +920,19 @@ pdf_drop_material(fz_context *ctx, pdf_material *mat)
}
static void
-copy_state(pdf_gstate *gs, pdf_gstate *old)
+copy_state(fz_context *ctx, pdf_gstate *gs, pdf_gstate *old)
{
gs->stroke = old->stroke;
gs->fill = old->fill;
gs->font = old->font;
gs->softmask = old->softmask;
- pdf_keep_material(&gs->stroke);
- pdf_keep_material(&gs->fill);
+ pdf_keep_material(ctx, &gs->stroke);
+ pdf_keep_material(ctx, &gs->fill);
if (gs->font)
- pdf_keep_font(gs->font);
+ pdf_keep_font(ctx, gs->font);
if (gs->softmask)
- pdf_keep_xobject(gs->softmask);
+ pdf_keep_xobject(ctx, gs->softmask);
}
@@ -975,7 +975,7 @@ pdf_new_csi(pdf_xref *xref, fz_device *dev, fz_matrix ctm, char *event, fz_cooki
csi->top_ctm = ctm;
pdf_init_gstate(&csi->gstate[0], ctm);
if (gstate)
- copy_state(&csi->gstate[0], gstate);
+ copy_state(ctx, &csi->gstate[0], gstate);
csi->gtop = 0;
csi->cookie = cookie;
@@ -1023,12 +1023,12 @@ pdf_gsave(pdf_csi *csi)
csi->gtop++;
gs = &csi->gstate[csi->gtop];
- pdf_keep_material(&gs->stroke);
- pdf_keep_material(&gs->fill);
+ pdf_keep_material(ctx, &gs->stroke);
+ pdf_keep_material(ctx, &gs->fill);
if (gs->font)
- pdf_keep_font(gs->font);
+ pdf_keep_font(ctx, gs->font);
if (gs->softmask)
- pdf_keep_xobject(gs->softmask);
+ pdf_keep_xobject(ctx, gs->softmask);
}
static void
@@ -1114,7 +1114,7 @@ pdf_set_colorspace(pdf_csi *csi, int what, fz_colorspace *colorspace)
fz_drop_colorspace(ctx, mat->colorspace);
mat->kind = PDF_MAT_COLOR;
- mat->colorspace = fz_keep_colorspace(colorspace);
+ mat->colorspace = fz_keep_colorspace(ctx, colorspace);
mat->v[0] = 0;
mat->v[1] = 0;
@@ -1167,7 +1167,7 @@ pdf_set_shade(pdf_csi *csi, int what, fz_shade *shade)
fz_drop_shade(ctx, mat->shade);
mat->kind = PDF_MAT_SHADE;
- mat->shade = fz_keep_shade(shade);
+ mat->shade = fz_keep_shade(ctx, shade);
}
static void
@@ -1186,7 +1186,7 @@ pdf_set_pattern(pdf_csi *csi, int what, pdf_pattern *pat, float *v)
mat->kind = PDF_MAT_PATTERN;
if (pat)
- mat->pattern = pdf_keep_pattern(pat);
+ mat->pattern = pdf_keep_pattern(ctx, pat);
else
mat->pattern = NULL;
@@ -1234,13 +1234,13 @@ pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, fz_rect area, int what)
if (what == PDF_FILL)
{
pdf_drop_material(ctx, &gstate->stroke);
- pdf_keep_material(&gstate->fill);
+ pdf_keep_material(ctx, &gstate->fill);
gstate->stroke = gstate->fill;
}
if (what == PDF_STROKE)
{
pdf_drop_material(ctx, &gstate->fill);
- pdf_keep_material(&gstate->stroke);
+ pdf_keep_material(ctx, &gstate->stroke);
gstate->fill = gstate->stroke;
}
}
@@ -1695,11 +1695,11 @@ static void pdf_run_cs_imp(pdf_csi *csi, fz_obj *rdb, int what)
else
{
if (!strcmp(csi->name, "DeviceGray"))
- colorspace = fz_keep_colorspace(fz_device_gray);
+ colorspace = fz_device_gray; /* No fz_keep_colorspace as static */
else if (!strcmp(csi->name, "DeviceRGB"))
- colorspace = fz_keep_colorspace(fz_device_rgb);
+ colorspace = fz_device_rgb; /* No fz_keep_colorspace as static */
else if (!strcmp(csi->name, "DeviceCMYK"))
- colorspace = fz_keep_colorspace(fz_device_cmyk);
+ colorspace = fz_device_cmyk; /* No fz_keep_colorspace as static */
else
{
dict = fz_dict_gets(rdb, "ColorSpace");
diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c
index 1fc356c7..2b4d32a2 100644
--- a/pdf/pdf_pattern.c
+++ b/pdf/pdf_pattern.c
@@ -2,9 +2,9 @@
#include "mupdf.h"
pdf_pattern *
-pdf_keep_pattern(pdf_pattern *pat)
+pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat)
{
- return (pdf_pattern *)fz_keep_storable(&pat->storable);
+ return (pdf_pattern *)fz_keep_storable(ctx, &pat->storable);
}
void
diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c
index 61daf9a4..e33ac858 100644
--- a/pdf/pdf_xobject.c
+++ b/pdf/pdf_xobject.c
@@ -2,9 +2,9 @@
#include "mupdf.h"
pdf_xobject *
-pdf_keep_xobject(pdf_xobject *xobj)
+pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj)
{
- return (pdf_xobject *)fz_keep_storable(&xobj->storable);
+ return (pdf_xobject *)fz_keep_storable(ctx, &xobj->storable);
}
void
diff --git a/scripts/cmapdump.c b/scripts/cmapdump.c
index 2d318f14..a41533f7 100644
--- a/scripts/cmapdump.c
+++ b/scripts/cmapdump.c
@@ -176,7 +176,7 @@ void fz_free_aa_context(fz_context *ctx)
{
}
-void *fz_keep_storable(fz_storable *s)
+void *fz_keep_storable(fz_context *ctx, fz_storable *s)
{
return s;
}
@@ -193,6 +193,11 @@ void fz_free_store_context(fz_context *ctx)
{
}
+fz_store *fz_store_keep(fz_context *ctx)
+{
+ return NULL;
+}
+
int fz_store_scavenge(fz_context *ctx, unsigned int size, int *phase)
{
return 0;