diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-05-04 21:19:38 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-05-13 11:42:00 +0200 |
commit | b557ece715c9324d4e3cde10bda94d6ae90311cc (patch) | |
tree | 3eaf638336a28ca3d00d2519dd5e00476f6f0fe1 /source/fitz | |
parent | 51bd5ba744a806d6b8ccfde7b8f51911a175f2fc (diff) | |
download | mupdf-b557ece715c9324d4e3cde10bda94d6ae90311cc.tar.xz |
Reference count fz_device.
Language bindings sometimes require objects to be reference counted.
Diffstat (limited to 'source/fitz')
-rw-r--r-- | source/fitz/device.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/source/fitz/device.c b/source/fitz/device.c index df2d4f86..4379bb21 100644 --- a/source/fitz/device.c +++ b/source/fitz/device.c @@ -3,7 +3,9 @@ void * fz_new_device(fz_context *ctx, int size) { - return Memento_label(fz_calloc(ctx, 1, size), "fz_device"); + fz_device *dev = Memento_label(fz_calloc(ctx, 1, size), "fz_device"); + dev->refs = 1; + return dev; } void @@ -40,15 +42,22 @@ fz_close_device(fz_context *ctx, fz_device *dev) dev->end_tile = NULL; } +fz_device * +fz_keep_device(fz_context *ctx, fz_device *dev) +{ + return fz_keep_imp(ctx, dev, &dev->refs); +} + void fz_drop_device(fz_context *ctx, fz_device *dev) { - if (dev == NULL) - return; - if (dev->close) - dev->close(ctx, dev); - fz_free(ctx, dev->container); - fz_free(ctx, dev); + if (fz_drop_imp(ctx, dev, &dev->refs)) + { + if (dev->close) + dev->close(ctx, dev); + fz_free(ctx, dev->container); + fz_free(ctx, dev); + } } void |