diff options
Diffstat (limited to 'source/fitz')
-rw-r--r-- | source/fitz/bitmap.c | 6 | ||||
-rw-r--r-- | source/fitz/buffer.c | 8 | ||||
-rw-r--r-- | source/fitz/document.c | 27 | ||||
-rw-r--r-- | source/fitz/halftone.c | 16 | ||||
-rw-r--r-- | source/fitz/path.c | 7 | ||||
-rw-r--r-- | source/fitz/separation.c | 20 | ||||
-rw-r--r-- | source/fitz/store.c | 26 | ||||
-rw-r--r-- | source/fitz/stream-open.c | 9 |
8 files changed, 39 insertions, 80 deletions
diff --git a/source/fitz/bitmap.c b/source/fitz/bitmap.c index b610737a..dc2645ec 100644 --- a/source/fitz/bitmap.c +++ b/source/fitz/bitmap.c @@ -284,15 +284,13 @@ fz_new_bitmap(fz_context *ctx, int w, int h, int n, int xres, int yres) fz_bitmap * fz_keep_bitmap(fz_context *ctx, fz_bitmap *bit) { - if (bit) - bit->refs++; - return bit; + return fz_keep_imp(ctx, bit, &bit->refs); } void fz_drop_bitmap(fz_context *ctx, fz_bitmap *bit) { - if (bit && --bit->refs == 0) + if (fz_drop_imp(ctx, bit, &bit->refs)) { fz_free(ctx, bit->samples); fz_free(ctx, bit); diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c index 190088e3..ba3451bf 100644 --- a/source/fitz/buffer.c +++ b/source/fitz/buffer.c @@ -90,17 +90,13 @@ fz_new_buffer_from_base64(fz_context *ctx, const char *data, size_t size) fz_buffer * fz_keep_buffer(fz_context *ctx, fz_buffer *buf) { - if (buf) - buf->refs ++; - return buf; + return fz_keep_imp(ctx, buf, &buf->refs); } void fz_drop_buffer(fz_context *ctx, fz_buffer *buf) { - if (!buf) - return; - if (--buf->refs == 0) + if (fz_drop_imp(ctx, buf, &buf->refs)) { if (!buf->shared) fz_free(ctx, buf->data); diff --git a/source/fitz/document.c b/source/fitz/document.c index ad602bc2..b2590f07 100644 --- a/source/fitz/document.c +++ b/source/fitz/document.c @@ -142,16 +142,15 @@ fz_new_document_of_size(fz_context *ctx, int size) fz_document * fz_keep_document(fz_context *ctx, fz_document *doc) { - if (doc) - ++doc->refs; - return doc; + return fz_keep_imp(ctx, doc, &doc->refs); } void fz_drop_document(fz_context *ctx, fz_document *doc) { - if (doc && --doc->refs == 0 && doc->drop_document) - doc->drop_document(ctx, doc); + if (fz_drop_imp(ctx, doc, &doc->refs)) + if (doc->drop_document) + doc->drop_document(ctx, doc); } static void @@ -352,15 +351,13 @@ fz_new_annot(fz_context *ctx, int size) fz_annot * fz_keep_annot(fz_context *ctx, fz_annot *annot) { - if (annot) - ++annot->refs; - return annot; + return fz_keep_imp(ctx, annot, &annot->refs); } void fz_drop_annot(fz_context *ctx, fz_annot *annot) { - if (annot && --annot->refs == 0) + if (fz_drop_imp(ctx, annot, &annot->refs)) { if (annot->drop_annot) annot->drop_annot(ctx, annot); @@ -379,21 +376,17 @@ fz_new_page(fz_context *ctx, int size) fz_page * fz_keep_page(fz_context *ctx, fz_page *page) { - if (page) - ++page->refs; - return page; + return fz_keep_imp(ctx, page, &page->refs); } void fz_drop_page(fz_context *ctx, fz_page *page) { - if (page) + if (fz_drop_imp(ctx, page, &page->refs)) { - if (--page->refs == 0 && page->drop_page) - { + if (page->drop_page) page->drop_page(ctx, page); - fz_free(ctx, page); - } + fz_free(ctx, page); } } diff --git a/source/fitz/halftone.c b/source/fitz/halftone.c index eb35dbdf..02353e76 100644 --- a/source/fitz/halftone.c +++ b/source/fitz/halftone.c @@ -18,21 +18,19 @@ fz_new_halftone(fz_context *ctx, int comps) fz_halftone * fz_keep_halftone(fz_context *ctx, fz_halftone *ht) { - if (ht) - ht->refs++; - return ht; + return fz_keep_imp(ctx, ht, &ht->refs); } void fz_drop_halftone(fz_context *ctx, fz_halftone *ht) { int i; - - if (!ht || --ht->refs != 0) - return; - for (i = 0; i < ht->n; i++) - fz_drop_pixmap(ctx, ht->comp[i]); - fz_free(ctx, ht); + if (fz_drop_imp(ctx, ht, &ht->refs)) + { + for (i = 0; i < ht->n; i++) + fz_drop_pixmap(ctx, ht->comp[i]); + fz_free(ctx, ht); + } } /* Default mono halftone, lifted from Ghostscript. */ diff --git a/source/fitz/path.c b/source/fitz/path.c index 0fce853b..3befcf23 100644 --- a/source/fitz/path.c +++ b/source/fitz/path.c @@ -1494,7 +1494,7 @@ fz_clone_stroke_state(fz_context *ctx, fz_stroke_state *stroke) fz_stroke_state * fz_unshare_stroke_state_with_dash_len(fz_context *ctx, fz_stroke_state *shared, int len) { - int single, unsize, shsize, shlen, drop; + int single, unsize, shsize, shlen; fz_stroke_state *unshared; fz_lock(ctx, FZ_LOCK_ALLOC); @@ -1516,10 +1516,7 @@ fz_unshare_stroke_state_with_dash_len(fz_context *ctx, fz_stroke_state *shared, memcpy(unshared, shared, (shsize > unsize ? unsize : shsize)); unshared->refs = 1; - fz_lock(ctx, FZ_LOCK_ALLOC); - drop = (shared->refs > 0 ? --shared->refs == 0 : 0); - fz_unlock(ctx, FZ_LOCK_ALLOC); - if (drop) + if (fz_drop_imp(ctx, shared, &shared->refs)) fz_free(ctx, shared); return unshared; } diff --git a/source/fitz/separation.c b/source/fitz/separation.c index e18691cf..9968b574 100644 --- a/source/fitz/separation.c +++ b/source/fitz/separation.c @@ -22,34 +22,20 @@ fz_separations *fz_new_separations(fz_context *ctx) fz_separations *fz_keep_separations(fz_context *ctx, fz_separations *sep) { - int i; - if (!ctx || !sep) return NULL; - fz_lock(ctx, FZ_LOCK_ALLOC); - i = sep->refs; - if (i > 0) - sep->refs++; - fz_unlock(ctx, FZ_LOCK_ALLOC); - - return sep; + return fz_keep_imp(ctx, sep, &sep->refs); } void fz_drop_separations(fz_context *ctx, fz_separations *sep) { - int i; - if (!ctx || !sep) return; - fz_lock(ctx, FZ_LOCK_ALLOC); - i = sep->refs; - if (i > 0) - sep->refs--; - fz_unlock(ctx, FZ_LOCK_ALLOC); - if (i == 1) + if (fz_drop_imp(ctx, sep, &sep->refs)) { + int i; for (i = 0; i < sep->num_separations; i++) fz_free(ctx, sep->name[i]); fz_free(ctx, sep); diff --git a/source/fitz/store.c b/source/fitz/store.c index 862c179c..f8feb591 100644 --- a/source/fitz/store.c +++ b/source/fitz/store.c @@ -101,8 +101,10 @@ evict(fz_context *ctx, fz_item *item) item->prev->next = item->next; else store->head = item->next; + /* Drop a reference to the value (freeing if required) */ drop = (item->val->refs > 0 && --item->val->refs == 0); + /* Remove from the hash table */ if (item->type->make_hash_key) { @@ -114,6 +116,7 @@ evict(fz_context *ctx, fz_item *item) fz_unlock(ctx, FZ_LOCK_ALLOC); if (drop) item->val->drop(ctx, item->val); + /* Always drops the key and drop the item */ item->type->drop_key(ctx, item->key); fz_free(ctx, item); @@ -457,28 +460,21 @@ fz_keep_store_context(fz_context *ctx) { if (ctx == NULL || ctx->store == NULL) return NULL; - fz_lock(ctx, FZ_LOCK_ALLOC); - ctx->store->refs++; - fz_unlock(ctx, FZ_LOCK_ALLOC); - return ctx->store; + return fz_keep_imp(ctx, ctx->store, &ctx->store->refs); } void fz_drop_store_context(fz_context *ctx) { - int refs; if (ctx == NULL || ctx->store == NULL) return; - fz_lock(ctx, FZ_LOCK_ALLOC); - refs = --ctx->store->refs; - fz_unlock(ctx, FZ_LOCK_ALLOC); - if (refs != 0) - return; - - fz_empty_store(ctx); - fz_drop_hash(ctx, ctx->store->hash); - fz_free(ctx, ctx->store); - ctx->store = NULL; + if (fz_drop_imp(ctx, ctx->store, &ctx->store->refs)) + { + fz_empty_store(ctx); + fz_drop_hash(ctx, ctx->store->hash); + fz_free(ctx, ctx->store); + ctx->store = NULL; + } } static void diff --git a/source/fitz/stream-open.c b/source/fitz/stream-open.c index 142df7c2..05cbc48a 100644 --- a/source/fitz/stream-open.c +++ b/source/fitz/stream-open.c @@ -46,18 +46,13 @@ fz_new_stream(fz_context *ctx, void *state, fz_stream_next_fn *next, fz_stream_c fz_stream * fz_keep_stream(fz_context *ctx, fz_stream *stm) { - if (Memento_takeRef(stm)) - stm->refs ++; - return stm; + return fz_keep_imp(ctx, stm, &stm->refs); } void fz_drop_stream(fz_context *ctx, fz_stream *stm) { - if (!Memento_dropRef(stm)) - return; - stm->refs --; - if (stm->refs == 0) + if (fz_drop_imp(ctx, stm, &stm->refs)) { if (stm->close) stm->close(ctx, stm->state); |