summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-11-11 16:05:30 +0000
committerRobin Watts <robin.watts@artifex.com>2016-11-14 16:09:39 +0000
commit37f95f87bdfb2e0b01d649afae5fffe60bf99d3a (patch)
treeda3491c62d6af86c1a5bc4e523e8f9ebe19793d1 /source/fitz
parentc0e1dfdab1a13def046e94d771f8a821ba2a10d9 (diff)
downloadmupdf-37f95f87bdfb2e0b01d649afae5fffe60bf99d3a.tar.xz
Make fz_buffer structure private to fitz.
Move the definition of the structure contents into new fitz-imp.h file. Make all code outside of fitz access the buffer through the defined API. Add a convenience API for people that want to get buffers as null terminated C strings.
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/buffer.c48
-rw-r--r--source/fitz/compressed-buffer.c2
-rw-r--r--source/fitz/filter-jbig2.c2
-rw-r--r--source/fitz/filter-leech.c2
-rw-r--r--source/fitz/fitz-imp.h15
-rw-r--r--source/fitz/font.c2
-rw-r--r--source/fitz/image.c2
-rw-r--r--source/fitz/load-gif.c2
-rw-r--r--source/fitz/output.c2
-rw-r--r--source/fitz/stext-output.c2
-rw-r--r--source/fitz/stext-search.c4
-rw-r--r--source/fitz/stream-open.c2
-rw-r--r--source/fitz/stream-read.c2
-rw-r--r--source/fitz/svg-device.c2
-rw-r--r--source/fitz/untar.c2
-rw-r--r--source/fitz/unzip.c2
-rw-r--r--source/fitz/zip.c2
17 files changed, 72 insertions, 23 deletions
diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c
index 10c0c055..13aae983 100644
--- a/source/fitz/buffer.c
+++ b/source/fitz/buffer.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
fz_buffer *
fz_new_buffer(fz_context *ctx, size_t size)
@@ -30,12 +30,20 @@ fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, size_t size)
{
fz_buffer *b;
- b = fz_malloc_struct(ctx, fz_buffer);
- b->refs = 1;
- b->data = data;
- b->cap = size;
- b->len = size;
- b->unused_bits = 0;
+ fz_try(ctx)
+ {
+ b = fz_malloc_struct(ctx, fz_buffer);
+ b->refs = 1;
+ b->data = data;
+ b->cap = size;
+ b->len = size;
+ b->unused_bits = 0;
+ }
+ fz_catch(ctx)
+ {
+ fz_free(ctx, data);
+ fz_rethrow(ctx);
+ }
return b;
}
@@ -152,6 +160,32 @@ fz_buffer_storage(fz_context *ctx, fz_buffer *buf, unsigned char **datap)
return (buf ? buf->len : 0);
}
+const char *
+fz_string_from_buffer(fz_context *ctx, fz_buffer *buf)
+{
+ if (!buf)
+ return "";
+
+ if (buf->data[buf->len-1] != 0)
+ fz_write_buffer_byte(ctx, buf, 0);
+
+ return (const char *)buf->data;
+}
+
+size_t
+fz_buffer_extract(fz_context *ctx, fz_buffer *buf, unsigned char **datap)
+{
+ size_t len = buf ? buf->len : 0;
+ *datap = (buf ? buf->data : NULL);
+
+ if (buf)
+ {
+ buf->data = NULL;
+ buf->len = 0;
+ }
+ return len;
+}
+
void
fz_append_buffer(fz_context *ctx, fz_buffer *buf, fz_buffer *extra)
{
diff --git a/source/fitz/compressed-buffer.c b/source/fitz/compressed-buffer.c
index 8c9b7e56..3846fcb2 100644
--- a/source/fitz/compressed-buffer.c
+++ b/source/fitz/compressed-buffer.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
/* This code needs to be kept out of stm_buffer.c to avoid it being
* pulled into cmapdump.c */
diff --git a/source/fitz/filter-jbig2.c b/source/fitz/filter-jbig2.c
index 404eb524..7e7a9420 100644
--- a/source/fitz/filter-jbig2.c
+++ b/source/fitz/filter-jbig2.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
#ifdef HAVE_LURATECH
diff --git a/source/fitz/filter-leech.c b/source/fitz/filter-leech.c
index c8f28b7c..b6d139e2 100644
--- a/source/fitz/filter-leech.c
+++ b/source/fitz/filter-leech.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
#include <zlib.h>
diff --git a/source/fitz/fitz-imp.h b/source/fitz/fitz-imp.h
new file mode 100644
index 00000000..9441aa9c
--- /dev/null
+++ b/source/fitz/fitz-imp.h
@@ -0,0 +1,15 @@
+#ifndef MUPDF_FITZ_IMP_H
+#define MUPDF_FITZ_IMP_H
+
+#include "mupdf/fitz.h"
+
+struct fz_buffer_s
+{
+ int refs;
+ unsigned char *data;
+ size_t cap, len;
+ int unused_bits;
+ int shared;
+};
+
+#endif
diff --git a/source/fitz/font.c b/source/fitz/font.c
index 7142414e..4e30579f 100644
--- a/source/fitz/font.c
+++ b/source/fitz/font.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
#include "font-imp.h"
diff --git a/source/fitz/image.c b/source/fitz/image.c
index f568df32..8fe49c0d 100644
--- a/source/fitz/image.c
+++ b/source/fitz/image.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
#define SANE_DPI 72.0f
#define INSANE_DPI 4800.0f
diff --git a/source/fitz/load-gif.c b/source/fitz/load-gif.c
index f41dee32..16c46637 100644
--- a/source/fitz/load-gif.c
+++ b/source/fitz/load-gif.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
struct info
{
diff --git a/source/fitz/output.c b/source/fitz/output.c
index 3133116c..c34b8736 100644
--- a/source/fitz/output.c
+++ b/source/fitz/output.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
struct fz_output_context_s
{
diff --git a/source/fitz/stext-output.c b/source/fitz/stext-output.c
index a6c51cb8..d671288f 100644
--- a/source/fitz/stext-output.c
+++ b/source/fitz/stext-output.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
#define SUBSCRIPT_OFFSET 0.2f
#define SUPERSCRIPT_OFFSET -0.2f
diff --git a/source/fitz/stext-search.c b/source/fitz/stext-search.c
index bba2c3f5..8d768a4f 100644
--- a/source/fitz/stext-search.c
+++ b/source/fitz/stext-search.c
@@ -280,7 +280,7 @@ fz_copy_selection(fz_context *ctx, fz_stext_page *page, fz_rect rect)
fz_write_buffer_byte(ctx, buffer, 0);
- s = (char*)buffer->data;
- fz_free(ctx, buffer);
+ fz_buffer_extract(ctx, buffer, &s);
+ fz_drop_buffer(ctx, buffer);
return s;
}
diff --git a/source/fitz/stream-open.c b/source/fitz/stream-open.c
index e70fc0e9..f999014b 100644
--- a/source/fitz/stream-open.c
+++ b/source/fitz/stream-open.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
int
fz_file_exists(fz_context *ctx, const char *path)
diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c
index b499d68f..2d2f28b1 100644
--- a/source/fitz/stream-read.c
+++ b/source/fitz/stream-read.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
#define MIN_BOMB (100 << 20)
diff --git a/source/fitz/svg-device.c b/source/fitz/svg-device.c
index 8a83c97b..5d05d808 100644
--- a/source/fitz/svg-device.c
+++ b/source/fitz/svg-device.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
typedef struct svg_device_s svg_device;
diff --git a/source/fitz/untar.c b/source/fitz/untar.c
index a364bf39..3c00425d 100644
--- a/source/fitz/untar.c
+++ b/source/fitz/untar.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
typedef struct tar_entry_s tar_entry;
typedef struct fz_tar_archive_s fz_tar_archive;
diff --git a/source/fitz/unzip.c b/source/fitz/unzip.c
index 491322fd..d7f2ad0e 100644
--- a/source/fitz/unzip.c
+++ b/source/fitz/unzip.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
#include <zlib.h>
diff --git a/source/fitz/zip.c b/source/fitz/zip.c
index 95f1bd03..cb51fd6d 100644
--- a/source/fitz/zip.c
+++ b/source/fitz/zip.c
@@ -1,4 +1,4 @@
-#include "mupdf/fitz.h"
+#include "fitz-imp.h"
#include <zlib.h>