summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Liddell <chris.liddell@artifex.com>2021-05-07 16:56:42 +0100
committerChris Liddell <chris.liddell@artifex.com>2021-05-11 11:39:16 +0100
commite67f5fbbfdd2604d53b8f54690c49ee8b092e1ea (patch)
tree1adb6e49cd86bd9cfbe305ea6c97ffb76b61dd26
parent0678e99a0570ab5a2617b95fe4fba47b8f384283 (diff)
downloadghostpdl-e67f5fbbfdd2604d53b8f54690c49ee8b092e1ea.tar.gz
Update the gs/pdfi interface to use the chunk allocator
Also, change pdfi_free_context() and pdfi_clear_context() to use the gs_memory_t embedded in the pdfi context, rather than taking an allocator as a parameter.
-rw-r--r--pdf/ghostpdf.c8
-rw-r--r--pdf/ghostpdf.h4
-rw-r--r--pdf/pdftop.c2
-rw-r--r--psi/int.mak1
-rw-r--r--psi/zpdfops.c48
5 files changed, 45 insertions, 18 deletions
diff --git a/pdf/ghostpdf.c b/pdf/ghostpdf.c
index 4ce091f4b..048b811b7 100644
--- a/pdf/ghostpdf.c
+++ b/pdf/ghostpdf.c
@@ -576,7 +576,7 @@ int pdfi_close_pdf_file(pdf_context *ctx)
ctx->filename = NULL;
}
- pdfi_clear_context(ctx->memory, ctx);
+ pdfi_clear_context(ctx);
return 0;
}
@@ -1229,7 +1229,7 @@ pdfi_print_cache(pdf_context *ctx)
* called by pdf_free_context (in case of errors during the file leaving state around)
* and by pdfi_close_pdf_file.
*/
-int pdfi_clear_context(gs_memory_t *pmem, pdf_context *ctx)
+int pdfi_clear_context(pdf_context *ctx)
{
#if CACHE_STATISTICS
float compressed_hit_rate = 0.0, hit_rate = 0.0;
@@ -1401,9 +1401,9 @@ int pdfi_clear_context(gs_memory_t *pmem, pdf_context *ctx)
return 0;
}
-int pdfi_free_context(gs_memory_t *pmem, pdf_context *ctx)
+int pdfi_free_context(pdf_context *ctx)
{
- pdfi_clear_context(pmem, ctx);
+ pdfi_clear_context(ctx);
gs_free_object(ctx->memory, ctx->stack_bot, "pdfi_free_context");
diff --git a/pdf/ghostpdf.h b/pdf/ghostpdf.h
index affcf4d62..93bb668c2 100644
--- a/pdf/ghostpdf.h
+++ b/pdf/ghostpdf.h
@@ -508,8 +508,8 @@ typedef struct pdf_context_s
#define OBJ_MEMORY(o) OBJ_CTX(o)->memory
pdf_context *pdfi_create_context(gs_memory_t *pmem);
-int pdfi_clear_context(gs_memory_t *pmem, pdf_context *ctx);
-int pdfi_free_context(gs_memory_t *pmem, pdf_context *ctx);
+int pdfi_clear_context(pdf_context *ctx);
+int pdfi_free_context(pdf_context *ctx);
int pdfi_get_name_index(pdf_context *ctx, char *name, int len, unsigned int *returned);
int pdfi_name_from_index(pdf_context *ctx, int index, unsigned char **name, unsigned int *len);
diff --git a/pdf/pdftop.c b/pdf/pdftop.c
index 989d811a3..6ab511a1f 100644
--- a/pdf/pdftop.c
+++ b/pdf/pdftop.c
@@ -634,7 +634,7 @@ pdf_impl_deallocate_interp_instance(pl_interp_implementation_t *impl)
gs_memory_t *mem = ctx->memory;
int code = 0;
- code = pdfi_free_context(mem, ctx);
+ code = pdfi_free_context(ctx);
gs_free_object(mem, instance, "pdf_impl_deallocate_interp_instance");
diff --git a/psi/int.mak b/psi/int.mak
index ac7dd5dcd..6499f5d9a 100644
--- a/psi/int.mak
+++ b/psi/int.mak
@@ -1810,6 +1810,7 @@ $(PSD)pdfops.dev : $(ECHOGS_XE) $(zpdfops_) $(INT_MAK) $(MAKEDIRS)
$(ADDMOD) $(PSD)pdfops -oper zpdfops
$(PSOBJ)zpdfops.$(OBJ) : $(PSSRC)zpdfops.c $(OP) $(MAKEFILE)\
+ $(ghost_h) $(gsmchunk_h) $(oper_h) \
$(igstate_h) $(istack_h) $(iutil_h) $(gspath_h) $(math__h) $(ialloc_h)\
$(string__h) $(store_h) $(INT_MAK) $(MAKEDIRS)
$(PSCC) $(PSO_)zpdfops.$(OBJ) $(C_) $(PSSRC)zpdfops.c
diff --git a/psi/zpdfops.c b/psi/zpdfops.c
index c0b2e9a9b..df8a23214 100644
--- a/psi/zpdfops.c
+++ b/psi/zpdfops.c
@@ -24,6 +24,7 @@
#endif
#include "ghost.h"
+#include "gsmchunk.h"
#include "oper.h"
#include "igstate.h"
#include "istack.h"
@@ -262,16 +263,24 @@ psi_pdf_end_page(pdf_context *ctx)
static int zdopdffile(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
- pdf_context *ctx;
+ pdf_context *ctx = NULL;
char pdffilename[gp_file_name_sizeof];
int code = 0, code2 = 0;
+ gs_memory_t *cmem;
check_read_type(*op, t_string);
if (r_size(op) > gp_file_name_sizeof - 2)
return_error(gs_error_limitcheck);
- ctx = pdfi_create_context(imemory->non_gc_memory);
- if (ctx == NULL) return_error(gs_error_VMerror);
+ code = gs_memory_chunk_wrap(&cmem, imemory->non_gc_memory);
+ if (code < 0)
+ return_error(gs_error_VMerror);
+
+ ctx = pdfi_create_context(cmem);
+ if (ctx == NULL) {
+ code = gs_note_error(gs_error_VMerror);
+ goto done;
+ }
code = gs_gsave(ctx->pgs);
if (code < 0)
@@ -287,7 +296,10 @@ static int zdopdffile(i_ctx_t *i_ctx_p)
code = pdfi_process_pdf_file(ctx, pdffilename);
code = gs_grestore(ctx->pgs);
done:
- code2 = pdfi_free_context(imemory->non_gc_memory, ctx);
+ if (ctx)
+ code2 = pdfi_free_context(ctx);
+ /* gs_memory_chunk_unwrap() returns the "wrapped" allocator, which we don't need */
+ (void)gs_memory_chunk_unwrap(cmem);
if (code == 0)
code = code2;
@@ -326,7 +338,7 @@ pdfctx_finalize(const gs_memory_t *cmem, void *vptr)
pdfctx_t *pdfctx = vptr;
if (cmem != NULL && pdfctx->ctx != NULL)
- (void)pdfi_free_context(cmem->non_gc_memory, pdfctx->ctx);
+ (void)pdfi_free_context(pdfctx->ctx);
}
static int zPDFstream(i_ctx_t *i_ctx_p)
@@ -399,7 +411,10 @@ static int zPDFclose(i_ctx_t *i_ctx_p)
pdfctx = r_ptr(op, pdfctx_t);
if (pdfctx->ctx != NULL) {
- code = pdfi_free_context(imemory, pdfctx->ctx);
+ gs_memory_t *cmem = pdfctx->ctx->memory;
+ code = pdfi_free_context(pdfctx->ctx);
+ /* gs_memory_chunk_unwrap() returns the "wrapped" allocator, which we don't need */
+ (void)gs_memory_chunk_unwrap(cmem);
pdfctx->ctx = NULL;
}
if (pdfctx->ps_stream) {
@@ -593,7 +608,7 @@ static int zPDFpageinfo(i_ctx_t *i_ctx_p)
return code;
}
- return_error(0);
+ return 0;
}
static int zPDFmetadata(i_ctx_t *i_ctx_p)
@@ -684,11 +699,18 @@ static int zPDFInit(i_ctx_t *i_ctx_p)
pdfctx_t *pdfctx = NULL;
pdf_context *ctx = NULL;
int code = 0;
+ gs_memory_t *cmem;
- ctx = pdfi_create_context(imemory->non_gc_memory);
- if (ctx == NULL)
+ code = gs_memory_chunk_wrap(&cmem, imemory->non_gc_memory);
+ if (code < 0)
return_error(gs_error_VMerror);
+ ctx = pdfi_create_context(cmem);
+ if (ctx == NULL) {
+ code = gs_note_error(gs_error_VMerror);
+ goto error;
+ }
+
pdfctx = gs_alloc_struct(imemory, pdfctx_t, &st_pdfctx_t, "PDFcontext");
if (!pdfctx) {
code = gs_note_error(gs_error_VMerror);
@@ -854,8 +876,12 @@ static int zPDFInit(i_ctx_t *i_ctx_p)
return 0;
error:
- pdfi_free_context(imemory->non_gc_memory, ctx);
- pdfctx->ctx = NULL;
+ if (ctx)
+ pdfi_free_context(ctx);
+ /* gs_memory_chunk_unwrap() returns the "wrapped" allocator, which we don't need */
+ (void)gs_memory_chunk_unwrap(cmem);
+ if (pdfctx)
+ gs_free_object(imemory, pdfctx, "PDFcontext");
return code;
}
#else