summaryrefslogtreecommitdiff
path: root/source/fitz/stream-read.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2015-01-21 16:42:45 +0100
committerTor Andersson <tor.andersson@artifex.com>2015-02-17 18:05:39 +0100
commitf84a189d5f94250e46d2cbd1a75aba00130e2dd6 (patch)
tree8ee614ab90de1baa8941f91ae4946ed5c2e70721 /source/fitz/stream-read.c
parent681039767f2ccc72e236246178893eb0989169c9 (diff)
downloadmupdf-f84a189d5f94250e46d2cbd1a75aba00130e2dd6.tar.xz
Add ctx parameter and remove embedded contexts for API regularity.
Purge several embedded contexts: Remove embedded context in fz_output. Remove embedded context in fz_stream. Remove embedded context in fz_device. Remove fz_rebind_stream (since it is no longer necessary). Remove embedded context in svg_device. Remove embedded context in XML parser. Add ctx argument to fz_document functions. Remove embedded context in fz_document. Remove embedded context in pdf_document. Remove embedded context in pdf_obj. Make fz_page independent of fz_document in the interface. We shouldn't need to pass the document to all functions handling a page. If a page is tied to the source document, it's redundant; otherwise it's just pointless. Fix reference counting oddity in fz_new_image_from_pixmap.
Diffstat (limited to 'source/fitz/stream-read.c')
-rw-r--r--source/fitz/stream-read.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c
index 49e1c1a3..75261ea5 100644
--- a/source/fitz/stream-read.c
+++ b/source/fitz/stream-read.c
@@ -3,14 +3,14 @@
#define MIN_BOMB (100 << 20)
int
-fz_read(fz_stream *stm, unsigned char *buf, int len)
+fz_read(fz_context *ctx, fz_stream *stm, unsigned char *buf, int len)
{
int count, n;
count = 0;
do
{
- n = fz_available(stm, len);
+ n = fz_available(ctx, stm, len);
if (n > len)
n = len;
if (n == 0)
@@ -28,17 +28,16 @@ fz_read(fz_stream *stm, unsigned char *buf, int len)
}
fz_buffer *
-fz_read_all(fz_stream *stm, int initial)
+fz_read_all(fz_context *ctx, fz_stream *stm, int initial)
{
- return fz_read_best(stm, initial, NULL);
+ return fz_read_best(ctx, stm, initial, NULL);
}
fz_buffer *
-fz_read_best(fz_stream *stm, int initial, int *truncated)
+fz_read_best(fz_context *ctx, fz_stream *stm, int initial, int *truncated)
{
fz_buffer *buf = NULL;
int n;
- fz_context *ctx = stm->ctx;
fz_var(buf);
@@ -62,7 +61,7 @@ fz_read_best(fz_stream *stm, int initial, int *truncated)
fz_throw(ctx, FZ_ERROR_GENERIC, "compression bomb detected");
}
- n = fz_read(stm, buf->data + buf->len, buf->cap - buf->len);
+ n = fz_read(ctx, stm, buf->data + buf->len, buf->cap - buf->len);
if (n == 0)
break;
@@ -91,19 +90,19 @@ fz_read_best(fz_stream *stm, int initial, int *truncated)
}
void
-fz_read_line(fz_stream *stm, char *mem, int n)
+fz_read_line(fz_context *ctx, fz_stream *stm, char *mem, int n)
{
char *s = mem;
int c = EOF;
while (n > 1)
{
- c = fz_read_byte(stm);
+ c = fz_read_byte(ctx, stm);
if (c == EOF)
break;
if (c == '\r') {
- c = fz_peek_byte(stm);
+ c = fz_peek_byte(ctx, stm);
if (c == '\n')
- fz_read_byte(stm);
+ fz_read_byte(ctx, stm);
break;
}
if (c == '\n')
@@ -116,50 +115,50 @@ fz_read_line(fz_stream *stm, char *mem, int n)
}
int
-fz_tell(fz_stream *stm)
+fz_tell(fz_context *ctx, fz_stream *stm)
{
return stm->pos - (stm->wp - stm->rp);
}
void
-fz_seek(fz_stream *stm, int offset, int whence)
+fz_seek(fz_context *ctx, fz_stream *stm, int offset, int whence)
{
stm->avail = 0; /* Reset bit reading */
if (stm->seek)
{
if (whence == 1)
{
- offset = fz_tell(stm) + offset;
+ offset = fz_tell(ctx, stm) + offset;
whence = 0;
}
- stm->seek(stm, offset, whence);
+ stm->seek(ctx, stm, offset, whence);
stm->eof = 0;
}
else if (whence != 2)
{
if (whence == 0)
- offset -= fz_tell(stm);
+ offset -= fz_tell(ctx, stm);
if (offset < 0)
- fz_warn(stm->ctx, "cannot seek backwards");
+ fz_warn(ctx, "cannot seek backwards");
/* dog slow, but rare enough */
while (offset-- > 0)
{
- if (fz_read_byte(stm) == EOF)
+ if (fz_read_byte(ctx, stm) == EOF)
{
- fz_warn(stm->ctx, "seek failed");
+ fz_warn(ctx, "seek failed");
break;
}
}
}
else
- fz_warn(stm->ctx, "cannot seek");
+ fz_warn(ctx, "cannot seek");
}
-int fz_stream_meta(fz_stream *stm, int key, int size, void *ptr)
+int fz_stream_meta(fz_context *ctx, fz_stream *stm, int key, int size, void *ptr)
{
if (!stm || !stm->meta)
return -1;
- return stm->meta(stm, key, size, ptr);
+ return stm->meta(ctx, stm, key, size, ptr);
}
fz_buffer *
@@ -173,11 +172,11 @@ fz_read_file(fz_context *ctx, const char *filename)
stm = fz_open_file(ctx, filename);
fz_try(ctx)
{
- buf = fz_read_all(stm, 0);
+ buf = fz_read_all(ctx, stm, 0);
}
fz_always(ctx)
{
- fz_drop_stream(stm);
+ fz_drop_stream(ctx, stm);
}
fz_catch(ctx)
{