diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-09-14 17:36:57 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2011-09-15 14:50:17 +0100 |
commit | b51ef0eea028c73b6379e832eaa34fff3fbbb927 (patch) | |
tree | 1ab685ccd356e7fdc832b2e3322c0486b2670cfb /fitz/stm_open.c | |
parent | 89ae81f651bfa112b8e07317eb6983beaf7cb212 (diff) | |
download | mupdf-b51ef0eea028c73b6379e832eaa34fff3fbbb927.tar.xz |
Add context to mupdf.
Huge pervasive change to lots of files, adding a context for exception
handling and allocation.
In time we'll move more statics into there.
Also fix some for(i = 0; i < function(...); i++) calls.
Diffstat (limited to 'fitz/stm_open.c')
-rw-r--r-- | fitz/stm_open.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/fitz/stm_open.c b/fitz/stm_open.c index 81eb819e..f06bdc50 100644 --- a/fitz/stm_open.c +++ b/fitz/stm_open.c @@ -1,13 +1,13 @@ #include "fitz.h" fz_stream * -fz_new_stream(void *state, +fz_new_stream(fz_context *ctx, void *state, int(*read)(fz_stream *stm, unsigned char *buf, int len), void(*close)(fz_stream *stm)) { fz_stream *stm; - stm = fz_malloc(sizeof(fz_stream)); + stm = fz_malloc(ctx, sizeof(fz_stream)); stm->refs = 1; stm->error = 0; @@ -26,6 +26,7 @@ fz_new_stream(void *state, stm->read = read; stm->close = close; stm->seek = NULL; + stm->ctx = ctx; return stm; } @@ -45,7 +46,7 @@ fz_close(fz_stream *stm) { if (stm->close) stm->close(stm); - fz_free(stm); + fz_free(stm->ctx, stm); } } @@ -74,41 +75,41 @@ static void close_file(fz_stream *stm) int n = close(*(int*)stm->state); if (n < 0) fz_warn("close error: %s", strerror(errno)); - fz_free(stm->state); + fz_free(stm->ctx, stm->state); } fz_stream * -fz_open_fd(int fd) +fz_open_fd(fz_context *ctx, int fd) { fz_stream *stm; int *state; - state = fz_malloc(sizeof(int)); + state = fz_malloc(ctx, sizeof(int)); *state = fd; - stm = fz_new_stream(state, read_file, close_file); + stm = fz_new_stream(ctx, state, read_file, close_file); stm->seek = seek_file; return stm; } fz_stream * -fz_open_file(const char *name) +fz_open_file(fz_context *ctx, const char *name) { int fd = open(name, O_BINARY | O_RDONLY, 0); if (fd == -1) return NULL; - return fz_open_fd(fd); + return fz_open_fd(ctx, fd); } #ifdef _WIN32 fz_stream * -fz_open_file_w(const wchar_t *name) +fz_open_file_w(fz_context *ctx, const wchar_t *name) { int fd = _wopen(name, O_BINARY | O_RDONLY, 0); if (fd == -1) return NULL; - return fz_open_fd(fd); + return fz_open_fd(ctx, fd); } #endif @@ -134,15 +135,15 @@ static void seek_buffer(fz_stream *stm, int offset, int whence) static void close_buffer(fz_stream *stm) { if (stm->state) - fz_drop_buffer(stm->state); + fz_drop_buffer(stm->ctx, stm->state); } fz_stream * -fz_open_buffer(fz_buffer *buf) +fz_open_buffer(fz_context *ctx, fz_buffer *buf) { fz_stream *stm; - stm = fz_new_stream(fz_keep_buffer(buf), read_buffer, close_buffer); + stm = fz_new_stream(ctx, fz_keep_buffer(buf), read_buffer, close_buffer); stm->seek = seek_buffer; stm->bp = buf->data; @@ -156,11 +157,11 @@ fz_open_buffer(fz_buffer *buf) } fz_stream * -fz_open_memory(unsigned char *data, int len) +fz_open_memory(fz_context *ctx, unsigned char *data, int len) { fz_stream *stm; - stm = fz_new_stream(NULL, read_buffer, close_buffer); + stm = fz_new_stream(ctx, NULL, read_buffer, close_buffer); stm->seek = seek_buffer; stm->bp = data; |