diff options
author | Stefan Kemper <stefan.kemper@artifex.com> | 2004-08-04 19:36:13 +0000 |
---|---|---|
committer | Stefan Kemper <stefan.kemper@artifex.com> | 2004-08-04 19:36:13 +0000 |
commit | 6c95585894bbef5272bc99f7504e2304b92d6236 (patch) | |
tree | fad6c41436d9698d33babe98ec7f394de1af6e3d /gs/src | |
parent | 53cf8957cca90409aac0092a899afbc18cae33a1 (diff) |
Addition of a Library Context to start the process of removing globals.
DETAILS :
The goals is to remove globals from the system, this includes static
globals that would hinder multiple threads from running at once.
gs_lib_ctx is intended to be used as the opaque "handle" object
that a client would use to associate with a thread running through
the library. Independent of a gs or a language switch build, this
needs a new iapi2.h that allows the use of better job control from the
client side.
gs_lib_ctx is stashed under the gs_memory_t object and all memory objects
used by a thread refer to the same gs_lib_ctx. This storage location was
choosen as a convenence since a memory_t pointer is common throughout the
system. Most of the turmoil is adding memory_t pointers to functions that
used global variables but didn't have a memory pointer.
FILE stdin, stdout, stderr are one per process by default.
stdin and stdout may be changed but stderr may not.
FILE stderr is one per process and shouldn't be changed.
Note the stderr_fn is also one per process, changing this function pointer
will not help as most users of stderr printing do not have a thread handle.
Changing to a thread local storage mechanism can solve this.
gs_id's are currently per thread with each thread starting over at 1.
This can be moved to per process with mutexes if so desired.
A library context has a pointer to the top_of_system the intent is that this
a void handle avaliable to make top of the system calls without knowing the
data type. In a postscript only build this would be gs_main_instance but
in a language switched build this would be an object above that main_universe.
Other members of gs_lib_ctx_t are nothing more than global objects relocated
to this "bag". gs_name_table, dict_autoexpand are examples of this. There
are a few more globals that will be moved.
At the moment iapi is still constrained to one thread, since some of the
globals haven't been removed yet.
The display device's callback function setting is supported for now
but this interface should be changed to a sDEVICE style call.
gs_memory_t is the base type the abstract type gs_raw_memory_t is gone,
this means that all memory types must derive from gs_memory_t.
In addition to a pointer to the gs_lib_ctx there is a pointer to a
non_gc_memory this will always point to a non garbage collected memory,
it maybe the current object or an object below the current gargabe
collected memory space. This can be used were the previous code
used the global gs_malloc_memory. gs_malloc() now takes a memory pointer,
it finds the non-gc memory from a valid memory pointer and allocates from it.
The gdevbit device has an improved algorthym for converting from cmyk to rgb,
this is never used by postscript but for pcl rops it puts the k plane into rgb.
git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@5215 a1074d23-0009-0410-80fe-cf8c14f379e6
Diffstat (limited to 'gs/src')
217 files changed, 2165 insertions, 1558 deletions
diff --git a/gs/src/bfont.h b/gs/src/bfont.h index 3893c13db..c8b0ca498 100644 --- a/gs/src/bfont.h +++ b/gs/src/bfont.h @@ -49,7 +49,8 @@ typedef enum { } build_font_options_t; /* In zbfont.c */ -int build_proc_name_refs(build_proc_refs * pbuild, +int build_proc_name_refs(const gs_memory_t *mem, + build_proc_refs * pbuild, const char *bcstr, const char *bgstr); int build_gs_font_procs(os_ptr, build_proc_refs *); #define BUILD_BASE_FONT_PROC(proc)\ @@ -75,7 +76,7 @@ int build_gs_sub_font(i_ctx_t *, const ref *, gs_font **, font_type, gs_memory_type_ptr_t, const build_proc_refs *, const ref *, ref *); int define_gs_font(gs_font *); -void get_font_name(ref * pfname, const ref * op); +void get_font_name(const gs_memory_t *mem, ref *pfname, const ref *op); void copy_font_name(gs_font_name * pfstr, const ref * pfname); gs_glyph zfont_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t ignored); gs_char gs_font_map_glyph_to_unicode(gs_font *font, gs_glyph glyph); diff --git a/gs/src/devs.mak b/gs/src/devs.mak index 2ca31d3d3..e9674afa4 100644 --- a/gs/src/devs.mak +++ b/gs/src/devs.mak @@ -790,11 +790,14 @@ pdfwrite_=$(pdfwrite1_) $(pdfwrite2_) $(pdfwrite3_) $(pdfwrite4_)\ $(pdfwrite5_) $(pdfwrite6_) $(pdfwrite7_) $(pdfwrite8_) $(pdfwrite9_)\ $(pdfwrite10_) $(pdfwrite11_) # Including the DSC parser here is clearly wrong: it requires a PostScript -# interpreter. We aren't sure what to do about this yet. +# interpreter. We aren't sure what to do about this yet. +# $(PSD)dscparse.dev\ +# $(ADDMOD) $(DD)pdfwrite -include $(PSD)dscparse + $(DD)pdfwrite.dev : $(DEVS_MAK) $(ECHOGS_XE) $(pdfwrite_)\ $(GLD)cmyklib.dev $(GLD)cfe.dev $(GLD)lzwe.dev\ $(GLD)rle.dev $(GLD)sdcte.dev $(GLD)sdeparam.dev $(GLD)smd5.dev\ - $(GLD)szlibe.dev $(GLD)psdf.dev $(PSD)dscparse.dev\ + $(GLD)szlibe.dev $(GLD)psdf.dev \ $(DD)pdtext.dev $(SETDEV2) $(DD)pdfwrite $(pdfwrite1_) $(ADDMOD) $(DD)pdfwrite $(pdfwrite2_) @@ -812,7 +815,6 @@ $(DD)pdfwrite.dev : $(DEVS_MAK) $(ECHOGS_XE) $(pdfwrite_)\ $(ADDMOD) $(DD)pdfwrite -include $(GLD)rle $(GLD)sdcte $(GLD)sdeparam $(ADDMOD) $(DD)pdfwrite -include $(GLD)smd5 $(GLD)szlibe $(ADDMOD) $(DD)pdfwrite -include $(GLD)psdf - $(ADDMOD) $(DD)pdfwrite -include $(PSD)dscparse $(ADDMOD) $(DD)pdfwrite -include $(DD)pdtext gdevpdfc_h=$(GLSRC)gdevpdfc.h @@ -1063,6 +1065,10 @@ $(DD)bitcmyk.dev : $(DEVS_MAK) $(bit_) $(GLD)page.dev $(GLD)cielib.dev $(SETPDEV2) $(DD)bitcmyk $(bit_) $(ADDMOD) $(DD)bitcmyk -include $(GLD)cielib +$(DD)bitrgbtags.dev : $(DEVS_MAK) $(bit_) $(GLD)page.dev $(GLD)cielib.dev + $(SETPDEV2) $(DD)bitrgbtags $(bit_) + $(ADDMOD) $(DD)bitrgbtags -include $(GLD)cielib + $(GLOBJ)gdevbit.$(OBJ) : $(GLSRC)gdevbit.c $(PDEVH) $(math__h)\ $(gdevdcrd_h) $(gscrd_h) $(gscrdp_h) $(gsparam_h) $(gxlum_h) $(GLCC) $(GLO_)gdevbit.$(OBJ) $(C_) $(GLSRC)gdevbit.c diff --git a/gs/src/dstack.h b/gs/src/dstack.h index 26a3be1c1..ceab926df 100644 --- a/gs/src/dstack.h +++ b/gs/src/dstack.h @@ -64,7 +64,7 @@ /* Name lookup */ #define dict_find_name_by_index(nidx)\ dstack_find_name_by_index(&idict_stack, nidx) -#define dict_find_name(pnref) dict_find_name_by_index(name_index(pnref)) +#define dict_find_name(pnref) dict_find_name_by_index(name_index(imemory, pnref)) #define dict_find_name_by_index_inline(nidx, htemp)\ dstack_find_name_by_index_inline(&idict_stack, nidx, htemp) #define if_dict_find_name_by_index_top(nidx, htemp, pvslot)\ diff --git a/gs/src/files.h b/gs/src/files.h index ae752acd4..1dad2aaa8 100644 --- a/gs/src/files.h +++ b/gs/src/files.h @@ -37,7 +37,6 @@ int zget_stdin(i_ctx_t *, stream **); int zget_stdout(i_ctx_t *, stream **); int zget_stderr(i_ctx_t *, stream **); -extern bool gs_stdin_is_interactive; /* Test whether a stream is stdin. */ bool zis_stdin(const stream *); @@ -115,13 +114,18 @@ int file_switch_to_write(const ref *); /* for zfilter.c and ziodev.c */ extern const uint file_default_buffer_size; +#ifndef gs_file_path_ptr_DEFINED +# define gs_file_path_ptr_DEFINED +typedef struct gs_file_path_s *gs_file_path_ptr; +#endif + /* Procedures exported by zfile.c. */ /* for imainarg.c */ -FILE *lib_fopen(const char *); +FILE *lib_fopen(const gs_file_path_ptr pfpath, const gs_memory_t *mem, const char *); /* for imain.c */ -int lib_file_open(i_ctx_t *, const char *, uint, byte *, uint, - uint *, ref *, gs_memory_t *); +int lib_file_open(const gs_file_path_ptr pfpath, i_ctx_t *, const char *, uint, byte *, uint, + uint *, ref *, gs_memory_t *); /* for imain.c */ #ifndef gs_ref_memory_DEFINED diff --git a/gs/src/gdevbj10.c b/gs/src/gdevbj10.c index 5c3eed365..e1cb5efe7 100644 --- a/gs/src/gdevbj10.c +++ b/gs/src/gdevbj10.c @@ -260,8 +260,8 @@ bj10e_print_page(gx_device_printer *pdev, FILE *prn_stream) int bytes_per_column = (yres == 180) ? 3 : 6; int bits_per_column = bytes_per_column * 8; int skip_unit = bytes_per_column * 3; - byte *in = (byte *)gs_malloc(8, line_size, "bj10e_print_page(in)"); - byte *out = (byte *)gs_malloc(bits_per_column, line_size, "bj10e_print_page(out)"); + byte *in = (byte *)gs_malloc(pdev->memory, 8, line_size, "bj10e_print_page(in)"); + byte *out = (byte *)gs_malloc(pdev->memory, bits_per_column, line_size, "bj10e_print_page(out)"); int lnum = 0; int skip = 0; int code = 0; @@ -442,9 +442,9 @@ notz: ; xit: fputc(014, prn_stream); /* form feed */ fflush(prn_stream); fin: if ( out != 0 ) - gs_free((char *)out, bits_per_column, line_size, + gs_free(pdev->memory, (char *)out, bits_per_column, line_size, "bj10e_print_page(out)"); if ( in != 0 ) - gs_free((char *)in, 8, line_size, "bj10e_print_page(in)"); + gs_free(pdev->memory, (char *)in, 8, line_size, "bj10e_print_page(in)"); return code; } diff --git a/gs/src/gdevcdj.c b/gs/src/gdevcdj.c index bb88872d1..044ec0b66 100644 --- a/gs/src/gdevcdj.c +++ b/gs/src/gdevcdj.c @@ -2047,10 +2047,10 @@ hp_colour_print_page(gx_device_printer * pdev, FILE * prn_stream, int ptype) storage_size_words = ((plane_size + plane_size) * num_comps + databuff_size + errbuff_size + outbuff_size) / W; - storage = (ulong *) gs_malloc(storage_size_words, W, "hp_colour_print_page"); + storage = (ulong *) gs_malloc(pdev->memory, storage_size_words, W, "hp_colour_print_page"); ep_storage_size_words = (plane_size * (num_comps + 1)) / W * img_rows + 16; /* Redundant space for sentinel and aligning. */ - ep_storage = (word *) gs_malloc(ep_storage_size_words, W, "ep_print_buffer"); + ep_storage = (word *) gs_malloc(pdev->memory, ep_storage_size_words, W, "ep_print_buffer"); /* * The principal data pointers are stored as pairs of values, with @@ -2660,8 +2660,8 @@ hp_colour_print_page(gx_device_printer * pdev, FILE * prn_stream, int ptype) fputs("\033&l0H", prn_stream); /* free temporary storage */ - gs_free((char *) ep_storage, ep_storage_size_words, W, "ep_print_buffer"); - gs_free((char *) storage, storage_size_words, W, "hp_colour_print_page"); + gs_free(pdev->memory, (char *) ep_storage, ep_storage_size_words, W, "ep_print_buffer"); + gs_free(pdev->memory, (char *) storage, storage_size_words, W, "hp_colour_print_page"); return 0; } diff --git a/gs/src/gdevdcrd.c b/gs/src/gdevdcrd.c index dcdb70122..931d9be6f 100644 --- a/gs/src/gdevdcrd.c +++ b/gs/src/gdevdcrd.c @@ -133,7 +133,7 @@ sample_device_crd_get_params(gx_device *pdev, gs_param_list *plist, tpqr = bit_TransformPQR; tpqr.driver_name = pdev->dname; - code = gs_cie_render1_initialize(pcrd, NULL, + code = gs_cie_render1_initialize(pdev->memory, pcrd, NULL, &bit_WhitePoint, NULL /*BlackPoint*/, NULL /*MatrixPQR*/, &bit_RangePQR, &tpqr, NULL /*MatrixLMN*/, &bit_EncodeLMN, &bit_RangeLMN, diff --git a/gs/src/gdevepsc.c b/gs/src/gdevepsc.c index 07293304d..25e68ba41 100644 --- a/gs/src/gdevepsc.c +++ b/gs/src/gdevepsc.c @@ -153,9 +153,9 @@ epsc_print_page(gx_device_printer *pdev, FILE *prn_stream) int y_mult = (y_24pin ? 3 : 1); int line_size = (pdev->width + 7) >> 3; /* always mono */ int in_size = line_size * (8 * y_mult); - byte *in = (byte *)gs_malloc(in_size+1, 1, "epsc_print_page(in)"); + byte *in = (byte *)gs_malloc(pdev->memory, in_size+1, 1, "epsc_print_page(in)"); int out_size = ((pdev->width + 7) & -8) * y_mult; - byte *out = (byte *)gs_malloc(out_size+1, 1, "epsc_print_page(out)"); + byte *out = (byte *)gs_malloc(pdev->memory, out_size+1, 1, "epsc_print_page(out)"); int x_dpi = (int)pdev->x_pixels_per_inch; char start_graphics = (char) ((y_24pin ? graphics_modes_24 : graphics_modes_9)[x_dpi / 60]); @@ -172,8 +172,8 @@ epsc_print_page(gx_device_printer *pdev, FILE *prn_stream) /* Check allocations */ if ( in == 0 || out == 0 ) - { if ( in ) gs_free((char *)in, in_size+1, 1, "epsc_print_page(in)"); - if ( out ) gs_free((char *)out, out_size+1, 1, "epsc_print_page(out)"); + { if ( in ) gs_free(pdev->memory, (char *)in, in_size+1, 1, "epsc_print_page(in)"); + if ( out ) gs_free(pdev->memory, (char *)out, out_size+1, 1, "epsc_print_page(out)"); return -1; } @@ -185,13 +185,13 @@ epsc_print_page(gx_device_printer *pdev, FILE *prn_stream) { color_line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev); color_in_size = color_line_size * (8 * y_mult); - if((color_in = (byte *)gs_malloc(color_in_size+1, 1, - "epsc_print_page(color)")) == 0) - { - gs_free((char *)in, in_size+1, 1, "epsc_print_page(in)"); - gs_free((char *)out, out_size+1, 1, "epsc_print_page(out)"); + if((color_in = (byte *)gs_malloc(pdev->memory, color_in_size+1, 1, + "epsc_print_page(color)")) == 0) + { + gs_free(pdev->memory, (char *)in, in_size+1, 1, "epsc_print_page(in)"); + gs_free(pdev->memory, (char *)out, out_size+1, 1, "epsc_print_page(out)"); return(-1); - } + } } else { @@ -417,10 +417,10 @@ epsc_print_page(gx_device_printer *pdev, FILE *prn_stream) fputs("\f\033@", prn_stream); - gs_free((char *)out, out_size+1, 1, "epsc_print_page(out)"); - gs_free((char *)in, in_size+1, 1, "epsc_print_page(in)"); + gs_free(pdev->memory, (char *)out, out_size+1, 1, "epsc_print_page(out)"); + gs_free(pdev->memory, (char *)in, in_size+1, 1, "epsc_print_page(in)"); if (gx_device_has_color(pdev)) - gs_free((char *)color_in, color_in_size+1, 1, "epsc_print_page(rin)"); + gs_free(pdev->memory, (char *)color_in, color_in_size+1, 1, "epsc_print_page(rin)"); return 0; } diff --git a/gs/src/gdevepsn.c b/gs/src/gdevepsn.c index bc731170e..7d976ca80 100644 --- a/gs/src/gdevepsn.c +++ b/gs/src/gdevepsn.c @@ -161,8 +161,8 @@ eps_print_page(gx_device_printer *pdev, FILE *prn_stream, int y_9pin_high, int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev); /* Note that in_size is a multiple of 8. */ int in_size = line_size * (8 * in_y_mult); - byte *buf1 = (byte *)gs_malloc(in_size, 1, "eps_print_page(buf1)"); - byte *buf2 = (byte *)gs_malloc(in_size, 1, "eps_print_page(buf2)"); + byte *buf1 = (byte *)gs_malloc(pdev->memory, in_size, 1, "eps_print_page(buf1)"); + byte *buf2 = (byte *)gs_malloc(pdev->memory, in_size, 1, "eps_print_page(buf2)"); byte *in = buf1; byte *out = buf2; int out_y_mult = (y_24pin ? 3 : 1); @@ -180,9 +180,9 @@ eps_print_page(gx_device_printer *pdev, FILE *prn_stream, int y_9pin_high, /* Check allocations */ if ( buf1 == 0 || buf2 == 0 ) { if ( buf1 ) - gs_free((char *)buf1, in_size, 1, "eps_print_page(buf1)"); + gs_free(pdev->memory, (char *)buf1, in_size, 1, "eps_print_page(buf1)"); if ( buf2 ) - gs_free((char *)buf2, in_size, 1, "eps_print_page(buf2)"); + gs_free(pdev->memory, (char *)buf2, in_size, 1, "eps_print_page(buf2)"); return_error(gs_error_VMerror); } @@ -393,8 +393,8 @@ eps_print_page(gx_device_printer *pdev, FILE *prn_stream, int y_9pin_high, fputs(end_string, prn_stream); fflush(prn_stream); - gs_free((char *)buf2, in_size, 1, "eps_print_page(buf2)"); - gs_free((char *)buf1, in_size, 1, "eps_print_page(buf1)"); + gs_free(pdev->memory, (char *)buf2, in_size, 1, "eps_print_page(buf2)"); + gs_free(pdev->memory, (char *)buf1, in_size, 1, "eps_print_page(buf1)"); return 0; } diff --git a/gs/src/gdevijs.c b/gs/src/gdevijs.c index 758ff2761..52230066b 100644 --- a/gs/src/gdevijs.c +++ b/gs/src/gdevijs.c @@ -588,18 +588,18 @@ gsijs_close(gx_device *dev) code = gdev_prn_close(dev); if (ijsdev->IjsParams) - gs_free(ijsdev->IjsParams, ijsdev->IjsParams_size, 1, + gs_free(dev->memory, ijsdev->IjsParams, ijsdev->IjsParams_size, 1, "gsijs_read_string_malloc"); if (ijsdev->ColorSpace) - gs_free(ijsdev->ColorSpace, + gs_free(dev->memory, ijsdev->ColorSpace, ijsdev->ColorSpace_size, 1, "gsijs_read_string_malloc"); if (ijsdev->DeviceManufacturer) - gs_free(ijsdev->DeviceManufacturer, + gs_free(dev->memory, ijsdev->DeviceManufacturer, ijsdev->DeviceManufacturer_size, 1, "gsijs_read_string_malloc"); if (ijsdev->DeviceModel) - gs_free(ijsdev->DeviceModel, ijsdev->DeviceModel_size, 1, + gs_free(dev->memory, ijsdev->DeviceModel, ijsdev->DeviceModel_size, 1, "gsijs_read_string_malloc"); ijsdev->IjsParams = NULL; ijsdev->IjsParams_size = 0; @@ -916,11 +916,11 @@ gsijs_read_string_malloc(gs_param_list *plist, gs_param_name pname, char **str, } if (new_value.size >= *size) { if (*str) - gs_free(str, *size, 1, "gsijs_read_string_malloc"); + gs_free(plist->memory, str, *size, 1, "gsijs_read_string_malloc"); *str = NULL; *size = 0; } - *str = gs_malloc(new_value.size + 1, 1, + *str = gs_malloc(plist->memory, new_value.size + 1, 1, "gsijs_read_string_malloc"); if (*str == NULL) { code = gs_note_error(gs_error_VMerror); diff --git a/gs/src/gdevp14.c b/gs/src/gdevp14.c index 3cd674c94..bd16f2df4 100644 --- a/gs/src/gdevp14.c +++ b/gs/src/gdevp14.c @@ -839,7 +839,7 @@ pdf14_put_image(pdf14_device *pdev, gs_state *pgs, gx_device *target) /* Set color space to RGB, in preparation for sending an RGB image. */ gs_setrgbcolor(pgs, 0, 0, 0); - gs_cspace_init_DeviceRGB(&cs); + gs_cspace_init_DeviceRGB(pgs->memory, &cs); gx_set_dev_color(pgs); gs_image_t_init_adjust(&image, &cs, false); image.ImageMatrix.xx = (float)width; diff --git a/gs/src/gdevpdfb.c b/gs/src/gdevpdfb.c index 589b2280c..65e8eb8cf 100644 --- a/gs/src/gdevpdfb.c +++ b/gs/src/gdevpdfb.c @@ -183,10 +183,10 @@ pdf_copy_mono(gx_device_pdf *pdev, &pdev->fill_used_process_color, &psdf_set_fill_color_commands); } else if (zero == pdev->black && one == pdev->white) { - gs_cspace_init_DeviceGray(&cs); + gs_cspace_init_DeviceGray(pdev->memory, &cs); gs_image_t_init(&image, &cs); } else if (zero == pdev->white && one == pdev->black) { - gs_cspace_init_DeviceGray(&cs); + gs_cspace_init_DeviceGray(pdev->memory, &cs); gs_image_t_init(&image, &cs); invert = 0xff; } else { @@ -202,12 +202,12 @@ pdf_copy_mono(gx_device_pdf *pdev, int ncomp = pdev->color_info.num_components; byte *p; - code = pdf_cspace_init_Device(&cs_base, ncomp); + code = pdf_cspace_init_Device(pdev->memory, &cs_base, ncomp); if (code < 0) return code; c[0] = psdf_adjust_color_index((gx_device_vector *)pdev, zero); c[1] = psdf_adjust_color_index((gx_device_vector *)pdev, one); - gs_cspace_init(&cs, &gs_color_space_type_Indexed, NULL); + gs_cspace_init(&cs, &gs_color_space_type_Indexed, pdev->memory, false); cs.params.indexed.base_space = *(gs_direct_color_space *)&cs_base; cs.params.indexed.hival = 1; p = palette; @@ -342,7 +342,7 @@ pdf_copy_color_data(gx_device_pdf * pdev, const byte * base, int sourcex, gs_color_space cs; cos_value_t cs_value; ulong nbytes; - int code = pdf_cspace_init_Device(&cs, bytes_per_pixel); + int code = pdf_cspace_init_Device(pdev->memory, &cs, bytes_per_pixel); const byte *row_base; int row_step; bool in_line; diff --git a/gs/src/gdevpdfc.c b/gs/src/gdevpdfc.c index 061dfcfe8..00735033e 100644 --- a/gs/src/gdevpdfc.c +++ b/gs/src/gdevpdfc.c @@ -321,12 +321,12 @@ const pdf_color_space_names_t pdf_color_space_names_short = { * given number of components. */ int -pdf_cspace_init_Device(gs_color_space *pcs, int num_components) +pdf_cspace_init_Device(const gs_memory_t *mem, gs_color_space *pcs, int num_components) { switch (num_components) { - case 1: gs_cspace_init_DeviceGray(pcs); break; - case 3: gs_cspace_init_DeviceRGB(pcs); break; - case 4: gs_cspace_init_DeviceCMYK(pcs); break; + case 1: gs_cspace_init_DeviceGray(mem, pcs); break; + case 3: gs_cspace_init_DeviceRGB(mem, pcs); break; + case 4: gs_cspace_init_DeviceCMYK(mem, pcs); break; default: return_error(gs_error_rangecheck); } return 0; @@ -450,7 +450,7 @@ pdf_indexed_color_space(gx_device_pdf *pdev, cos_value_t *pvalue, for (i = 0; i < num_entries; ++i) palette[i] = palette[i * 3]; table_size = num_entries; - gs_cspace_init_DeviceGray(&cs_gray); + gs_cspace_init_DeviceGray(mem, &cs_gray); base_space = &cs_gray; } } @@ -788,7 +788,8 @@ pdf_color_space_named(gx_device_pdf *pdev, cos_value_t *pvalue, return_error(gs_error_VMerror); for (i = 0; i < pcs->params.device_n.num_components; ++i) { if ((code = pcs->params.device_n.get_colorname_string( - pcs->params.device_n.names[i], &name_string, + pdev->memory, + pcs->params.device_n.names[i], &name_string, &name_string_length)) < 0 || (code = pdf_string_to_cos_name(pdev, name_string, name_string_length, &v)) < 0 || @@ -813,6 +814,7 @@ pdf_color_space_named(gx_device_pdf *pdev, cos_value_t *pvalue, byte *name_string; uint name_string_length; if ((code = pcs->params.separation.get_colorname_string( + pdev->memory, pcs->params.separation.sep_name, &name_string, &name_string_length)) < 0 || (code = pdf_string_to_cos_name(pdev, name_string, diff --git a/gs/src/gdevpdfg.c b/gs/src/gdevpdfg.c index 5e94d39ae..eade4ecb6 100644 --- a/gs/src/gdevpdfg.c +++ b/gs/src/gdevpdfg.c @@ -1036,7 +1036,7 @@ pdf_write_multiple_halftone(gx_device_pdf *pdev, done_Default = true; } phtc = &pmht->components[code]; - if ((code = pmht->get_colorname_string(phtc->cname, &str, &len)) < 0 || + if ((code = pmht->get_colorname_string(pdev->memory, phtc->cname, &str, &len)) < 0 || (code = pdf_string_to_cos_name(pdev, str, len, &value)) < 0) return code; cos_value_write(&value, pdev); diff --git a/gs/src/gdevpdfg.h b/gs/src/gdevpdfg.h index 0b475d919..96a4af0eb 100644 --- a/gs/src/gdevpdfg.h +++ b/gs/src/gdevpdfg.h @@ -71,7 +71,7 @@ struct pdf_color_space_s { * Create a local Device{Gray,RGB,CMYK} color space corresponding to the * given number of components. */ -int pdf_cspace_init_Device(gs_color_space *pcs, int num_components); +int pdf_cspace_init_Device(const gs_memory_t *mem, gs_color_space *pcs, int num_components); /* * Create a PDF color space corresponding to a PostScript color space. diff --git a/gs/src/gdevpdfi.c b/gs/src/gdevpdfi.c index e3a25feb9..d88a48f7d 100644 --- a/gs/src/gdevpdfi.c +++ b/gs/src/gdevpdfi.c @@ -384,7 +384,7 @@ pdf_begin_typed_image(gx_device_pdf *pdev, const gs_imager_state * pis, * color space, which pdf_color_space() can't handle. Patch it * to DeviceGray here. */ - gs_cspace_init_DeviceGray(&cs_gray_temp); + gs_cspace_init_DeviceGray(pdev->memory, &cs_gray_temp); pcs = &cs_gray_temp; } else if (is_mask) code = pdf_prepare_imagemask(pdev, pis, pdcolor); diff --git a/gs/src/gdevpdfk.c b/gs/src/gdevpdfk.c index 7b0a096a3..a012ddca9 100644 --- a/gs/src/gdevpdfk.c +++ b/gs/src/gdevpdfk.c @@ -612,7 +612,7 @@ pdf_convert_cie_to_iccbased(gx_device_pdf *pdev, cos_array_t *pca, profile_table_t tables[MAX_NUM_TABLES]; profile_table_t *next_table = tables; - pdf_cspace_init_Device(&alt_space, ncomps); /* can't fail */ + pdf_cspace_init_Device(pdev->memory, &alt_space, ncomps); /* can't fail */ code = pdf_make_iccbased(pdev, pca, ncomps, prange, &alt_space, &pcstrm, pprange); if (code < 0) diff --git a/gs/src/gdevpdfv.c b/gs/src/gdevpdfv.c index 9bcadcd70..3c17542e6 100644 --- a/gs/src/gdevpdfv.c +++ b/gs/src/gdevpdfv.c @@ -421,7 +421,7 @@ pdf_put_colored_pattern(gx_device_pdf *pdev, const gx_drawing_color *pdc, code = pdf_cs_Pattern_colored(pdev, &v); if (code < 0) return code; - pdf_cspace_init_Device(&cs_Device, pdev->color_info.num_components); + pdf_cspace_init_Device(pdev->memory, &cs_Device, pdev->color_info.num_components); /* * We don't have to worry about color space scaling: the color * space is always a Device space. diff --git a/gs/src/gdevpdti.c b/gs/src/gdevpdti.c index 981e945f4..563689844 100644 --- a/gs/src/gdevpdti.c +++ b/gs/src/gdevpdti.c @@ -385,8 +385,8 @@ pdf_start_charproc_accum(gx_device_pdf *pdev) { pdf_char_proc_t *pcp; pdf_resource_t *pres; - int code = pdf_enter_substream(pdev, resourceCharProc, gs_next_ids(1), &pres, - false, pdev->CompressFonts); + int code = pdf_enter_substream(pdev, resourceCharProc, gs_next_ids(pdev->memory, 1), + &pres, false, pdev->CompressFonts); if (code < 0) return code; diff --git a/gs/src/gdevplnx.c b/gs/src/gdevplnx.c index f6c0b2a00..784b4b9df 100644 --- a/gs/src/gdevplnx.c +++ b/gs/src/gdevplnx.c @@ -985,7 +985,7 @@ plane_begin_typed_image(gx_device * dev, *((gx_image_enum_common_t *)info) = *info->info; info->procs = &plane_image_enum_procs; info->dev = (gx_device *)edev; - info->id = gs_next_ids(1); + info->id = gs_next_ids(memory, 1); info->memory = memory; info->pis = pis; info->pis_image = pis_image; diff --git a/gs/src/gdevprn.c b/gs/src/gdevprn.c index 361e46cbe..1b565c476 100644 --- a/gs/src/gdevprn.c +++ b/gs/src/gdevprn.c @@ -141,7 +141,7 @@ open_c: clist_init_params(pclist_dev, base, space, pdev, ppdev->printer_procs.buf_procs, space_params->band, ppdev->is_async_renderer, - (ppdev->bandlist_memory == 0 ? &gs_memory_default : + (ppdev->bandlist_memory == 0 ? pdev->memory->non_gc_memory: ppdev->bandlist_memory), ppdev->free_up_bandlist_memory, ppdev->clist_disable_mask); @@ -227,7 +227,7 @@ gdev_prn_allocate(gx_device *pdev, gdev_prn_space_params *new_space_params, int ecode = 0; int pass; gs_memory_t *buffer_memory = - (ppdev->buffer_memory == 0 ? &gs_memory_default : + (ppdev->buffer_memory == 0 ? pdev->memory->non_gc_memory : ppdev->buffer_memory); /* If reallocate, find allocated memory & tear down buffer device */ @@ -307,7 +307,7 @@ gdev_prn_allocate(gx_device *pdev, gdev_prn_space_params *new_space_params, the_memory = base; } if (!is_command_list && pass == 1 && PRN_MIN_MEMORY_LEFT != 0 - && buffer_memory == &gs_memory_default) { + && buffer_memory == pdev->memory->non_gc_memory) { /* before using full memory buffer, ensure enough working mem left */ byte * left = gs_alloc_bytes( buffer_memory, PRN_MIN_MEMORY_LEFT, "printer mem left"); @@ -433,7 +433,7 @@ gdev_prn_free_memory(gx_device *pdev) gx_device_printer * const ppdev = (gx_device_printer *)pdev; byte *the_memory = 0; gs_memory_t *buffer_memory = - (ppdev->buffer_memory == 0 ? &gs_memory_default : + (ppdev->buffer_memory == 0 ? pdev->memory->non_gc_memory : ppdev->buffer_memory); gdev_prn_tear_down(pdev, &the_memory); diff --git a/gs/src/gdevprna.c b/gs/src/gdevprna.c index 541977eb4..82360a1b2 100644 --- a/gs/src/gdevprna.c +++ b/gs/src/gdevprna.c @@ -99,7 +99,7 @@ gdev_prn_async_write_open(gx_device_printer * pwdev, int max_raster, /* The * 2's in the next statement are a ****** HACK ****** to deal with */ /* sandbars in the memory manager. */ if ((code = alloc_render_memory(&render_memory, - &gs_memory_default, RendererAllocationOverheadBytes + max_raster + pwdev->memory->non_gc_memory, RendererAllocationOverheadBytes + max_raster /* the first * 2 is not a hack */ + (max_raster + sizeof(void *) * 2) * min_band_height + max_src_image_row + gx_ht_cache_default_bits() * 2)) < 0) @@ -109,7 +109,7 @@ gdev_prn_async_write_open(gx_device_printer * pwdev, int max_raster, /* Bandlist mem is threadsafe & common to rdr/wtr, so it's used */ /* for page queue & cmd list buffers. */ if ((code = alloc_bandlist_memory - (&pwdev->bandlist_memory, &gs_memory_default)) < 0) + (&pwdev->bandlist_memory, pwdev->memory->non_gc_memory)) < 0) goto open_err; /* Dictate banding parameters for both renderer & writer */ @@ -173,7 +173,7 @@ gdev_prn_async_write_open(gx_device_printer * pwdev, int max_raster, prdev->page_queue = pwdev->page_queue; /* Start renderer thread & wait for its successful open of device */ - if (!(open_semaphore = gx_semaphore_alloc(&gs_memory_default))) + if (!(open_semaphore = gx_semaphore_alloc(prdev->memory))) code = gs_note_error(gs_error_VMerror); else { gdev_prn_start_render_params thread_params; @@ -192,7 +192,7 @@ gdev_prn_async_write_open(gx_device_printer * pwdev, int max_raster, /* ----- Set the recovery procedure for the mem allocator ----- */ if (code >= 0) { gs_memory_retrying_set_recover( - (gs_memory_retrying_t *)&gs_memory_default, + (gs_memory_retrying_t *)pwdev->memory->non_gc_memory, prna_mem_recover, (void *)pcwdev ); @@ -759,7 +759,7 @@ alloc_render_memory(gs_memory_t **final_allocator, gs_memory_t *base_allocator, long space) { gs_ref_memory_t *rmem = - ialloc_alloc_state((gs_raw_memory_t *)base_allocator, space); + ialloc_alloc_state((gs_memory_t *)base_allocator, space); vm_spaces spaces; int i, code; diff --git a/gs/src/gdevpsdi.c b/gs/src/gdevpsdi.c index 86316d2b8..10f5245c5 100644 --- a/gs/src/gdevpsdi.c +++ b/gs/src/gdevpsdi.c @@ -122,8 +122,9 @@ setup_image_compression(psdf_binary_writer *pbw, const psdf_image_params *pdip, } dict = pdip->ACSDict; } else if (!lossless) - return gs_error_rangecheck; /* Reject the alternative stream. */ - gs_c_param_list_read(dict); /* ensure param list is in read mode */ + return gs_error_rangecheck; /* Reject the alternative stream. */ + if (dict) /* NB: rather than dereference NULL lets continue on without a dict */ + gs_c_param_list_read(dict); /* ensure param list is in read mode */ if (template == 0) /* no compression */ return 0; if (pim->Width < 200 && pim->Height < 200) /* Prevent a fixed overflow. */ @@ -367,7 +368,7 @@ psdf_setup_image_filters(gx_device_psdf * pdev, psdf_binary_writer * pbw, gs_color_space *rgb_cs = gs_alloc_struct(mem, gs_color_space, &st_color_space, "psdf_setup_image_filters"); - gs_cspace_init_DeviceRGB(rgb_cs); /* idempotent initialization */ + gs_cspace_init_DeviceRGB(mem, rgb_cs); /* idempotent initialization */ pim->ColorSpace = rgb_cs; } if (params.Depth == -1) diff --git a/gs/src/gdevpxat.h b/gs/src/gdevpxat.h index 140985528..f5bd69c14 100644 --- a/gs/src/gdevpxat.h +++ b/gs/src/gdevpxat.h @@ -43,7 +43,11 @@ typedef enum { pxaCRGBMinMax, /* 2.0 */ pxaGammaGain, /* 2.0 */ - pxaDeviceMatrix = 33, + pxaAllObjectTypes = 29, /* 3.0 */ + pxaTextObjects, /* 3.0 */ + pxaVectorObjects, /* 3.0 */ + pxaRasterObjects, /* 3.0 */ + pxaDeviceMatrix, pxaDitherMatrixDataType, pxaDitherOrigin, pxaMediaDestination, @@ -104,6 +108,8 @@ typedef enum { pxaNumberOfScanLines = 115, + pxaColorTreatment = 120, + pxaCommentData = 129, pxaDataOrg, @@ -116,6 +122,8 @@ typedef enum { pxaStreamDataLength, pxaErrorReport = 143, + pxaVUExtension = 145, + pxaVUAttr1 = 147, pxaCharAngle = 161, pxaCharCode, @@ -129,8 +137,7 @@ typedef enum { pxaSymbolSet, pxaTextData, pxaCharSubModeArray, - pxaWritingMode, /* 2.0 */ - + pxaWritingMode, pxaXSpacingData = 175, pxaYSpacingData, pxaCharBoldValue, diff --git a/gs/src/gdevpxen.h b/gs/src/gdevpxen.h index 9e879775a..0e302493c 100644 --- a/gs/src/gdevpxen.h +++ b/gs/src/gdevpxen.h @@ -75,6 +75,7 @@ typedef enum { eNoCompression = 0, eRLECompression, eJPEGCompression, /* 2.0 */ + eDeltaRowCompression, /* 2.1 */ pxeCompressMode_next } pxeCompressMode_t; @@ -182,11 +183,16 @@ typedef enum { eJB4Paper, eJB5Paper, eB5Envelope, + eB5Paper, /* 2.1 */ eJPostcard, eJDoublePostcard, eA5Paper, eA6Paper, /* 2.0 */ eJB6Paper, /* 2.0 */ + eJIS8K, /* 2.1 */ + eJIS16K, /* 2.1 */ + eJISExec, /* 2.1 */ + eDefaultPaperSize = 96, /* 2.1 */ pxeMediaSize_next } pxeMediaSize_t; @@ -196,6 +202,7 @@ typedef enum { * media size code, resolution for width/height, width, height. */ #define px_enumerate_media(m)\ + m(eDefaultPaperSize, -1, -1, -1)\ m(eLetterPaper, 300, 2550, 3300)\ m(eLegalPaper, 300, 2550, 5300)\ m(eA4Paper, 300, 2480, 3507)\ @@ -206,7 +213,18 @@ typedef enum { m(eMonarchEnvelope, 300, 1162, 2250)\ m(eC5Envelope, 300, 1913, 2704)\ m(eDLEnvelope, 300, 1299, 2598)\ - m(eB5Envelope, 300, 2078, 2952) + m(eJB4Paper, -1, -1, -1)\ + m(eJB5Paper, -1, -1, -1)\ + m(eB5Envelope, 300, 2078, 2952)\ + m(eB5Paper, -1, -1, -1)\ + m(eJPostcard, -1, -1, -1)\ + m(eJDoublePostcard, -1, -1, -1)\ + m(eA5Paper,-1, -1, -1)\ + m(eA6Paper,-1, -1, -1)\ + m(eJB6Paper,-1, -1, -1)\ + m(eJIS8K, -1, -1, -1)\ + m(eJIS16K, -1, -1, -1)\ + m(eJISExec, -1, -1, -1) typedef enum { eDefaultSource = 0, @@ -216,7 +234,7 @@ typedef enum { eUpperCassette, eLowerCassette, eEnvelopeTray, - eThirdCassette, /* 2.0 */ + eThirdCassette, pxeMediaSource_next } pxeMediaSource_t; @@ -231,6 +249,7 @@ typedef enum { eLandscapeOrientation, eReversePortrait, eReverseLandscape, + eDefaultOrientation, /* 2.1 */ pxeOrientation_next } pxeOrientation_t; @@ -258,4 +277,42 @@ typedef enum { pxeWritingMode_next } pxeWritingMode_t; /* 2.0 */ +/* the following 4 enumerations are new with XL 3.0 */ + +typedef enum { + eDisableAH = 0, /* the documentation uses a eDisable here and in + Trapping - add AH to avoid duplicate + identifier. */ + eEnableAH, + pxeAdaptive_Halftoning_next +} pxeAdaptiveHalftone_t; + +typedef enum { + eHighLPI = 0, + eMediumLPI, + eLowLPI, + pxeeHalftoneMethod_next +} pxeHalftoneMethod_t; + +typedef enum { + eDisableCT = 0, + eMax, + eNormal, + eLight, + pxeColorTrapping_next +} pxeColorTrapping_t; + +typedef enum { + eTonerBlack = 0, + eProcessBlack, + pxeNeutralAxis_next +} pxeNeutralAxis_t; + +typedef enum { + eNoTreatment = 0, + eScreenMatch, + eVivid, + pxeColorTreatment_next +} pxeColorTreatment; + #endif /* gdevpxen_INCLUDED */ diff --git a/gs/src/gdevstc.c b/gs/src/gdevstc.c index 9fbe24ce4..799b018e3 100644 --- a/gs/src/gdevstc.c +++ b/gs/src/gdevstc.c @@ -275,9 +275,9 @@ stc_print_setup(stcolor_device *sd) if(need != sd->stc.escp_init.size) { /* Reallocate */ - if(NULL != (bp = gs_malloc(need,1,"stcolor/init"))) { /* Replace */ + if(NULL != (bp = gs_malloc(sd->memory, need,1,"stcolor/init"))) { /* Replace */ if(0 != sd->stc.escp_init.size) - gs_free((byte *)sd->stc.escp_init.data,sd->stc.escp_init.size,1, + gs_free(sd->memory, (byte *)sd->stc.escp_init.data,sd->stc.escp_init.size,1, "stcolor/init"); sd->stc.escp_init.data = bp; sd->stc.escp_init.size = need; @@ -320,9 +320,9 @@ stc_print_setup(stcolor_device *sd) if(need != sd->stc.escp_release.size) { /* Reallocate */ - if(NULL != (bp = gs_malloc(need,1,"stcolor/release"))) { /* Replace */ + if(NULL != (bp = gs_malloc(sd->memory, need,1,"stcolor/release"))) { /* Replace */ if(0 != sd->stc.escp_release.size) - gs_free((byte *)sd->stc.escp_release.data,sd->stc.escp_release.size,1, + gs_free(sd->memory, (byte *)sd->stc.escp_release.data,sd->stc.escp_release.size,1, "stcolor/release"); sd->stc.escp_release.data = bp; sd->stc.escp_release.size = need; @@ -376,7 +376,7 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) ***/ ext_size = gdev_prn_raster(sd); - ext_line = gs_malloc(ext_size,1,"stc_print_page/ext_line"); + ext_line = gs_malloc(sd->memory, ext_size,1,"stc_print_page/ext_line"); if(ext_line == NULL) SORRY; prt_pixels = sd->stc.escp_width; @@ -386,7 +386,7 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) sd->stc.prt_scans = (int)(sd->height - (dev_t_margin(sd)+dev_b_margin(sd))*sd->y_pixels_per_inch); - col_line = gs_malloc(prt_pixels,1,"stc_print_page/col_line"); + col_line = gs_malloc(sd->memory, prt_pixels,1,"stc_print_page/col_line"); if(col_line == NULL) SORRY; alg_size = prt_pixels; @@ -397,14 +397,14 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) (sd->stc.alg_item == 1))) { alg_line = NULL; } else { - alg_line = gs_malloc(alg_size,sd->stc.alg_item,"stc_print_page/alg_line"); + alg_line = gs_malloc(sd->memory, alg_size,sd->stc.alg_item,"stc_print_page/alg_line"); if(alg_line == NULL) SORRY; } buf_size = sd->stc.dither->bufadd + alg_size*(sd->stc.dither->flags/STC_SCAN); if(buf_size > 0) { - buf = gs_malloc(buf_size,sd->stc.alg_item,"stc_print_page/buf"); + buf = gs_malloc(sd->memory, buf_size,sd->stc.alg_item,"stc_print_page/buf"); if(buf == NULL) SORRY; } else { buf = NULL; @@ -418,11 +418,11 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) sd->stc.prt_buf <<= 1); if(sd->color_info.num_components > 1) sd->stc.prt_buf *= 4; - sd->stc.prt_width = gs_malloc(sd->stc.prt_buf,sizeof(int), + sd->stc.prt_width = gs_malloc(sd->memory, sd->stc.prt_buf,sizeof(int), "stc_print_page/prt_width"); if(sd->stc.prt_width == NULL) SORRY; - sd->stc.prt_data = gs_malloc(sd->stc.prt_buf,sizeof(byte *), + sd->stc.prt_data = gs_malloc(sd->memory, sd->stc.prt_buf,sizeof(byte *), "stc_print_page/prt_data"); if(sd->stc.prt_data == NULL) { @@ -431,7 +431,7 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) int i; for(i = 0; i < sd->stc.prt_buf; ++i) { - sd->stc.prt_data[i] = gs_malloc(sd->stc.prt_size,1, + sd->stc.prt_data[i] = gs_malloc(sd->memory, sd->stc.prt_size,1, "stc_print_page/prt"); if(sd->stc.prt_data[i] == NULL) SORRY; } @@ -442,7 +442,7 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) int i; for(i = 0; i < sd->color_info.num_components; ++i) { if((flags & STCCOMP) == STCDELTA) { - sd->stc.seed_row[i] = gs_malloc(sd->stc.seed_size,sizeof(int), + sd->stc.seed_row[i] = gs_malloc(sd->memory, sd->stc.seed_size,sizeof(int), "stc_print_page/seed_row"); if(sd->stc.seed_row[i] == NULL) SORRY; else memset(sd->stc.seed_row[i],0,sd->stc.seed_size*sizeof(int)); @@ -466,7 +466,7 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) break; } - sd->stc.escp_data = gs_malloc(sd->stc.escp_size,1, + sd->stc.escp_data = gs_malloc(sd->memory, sd->stc.escp_size,1, "stc_print_page/escp_data"); if(sd->stc.escp_data == NULL) SORRY; @@ -749,20 +749,20 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) ***/ if(ext_line != NULL) - gs_free(ext_line,ext_size,1,"stc_print_page/ext_line"); + gs_free(sd->memory, ext_line,ext_size,1,"stc_print_page/ext_line"); if(col_line != NULL) - gs_free(col_line,prt_pixels,1,"stc_print_page/col_line"); + gs_free(sd->memory, col_line,prt_pixels,1,"stc_print_page/col_line"); if(alg_line != NULL) - gs_free(alg_line,alg_size,sd->stc.alg_item, + gs_free(sd->memory, alg_line,alg_size,sd->stc.alg_item, "stc_print_page/alg_line"); if(buf != NULL) - gs_free(buf,buf_size,sd->stc.alg_item,"stc_print_page/buf"); + gs_free(sd->memory, buf,buf_size,sd->stc.alg_item,"stc_print_page/buf"); if(sd->stc.prt_width != NULL) - gs_free(sd->stc.prt_width,sd->stc.prt_buf,sizeof(int), + gs_free(sd->memory, sd->stc.prt_width,sd->stc.prt_buf,sizeof(int), "stc_print_page/prt_width"); if(sd->stc.prt_data != NULL) { @@ -770,11 +770,11 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) for(i = 0; i < sd->stc.prt_buf; ++i) { if(sd->stc.prt_data[i] != NULL) - gs_free(sd->stc.prt_data[i],sd->stc.prt_size,1, + gs_free(sd->memory, sd->stc.prt_data[i],sd->stc.prt_size,1, "stc_print_page/prt"); } - gs_free(sd->stc.prt_data,sd->stc.prt_buf,sizeof(byte *), + gs_free(sd->memory, sd->stc.prt_data,sd->stc.prt_buf,sizeof(byte *), "stc_print_page/prt_data"); } @@ -782,13 +782,13 @@ stc_print_page(gx_device_printer * pdev, FILE * prn_stream) int i; for(i = 0; i < sd->color_info.num_components; ++i) { if(sd->stc.seed_row[i] != NULL) - gs_free(sd->stc.seed_row[i],sd->stc.seed_size,sizeof(int), + gs_free(sd->memory, sd->stc.seed_row[i],sd->stc.seed_size,sizeof(int), "stc_print_page/seed_row"); } } if(sd->stc.escp_data != NULL) - gs_free(sd->stc.escp_data,sd->stc.escp_size,1, + gs_free(sd->memory, sd->stc.escp_data,sd->stc.escp_size,1, "stc_print_page/escp_data"); return OK4GO ? 0 : gs_error_undefined; @@ -1528,7 +1528,7 @@ stc_print_delta(stcolor_device *sd, FILE *prn_stream) *** Free-Data: release the specific-Arrays ***/ private void -stc_freedata(stc_t *stc) +stc_freedata(gs_memory_t *mem, stc_t *stc) { int i,j; @@ -1537,7 +1537,7 @@ stc_freedata(stc_t *stc) for(j = 0; j < i; ++j) if(stc->code[i] == stc->code[j]) break; - if(i == j) gs_free(stc->code[i],1<<stc->bits,sizeof(gx_color_value), + if(i == j) gs_free(mem, stc->code[i],1<<stc->bits,sizeof(gx_color_value), "stcolor/code"); } @@ -1546,7 +1546,7 @@ stc_freedata(stc_t *stc) for(j = 0; j < i; ++j) if(stc->vals[i] == stc->vals[j]) break; - if(i == j) gs_free(stc->vals[i],1<<stc->bits,sd->stc.alg_item, + if(i == j) gs_free(mem, stc->vals[i],1<<stc->bits,sd->stc.alg_item, "stcolor/transfer"); } } @@ -1577,7 +1577,7 @@ stc_open(gx_device *pdev) /* setup margins & arrays */ gs_param_string *dp; for(i = 0; stc_dither[i].name != NULL; ++i); /* count 'em */ sd->stc.algorithms.size = i; - dp = gs_malloc(i,sizeof(gs_param_string), + dp = gs_malloc(sd->memory, i,sizeof(gs_param_string), "stcolor/algorithms"); if(dp == NULL) { code = gs_error_VMerror; @@ -1608,7 +1608,7 @@ stc_open(gx_device *pdev) /* setup margins & arrays */ for(j = 0; j < i; ++j) if(sd->stc.extc[i] == sd->stc.extc[j]) break; if(i == j) { /* new one */ - sd->stc.code[i] = gs_malloc(1<<sd->stc.bits,sizeof(gx_color_value), + sd->stc.code[i] = gs_malloc(sd->memory, 1<<sd->stc.bits,sizeof(gx_color_value), "stcolor/code"); if(sd->stc.code[i] == NULL) { /* error */ @@ -1674,7 +1674,7 @@ stc_open(gx_device *pdev) /* setup margins & arrays */ if(i == j) { /* new one */ sd->stc.vals[i] = - gs_malloc(1<<sd->stc.bits,sd->stc.alg_item,"stcolor/transfer"); + gs_malloc(sd->memory, 1<<sd->stc.bits,sd->stc.alg_item,"stcolor/transfer"); if(sd->stc.vals[i] == NULL) { @@ -1899,7 +1899,7 @@ stc_open(gx_device *pdev) /* setup margins & arrays */ } else { - stc_freedata(&sd->stc); + stc_freedata(sd->memory, &sd->stc); return_error(code); } @@ -1912,7 +1912,7 @@ stc_open(gx_device *pdev) /* setup margins & arrays */ private int stc_close(gx_device *pdev) { - stc_freedata(&((stcolor_device *) pdev)->stc); + stc_freedata(pdev->memory, &((stcolor_device *) pdev)->stc); ((stcolor_device *) pdev)->stc.flags &= ~STCOK4GO; return gdev_prn_close(pdev); } @@ -3100,7 +3100,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) if(j < i) { sd->stc.extv[i] = sd->stc.extv[j]; } else { - fp = gs_malloc(sd->stc.sizv[i],sizeof(float),"stc_put_params"); + fp = gs_malloc(sd->memory, sd->stc.sizv[i],sizeof(float),"stc_put_params"); if(fp != NULL) memcpy(fp,sd->stc.extv[i],sd->stc.sizv[i]*sizeof(float)); else @@ -3120,7 +3120,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) if(j < i) { sd->stc.extc[i] = sd->stc.extc[j]; } else { - fp = gs_malloc(sd->stc.sizc[i],sizeof(float),"stc_put_params"); + fp = gs_malloc(sd->memory, sd->stc.sizc[i],sizeof(float),"stc_put_params"); if(fp != NULL) memcpy(fp,sd->stc.extc[i],sd->stc.sizc[i]*sizeof(float)); else @@ -3135,7 +3135,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) if( sd->color_info.num_components == 1) i = 3; else if(sd->color_info.num_components == 3) i = 9; else i = 16; - fp = gs_malloc(i,sizeof(float),"stc_put_params"); + fp = gs_malloc(sd->memory, i,sizeof(float),"stc_put_params"); if(fp != NULL) memcpy(fp,sd->stc.am,i*sizeof(float)); else code = gs_error_VMerror; sd->stc.am = fp; @@ -3145,7 +3145,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) byte *ip = NULL; if(sd->stc.escp_init.size > 0) { - ip = gs_malloc(sd->stc.escp_init.size,1,"stcolor/init"); + ip = gs_malloc(sd->memory, sd->stc.escp_init.size,1,"stcolor/init"); if(ip == NULL) { code = gs_error_VMerror; sd->stc.escp_init.size = 0; @@ -3161,7 +3161,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) byte *ip = NULL; if(sd->stc.escp_release.size > 0) { - ip = gs_malloc(sd->stc.escp_release.size,1,"stcolor/release"); + ip = gs_malloc(sd->memory, sd->stc.escp_release.size,1,"stcolor/release"); if(ip == NULL) { code = gs_error_VMerror; sd->stc.escp_release.size = 0; @@ -3179,17 +3179,17 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) if( sd->color_info.num_components == 1) i = 3; else if(sd->color_info.num_components == 3) i = 9; else i = 16; - gs_free(sd->stc.am,i,sizeof(float),"stc_put_params"); + gs_free(sd->memory, sd->stc.am,i,sizeof(float),"stc_put_params"); } if((sd->stc.escp_init.data != NULL) && (sd->stc.escp_init.data != oldstc.escp_init.data)) - gs_free((byte *) sd->stc.escp_init.data,sd->stc.escp_init.size,1, + gs_free(sd->memory, (byte *) sd->stc.escp_init.data,sd->stc.escp_init.size,1, "stcolor/init"); if((sd->stc.escp_release.data != NULL) && (sd->stc.escp_release.data != oldstc.escp_release.data)) - gs_free((byte *) sd->stc.escp_release.data,sd->stc.escp_release. + gs_free(sd->memory, (byte *) sd->stc.escp_release.data,sd->stc.escp_release. size,1,"stcolor/release"); for(i = 0; i < sd->color_info.num_components; ++i) { /* components */ @@ -3202,7 +3202,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) for(j = 0; j < i; ++j) if(sd->stc.extc[i] == sd->stc.extc[j]) break; - if(i == j) gs_free(sd->stc.extc[i],sd->stc.sizc[i],sizeof(float), + if(i == j) gs_free(sd->memory, sd->stc.extc[i],sd->stc.sizc[i],sizeof(float), "stc_put_params"); } @@ -3213,7 +3213,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) for(j = 0; j < i; ++j) if(sd->stc.extv[i] == sd->stc.extv[j]) break; - if(i == j) gs_free(sd->stc.extv[i],sd->stc.sizv[i],sizeof(float), + if(i == j) gs_free(sd->memory, sd->stc.extv[i],sd->stc.sizv[i],sizeof(float), "stc_put_params"); } } /* components */ @@ -3232,13 +3232,13 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) if((oldstc.escp_init.data != NULL) && (oldstc.escp_init.data != sd->stc.escp_init.data)) { - gs_free((byte *)oldstc.escp_init.data, + gs_free(sd->memory, (byte *)oldstc.escp_init.data, oldstc.escp_init.size,1,"stcolor/init"); } if((oldstc.escp_release.data != NULL) && (oldstc.escp_release.data != sd->stc.escp_release.data)) { - gs_free((byte *)oldstc.escp_release.data, + gs_free(sd->memory, (byte *)oldstc.escp_release.data, oldstc.escp_release.size,1,"stcolor/release"); } @@ -3246,7 +3246,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) if( oldcolor.num_components == 1) i = 3; else if(oldcolor.num_components == 3) i = 9; else i = 16; - gs_free(oldstc.am,i,sizeof(float),"stc_put_params"); + gs_free(sd->memory, oldstc.am,i,sizeof(float),"stc_put_params"); } for(i = 0; i < 4; ++i) { @@ -3259,7 +3259,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) for(j = 0; j < i; ++j) if(oldstc.extc[i] == oldstc.extc[j]) break; - if(i == j) gs_free(oldstc.extc[i],oldstc.sizc[i],sizeof(float), + if(i == j) gs_free(sd->memory, oldstc.extc[i],oldstc.sizc[i],sizeof(float), "stc_put_params"); } @@ -3269,7 +3269,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) for(j = 0; j < i; ++j) if(oldstc.extv[i] == oldstc.extv[j]) break; - if(i == j) gs_free(oldstc.extv[i],oldstc.sizv[i],sizeof(float), + if(i == j) gs_free(sd->memory, oldstc.extv[i],oldstc.sizv[i],sizeof(float), "stc_put_params"); } } @@ -3291,7 +3291,7 @@ stc_put_params(gx_device *pdev, gs_param_list *plist) if(sd->stc.extc[i] != oldstc.extc[i]) doclose = true; } if(doclose) { - stc_freedata(&oldstc); + stc_freedata(pdev->memory, &oldstc); for(i = 0; i < 4; ++i) { sd->stc.vals[i] = NULL; sd->stc.code[i] = NULL; diff --git a/gs/src/gdevupd.c b/gs/src/gdevupd.c index a4aab782b..808962a4b 100644 --- a/gs/src/gdevupd.c +++ b/gs/src/gdevupd.c @@ -889,10 +889,10 @@ Here are several Macros, named "UPD_MM_*" to deal with that. */ /** UPD_MM_GET_ARRAY allocates & initializes an array of values */ -#define UPD_MM_GET_ARRAY(Which,Nelts) \ +#define UPD_MM_GET_ARRAY(mem, Which,Nelts) \ Which = NULL; \ if(0 < (Nelts)) { \ - byte *tmp = gs_malloc(Nelts,sizeof(Which[0]),"uniprint/params");\ + byte *tmp = gs_malloc(mem, Nelts,sizeof(Which[0]),"uniprint/params");\ if(tmp) { \ memset(tmp,0,(Nelts)*sizeof(Which[0])); \ Which = (void *) tmp; \ @@ -902,50 +902,52 @@ Here are several Macros, named "UPD_MM_*" to deal with that. } /** UPD_MM_DEL_ARRAY frees an array of values */ -#define UPD_MM_DEL_ARRAY(Which,Nelts,Delete) \ +#define UPD_MM_DEL_ARRAY(mem, Which,Nelts,Delete) \ if(Which && 0 < (Nelts)) { \ uint ii; \ - for(ii = 0; (Nelts) > ii; ++ii) Delete(Which[ii]); \ - gs_free(upd_cast(Which),Nelts,sizeof(Which[0]),"uniprint/params");\ + for(ii = 0; (Nelts) > ii; ++ii) Delete(mem, Which[ii]); \ + gs_free(mem, upd_cast(Which),Nelts,sizeof(Which[0]),"uniprint/params");\ } \ Which = 0 /** UPD_MM_DEL_VALUE deletes a value, does nothing */ -#define UPD_MM_DEL_VALUE(Which) /* */ +#define UPD_MM_DEL_VALUE(mem, Which) /* */ /** UPD_MM_DEL_PARAM deletes a single gs-array-parameter */ -#define UPD_MM_DEL_PARAM(Which) { \ +#define UPD_MM_DEL_PARAM(mem, Which) { \ if(Which.data && Which.size) \ - gs_free(upd_cast(Which.data),Which.size,sizeof(Which.data[0]),\ + gs_free(mem, upd_cast(Which.data),Which.size,sizeof(Which.data[0]),\ "uniprint/params"); \ } /** UPD_MM_DEL_APARAM deletes a nested gs-array-parameter */ -#define UPD_MM_DEL_APARAM(Which) { \ +#define UPD_MM_DEL_APARAM(mem, Which) { \ if(Which.data && Which.size) { \ uint iii; \ for(iii = 0; iii < Which.size; ++iii) \ - UPD_MM_DEL_PARAM(Which.data[iii]); \ - gs_free(upd_cast(Which.data),Which.size,sizeof(Which.data[0]),\ + UPD_MM_DEL_PARAM(mem, Which.data[iii]); \ + gs_free(mem, upd_cast(Which.data),Which.size,sizeof(Which.data[0]),\ "uniprint/params"); \ } \ } /** UPD_MM_CPY_ARRAY creates a new copy of an array of values */ -#define UPD_MM_CPY_ARRAY(To,From,Nelts,Copy) \ - UPD_MM_GET_ARRAY(To,Nelts); \ +#define UPD_MM_CPY_ARRAY(mem, To,From,Nelts,Copy) \ + UPD_MM_GET_ARRAY(mem, To,Nelts); \ if(To && From) { \ uint ii; \ - for(ii = 0; (Nelts) > ii; ++ii) Copy(To[ii],From[ii]);\ + for(ii = 0; (Nelts) > ii; ++ii) Copy(mem, To[ii],From[ii]);\ } /** UPD_MM_CPY_VALUE Copies a simple Value */ -#define UPD_MM_CPY_VALUE(To,From) To = From +#define UPD_MM_CPY_VALUE(mem,To,From) To = From + +#define UPD_MM_CPY_VALUE_3(mem,To,From) To = From /** UPD_MM_CPY_PARAM Creates a copy of a gs-parameter */ -#define UPD_MM_CPY_PARAM(To,From) \ +#define UPD_MM_CPY_PARAM(mem, To, From) \ if(From.data && From.size) { \ - UPD_MM_GET_ARRAY(To.data,From.size); \ + UPD_MM_GET_ARRAY(mem, To.data,From.size); \ if(To.data) { \ To.size = From.size; \ memcpy(upd_cast(To.data),From.data,To.size*sizeof(To.data[0]));\ @@ -953,15 +955,15 @@ Here are several Macros, named "UPD_MM_*" to deal with that. } /** UPD_MM_CPY_APARAM Creates a copy of a nested gs-parameter */ -#define UPD_MM_CPY_APARAM(To,From) \ +#define UPD_MM_CPY_APARAM(mem, To,From) \ if(From.data && From.size) { \ - UPD_MM_GET_ARRAY(To.data,From.size); \ + UPD_MM_GET_ARRAY(mem, To.data,From.size); \ if(To.data) { \ gs_param_string *tmp2 = (gs_param_string *) upd_cast(To.data);\ uint iii; \ To.size = From.size; \ for(iii = 0; To.size > iii; ++iii) \ - UPD_MM_CPY_PARAM(tmp2[iii],From.data[iii]); \ + UPD_MM_CPY_PARAM(mem, tmp2[iii],From.data[iii]); \ } \ } @@ -1306,7 +1308,7 @@ buffer for the raw raster-data if(B_MAP & upd->flags) { /* Only if prerequisites were met */ uint want = gx_device_raster(pdev,true); - upd->gsbuf = gs_malloc(want,1,"upd/gsbuf"); + upd->gsbuf = gs_malloc(pdev->memory, want,1,"upd/gsbuf"); if(upd->gsbuf) { upd->ngsbuf = want; @@ -1489,7 +1491,7 @@ upd_close(gx_device *pdev) upd_close_writer(udev); if(upd->gsbuf) - gs_free(upd->gsbuf,upd->ngsbuf,1,"uniprint/gsbuf"); + gs_free(pdev->memory, upd->gsbuf,upd->ngsbuf,1,"uniprint/gsbuf"); upd->gsbuf = NULL; upd->ngsbuf = 0; upd->flags &= ~B_BUF; @@ -1497,14 +1499,14 @@ upd_close(gx_device *pdev) upd_close_render(udev); upd_close_map(udev); - UPD_MM_DEL_ARRAY(upd->choice, countof(upd_choice), UPD_MM_DEL_VALUE); - UPD_MM_DEL_ARRAY(upd->ints, countof(upd_ints), UPD_MM_DEL_VALUE); - UPD_MM_DEL_ARRAY(upd->int_a, countof(upd_int_a), UPD_MM_DEL_PARAM); - UPD_MM_DEL_ARRAY(upd->strings, countof(upd_strings), UPD_MM_DEL_PARAM); - UPD_MM_DEL_ARRAY(upd->string_a,countof(upd_string_a),UPD_MM_DEL_APARAM); - UPD_MM_DEL_ARRAY(upd->float_a, countof(upd_float_a), UPD_MM_DEL_PARAM); + UPD_MM_DEL_ARRAY(pdev->memory, upd->choice, countof(upd_choice), UPD_MM_DEL_VALUE); + UPD_MM_DEL_ARRAY(pdev->memory, upd->ints, countof(upd_ints), UPD_MM_DEL_VALUE); + UPD_MM_DEL_ARRAY(pdev->memory, upd->int_a, countof(upd_int_a), UPD_MM_DEL_PARAM); + UPD_MM_DEL_ARRAY(pdev->memory, upd->strings, countof(upd_strings), UPD_MM_DEL_PARAM); + UPD_MM_DEL_ARRAY(pdev->memory, upd->string_a,countof(upd_string_a),UPD_MM_DEL_APARAM); + UPD_MM_DEL_ARRAY(pdev->memory, upd->float_a, countof(upd_float_a), UPD_MM_DEL_PARAM); - gs_free(upd,sizeof(upd[0]),1,"uniprint"); + gs_free(pdev->memory, upd,sizeof(upd[0]),1,"uniprint"); udev->upd = NULL; } @@ -1792,26 +1794,26 @@ out on this copies. color_info = udev->color_info; if(upd) { flags = upd->flags; - UPD_MM_CPY_ARRAY(choice, upd->choice, countof(upd_choice), + UPD_MM_CPY_ARRAY(udev->memory, choice, upd->choice, countof(upd_choice), UPD_MM_CPY_VALUE); - UPD_MM_CPY_ARRAY(ints, upd->ints, countof(upd_ints), + UPD_MM_CPY_ARRAY(udev->memory, ints, upd->ints, countof(upd_ints), UPD_MM_CPY_VALUE); - UPD_MM_CPY_ARRAY(int_a, upd->int_a, countof(upd_int_a), + UPD_MM_CPY_ARRAY(udev->memory, int_a, upd->int_a, countof(upd_int_a), UPD_MM_CPY_PARAM); - UPD_MM_CPY_ARRAY(strings, upd->strings, countof(upd_strings), + UPD_MM_CPY_ARRAY(udev->memory, strings, upd->strings, countof(upd_strings), UPD_MM_CPY_PARAM); - UPD_MM_CPY_ARRAY(string_a,upd->string_a,countof(upd_string_a), + UPD_MM_CPY_ARRAY(udev->memory, string_a,upd->string_a,countof(upd_string_a), UPD_MM_CPY_APARAM); - UPD_MM_CPY_ARRAY(float_a, upd->float_a, countof(upd_float_a), + UPD_MM_CPY_ARRAY(udev->memory, float_a, upd->float_a, countof(upd_float_a), UPD_MM_CPY_PARAM); } else { flags = 0; - UPD_MM_GET_ARRAY(choice, countof(upd_choice)); - UPD_MM_GET_ARRAY(ints, countof(upd_ints)); - UPD_MM_GET_ARRAY(int_a, countof(upd_int_a)); - UPD_MM_GET_ARRAY(strings, countof(upd_strings)); - UPD_MM_GET_ARRAY(string_a,countof(upd_string_a)); - UPD_MM_GET_ARRAY(float_a, countof(upd_float_a)); + UPD_MM_GET_ARRAY(udev->memory, choice, countof(upd_choice)); + UPD_MM_GET_ARRAY(udev->memory, ints, countof(upd_ints)); + UPD_MM_GET_ARRAY(udev->memory, int_a, countof(upd_int_a)); + UPD_MM_GET_ARRAY(udev->memory, strings, countof(upd_strings)); + UPD_MM_GET_ARRAY(udev->memory, string_a,countof(upd_string_a)); + UPD_MM_GET_ARRAY(udev->memory, float_a, countof(upd_float_a)); } /** Import the Multiple-Choices */ @@ -1867,12 +1869,12 @@ out on this copies. UPD_PARAM_READ(param_read_int_array,upd_int_a[i],value); if(0 == code) { if(0 <= error) error |= UPD_PUT_INT_A; - UPD_MM_DEL_PARAM(int_a[i]); + UPD_MM_DEL_PARAM(udev->memory, int_a[i]); if(!value.size) { value.data = NULL; int_a[i] = value; } else { - UPD_MM_CPY_PARAM(int_a[i],value); + UPD_MM_CPY_PARAM(udev->memory, int_a[i],value); } } } @@ -1884,12 +1886,12 @@ out on this copies. UPD_PARAM_READ(param_read_string,upd_strings[i],value); if(0 == code) { if(0 <= error) error |= UPD_PUT_STRINGS; - UPD_MM_DEL_PARAM(strings[i]); + UPD_MM_DEL_PARAM(udev->memory, strings[i]); if(!value.size) { value.data = NULL; strings[i] = value; } else { - UPD_MM_CPY_PARAM(strings[i],value); + UPD_MM_CPY_PARAM(udev->memory, strings[i],value); } } } @@ -1901,12 +1903,12 @@ out on this copies. UPD_PARAM_READ(param_read_string_array,upd_string_a[i],value); if(0 == code) { if(0 <= error) error |= UPD_PUT_STRING_A; - UPD_MM_DEL_APARAM(string_a[i]); + UPD_MM_DEL_APARAM(udev->memory, string_a[i]); if(!value.size) { value.data = NULL; string_a[i] = value; } else { - UPD_MM_CPY_APARAM(string_a[i],value); + UPD_MM_CPY_APARAM(udev->memory, string_a[i],value); } } } @@ -1918,12 +1920,12 @@ out on this copies. UPD_PARAM_READ(param_read_float_array,upd_float_a[i],value); if(0 == code) { if(0 <= error) error |= UPD_PUT_FLOAT_A; - UPD_MM_DEL_PARAM(float_a[i]); + UPD_MM_DEL_PARAM(udev->memory, float_a[i]); if(!value.size) { value.data = NULL; float_a[i] = value; } else { - UPD_MM_CPY_PARAM(float_a[i],value); + UPD_MM_CPY_PARAM(udev->memory, float_a[i],value); } } } @@ -1939,8 +1941,8 @@ In addition to that, Resolution & Margin-Parameters are tested & adjusted. int *ip,*ip2,ncomp,nbits; if(6 > int_a[IA_COLOR_INFO].size) { - UPD_MM_DEL_PARAM(int_a[IA_COLOR_INFO]); - UPD_MM_GET_ARRAY(int_a[IA_COLOR_INFO].data,6); + UPD_MM_DEL_PARAM(udev->memory, int_a[IA_COLOR_INFO]); + UPD_MM_GET_ARRAY(udev->memory, int_a[IA_COLOR_INFO].data,6); int_a[IA_COLOR_INFO].size = 6; } ip = (int *) upd_cast(int_a[IA_COLOR_INFO].data); @@ -1971,11 +1973,11 @@ In addition to that, Resolution & Margin-Parameters are tested & adjusted. if(UPD_CMAP_MAX < ncomp) ncomp = UPD_CMAP_MAX; if(ncomp > int_a[IA_COMPBITS].size) { /* Default ComponentBits */ - UPD_MM_GET_ARRAY(ip2,ncomp); + UPD_MM_GET_ARRAY(udev->memory, ip2,ncomp); nbits = 32 / ncomp; if(8 < nbits) nbits = 8; for(i = 0; i < ncomp; ++i) ip2[i] = nbits; - UPD_MM_DEL_PARAM(int_a[IA_COMPBITS]); + UPD_MM_DEL_PARAM(udev->memory, int_a[IA_COMPBITS]); int_a[IA_COMPBITS].data = ip2; int_a[IA_COMPBITS].size = ncomp; } /* Default ComponentBits */ @@ -1983,12 +1985,12 @@ In addition to that, Resolution & Margin-Parameters are tested & adjusted. if(ncomp > int_a[IA_COMPSHIFT].size) { /* Default ComponentShift */ nbits = 0; for(i = 0; i < ncomp; ++i) nbits += int_a[IA_COMPBITS].data[i]; - UPD_MM_GET_ARRAY(ip2,ncomp); + UPD_MM_GET_ARRAY(udev->memory, ip2,ncomp); for(i = 0; i < ncomp; ++i) { ip2[i] = nbits - int_a[IA_COMPBITS].data[i]; nbits -= int_a[IA_COMPBITS].data[i]; } - UPD_MM_DEL_PARAM(int_a[IA_COMPSHIFT]); + UPD_MM_DEL_PARAM(udev->memory, int_a[IA_COMPSHIFT]); int_a[IA_COMPSHIFT].data = ip2; int_a[IA_COMPSHIFT].size = ncomp; } /* Default ComponentShift */ @@ -2097,15 +2099,15 @@ transferred into the device-structure. In the case of "uniprint", this may if(0 < error) { /* Actually something loaded without error */ if(!(upd = udev->upd)) { - UPD_MM_GET_ARRAY(udev->upd,1); + UPD_MM_GET_ARRAY(udev->memory, udev->upd,1); upd = udev->upd; } else { - UPD_MM_DEL_ARRAY(upd->choice, countof(upd_choice), UPD_MM_DEL_VALUE); - UPD_MM_DEL_ARRAY(upd->ints, countof(upd_ints), UPD_MM_DEL_VALUE); - UPD_MM_DEL_ARRAY(upd->int_a, countof(upd_int_a), UPD_MM_DEL_PARAM); - UPD_MM_DEL_ARRAY(upd->strings, countof(upd_strings), UPD_MM_DEL_PARAM); - UPD_MM_DEL_ARRAY(upd->string_a,countof(upd_string_a),UPD_MM_DEL_APARAM); - UPD_MM_DEL_ARRAY(upd->float_a, countof(upd_float_a), UPD_MM_DEL_PARAM); + UPD_MM_DEL_ARRAY(udev->memory, upd->choice, countof(upd_choice), UPD_MM_DEL_VALUE); + UPD_MM_DEL_ARRAY(udev->memory, upd->ints, countof(upd_ints), UPD_MM_DEL_VALUE); + UPD_MM_DEL_ARRAY(udev->memory, upd->int_a, countof(upd_int_a), UPD_MM_DEL_PARAM); + UPD_MM_DEL_ARRAY(udev->memory, upd->strings, countof(upd_strings), UPD_MM_DEL_PARAM); + UPD_MM_DEL_ARRAY(udev->memory, upd->string_a,countof(upd_string_a),UPD_MM_DEL_APARAM); + UPD_MM_DEL_ARRAY(udev->memory, upd->float_a, countof(upd_float_a), UPD_MM_DEL_PARAM); } upd->choice = choice; @@ -2126,12 +2128,12 @@ transferred into the device-structure. In the case of "uniprint", this may udev->MarginsHWResolution[1] = MarginsHWResolution[1]; udev->color_info = color_info; - UPD_MM_DEL_ARRAY(choice, countof(upd_choice), UPD_MM_DEL_VALUE); - UPD_MM_DEL_ARRAY(ints, countof(upd_ints), UPD_MM_DEL_VALUE); - UPD_MM_DEL_ARRAY(int_a, countof(upd_int_a), UPD_MM_DEL_PARAM); - UPD_MM_DEL_ARRAY(strings, countof(upd_strings), UPD_MM_DEL_PARAM); - UPD_MM_DEL_ARRAY(string_a,countof(upd_string_a),UPD_MM_DEL_APARAM); - UPD_MM_DEL_ARRAY(float_a, countof(upd_float_a), UPD_MM_DEL_PARAM); + UPD_MM_DEL_ARRAY(udev->memory, choice, countof(upd_choice), UPD_MM_DEL_VALUE); + UPD_MM_DEL_ARRAY(udev->memory, ints, countof(upd_ints), UPD_MM_DEL_VALUE); + UPD_MM_DEL_ARRAY(udev->memory, int_a, countof(upd_int_a), UPD_MM_DEL_PARAM); + UPD_MM_DEL_ARRAY(udev->memory, strings, countof(upd_strings), UPD_MM_DEL_PARAM); + UPD_MM_DEL_ARRAY(udev->memory, string_a,countof(upd_string_a),UPD_MM_DEL_APARAM); + UPD_MM_DEL_ARRAY(udev->memory, float_a, countof(upd_float_a), UPD_MM_DEL_PARAM); } @@ -2894,8 +2896,8 @@ upd_open_map(upd_device *udev) if((NULL == upd->float_a[upd->cmap[imap].xfer].data) || (2 > upd->float_a[upd->cmap[imap].xfer].size) ) { float *fp; - UPD_MM_DEL_PARAM(upd->float_a[upd->cmap[imap].xfer]); - UPD_MM_GET_ARRAY(fp,2); + UPD_MM_DEL_PARAM(udev->memory, upd->float_a[upd->cmap[imap].xfer]); + UPD_MM_GET_ARRAY(udev->memory, fp,2); fp[0] = 0.0; fp[1] = 1.0; upd->float_a[upd->cmap[imap].xfer].data = fp; @@ -2963,7 +2965,7 @@ upd_open_map(upd_device *udev) upd->float_a[upd->cmap[imap].xfer].data[ upd->float_a[upd->cmap[imap].xfer].size-1] ? true : false; - upd->cmap[imap].code = gs_malloc(upd->cmap[imap].bitmsk+1, + upd->cmap[imap].code = gs_malloc(udev->memory, upd->cmap[imap].bitmsk+1, sizeof(upd->cmap[imap].code[0]),"upd/code"); if(!upd->cmap[imap].code) break; } @@ -3192,7 +3194,7 @@ upd_close_map(upd_device *udev) for(imap = 0; UPD_CMAP_MAX > imap; ++imap) { if(upd->cmap[imap].code) - gs_free(upd->cmap[imap].code,sizeof(upd->cmap[imap].code[0]), + gs_free(udev->memory, upd->cmap[imap].code,sizeof(upd->cmap[imap].code[0]), upd->cmap[imap].bitmsk+1,"upd/code"); upd->cmap[imap].code = NULL; @@ -3291,7 +3293,7 @@ upd_close_render(upd_device *udev) (upd->render == upd_fscmyk) ) upd_close_fscomp(udev); if((0 < upd->nvalbuf) && upd->valbuf) - gs_free(upd->valbuf,upd->nvalbuf,sizeof(upd->valbuf[0]),"upd/valbuf"); + gs_free(udev->memory, upd->valbuf,upd->nvalbuf,sizeof(upd->valbuf[0]),"upd/valbuf"); upd->valbuf = NULL; upd->nvalbuf = 0; @@ -3360,7 +3362,7 @@ If anything was ok. up to now, memory get's allocated. if(icomp) { for(icomp = 0; upd->ncomp > icomp; ++icomp) { - upd->valptr[icomp] = gs_malloc(1,sizeof(updcomp_t),"upd/fscomp"); + upd->valptr[icomp] = gs_malloc(udev->memory, 1,sizeof(updcomp_t),"upd/fscomp"); if(NULL == upd->valptr[icomp]) { #if UPD_MESSAGES & UPD_M_ERROR errprintf( @@ -3377,7 +3379,7 @@ If anything was ok. up to now, memory get's allocated. uint need; need = (2 + upd->rwidth) * upd->ncomp; - upd->valbuf = gs_malloc(need,sizeof(upd->valbuf[0]),"upd/valbuf"); + upd->valbuf = gs_malloc(udev->memory, need,sizeof(upd->valbuf[0]),"upd/valbuf"); if(upd->valbuf) { upd->nvalbuf = need; @@ -3530,7 +3532,7 @@ upd_close_fscomp(upd_device *udev) for(icomp = 0; UPD_VALPTR_MAX > icomp; ++icomp) { if(!upd->valptr[icomp]) continue; - gs_free(upd->valptr[icomp],1,sizeof(updcomp_t),"upd/fscomp"); + gs_free(udev->memory, upd->valptr[icomp],1,sizeof(updcomp_t),"upd/fscomp"); upd->valptr[icomp] = NULL; } } @@ -4174,8 +4176,8 @@ upd_open_writer(upd_device *udev) if(upd->ints[I_NPASS] > upd->int_a[IA_STD_DY].size) { int ix,iy,*ip; - UPD_MM_DEL_PARAM(upd->int_a[IA_STD_DY]); - UPD_MM_GET_ARRAY(ip,upd->ints[I_NPASS]); + UPD_MM_DEL_PARAM(udev->memory, upd->int_a[IA_STD_DY]); + UPD_MM_GET_ARRAY(udev->memory, ip,upd->ints[I_NPASS]); upd->int_a[IA_STD_DY].data = ip; upd->int_a[IA_STD_DY].size = upd->ints[I_NPASS]; @@ -4221,8 +4223,8 @@ upd_open_writer(upd_device *udev) if(0 >= upd->int_a[IA_STD_IX].size) { int ix,i,*ip; - UPD_MM_DEL_PARAM(upd->int_a[IA_STD_IX]); - UPD_MM_GET_ARRAY(ip,upd->int_a[IA_STD_DY].size); + UPD_MM_DEL_PARAM(udev->memory, upd->int_a[IA_STD_IX]); + UPD_MM_GET_ARRAY(udev->memory, ip,upd->int_a[IA_STD_DY].size); upd->int_a[IA_STD_IX].data = ip; upd->int_a[IA_STD_IX].size = upd->int_a[IA_STD_DY].size; @@ -4235,8 +4237,8 @@ upd_open_writer(upd_device *udev) if((0 >= upd->int_a[IA_BEG_IX].size) && (0 < upd->int_a[IA_BEG_DY].size) ) { int ix,i,*ip; - UPD_MM_DEL_PARAM(upd->int_a[IA_BEG_IX]); - UPD_MM_GET_ARRAY(ip,upd->int_a[IA_BEG_DY].size); + UPD_MM_DEL_PARAM(udev->memory, upd->int_a[IA_BEG_IX]); + UPD_MM_GET_ARRAY(udev->memory, ip,upd->int_a[IA_BEG_DY].size); upd->int_a[IA_BEG_IX].data = ip; upd->int_a[IA_BEG_IX].size = upd->int_a[IA_BEG_DY].size; @@ -4249,8 +4251,8 @@ upd_open_writer(upd_device *udev) if((0 >= upd->int_a[IA_END_IX].size) && (0 < upd->int_a[IA_END_DY].size) ) { int ix,i,*ip; - UPD_MM_DEL_PARAM(upd->int_a[IA_END_IX]); - UPD_MM_GET_ARRAY(ip,upd->int_a[IA_END_DY].size); + UPD_MM_DEL_PARAM(udev->memory, upd->int_a[IA_END_IX]); + UPD_MM_GET_ARRAY(udev->memory, ip,upd->int_a[IA_END_DY].size); upd->int_a[IA_END_IX].data = ip; upd->int_a[IA_END_IX].size = upd->int_a[IA_END_DY].size; @@ -4460,20 +4462,20 @@ upd_open_writer(upd_device *udev) /** Allocate the Outputbuffer */ if(success && (0 < upd->noutbuf)) { /* Allocate outbuf */ - upd->outbuf = gs_malloc(upd->noutbuf,sizeof(upd->outbuf[0]),"upd/outbuf"); + upd->outbuf = gs_malloc(udev->memory, upd->noutbuf,sizeof(upd->outbuf[0]),"upd/outbuf"); if(!upd->outbuf) success = false; } /* Allocate outbuf */ /** Allocate the desired scan-buffer-pointers */ if(success) { - upd->scnbuf = gs_malloc(upd->nscnbuf,sizeof(upd->scnbuf[0]),"upd/scnbuf"); + upd->scnbuf = gs_malloc(udev->memory, upd->nscnbuf,sizeof(upd->scnbuf[0]),"upd/scnbuf"); if(NULL == upd->scnbuf) { success = false; } else { int ibuf; for(ibuf = 0; ibuf < upd->nscnbuf; ++ibuf) { if(success) upd->scnbuf[ibuf] = - gs_malloc(upd->ocomp,sizeof(upd->scnbuf[0][0]),"upd/scnbuf[]"); + gs_malloc(udev->memory, upd->ocomp,sizeof(upd->scnbuf[0][0]),"upd/scnbuf[]"); else upd->scnbuf[ibuf] = NULL; if(!upd->scnbuf[ibuf]) { @@ -4482,18 +4484,18 @@ upd_open_writer(upd_device *udev) int icomp; for(icomp = 0; icomp < upd->ocomp; ++icomp) { if(success) upd->scnbuf[ibuf][icomp].bytes = - gs_malloc(upd->nbytes,sizeof(upd->scnbuf[0][0].bytes[0]), + gs_malloc(udev->memory, upd->nbytes,sizeof(upd->scnbuf[0][0].bytes[0]), "upd/bytes"); else upd->scnbuf[ibuf][icomp].bytes = NULL; if(!upd->scnbuf[ibuf][icomp].bytes) success = false; if(0 < upd->nlimits) { - upd->scnbuf[ibuf][icomp].xbegin = gs_malloc(upd->nlimits, + upd->scnbuf[ibuf][icomp].xbegin = gs_malloc(udev->memory, upd->nlimits, sizeof(upd->scnbuf[0][0].xbegin[0]),"upd/xbegin"); if(!upd->scnbuf[ibuf][icomp].xbegin) success = false; - upd->scnbuf[ibuf][icomp].xend = gs_malloc(upd->nlimits, + upd->scnbuf[ibuf][icomp].xend = gs_malloc(udev->memory, upd->nlimits, sizeof(upd->scnbuf[0][0].xend[0]),"upd/xend"); if(!upd->scnbuf[ibuf][icomp].xbegin) success = false; @@ -4528,7 +4530,7 @@ upd_close_writer(upd_device *udev) int ibuf,icomp; if((0 < upd->noutbuf) && upd->outbuf) - gs_free(upd->outbuf,upd->noutbuf,sizeof(upd->outbuf[0]),"upd/outbuf"); + gs_free(udev->memory, upd->outbuf,upd->noutbuf,sizeof(upd->outbuf[0]),"upd/outbuf"); upd->noutbuf = 0; upd->outbuf = NULL; @@ -4540,28 +4542,28 @@ upd_close_writer(upd_device *udev) for(icomp = 0; icomp < upd->ocomp; ++icomp) { if((0 < upd->nbytes) && upd->scnbuf[ibuf][icomp].bytes) - gs_free(upd->scnbuf[ibuf][icomp].bytes,upd->nbytes, + gs_free(udev->memory, upd->scnbuf[ibuf][icomp].bytes,upd->nbytes, sizeof(upd->scnbuf[ibuf][icomp].words[0]),"upd/bytes"); upd->scnbuf[ibuf][icomp].bytes = NULL; if((0 < upd->nlimits) && upd->scnbuf[ibuf][icomp].xbegin) - gs_free(upd->scnbuf[ibuf][icomp].xbegin,upd->nlimits, + gs_free(udev->memory, upd->scnbuf[ibuf][icomp].xbegin,upd->nlimits, sizeof(upd->scnbuf[ibuf][icomp].xbegin[0]),"upd/xbegin"); upd->scnbuf[ibuf][icomp].xbegin = NULL; if((0 < upd->nlimits) && upd->scnbuf[ibuf][icomp].xend) - gs_free(upd->scnbuf[ibuf][icomp].xend,upd->nlimits, + gs_free(udev->memory, upd->scnbuf[ibuf][icomp].xend,upd->nlimits, sizeof(upd->scnbuf[ibuf][icomp].xend[0]),"upd/xend"); upd->scnbuf[ibuf][icomp].xend = NULL; } if(icomp) - gs_free(upd->scnbuf[ibuf],upd->ocomp,sizeof(upd->scnbuf[0][0]), + gs_free(udev->memory, upd->scnbuf[ibuf],upd->ocomp,sizeof(upd->scnbuf[0][0]), "upd/scnbuf[]"); upd->scnbuf[ibuf] = NULL; } - gs_free(upd->scnbuf,upd->nscnbuf,sizeof(upd->scnbuf[0]),"upd/scnbuf"); + gs_free(udev->memory, upd->scnbuf,upd->nscnbuf,sizeof(upd->scnbuf[0]),"upd/scnbuf"); } @@ -5332,8 +5334,8 @@ upd_open_wrtescp2(upd_device *udev) /** Create Y-Move-Command, if not given */ if(0 == upd->strings[S_YMOVE].size) { byte *bp; - UPD_MM_DEL_PARAM(upd->strings[S_YMOVE]); - UPD_MM_GET_ARRAY(bp,5); + UPD_MM_DEL_PARAM(udev->memory, upd->strings[S_YMOVE]); + UPD_MM_GET_ARRAY(udev->memory, bp,5); upd->strings[S_YMOVE].data = bp; upd->strings[S_YMOVE].size = 5; *bp++ = 0x1b; /* ESC */ @@ -5369,8 +5371,8 @@ upd_open_wrtescp2(upd_device *udev) if(2 == upd->ints[I_NXPASS]) { /* Use a relative Step */ - UPD_MM_DEL_PARAM(upd->strings[S_XSTEP]); - UPD_MM_GET_ARRAY(bp,4); + UPD_MM_DEL_PARAM(udev->memory, upd->strings[S_XSTEP]); + UPD_MM_GET_ARRAY(udev->memory, bp,4); upd->strings[S_XSTEP].size = 4; upd->strings[S_XSTEP].data = bp; *bp++ = 0x1b; @@ -5380,8 +5382,8 @@ upd_open_wrtescp2(upd_device *udev) } else { /* Use relative or absolute Move */ - UPD_MM_DEL_PARAM(upd->strings[S_XMOVE]); - UPD_MM_GET_ARRAY(bp,2); + UPD_MM_DEL_PARAM(udev->memory, upd->strings[S_XMOVE]); + UPD_MM_GET_ARRAY(udev->memory, bp,2); upd->strings[S_XMOVE].size = 2; upd->strings[S_XMOVE].data = bp; *bp++ = 0x1b; @@ -5405,8 +5407,8 @@ upd_open_wrtescp2(upd_device *udev) /* RowMask - default is all 1's */ if( upd->ints[I_PATRPT] != upd->int_a[IA_ROWMASK].size ) { int i, *bp; - UPD_MM_DEL_PARAM(upd->int_a[IA_ROWMASK]); - UPD_MM_GET_ARRAY(bp,upd->ints[I_PATRPT]); + UPD_MM_DEL_PARAM(udev->memory, upd->int_a[IA_ROWMASK]); + UPD_MM_GET_ARRAY(udev->memory, bp,upd->ints[I_PATRPT]); upd->int_a[IA_ROWMASK].size = upd->ints[I_PATRPT]; upd->int_a[IA_ROWMASK].data = bp; for (i = 0 ; i < upd->ints[I_PATRPT] ; i++){ @@ -5416,8 +5418,8 @@ upd_open_wrtescp2(upd_device *udev) /* MaskScanOffset - default is 0-patternRepeat */ if( upd->ints[I_PATRPT] != upd->int_a[IA_SCNOFS].size ) { int i, *bp; - UPD_MM_DEL_PARAM(upd->int_a[IA_SCNOFS]); - UPD_MM_GET_ARRAY(bp,upd->ints[I_PATRPT]); + UPD_MM_DEL_PARAM(udev->memory, upd->int_a[IA_SCNOFS]); + UPD_MM_GET_ARRAY(udev->memory, bp,upd->ints[I_PATRPT]); upd->int_a[IA_SCNOFS].size = upd->ints[I_PATRPT]; upd->int_a[IA_SCNOFS].data = bp; for (i = 0 ; i < upd->ints[I_PATRPT] ; i++){ @@ -5441,12 +5443,12 @@ upd_open_wrtescp2(upd_device *udev) int i; if(4 == upd->ocomp) { /* Establish Component-Selection */ - UPD_MM_DEL_APARAM(upd->string_a[SA_SETCOMP]); - UPD_MM_GET_ARRAY(ap,4); + UPD_MM_DEL_APARAM(udev->memory, upd->string_a[SA_SETCOMP]); + UPD_MM_GET_ARRAY(udev->memory, ap,4); upd->string_a[SA_SETCOMP].data = ap; upd->string_a[SA_SETCOMP].size = 4; for(i = 0; i < 4; ++i) { - UPD_MM_GET_ARRAY(bp,3); + UPD_MM_GET_ARRAY(udev->memory, bp,3); ap[i].size = 3; ap[i].data = bp; *bp++ = 0x1b; @@ -5460,12 +5462,12 @@ upd_open_wrtescp2(upd_device *udev) } } /* Establish Component-Selection */ - UPD_MM_DEL_APARAM(upd->string_a[SA_WRITECOMP]); - UPD_MM_GET_ARRAY(ap,upd->ocomp); + UPD_MM_DEL_APARAM(udev->memory, upd->string_a[SA_WRITECOMP]); + UPD_MM_GET_ARRAY(udev->memory, ap,upd->ocomp); upd->string_a[SA_WRITECOMP].data = ap; upd->string_a[SA_WRITECOMP].size = upd->ncomp; for(i = 0; i < upd->ocomp; ++i) { - UPD_MM_GET_ARRAY(bp,6); + UPD_MM_GET_ARRAY(udev->memory, bp,6); ap[i].size = 6; ap[i].data = bp; *bp++ = 0x1b; @@ -6497,14 +6499,14 @@ upd_open_wrtrtl(upd_device *udev) ncv = strlen(cv); nbp = (j+1) + ncv + (upd->strings[S_BEGIN].size-i); - UPD_MM_GET_ARRAY(bp,nbp); + UPD_MM_GET_ARRAY(udev->memory, bp,nbp); if(0 <= j) memcpy(bp,upd->strings[S_BEGIN].data,j+1); memcpy(bp+j+1, cv,ncv); memcpy(bp+j+1+ncv,upd->strings[S_BEGIN].data+i, upd->strings[S_BEGIN].size-i); i = j+1+ncv; - UPD_MM_DEL_PARAM(upd->strings[S_BEGIN]); + UPD_MM_DEL_PARAM(udev->memory, upd->strings[S_BEGIN]); upd->strings[S_BEGIN].data = bp; upd->strings[S_BEGIN].size = nbp; @@ -6515,14 +6517,14 @@ upd_open_wrtrtl(upd_device *udev) ncv = strlen(cv); nbp = (j+1) + ncv + (upd->strings[S_BEGIN].size-i); - UPD_MM_GET_ARRAY(bp,nbp); + UPD_MM_GET_ARRAY(udev->memory, bp,nbp); if(0 <= j) memcpy(bp,upd->strings[S_BEGIN].data,j+1); memcpy(bp+j+1, cv,ncv); memcpy(bp+j+1+ncv,upd->strings[S_BEGIN].data+i, upd->strings[S_BEGIN].size-i); i = j+1+ncv; - UPD_MM_DEL_PARAM(upd->strings[S_BEGIN]); + UPD_MM_DEL_PARAM(udev->memory, upd->strings[S_BEGIN]); upd->strings[S_BEGIN].data = bp; upd->strings[S_BEGIN].size = nbp; @@ -6547,14 +6549,14 @@ upd_open_wrtrtl(upd_device *udev) ncv = strlen(cv); nbp = (j+1) + ncv + (upd->strings[S_BEGIN].size-i); - UPD_MM_GET_ARRAY(bp,nbp); + UPD_MM_GET_ARRAY(udev->memory, bp,nbp); if(0 <= j) memcpy(bp,upd->strings[S_BEGIN].data,j+1); memcpy(bp+j+1, cv,ncv); memcpy(bp+j+1+ncv,upd->strings[S_BEGIN].data+i, upd->strings[S_BEGIN].size-i); i = j+1+ncv; - UPD_MM_DEL_PARAM(upd->strings[S_BEGIN]); + UPD_MM_DEL_PARAM(udev->memory, upd->strings[S_BEGIN]); upd->strings[S_BEGIN].data = bp; upd->strings[S_BEGIN].size = nbp; @@ -6752,14 +6754,14 @@ upd_open_wrtrtl(upd_device *udev) ncv = strlen(cv); nbp = (j+1) + ncv + (upd->strings[S_BEGIN].size-i); - UPD_MM_GET_ARRAY(bp,nbp); + UPD_MM_GET_ARRAY(udev->memory, bp,nbp); if(0 <= j) memcpy(bp,upd->strings[S_BEGIN].data,j+1); memcpy(bp+j+1, cv,ncv); memcpy(bp+j+1+ncv,upd->strings[S_BEGIN].data+i, upd->strings[S_BEGIN].size-i); i = j+1+ncv; - UPD_MM_DEL_PARAM(upd->strings[S_BEGIN]); + UPD_MM_DEL_PARAM(udev->memory, upd->strings[S_BEGIN]); upd->strings[S_BEGIN].data = bp; upd->strings[S_BEGIN].size = nbp; } /* insert new number */ @@ -6817,14 +6819,14 @@ upd_open_wrtrtl(upd_device *udev) ncv = strlen(cv); nbp = (j+1) + ncv + (upd->strings[S_BEGIN].size-i); - UPD_MM_GET_ARRAY(bp,nbp); + UPD_MM_GET_ARRAY(udev->memory, bp,nbp); if(0 <= j) memcpy(bp,upd->strings[S_BEGIN].data,j+1); memcpy(bp+j+1, cv,ncv); memcpy(bp+j+1+ncv,upd->strings[S_BEGIN].data+i, upd->strings[S_BEGIN].size-i); i = j+1+ncv; - UPD_MM_DEL_PARAM(upd->strings[S_BEGIN]); + UPD_MM_DEL_PARAM(udev->memory, upd->strings[S_BEGIN]); upd->strings[S_BEGIN].data = bp; upd->strings[S_BEGIN].size = nbp; } /* insert new number */ @@ -6914,14 +6916,14 @@ upd_open_wrtrtl(upd_device *udev) ncv = strlen(cv); nbp = (j+1) + ncv + (upd->strings[S_BEGIN].size-i); - UPD_MM_GET_ARRAY(bp,nbp); + UPD_MM_GET_ARRAY(udev->memory, bp,nbp); if(0 <= j) memcpy(bp,upd->strings[S_BEGIN].data,j+1); memcpy(bp+j+1, cv,ncv); memcpy(bp+j+1+ncv,upd->strings[S_BEGIN].data+i, upd->strings[S_BEGIN].size-i); i = j+1+ncv; - UPD_MM_DEL_PARAM(upd->strings[S_BEGIN]); + UPD_MM_DEL_PARAM(udev->memory, upd->strings[S_BEGIN]); upd->strings[S_BEGIN].data = bp; upd->strings[S_BEGIN].size = nbp; } /* insert new number */ diff --git a/gs/src/gdevvec.c b/gs/src/gdevvec.c index 8a7dce814..82ee119d3 100644 --- a/gs/src/gdevvec.c +++ b/gs/src/gdevvec.c @@ -255,7 +255,7 @@ gdev_vector_reset(gx_device_vector * vdev) gx_hld_saved_color_init(&vdev->saved_fill_color); gx_hld_saved_color_init(&vdev->saved_stroke_color); vdev->clip_path_id = - vdev->no_clip_path_id = gs_next_ids(1); + vdev->no_clip_path_id = gs_next_ids(vdev->memory, 1); } /* Open the output file and stream. */ diff --git a/gs/src/gdevxcmp.c b/gs/src/gdevxcmp.c index dab02dc89..8a8f238ae 100644 --- a/gs/src/gdevxcmp.c +++ b/gs/src/gdevxcmp.c @@ -26,9 +26,9 @@ /* ---------------- Utilities ---------------- */ private void -gs_x_free(void *obj, client_name_t cname) +gs_x_free(gs_memory_t *mem, void *obj, client_name_t cname) { - gs_free(obj, 0 /*ignored*/, 0 /*ignored*/, cname); + gs_free(mem, obj, 0 /*ignored*/, 0 /*ignored*/, cname); } /* ---------------- Color mapping setup / cleanup ---------------- */ @@ -136,7 +136,7 @@ alloc_dynamic_colors(gx_device_X * xdev, int num_colors) { if (num_colors > 0) { xdev->cman.dynamic.colors = (x11_color_t **) - gs_malloc(sizeof(x11_color_t *), xdev->cman.num_rgb, + gs_malloc(xdev->memory, sizeof(x11_color_t *), xdev->cman.num_rgb, "x11 cman.dynamic.colors"); if (xdev->cman.dynamic.colors) { int i; @@ -192,7 +192,7 @@ free_ramp(gx_device_X * xdev, int num_used, int size) { if (num_used - 1 > 0) x_free_colors(xdev, xdev->cman.dither_ramp + 1, num_used - 1); - gs_x_free(xdev->cman.dither_ramp, "x11_setup_colors"); + gs_x_free(xdev->memory, xdev->cman.dither_ramp, "x11_setup_colors"); xdev->cman.dither_ramp = NULL; } @@ -216,7 +216,7 @@ setup_cube(gx_device_X * xdev, int ramp_size, bool colors) } xdev->cman.dither_ramp = - (x_pixel *) gs_malloc(sizeof(x_pixel), num_entries, + (x_pixel *) gs_malloc(xdev->memory, sizeof(x_pixel), num_entries, "gdevx setup_cube"); if (xdev->cman.dither_ramp == NULL) return false; @@ -315,7 +315,7 @@ gdev_x_setup_colors(gx_device_X * xdev) int count = 1 << min(xdev->color_info.depth, 8); xdev->cman.color_to_rgb.values = - (x11_rgb_t *)gs_malloc(sizeof(x11_rgb_t), count, + (x11_rgb_t *)gs_malloc(xdev->memory, sizeof(x11_rgb_t), count, "gdevx color_to_rgb"); if (xdev->cman.color_to_rgb.values) { int i; @@ -437,7 +437,7 @@ monochrome: default: eprintf1("Unknown palette: %s\n", xdev->palette); if (xdev->cman.color_to_rgb.values) { - gs_x_free(xdev->cman.color_to_rgb.values, "gdevx color_to_rgb"); + gs_x_free(xdev->memory, xdev->cman.color_to_rgb.values, "gdevx color_to_rgb"); xdev->cman.color_to_rgb.values = 0; } return_error(gs_error_rangecheck); @@ -478,7 +478,7 @@ gdev_x_free_dynamic_colors(gx_device_X *xdev) next = xcp->next; if (xcp->color.pad) x_free_colors(xdev, &xcp->color.pixel, 1); - gs_x_free(xcp, "x11_dynamic_color"); + gs_x_free(xdev->memory, xcp, "x11_dynamic_color"); } xdev->cman.dynamic.colors[i] = NULL; } @@ -501,14 +501,14 @@ gdev_x_free_colors(gx_device_X *xdev) } xdev->cman.std_cmap.map = 0; if (xdev->cman.dither_ramp) - gs_x_free(xdev->cman.dither_ramp, "x11 dither_colors"); + gs_x_free(xdev->memory, xdev->cman.dither_ramp, "x11 dither_colors"); if (xdev->cman.dynamic.colors) { gdev_x_free_dynamic_colors(xdev); - gs_x_free(xdev->cman.dynamic.colors, "x11 cman.dynamic.colors"); + gs_x_free(xdev->memory, xdev->cman.dynamic.colors, "x11 cman.dynamic.colors"); xdev->cman.dynamic.colors = NULL; } if (xdev->cman.color_to_rgb.values) { - gs_x_free(xdev->cman.color_to_rgb.values, "x11 color_to_rgb"); + gs_x_free(xdev->memory, xdev->cman.color_to_rgb.values, "x11 color_to_rgb"); xdev->cman.color_to_rgb.values = NULL; xdev->cman.color_to_rgb.size = 0; } @@ -740,7 +740,7 @@ gdev_x_map_rgb_color(gx_device * dev, const gx_color_value cv[]) return gx_no_color_index; } xcp = (x11_color_t *) - gs_malloc(sizeof(x11_color_t), 1, "x11_dynamic_color"); + gs_malloc(xdev->memory, sizeof(x11_color_t), 1, "x11_dynamic_color"); if (!xcp) return gx_no_color_index; xc.red = xcp->color.red = dr; diff --git a/gs/src/gdevxxf.c b/gs/src/gdevxxf.c index 6c796c3e8..ab4818ee0 100644 --- a/gs/src/gdevxxf.c +++ b/gs/src/gdevxxf.c @@ -421,7 +421,7 @@ x_render_char(gx_xfont * xf, gx_xglyph xg, gx_device * dev, h = bbox.q.y - bbox.p.y; wbm = ROUND_UP(w, align_bitmap_mod * 8); raster = wbm >> 3; - bits = (byte *) gs_malloc(h, raster, "x_render_char"); + bits = (byte *) gs_malloc(xdev->memory, h, raster, "x_render_char"); if (bits == 0) return gs_error_limitcheck; xpm = XCreatePixmap(xdev->dpy, xdev->win, w, h, 1); @@ -447,7 +447,7 @@ x_render_char(gx_xfont * xf, gx_xglyph xg, gx_device * dev, code = (*copy_mono) (dev, bits, 0, raster, gx_no_bitmap_id, xo + bbox.p.x, yo + bbox.p.y, w, h, gx_no_color_index, color); - gs_free((char *)bits, h, raster, "x_render_char"); + gs_free(xdev->memory, (char *)bits, h, raster, "x_render_char"); XFreePixmap(xdev->dpy, xpm); XFreeGC(xdev->dpy, fgc); XDestroyImage(xim); diff --git a/gs/src/gp_mac.c b/gs/src/gp_mac.c index b2a0eb02d..b7a994884 100644 --- a/gs/src/gp_mac.c +++ b/gs/src/gp_mac.c @@ -142,7 +142,7 @@ gp_get_realtime(long *pdt) if (gettimeofday(&tp) == -1) { lprintf("Ghostscript: gettimeofday failed!\n"); - gs_abort(); + gs_abort(NULL); } /* tp.tv_sec is #secs since Jan 1, 1970 */ diff --git a/gs/src/gs.c b/gs/src/gs.c index 057fdc11c..d9cb26f62 100644 --- a/gs/src/gs.c +++ b/gs/src/gs.c @@ -41,7 +41,8 @@ int main(int argc, char *argv[]) { int exit_status = 0; - gs_main_instance *minst = gs_main_instance_default(); + gs_main_instance *minst = gs_main_alloc_instance(gs_malloc_init(NULL)); + int code = gs_main_init_with_args(minst, argc, argv); #ifdef RUN_STRINGS @@ -84,7 +85,7 @@ main(int argc, char *argv[]) exit_status = 255; } - gs_to_exit_with_code(exit_status, code); + gs_to_exit_with_code(minst->heap, exit_status, code); switch (exit_status) { case 0: diff --git a/gs/src/gs_dll_call.h b/gs/src/gs_dll_call.h new file mode 100644 index 000000000..34d63738a --- /dev/null +++ b/gs/src/gs_dll_call.h @@ -0,0 +1,66 @@ +/* Portions Copyright (C) 2003 artofcode LLC. + Portions Copyright (C) 2003 Artifex Software Inc. + This software is based in part on the work of the Independent JPEG Group. + All Rights Reserved. + + This software is distributed under license and may not be copied, modified + or distributed except as expressly authorized under the terms of that + license. Refer to licensing information at http://www.artifex.com/ or + contact Artifex Software, Inc., 101 Lucas Valley Road #110, + San Rafael, CA 94903, (415)492-9861, for further information. */ +/*$Id$ */ + +/* calling convention macros for windows style dlls. + */ +#ifndef GS_DLL_CALL_H +#define GS_DLL_CALL_H + + +#ifdef __WINDOWS__ +# define _Windows +#endif + +#ifdef _Windows +# ifndef GSDLLEXPORT +# define GSDLLEXPORT __declspec(dllexport) +# endif +# ifndef GSDLLAPI +# define GSDLLAPI __stdcall +# endif +# ifndef GSDLLCALL +# define GSDLLCALL __stdcall +# endif +#endif /* _Windows */ + +#if defined(OS2) && defined(__IBMC__) +# ifndef GSDLLAPI +# define GSDLLAPI _System +# endif +# ifndef GSDLLCALL +# define GSDLLCALL _System +# endif +#endif /* OS2 && __IBMC */ + +#ifdef __MACOS__ +# pragma export on +#endif + +#ifndef GSDLLEXPORT +# define GSDLLEXPORT +#endif +#ifndef GSDLLAPI +# define GSDLLAPI +#endif +#ifndef GSDLLCALL +# define GSDLLCALL +#endif + +#if defined(__IBMC__) +# define GSDLLAPIPTR * GSDLLAPI +# define GSDLLCALLPTR * GSDLLCALL +#else +# define GSDLLAPIPTR GSDLLAPI * +# define GSDLLCALLPTR GSDLLCALL * +#endif + +#endif /* GS_DLL_CALL_H */ diff --git a/gs/src/gsalloc.c b/gs/src/gsalloc.c index 07f88df5b..4b72515e8 100644 --- a/gs/src/gsalloc.c +++ b/gs/src/gsalloc.c @@ -185,10 +185,10 @@ const gs_memory_procs_t gs_ref_memory_procs = * Allocate and mostly initialize the state of an allocator (system, global, * or local). Does not initialize global or space. */ -private void *ialloc_solo(gs_raw_memory_t *, gs_memory_type_ptr_t, +private void *ialloc_solo(gs_memory_t *, gs_memory_type_ptr_t, chunk_t **); gs_ref_memory_t * -ialloc_alloc_state(gs_raw_memory_t * parent, uint chunk_size) +ialloc_alloc_state(gs_memory_t * parent, uint chunk_size) { chunk_t *cp; gs_ref_memory_t *iimem = ialloc_solo(parent, &st_ref_memory, &cp); @@ -197,7 +197,8 @@ ialloc_alloc_state(gs_raw_memory_t * parent, uint chunk_size) return 0; iimem->stable_memory = (gs_memory_t *)iimem; iimem->procs = gs_ref_memory_procs; - iimem->parent = parent; + iimem->gs_lib_ctx = parent->gs_lib_ctx; + iimem->non_gc_memory = parent; iimem->chunk_size = chunk_size; iimem->large_size = ((chunk_size / 4) & -obj_align_mod) + 1; iimem->is_controlled = false; @@ -228,7 +229,7 @@ ialloc_alloc_state(gs_raw_memory_t * parent, uint chunk_size) /* Allocate a 'solo' object with its own chunk. */ private void * -ialloc_solo(gs_raw_memory_t * parent, gs_memory_type_ptr_t pstype, +ialloc_solo(gs_memory_t * parent, gs_memory_type_ptr_t pstype, chunk_t ** pcp) { /* * We can't assume that the parent uses the same object header @@ -1539,7 +1540,7 @@ i_register_root(gs_memory_t * mem, gs_gc_root_t * rp, gs_ptr_type_t ptype, gs_ref_memory_t * const imem = (gs_ref_memory_t *)mem; if (rp == NULL) { - rp = gs_raw_alloc_struct_immovable(imem->parent, &st_gc_root_t, + rp = gs_raw_alloc_struct_immovable(imem->non_gc_memory, &st_gc_root_t, "i_register_root"); if (rp == 0) return_error(gs_error_VMerror); @@ -1568,7 +1569,7 @@ i_unregister_root(gs_memory_t * mem, gs_gc_root_t * rp, client_name_t cname) rpp = &(*rpp)->next; *rpp = (*rpp)->next; if (rp->free_on_unregister) - gs_free_object(imem->parent, rp, "i_unregister_root"); + gs_free_object(imem->non_gc_memory, rp, "i_unregister_root"); } /* ================ Chunks ================ */ @@ -1638,7 +1639,7 @@ private chunk_t * alloc_acquire_chunk(gs_ref_memory_t * mem, ulong csize, bool has_strings, client_name_t cname) { - gs_raw_memory_t *parent = mem->parent; + gs_memory_t *parent = mem->non_gc_memory; chunk_t *cp; byte *cdata; @@ -1648,16 +1649,20 @@ alloc_acquire_chunk(gs_ref_memory_t * mem, ulong csize, bool has_strings, return 0; #endif cp = gs_raw_alloc_struct_immovable(parent, &st_chunk, cname); - if ((ulong) (mem->allocated + mem->inherited) >= mem->limit) { - mem->gc_status.requested += csize; - if (mem->limit >= mem->gc_status.max_vm || - mem->gc_status.psignal == 0 - ) - return 0; - if_debug4('0', "[0]signaling space=%d, allocated=%ld, limit=%ld, requested=%ld\n", - mem->space, (long)mem->allocated, - (long)mem->limit, (long)mem->gc_status.requested); - *mem->gc_status.psignal = mem->gc_status.signal_value; + + if( mem->gc_status.psignal != 0) { + /* we have a garbage collector */ + if ((ulong) (mem->allocated + mem->inherited) >= mem->limit) { + mem->gc_status.requested += csize; + if (mem->limit >= mem->gc_status.max_vm) { + gs_free_object(parent, cp, cname); + return 0; + } + if_debug4('0', "[0]signaling space=%d, allocated=%ld, limit=%ld, requested=%ld\n", + mem->space, (long)mem->allocated, + (long)mem->limit, (long)mem->gc_status.requested); + *mem->gc_status.psignal = mem->gc_status.signal_value; + } } cdata = gs_alloc_bytes_immovable(parent, csize, cname); if (cp == 0 || cdata == 0) { @@ -1802,7 +1807,7 @@ alloc_unlink_chunk(chunk_t * cp, gs_ref_memory_t * mem) void alloc_free_chunk(chunk_t * cp, gs_ref_memory_t * mem) { - gs_raw_memory_t *parent = mem->parent; + gs_memory_t *parent = mem->non_gc_memory; byte *cdata = (byte *)cp->chead; ulong csize = (byte *)cp->cend - cdata; @@ -1964,7 +1969,7 @@ debug_dump_contents(const byte * bot, const byte * top, int indent, /* Relevant options: type_addresses, no_types, pointers, pointed_strings, */ /* contents. */ void -debug_print_object(const void *obj, const dump_control_t * control) +debug_print_object(const gs_memory_t *mem, const void *obj, const dump_control_t * control) { const obj_header_t *pre = ((const obj_header_t *)obj) - 1; ulong size = pre_obj_contents_size(pre); @@ -1999,7 +2004,7 @@ debug_print_object(const void *obj, const dump_control_t * control) gs_ptr_type_t ptype; if (proc != gs_no_struct_enum_ptrs) - for (; (ptype = (*proc)(pre + 1, size, index, &eptr, type, NULL)) != 0; + for (; (ptype = (*proc)(mem, pre + 1, size, index, &eptr, type, NULL)) != 0; ++index ) { const void *ptr = eptr.ptr; @@ -2031,7 +2036,7 @@ debug_print_object(const void *obj, const dump_control_t * control) /* Print the contents of a chunk with the given options. */ /* Relevant options: all. */ void -debug_dump_chunk(const chunk_t * cp, const dump_control_t * control) +debug_dump_chunk(const gs_memory_t *mem, const chunk_t * cp, const dump_control_t * control) { dprintf1("chunk at 0x%lx:\n", (ulong) cp); dprintf3(" chead=0x%lx cbase=0x%lx sbase=0x%lx\n", @@ -2062,16 +2067,16 @@ debug_dump_chunk(const chunk_t * cp, const dump_control_t * control) (const byte *)(pre + 1) + size, control) ) - debug_print_object(pre + 1, control); + debug_print_object(mem, pre + 1, control); END_OBJECTS_SCAN_NO_ABORT } void -debug_print_chunk(const chunk_t * cp) +debug_print_chunk(const gs_memory_t *mem, const chunk_t * cp) { dump_control_t control; control = dump_control_default; - debug_dump_chunk(cp, &control); + debug_dump_chunk(mem, cp, &control); } /* Print the contents of all chunks managed by an allocator. */ @@ -2085,7 +2090,7 @@ debug_dump_memory(const gs_ref_memory_t * mem, const dump_control_t * control) const chunk_t *cp = (mcp == mem->pcc ? &mem->cc : mcp); if (obj_in_control_region(cp->cbase, cp->cend, control)) - debug_dump_chunk(cp, control); + debug_dump_chunk((const gs_memory_t *)mem, cp, control); } } @@ -2107,10 +2112,10 @@ debug_find_pointers(const gs_ref_memory_t *mem, const void *target) enum_ptr_t eptr; if (proc) /* doesn't trace refs */ - for (; (*proc)(pre + 1, size, index, &eptr, pre->o_type, NULL); ++index) + for (; (*proc)(mem, pre + 1, size, index, &eptr, pre->o_type, NULL); ++index) if (eptr.ptr == target) { dprintf1("Index %d in", index); - debug_print_object(pre + 1, &control); + debug_print_object((const gs_memory_t *)mem, pre + 1, &control); } END_OBJECTS_SCAN_NO_ABORT } diff --git a/gs/src/gsalloc.h b/gs/src/gsalloc.h index 72fa3572b..4aeb08870 100644 --- a/gs/src/gsalloc.h +++ b/gs/src/gsalloc.h @@ -52,7 +52,7 @@ void gs_memory_set_vm_reclaim(gs_ref_memory_t * mem, bool enabled); * Allocate and mostly initialize the state of an allocator (system, global, * or local). Does not initialize global or space. */ -gs_ref_memory_t *ialloc_alloc_state(gs_raw_memory_t *, uint); +gs_ref_memory_t *ialloc_alloc_state(gs_memory_t *, uint); /* * Add a chunk to an externally controlled allocator. Such allocators diff --git a/gs/src/gsalphac.c b/gs/src/gsalphac.c index 1ecef7437..a9e421159 100644 --- a/gs/src/gsalphac.c +++ b/gs/src/gsalphac.c @@ -124,7 +124,7 @@ gs_create_composite_alpha(gs_composite_t ** ppcte, mem, return_error(gs_error_VMerror), "gs_create_composite_alpha"); pcte->type = &gs_composite_alpha_type; - pcte->id = gs_next_ids(1); + pcte->id = gs_next_ids(mem, 1); pcte->params = *params; *ppcte = (gs_composite_t *) pcte; return 0; diff --git a/gs/src/gsccode.h b/gs/src/gsccode.h index 094b54d7b..00a298697 100644 --- a/gs/src/gsccode.h +++ b/gs/src/gsccode.h @@ -90,7 +90,7 @@ typedef ulong gs_glyph; #define gs_max_glyph GS_MAX_GLYPH /* Define a procedure for marking a gs_glyph during garbage collection. */ -typedef bool (*gs_glyph_mark_proc_t)(gs_glyph glyph, void *proc_data); +typedef bool (*gs_glyph_mark_proc_t)(const gs_memory_t *mem, gs_glyph glyph, void *proc_data); /* Define the indices for known encodings. */ typedef enum { diff --git a/gs/src/gscdevn.c b/gs/src/gscdevn.c index 172b8b819..d0d2a4ceb 100644 --- a/gs/src/gscdevn.c +++ b/gs/src/gscdevn.c @@ -455,7 +455,7 @@ check_DeviceN_component_names(const gs_color_space * pcs, gs_state * pgs) /* * Get the character string and length for the component name. */ - pcs->params.device_n.get_colorname_string(names[i], &pname, &name_size); + pcs->params.device_n.get_colorname_string(dev->memory, names[i], &pname, &name_size); /* * Postscript does not accept /None as a color component but it is * allowed in PDF so we accept it. It is also accepted as a diff --git a/gs/src/gscolor.c b/gs/src/gscolor.c index 51af7e871..c29e97309 100644 --- a/gs/src/gscolor.c +++ b/gs/src/gscolor.c @@ -109,7 +109,7 @@ gs_setgray(gs_state * pgs, floatp gray) gs_color_space cs; int code; - gs_cspace_init_DeviceGray(&cs); + gs_cspace_init_DeviceGray(pgs->memory, &cs); if ((code = gs_setcolorspace(pgs, &cs)) >= 0) { gs_client_color * pcc = pgs->ccolor; @@ -128,7 +128,7 @@ gs_setrgbcolor(gs_state * pgs, floatp r, floatp g, floatp b) gs_color_space cs; int code; - gs_cspace_init_DeviceRGB(&cs); + gs_cspace_init_DeviceRGB(pgs->memory, &cs); if ((code = gs_setcolorspace(pgs, &cs)) >= 0) { gs_client_color * pcc = pgs->ccolor; @@ -177,7 +177,7 @@ gs_settransfer_remap(gs_state * pgs, gs_mapping_proc tproc, bool remap) rc_unshare_struct(ptran->gray, gx_transfer_map, &st_transfer_map, pgs->memory, goto fail, "gs_settransfer"); ptran->gray->proc = tproc; - ptran->gray->id = gs_next_ids(1); + ptran->gray->id = gs_next_ids(pgs->memory, 1); ptran->red = 0; ptran->green = 0; ptran->blue = 0; @@ -213,7 +213,7 @@ gx_set_device_color_1(gs_state * pgs) gs_setoverprint(pgs, false); gs_setoverprintmode(pgs, 0); - gs_cspace_init_DeviceGray(&cs); + gs_cspace_init_DeviceGray(pgs->memory, &cs); gs_setcolorspace(pgs, &cs); set_nonclient_dev_color(pgs->dev_color, 1); pgs->log_op = lop_default; diff --git a/gs/src/gscolor1.c b/gs/src/gscolor1.c index cc5eed386..f56f1ef05 100644 --- a/gs/src/gscolor1.c +++ b/gs/src/gscolor1.c @@ -47,7 +47,7 @@ gs_setcmykcolor(gs_state * pgs, floatp c, floatp m, floatp y, floatp k) gs_color_space cs; int code; - gs_cspace_init_DeviceCMYK(&cs); + gs_cspace_init_DeviceCMYK(pgs->memory, &cs); if ((code = gs_setcolorspace(pgs, &cs)) >= 0) { gs_client_color * pcc = pgs->ccolor; @@ -78,7 +78,7 @@ gs_setblackgeneration_remap(gs_state * pgs, gs_mapping_proc proc, bool remap) return_error(gs_error_VMerror), "gs_setblackgeneration"); pgs->black_generation->proc = proc; - pgs->black_generation->id = gs_next_ids(1); + pgs->black_generation->id = gs_next_ids(pgs->memory, 1); if (remap) { load_transfer_map(pgs, pgs->black_generation, 0.0); gx_unset_dev_color(pgs); @@ -108,7 +108,7 @@ gs_setundercolorremoval_remap(gs_state * pgs, gs_mapping_proc proc, bool remap) return_error(gs_error_VMerror), "gs_setundercolorremoval"); pgs->undercolor_removal->proc = proc; - pgs->undercolor_removal->id = gs_next_ids(1); + pgs->undercolor_removal->id = gs_next_ids(pgs->memory, 1); if (remap) { load_transfer_map(pgs, pgs->undercolor_removal, -1.0); gx_unset_dev_color(pgs); @@ -133,7 +133,7 @@ gs_setcolortransfer_remap(gs_state * pgs, gs_mapping_proc red_proc, { gx_transfer *ptran = &pgs->set_transfer; gx_transfer old; - gs_id new_ids = gs_next_ids(4); + gs_id new_ids = gs_next_ids(pgs->memory, 4); gx_device * dev = pgs->device; old = *ptran; diff --git a/gs/src/gscolor3.c b/gs/src/gscolor3.c index df4e2ca9e..84a572b82 100644 --- a/gs/src/gscolor3.c +++ b/gs/src/gscolor3.c @@ -74,7 +74,7 @@ gs_shfill(gs_state * pgs, const gs_shading_t * psh) pgs->memory); if (code < 0) return code; - gs_cspace_init(&cs, &gs_color_space_type_Pattern, NULL); + gs_cspace_init(&cs, &gs_color_space_type_Pattern, pgs->memory, false); cs.params.pattern.has_base_space = false; code = cs.type->remap_color(&cc, &cs, &devc, (gs_imager_state *)pgs, pgs->device, gs_color_select_texture); diff --git a/gs/src/gscparam.c b/gs/src/gscparam.c index e04971430..917dabbb9 100644 --- a/gs/src/gscparam.c +++ b/gs/src/gscparam.c @@ -73,7 +73,7 @@ ENUM_PTRS_WITH(c_param_enum_ptrs, gs_c_param *param) { value.value = *(const gs_param_value *)¶m->value; value.type = param->type; - return gs_param_typed_value_enum_ptrs(&value, sizeof(value), index, + return gs_param_typed_value_enum_ptrs(mem, &value, sizeof(value), index, pep, NULL, gcst); } } diff --git a/gs/src/gscpixel.c b/gs/src/gscpixel.c index 4479c92c1..4dabbcfa6 100644 --- a/gs/src/gscpixel.c +++ b/gs/src/gscpixel.c @@ -50,7 +50,7 @@ private const gs_color_space_type gs_color_space_type_DevicePixel = { /* Initialize a DevicePixel color space. */ int -gs_cspace_init_DevicePixel(gs_color_space * pcs, int depth) +gs_cspace_init_DevicePixel(const gs_memory_t *mem, gs_color_space * pcs, int depth) { switch (depth) { case 1: @@ -64,7 +64,7 @@ gs_cspace_init_DevicePixel(gs_color_space * pcs, int depth) default: return_error(gs_error_rangecheck); } - gs_cspace_init(pcs, &gs_color_space_type_DevicePixel, NULL); + gs_cspace_init(pcs, &gs_color_space_type_DevicePixel, mem, false); pcs->params.pixel.depth = depth; return 0; } diff --git a/gs/src/gscpixel.h b/gs/src/gscpixel.h index 061bc5105..535e00e3e 100644 --- a/gs/src/gscpixel.h +++ b/gs/src/gscpixel.h @@ -22,6 +22,6 @@ # define gscpixel_INCLUDED /* Initialize a DevicePixel color space. */ -int gs_cspace_init_DevicePixel(gs_color_space * pcs, int depth); +int gs_cspace_init_DevicePixel(const gs_memory_t *mem, gs_color_space * pcs, int depth); #endif /* gscpixel_INCLUDED */ diff --git a/gs/src/gscrd.c b/gs/src/gscrd.c index 2366637d3..ed5cbca1f 100644 --- a/gs/src/gscrd.c +++ b/gs/src/gscrd.c @@ -255,7 +255,7 @@ gs_cie_render1_build(gs_cie_render ** ppcrd, gs_memory_t * mem, rc_alloc_struct_1(pcrd, gs_cie_render, &st_cie_render1, mem, return_error(gs_error_VMerror), cname); - pcrd->id = gs_next_ids(1); + pcrd->id = gs_next_ids(mem, 1); /* Initialize pointers for the GC. */ pcrd->client_data = 0; pcrd->RenderTable.lookup.table = 0; @@ -279,7 +279,9 @@ gs_cie_render1_build(gs_cie_render ** ppcrd, gs_memory_t * mem, * default values. */ int -gs_cie_render1_init_from(gs_cie_render * pcrd, void *client_data, +gs_cie_render1_init_from(const gs_memory_t *mem, + gs_cie_render * pcrd, + void *client_data, const gs_cie_render * pfrom_crd, const gs_vector3 * WhitePoint, const gs_vector3 * BlackPoint, @@ -294,7 +296,7 @@ gs_cie_render1_init_from(gs_cie_render * pcrd, void *client_data, const gs_range3 * RangeABC, const gs_cie_render_table_t * RenderTable) { - pcrd->id = gs_next_ids(1); + pcrd->id = gs_next_ids(mem, 1); pcrd->client_data = client_data; pcrd->points.WhitePoint = *WhitePoint; pcrd->points.BlackPoint = @@ -343,7 +345,8 @@ gs_cie_render1_init_from(gs_cie_render * pcrd, void *client_data, * Initialize a CRD without the option of copying cached values. */ int -gs_cie_render1_initialize(gs_cie_render * pcrd, void *client_data, +gs_cie_render1_initialize(const gs_memory_t *mem, + gs_cie_render * pcrd, void *client_data, const gs_vector3 * WhitePoint, const gs_vector3 * BlackPoint, const gs_matrix3 * MatrixPQR, @@ -357,7 +360,7 @@ gs_cie_render1_initialize(gs_cie_render * pcrd, void *client_data, const gs_range3 * RangeABC, const gs_cie_render_table_t * RenderTable) { - return gs_cie_render1_init_from(pcrd, client_data, NULL, + return gs_cie_render1_init_from(mem, pcrd, client_data, NULL, WhitePoint, BlackPoint, MatrixPQR, RangePQR, TransformPQR, MatrixLMN, EncodeLMN, RangeLMN, diff --git a/gs/src/gscrd.h b/gs/src/gscrd.h index dbb54abb3..dcad21811 100644 --- a/gs/src/gscrd.h +++ b/gs/src/gscrd.h @@ -50,7 +50,9 @@ int * default values. */ int - gs_cie_render1_init_from(gs_cie_render * pcrd, void *client_data, + gs_cie_render1_init_from(const gs_memory_t *mem, + gs_cie_render *pcrd, + void *client_data, const gs_cie_render * pfrom_crd, const gs_vector3 * WhitePoint, const gs_vector3 * BlackPoint, @@ -68,7 +70,9 @@ int * Initialize a CRD without the option of copying cached values. */ int - gs_cie_render1_initialize(gs_cie_render * pcrd, void *client_data, + gs_cie_render1_initialize(const gs_memory_t *mem, + gs_cie_render *pcrd, + void *client_data, const gs_vector3 * WhitePoint, const gs_vector3 * BlackPoint, const gs_matrix3 * MatrixPQR, diff --git a/gs/src/gscscie.c b/gs/src/gscscie.c index 31aa6e069..97fca2327 100644 --- a/gs/src/gscscie.c +++ b/gs/src/gscscie.c @@ -133,10 +133,10 @@ gx_concrete_space_CIE(const gs_color_space * pcs, const gs_imager_state * pis) if (pcie == 0 || pcie->RenderTable.lookup.table == 0 || pcie->RenderTable.lookup.m == 3 ) { - gs_cspace_init_DeviceRGB(&rgb_cs); /* idempotent initialization */ + gs_cspace_init_DeviceRGB(pis->memory, &rgb_cs); /* idempotent initialization */ return &rgb_cs; } else { /* pcie->RenderTable.lookup.m == 4 */ - gs_cspace_init_DeviceCMYK(&cmyk_cs); /* idempotent initialization */ + gs_cspace_init_DeviceCMYK(pis->memory, &cmyk_cs); /* idempotent initialization */ return &cmyk_cs; } } diff --git a/gs/src/gscsepr.c b/gs/src/gscsepr.c index 101cd69da..abc0e9ad4 100644 --- a/gs/src/gscsepr.c +++ b/gs/src/gscsepr.c @@ -445,7 +445,7 @@ check_Separation_component_name(const gs_color_space * pcs, gs_state * pgs) /* * Get the character string and length for the component name. */ - pcs->params.separation.get_colorname_string(name, &pname, &name_size); + pcs->params.separation.get_colorname_string(dev->memory, name, &pname, &name_size); /* * Compare the colorant name to the device's. If the device's * compare routine returns GX_DEVICE_COLOR_MAX_COMPONENTS then the diff --git a/gs/src/gscspace.c b/gs/src/gscspace.c index 80bc11003..05c1a0135 100644 --- a/gs/src/gscspace.c +++ b/gs/src/gscspace.c @@ -90,11 +90,11 @@ public_st_base_color_space(); void gs_cspace_init(gs_color_space *pcs, const gs_color_space_type * pcstype, - gs_memory_t *mem) + gs_memory_t *mem, bool isheap) { pcs->type = pcstype; - pcs->pmem = mem; - pcs->id = gs_next_ids(1); + pcs->pmem = isheap ? mem : NULL; + pcs->id = gs_next_ids(mem, 1); } int @@ -109,13 +109,13 @@ gs_cspace_alloc(gs_color_space ** ppcspace, if (pcspace == 0) return_error(gs_error_VMerror); if (pcstype != 0) - gs_cspace_init(pcspace, pcstype, mem); + gs_cspace_init(pcspace, pcstype, mem, true); *ppcspace = pcspace; return 0; } int -gs_cspace_init_DeviceGray(gs_color_space *pcs) +gs_cspace_init_DeviceGray(const gs_memory_t *mem, gs_color_space *pcs) { /* parameterless color space; no re-entrancy problems */ static gs_color_space dev_gray_proto; @@ -123,7 +123,7 @@ gs_cspace_init_DeviceGray(gs_color_space *pcs) if (dev_gray_proto.id == 0) gs_cspace_init( &dev_gray_proto, &gs_color_space_type_DeviceGray, - NULL ); + mem, false ); *pcs = dev_gray_proto; return 0; } @@ -133,12 +133,12 @@ gs_cspace_build_DeviceGray(gs_color_space ** ppcspace, gs_memory_t * pmem) int code = gs_cspace_alloc(ppcspace, NULL, pmem); if (code >= 0) - code = gs_cspace_init_DeviceGray(*ppcspace); + code = gs_cspace_init_DeviceGray(pmem, *ppcspace); return code; } int -gs_cspace_init_DeviceRGB(gs_color_space *pcs) +gs_cspace_init_DeviceRGB(const gs_memory_t *mem, gs_color_space *pcs) { /* parameterless color space; no re-entrancy problems */ static gs_color_space dev_rgb_proto; @@ -146,7 +146,7 @@ gs_cspace_init_DeviceRGB(gs_color_space *pcs) if (dev_rgb_proto.id == 0) gs_cspace_init( &dev_rgb_proto, &gs_color_space_type_DeviceRGB, - NULL ); + mem, false ); *pcs = dev_rgb_proto; return 0; } @@ -156,12 +156,12 @@ gs_cspace_build_DeviceRGB(gs_color_space ** ppcspace, gs_memory_t * pmem) int code = gs_cspace_alloc(ppcspace, NULL, pmem); if (code >= 0) - code = gs_cspace_init_DeviceRGB(*ppcspace); + code = gs_cspace_init_DeviceRGB(pmem, *ppcspace); return code; } int -gs_cspace_init_DeviceCMYK(gs_color_space *pcs) +gs_cspace_init_DeviceCMYK(const gs_memory_t *mem, gs_color_space *pcs) { /* parameterless color space; no re-entrancy problems */ static gs_color_space dev_cmyk_proto; @@ -169,7 +169,7 @@ gs_cspace_init_DeviceCMYK(gs_color_space *pcs) if (dev_cmyk_proto.id == 0) gs_cspace_init( &dev_cmyk_proto, &gs_color_space_type_DeviceCMYK, - NULL ); + mem, false ); *pcs = dev_cmyk_proto; return 0; } @@ -179,7 +179,7 @@ gs_cspace_build_DeviceCMYK(gs_color_space ** ppcspace, gs_memory_t * pmem) int code = gs_cspace_alloc(ppcspace, NULL, pmem); if (code >= 0) - code = gs_cspace_init_DeviceCMYK(*ppcspace); + code = gs_cspace_init_DeviceCMYK(pmem, *ppcspace); return code; } diff --git a/gs/src/gscspace.h b/gs/src/gscspace.h index a489320b6..e9bde4fdc 100644 --- a/gs/src/gscspace.h +++ b/gs/src/gscspace.h @@ -287,7 +287,7 @@ typedef ulong gs_separation_name; /* BOGUS */ * names. */ typedef int (gs_callback_func_get_colorname_string) - (gs_separation_name colorname, unsigned char **ppstr, unsigned int *plen); + (const gs_memory_t *mem, gs_separation_name colorname, unsigned char **ppstr, unsigned int *plen); typedef enum { SEP_NONE, SEP_ALL, SEP_OTHER } separation_type; @@ -426,13 +426,13 @@ typedef struct gs_color_space_s gs_color_space; */ extern int - gs_cspace_init_DeviceGray(gs_color_space *pcs), + gs_cspace_init_DeviceGray(const gs_memory_t *mem, gs_color_space *pcs), gs_cspace_build_DeviceGray(gs_color_space ** ppcspace, gs_memory_t * pmem), - gs_cspace_init_DeviceRGB(gs_color_space *pcs), + gs_cspace_init_DeviceRGB(const gs_memory_t *mem, gs_color_space *pcs), gs_cspace_build_DeviceRGB(gs_color_space ** ppcspace, gs_memory_t * pmem), - gs_cspace_init_DeviceCMYK(gs_color_space *pcs), + gs_cspace_init_DeviceCMYK(const gs_memory_t *mem, gs_color_space *pcs), gs_cspace_build_DeviceCMYK(gs_color_space ** ppcspace, gs_memory_t * pmem); diff --git a/gs/src/gsdevice.c b/gs/src/gsdevice.c index f94e8b490..3240e8261 100644 --- a/gs/src/gsdevice.c +++ b/gs/src/gsdevice.c @@ -53,7 +53,7 @@ gx_device_finalize(void *vptr) dev->finalize(dev); discard(gs_closedevice(dev)); if (dev->stype_is_dynamic) - gs_free_const_object(&gs_memory_default, dev->stype, + gs_free_const_object(dev->memory->non_gc_memory, dev->stype, "gx_device_finalize"); } @@ -251,7 +251,7 @@ gs_copydevice2(gx_device ** pnew_dev, const gx_device * dev, bool keep_open, * Just allocate a new stype and copy the old one into it. */ a_std = (gs_memory_struct_type_t *) - gs_alloc_bytes_immovable(&gs_memory_default, sizeof(*std), + gs_alloc_bytes_immovable(mem->non_gc_memory, sizeof(*std), "gs_copydevice(stype)"); if (!a_std) return_error(gs_error_VMerror); @@ -263,7 +263,7 @@ gs_copydevice2(gx_device ** pnew_dev, const gx_device * dev, bool keep_open, } else { /* We need to figure out or adjust the stype. */ a_std = (gs_memory_struct_type_t *) - gs_alloc_bytes_immovable(&gs_memory_default, sizeof(*std), + gs_alloc_bytes_immovable(mem->non_gc_memory, sizeof(*std), "gs_copydevice(stype)"); if (!a_std) return_error(gs_error_VMerror); @@ -295,7 +295,7 @@ gs_copydevice2(gx_device ** pnew_dev, const gx_device * dev, bool keep_open, if (code < 0) { gs_free_object(mem, new_dev, "gs_copydevice(device)"); if (a_std) - gs_free_object(&gs_memory_default, a_std, "gs_copydevice(stype)"); + gs_free_object(dev->memory->non_gc_memory, a_std, "gs_copydevice(stype)"); return code; } *pnew_dev = new_dev; @@ -551,6 +551,24 @@ gx_device_set_margins(gx_device * dev, const float *margins /*[4] */ , } } + +/* Handle 90 and 270 degree rotation of the Tray + * Device must support TrayOrientation in its InitialMatrix and get/put params + */ +private void +gx_device_TrayOrientationRotate(gx_device *dev) +{ + if ( dev->TrayOrientation == 90 || dev->TrayOrientation == 270) { + /* page sizes don't rotate, height and width do rotate + * HWResolution, HWSize, and MediaSize parameters interact, + * and must be set before TrayOrientation + */ + floatp tmp = dev->height; + dev->height = dev->width; + dev->width = tmp; + } +} + /* Set the width and height, updating MediaSize to remain consistent. */ void gx_device_set_width_height(gx_device * dev, int width, int height) @@ -559,6 +577,7 @@ gx_device_set_width_height(gx_device * dev, int width, int height) dev->height = height; dev->MediaSize[0] = width * 72.0 / dev->HWResolution[0]; dev->MediaSize[1] = height * 72.0 / dev->HWResolution[1]; + gx_device_TrayOrientationRotate(dev); } /* Set the resolution, updating width and height to remain consistent. */ @@ -569,6 +588,7 @@ gx_device_set_resolution(gx_device * dev, floatp x_dpi, floatp y_dpi) dev->HWResolution[1] = y_dpi; dev->width = (int)(dev->MediaSize[0] * x_dpi / 72.0 + 0.5); dev->height = (int)(dev->MediaSize[1] * y_dpi / 72.0 + 0.5); + gx_device_TrayOrientationRotate(dev); } /* Set the MediaSize, updating width and height to remain consistent. */ @@ -579,6 +599,7 @@ gx_device_set_media_size(gx_device * dev, floatp media_width, floatp media_heigh dev->MediaSize[1] = media_height; dev->width = (int)(media_width * dev->HWResolution[0] / 72.0 + 0.499); dev->height = (int)(media_height * dev->HWResolution[1] / 72.0 + 0.499); + gx_device_TrayOrientationRotate(dev); } /* @@ -790,7 +811,7 @@ gx_device_open_output_file(const gx_device * dev, char *fname, if (parsed.iodev && !strcmp(parsed.iodev->dname, "%stdout%")) { if (parsed.fname) return_error(gs_error_undefinedfilename); - *pfile = gs_stdout; + *pfile = dev->memory->gs_lib_ctx->fstdout; /* Force stdout to binary. */ return gp_setmode_binary(*pfile, true); } diff --git a/gs/src/gsequivc.c b/gs/src/gsequivc.c index 48998ad4b..03d816eb2 100644 --- a/gs/src/gsequivc.c +++ b/gs/src/gsequivc.c @@ -134,8 +134,8 @@ update_Separation_spot_equivalent_cmyk_colors(gx_device * pdev, unsigned char * pcs_sep_name; pcs->params.separation.get_colorname_string - (pcs->params.separation.sep_name, &pcs_sep_name, - &cs_sep_name_size); + (pdev->memory, pcs->params.separation.sep_name, &pcs_sep_name, + &cs_sep_name_size); if (compare_color_names(dev_sep_name->data, dev_sep_name->size, pcs_sep_name, cs_sep_name_size)) { gs_color_space temp_cs = *pcs; @@ -177,8 +177,8 @@ update_DeviceN_spot_equivalent_cmyk_colors(gx_device * pdev, */ for (j = 0; j < pcs->params.device_n.num_components; j++) { pcs->params.device_n.get_colorname_string - (pcs->params.device_n.names[j], &pcs_sep_name, - &cs_sep_name_size); + (pdev->memory, pcs->params.device_n.names[j], + &pcs_sep_name, &cs_sep_name_size); if (compare_color_names("None", 4, pcs_sep_name, cs_sep_name_size)) return; } @@ -194,8 +194,8 @@ update_DeviceN_spot_equivalent_cmyk_colors(gx_device * pdev, for (j = 0; j < pcs->params.device_n.num_components; j++) { pcs->params.device_n.get_colorname_string - (pcs->params.device_n.names[j], &pcs_sep_name, - &cs_sep_name_size); + (pdev->memory, pcs->params.device_n.names[j], &pcs_sep_name, + &cs_sep_name_size); if (compare_color_names(dev_sep_name->data, dev_sep_name->size, pcs_sep_name, cs_sep_name_size)) { gs_color_space temp_cs = *pcs; diff --git a/gs/src/gsexit.h b/gs/src/gsexit.h index 43353332f..c89afbca4 100644 --- a/gs/src/gsexit.h +++ b/gs/src/gsexit.h @@ -25,17 +25,17 @@ * normally they do exit cleanup and error messaging * without calling system exit() returning to the caller. */ -int gs_to_exit(int exit_status); +int gs_to_exit(const gs_memory_t *mem, int exit_status); /** some clients prefer this to return the postscript error code * to the caller otherwise the same as gs_to_exit() */ -int gs_to_exit_with_code(int exit_status, int code); +int gs_to_exit_with_code(const gs_memory_t *mem, int exit_status, int code); /** The client must provide this. * After possible cleanup it may call gp_do_exit() which calls exit() in a platform * independent way. This is a fatal error so returning is not a good idea. */ -void gs_abort(void); +void gs_abort(const gs_memory_t *mem); #endif /* gsexit_INCLUDED */ diff --git a/gs/src/gsfcid2.c b/gs/src/gsfcid2.c index c32ec9ed3..2da0c09f2 100644 --- a/gs/src/gsfcid2.c +++ b/gs/src/gsfcid2.c @@ -55,7 +55,7 @@ gs_font_cid2_from_type42(gs_font_cid2 **ppfcid, gs_font_type42 *pfont42, pfcid->next = pfcid->prev = 0; /* probably not necessary */ pfcid->is_resource = 0; gs_font_notify_init((gs_font *)pfcid); - pfcid->id = gs_next_ids(1); + pfcid->id = gs_next_ids(mem, 1); pfcid->base = (gs_font *)pfcid; pfcid->FontType = ft_CID_TrueType; /* Fill in the rest of the CIDFont data. */ diff --git a/gs/src/gsfcmap.c b/gs/src/gsfcmap.c index b17c8aa05..b89583f57 100644 --- a/gs/src/gsfcmap.c +++ b/gs/src/gsfcmap.c @@ -287,13 +287,13 @@ gs_cmap_enum_next_entry(gs_cmap_lookups_enum_t *penum) * for the GC. Note that this only initializes the common part. */ void -gs_cmap_init(gs_cmap_t *pcmap, int num_fonts) +gs_cmap_init(const gs_memory_t *mem, gs_cmap_t *pcmap, int num_fonts) { memset(pcmap, 0, sizeof(*pcmap)); /* We reserve a range of IDs for pdfwrite needs, to allow an identification of submaps for a particular subfont. */ - pcmap->id = gs_next_ids(num_fonts); + pcmap->id = gs_next_ids(mem, num_fonts); pcmap->num_fonts = num_fonts; uid_set_invalid(&pcmap->uid); } @@ -319,7 +319,7 @@ gs_cmap_alloc(gs_cmap_t **ppcmap, const gs_memory_struct_type_t *pstype, gs_free_object(mem, pcmap, "gs_cmap_alloc(CMap)"); return_error(gs_error_VMerror); } - gs_cmap_init(pcmap, num_fonts); /* id, uid, num_fonts */ + gs_cmap_init(mem, pcmap, num_fonts); /* id, uid, num_fonts */ pcmap->CMapType = 1; pcmap->CMapName.data = map_name; pcmap->CMapName.size = name_size; diff --git a/gs/src/gsfcmap1.c b/gs/src/gsfcmap1.c index 3fc73fcb3..7609b46b6 100644 --- a/gs/src/gsfcmap1.c +++ b/gs/src/gsfcmap1.c @@ -53,7 +53,7 @@ case 0: for (k = 0; k < pclr->num_entries; ++k, pv += size) { gs_glyph glyph = bytes2int(pv, size); - pclr->cmap->mark_glyph(glyph, pclr->cmap->mark_glyph_data); + pclr->cmap->mark_glyph(mem, glyph, pclr->cmap->mark_glyph_data); } } return ENUM_OBJ(pclr->cmap); diff --git a/gs/src/gsfont.c b/gs/src/gsfont.c index 79dc223f8..7461af2ed 100644 --- a/gs/src/gsfont.c +++ b/gs/src/gsfont.c @@ -109,7 +109,7 @@ ENUM_PTRS_WITH(font_dir_enum_ptrs, gs_font_dir *dir) if (cc != 0 && !--count) { (*dir->ccache.mark_glyph) - (cc->code, dir->ccache.mark_glyph_data); + (mem, cc->code, dir->ccache.mark_glyph_data); /****** HACK: break const. We'll fix this someday. ******/ ((gs_font_dir *)dir)->enum_index = cci; ((gs_font_dir *)dir)->enum_offset = offset; @@ -209,7 +209,7 @@ RELOC_PTRS_END /* Allocate a font directory */ private bool -cc_no_mark_glyph(gs_glyph glyph, void *ignore_data) +cc_no_mark_glyph(const gs_memory_t *mem, gs_glyph glyph, void *ignore_data) { return false; } @@ -285,7 +285,7 @@ gs_font_alloc(gs_memory_t *mem, gs_memory_type_ptr_t pstype, pfont->dir = dir; pfont->is_resource = false; gs_font_notify_init(pfont); - pfont->id = gs_next_ids(1); + pfont->id = gs_next_ids(mem, 1); pfont->base = pfont; pfont->client_data = 0; /* not FontMatrix, FontType */ diff --git a/gs/src/gsht.c b/gs/src/gsht.c index 7494d2df6..548dedc43 100644 --- a/gs/src/gsht.c +++ b/gs/src/gsht.c @@ -962,7 +962,7 @@ gx_imager_dev_ht_install( /* construct the new device halftone structure */ memset(&dht.order, 0, sizeof(dht.order)); /* the rc field is filled in later */ - dht.id = gs_next_ids(1); + dht.id = gs_next_ids(pis->memory, 1); dht.type = type; dht.components = gs_alloc_struct_array( pis->memory, @@ -1104,7 +1104,7 @@ gx_imager_dev_ht_install( code = gs_error_VMerror; else { porder->cache = pcache; - gx_ht_init_cache(pcache, porder); + gx_ht_init_cache(pis->memory, pcache, porder); } } } diff --git a/gs/src/gsht1.c b/gs/src/gsht1.c index 8e625bdf6..885a07e5a 100644 --- a/gs/src/gsht1.c +++ b/gs/src/gsht1.c @@ -346,7 +346,7 @@ process_transfer(gx_ht_order * porder, gs_state * pgs, "process_transfer"); pmap->proc = proc; /* 0 => use closure */ pmap->closure = *pmc; - pmap->id = gs_next_ids(1); + pmap->id = gs_next_ids(mem, 1); load_transfer_map(pgs, pmap, 0.0); porder->transfer = pmap; return 0; diff --git a/gs/src/gshtx.c b/gs/src/gshtx.c index ba9da8f84..26db408e0 100644 --- a/gs/src/gshtx.c +++ b/gs/src/gshtx.c @@ -303,7 +303,7 @@ alloc_ht_order( return 0; } pmap->proc = gs_mapped_transfer; - pmap->id = gs_next_ids(1); + pmap->id = gs_next_ids(pmem, 1); pocs[inext].corder.levels = 0; pocs[inext].corder.bit_data = 0; pocs[inext].corder.cache = 0; @@ -444,7 +444,7 @@ gs_ht_install( code = gs_note_error(gs_error_VMerror); else { pocs[j].corder.cache = pcache; - gx_ht_init_cache(pcache, &(pocs[j].corder)); + gx_ht_init_cache(pmem, pcache, &(pocs[j].corder)); } } if (code < 0) diff --git a/gs/src/gsimage.c b/gs/src/gsimage.c index c58f3d070..23e98c398 100644 --- a/gs/src/gsimage.c +++ b/gs/src/gsimage.c @@ -219,7 +219,7 @@ gs_image_init(gs_image_enum * penum, const gs_image_t * pim, bool multi, * non-current color space is potentially incorrect, but * it appears this case doesn't arise. */ - gs_cspace_init_DeviceGray(&cs); + gs_cspace_init_DeviceGray(pgs->memory, &cs); image.ColorSpace = &cs; } } diff --git a/gs/src/gsinit.c b/gs/src/gsinit.c index 062e43593..a9ec3d4c7 100644 --- a/gs/src/gsinit.c +++ b/gs/src/gsinit.c @@ -25,9 +25,6 @@ #include "gp.h" #include "gslib.h" /* interface definition */ -/* Imported from gsmisc.c */ -extern FILE *gs_debug_out; - /* Configuration information from gconfig.c. */ extern_gx_init_table(); @@ -42,8 +39,8 @@ gs_lib_init0(FILE * debug_out) { gs_memory_t *mem; - gs_debug_out = debug_out; - mem = (gs_memory_t *) gs_malloc_init(); + mem = (gs_memory_t *) gs_malloc_init(NULL); + /* Reset debugging flags */ memset(gs_debug, 0, 128); gs_log_errors = 0; @@ -64,9 +61,9 @@ gs_lib_init1(gs_memory_t * mem) /* Clean up after execution. */ void -gs_lib_finit(int exit_status, int code) +gs_lib_finit(int exit_status, int code, gs_memory_t *mem) { /* Do platform-specific cleanup. */ gp_exit(exit_status, code); - gs_malloc_release(); + gs_malloc_release(mem); } diff --git a/gs/src/gsio.h b/gs/src/gsio.h index 647e6f9b9..3b4c4b3dd 100644 --- a/gs/src/gsio.h +++ b/gs/src/gsio.h @@ -21,15 +21,6 @@ # define gsio_INCLUDED /* - * Define substitutes for stdin/out/err. Eventually these will always be - * referenced through an instance structure. - */ -extern FILE *gs_stdio[3]; -#define gs_stdin (gs_stdio[0]) -#define gs_stdout (gs_stdio[1]) -#define gs_stderr (gs_stdio[2]) - -/* * The library and interpreter must never use stdin/out/err directly. * Make references to them illegal. */ diff --git a/gs/src/gsiodevs.c b/gs/src/gsiodevs.c index 696d94d72..71f290b60 100644 --- a/gs/src/gsiodevs.c +++ b/gs/src/gsiodevs.c @@ -71,7 +71,8 @@ private int stdin_open(gx_io_device * iodev, const char *access, stream ** ps, gs_memory_t * mem) { - return stdio_open(iodev, access, ps, mem, 'r', gs_stdin, sread_file); + return stdio_open(iodev, access, ps, mem, 'r', + mem->gs_lib_ctx->fstdin, sread_file); } const gx_io_device gs_iodev_stdin = iodev_stdio("%stdin%", stdin_open); @@ -79,7 +80,8 @@ private int stdout_open(gx_io_device * iodev, const char *access, stream ** ps, gs_memory_t * mem) { - return stdio_open(iodev, access, ps, mem, 'w', gs_stdout, swrite_file); + return stdio_open(iodev, access, ps, mem, 'w', + mem->gs_lib_ctx->fstdout, swrite_file); } const gx_io_device gs_iodev_stdout = iodev_stdio("%stdout%", stdout_open); @@ -87,6 +89,7 @@ private int stderr_open(gx_io_device * iodev, const char *access, stream ** ps, gs_memory_t * mem) { - return stdio_open(iodev, access, ps, mem, 'w', gs_stderr, swrite_file); + return stdio_open(iodev, access, ps, mem, 'w', + mem->gs_lib_ctx->fstderr, swrite_file); } const gx_io_device gs_iodev_stderr = iodev_stdio("%stderr%", stderr_open); diff --git a/gs/src/gsistate.c b/gs/src/gsistate.c index d3749176c..15eeafd38 100644 --- a/gs/src/gsistate.c +++ b/gs/src/gsistate.c @@ -125,7 +125,7 @@ gs_imager_state_initialize(gs_imager_state * pis, gs_memory_t * mem) mem, return_error(gs_error_VMerror), "gs_imager_state_init(transfer)", 1); pis->set_transfer.gray->proc = imager_null_transfer; - pis->set_transfer.gray->id = gs_next_ids(1); + pis->set_transfer.gray->id = gs_next_ids(pis->memory, 1); pis->set_transfer.gray->values[0] = frac_0; pis->set_transfer.red = pis->set_transfer.green = diff --git a/gs/src/gslib.c b/gs/src/gslib.c index 98921c0dc..a3576deb6 100644 --- a/gs/src/gslib.c +++ b/gs/src/gslib.c @@ -89,30 +89,6 @@ extern_gs_lib_device_list(); /* Forward references */ private float odsf(floatp, floatp); -/* Provide a single point for all "C" stdout and stderr. - * Eventually these will always be referenced through an instance structure. - */ - -int outwrite(const char *str, int len) -{ - return fwrite(str, 1, len, gs_stdout); -} - -int errwrite(const char *str, int len) -{ - return fwrite(str, 1, len, gs_stderr); -} - -void outflush() -{ - fflush(gs_stdout); -} - -void errflush() -{ - fflush(gs_stderr); -} - int main(int argc, const char *argv[]) @@ -303,15 +279,15 @@ gs_reloc_const_string(gs_const_string * sptr, gc_state_t * gcst) /* Other stubs */ void -gs_to_exit(int exit_status) +gs_to_exit(const gs_memory_t *mem, int exit_status) { - gs_lib_finit(exit_status, 0); + gs_lib_finit(mem, exit_status, 0); } void -gs_abort(void) +gs_abort(const gs_memory_t *mem) { - gs_to_exit(1); /* cleanup */ + gs_to_exit(mem, 1); /* cleanup */ gp_do_exit(1); /* system independent exit() */ } diff --git a/gs/src/gslib.h b/gs/src/gslib.h index 130442a4d..0601583b1 100644 --- a/gs/src/gslib.h +++ b/gs/src/gslib.h @@ -32,6 +32,6 @@ gs_memory_t *gs_lib_init0(FILE * debug_out); int gs_lib_init1(gs_memory_t *); /* Clean up after execution. */ -void gs_lib_finit(int exit_status, int code); +void gs_lib_finit(int exit_status, int code, gs_memory_t *); #endif /* gslib_INCLUDED */ diff --git a/gs/src/gslibctx.c b/gs/src/gslibctx.c new file mode 100644 index 000000000..35670b3cf --- /dev/null +++ b/gs/src/gslibctx.c @@ -0,0 +1,139 @@ +/* Portions Copyright (C) 2003 artofcode LLC. + Portions Copyright (C) 2003 Artifex Software Inc. + This software is based in part on the work of the Independent JPEG Group. + All Rights Reserved. + + This software is distributed under license and may not be copied, modified + or distributed except as expressly authorized under the terms of that + license. Refer to licensing information at http://www.artifex.com/ or + contact Artifex Software, Inc., 101 Lucas Valley Road #110, + San Rafael, CA 94903, (415)492-9861, for further information. */ + +/*$Id$ */ + +/* library context functionality for ghostscript + * api callers get a gs_main_instance + */ + +/* Capture stdin/out/err before gs.h redefines them. */ +#include <stdio.h> + +static void +gs_lib_ctx_get_real_stdio(FILE **in, FILE **out, FILE **err) +{ + *in = stdin; + *out = stdout; + *err = stderr; +} + + +#include "gslibctx.h" +#include "gsmemory.h" + +static gs_memory_t *mem_err_print = NULL; + + +const gs_memory_t * +gs_lib_ctx_get_non_gc_memory_t() +{ + return mem_err_print ? mem_err_print->non_gc_memory : NULL; +} + + +int gs_lib_ctx_init( gs_memory_t *mem ) +{ + gs_lib_ctx_t *pio = 0; + + if ( mem == 0 ) + return -1; /* assert mem != 0 */ + + mem_err_print = mem; + + if (mem->gs_lib_ctx) /* one time initialization */ + return 0; + + pio = mem->gs_lib_ctx = + (gs_lib_ctx_t*)gs_alloc_bytes_immovable(mem, + sizeof(gs_lib_ctx_t), + "gs_lib_ctx_init"); + if( pio == 0 ) + return -1; + + gs_lib_ctx_get_real_stdio(&pio->fstdin, &pio->fstdout, &pio->fstderr ); + + pio->stdout_is_redirected = false; + pio->stdout_to_stderr = false; + pio->stdin_is_interactive = true; + pio->stdin_fn = 0; + pio->stdout_fn = 0; + pio->stderr_fn = 0; + pio->poll_fn = 0; + + pio->gs_next_id = 1; /* this implies that each thread has its own complete state */ + + pio->dict_auto_expand = false; + return 0; +} + +/* Provide a single point for all "C" stdout and stderr. + */ + +int outwrite(const gs_memory_t *mem, const char *str, int len) +{ + int code; + FILE *fout; + gs_lib_ctx_t *pio = mem->gs_lib_ctx; + + if (len == 0) + return 0; + if (pio->stdout_is_redirected) { + if (pio->stdout_to_stderr) + return errwrite(str, len); + fout = pio->fstdout2; + } + else if (pio->stdout_fn) { + return (*pio->stdout_fn)(pio->caller_handle, str, len); + } + else { + fout = pio->fstdout; + } + code = fwrite(str, 1, len, fout); + fflush(fout); + return code; +} + +int errwrite(const char *str, int len) +{ + int code; + if (len == 0) + return 0; + if (mem_err_print->gs_lib_ctx->stderr_fn) + return (*mem_err_print->gs_lib_ctx->stderr_fn)(mem_err_print->gs_lib_ctx->caller_handle, str, len); + + code = fwrite(str, 1, len, mem_err_print->gs_lib_ctx->fstderr); + fflush(mem_err_print->gs_lib_ctx->fstderr); + return code; +} + +void outflush(const gs_memory_t *mem) +{ + if (mem->gs_lib_ctx->stdout_is_redirected) { + if (mem->gs_lib_ctx->stdout_to_stderr) { + if (!mem->gs_lib_ctx->stderr_fn) + fflush(mem->gs_lib_ctx->fstderr); + } + else + fflush(mem->gs_lib_ctx->fstdout2); + } + else if (!mem->gs_lib_ctx->stdout_fn) + fflush(mem->gs_lib_ctx->fstdout); +} + +void errflush(void) +{ + if (!mem_err_print->gs_lib_ctx->stderr_fn) + fflush(mem_err_print->gs_lib_ctx->fstderr); + /* else nothing to flush */ +} + + diff --git a/gs/src/gslibctx.h b/gs/src/gslibctx.h new file mode 100644 index 000000000..58e3a3696 --- /dev/null +++ b/gs/src/gslibctx.h @@ -0,0 +1,61 @@ +/* Portions Copyright (C) 2003 artofcode LLC. + Portions Copyright (C) 2003 Artifex Software Inc. + This software is based in part on the work of the Independent JPEG Group. + All Rights Reserved. + + This software is distributed under license and may not be copied, modified + or distributed except as expressly authorized under the terms of that + license. Refer to licensing information at http://www.artifex.com/ or + contact Artifex Software, Inc., 101 Lucas Valley Road #110, + San Rafael, CA 94903, (415)492-9861, for further information. */ + +/*$Id$ */ +#ifndef GSLIBCTX_H +#define GSLIBCTX_H + +#include "std.h" +#include "stdio.h" +#include "gs_dll_call.h" + + +typedef struct name_table_s *name_table_ptr; + +typedef struct gs_lib_ctx_s +{ + FILE *fstdin; + FILE *fstdout; + FILE *fstderr; + FILE *fstdout2; /* for redirecting %stdout and diagnostics */ + bool stdout_is_redirected; /* to stderr or fstdout2 */ + bool stdout_to_stderr; + bool stdin_is_interactive; + void *caller_handle; /* identifies caller of GS DLL/shared object */ + int (GSDLLCALL *stdin_fn)(void *caller_handle, char *buf, int len); + int (GSDLLCALL *stdout_fn)(void *caller_handle, const char *str, int len); + int (GSDLLCALL *stderr_fn)(void *caller_handle, const char *str, int len); + int (GSDLLCALL *poll_fn)(void *caller_handle); + ulong gs_next_id; /* gs_id initialized here, private variable of gs_next_ids() */ + void *top_of_system; /* use accessor functions to walk down the system + * to the desired structure gs_lib_ctx_get_*() + */ + name_table_ptr gs_name_table; /* hack this is the ps interpreters name table + * doesn't belong here + */ + /* Define whether dictionaries expand automatically when full. */ + bool dict_auto_expand; /* ps dictionary: false level 1 true level 2 or 3 */ +} gs_lib_ctx_t; + +/** initializes and stores itself in the given gs_memory_t pointer. + * it is the responsibility of the gs_memory_t objects to copy + * the pointer to subsequent memory objects. + */ +int gs_lib_ctx_init( gs_memory_t *mem ); + +void *gs_lib_ctx_get_interp_instance( gs_memory_t *mem ); + +/* HACK to get at non garbage collection memory pointer + * + */ +const gs_memory_t * gs_lib_ctx_get_non_gc_memory_t(void); + +#endif /* GSLIBCTX_H */ diff --git a/gs/src/gsmalloc.c b/gs/src/gsmalloc.c index 060e3df55..0beeb84b3 100644 --- a/gs/src/gsmalloc.c +++ b/gs/src/gsmalloc.c @@ -27,6 +27,7 @@ #include "gsmalloc.h" #include "gsmemlok.h" /* locking (multithreading) wrapper */ #include "gsmemret.h" /* retrying wrapper */ +#include "gslibctx.h" /* ------ Heap allocator ------ */ @@ -118,6 +119,9 @@ gs_malloc_memory_init(void) mem->limit = max_long; mem->used = 0; mem->max_used = 0; + mem->gs_lib_ctx = 0; + mem->non_gc_memory = (gs_memory_t *)mem; + return mem; } /* @@ -128,7 +132,7 @@ gs_malloc_memory_init(void) #define max_malloc_probes 20 #define malloc_probe_size 64000 private long -heap_available(void) +heap_available() { long avail = 0; void *probes[max_malloc_probes]; @@ -179,7 +183,7 @@ gs_heap_alloc_bytes(gs_memory_t * mem, uint size, client_name_t cname) * We would like to check that malloc aligns blocks at least as * strictly as the compiler (as defined by arch_align_memory_mod). * However, Microsoft VC 6 does not satisfy this requirement. - * See gsmemraw.h for more explanation. + * See gsmemory.h for more explanation. */ set_msg(ok_msg); if (mmem->allocated) @@ -466,8 +470,9 @@ gs_malloc_wrapped_contents(gs_memory_t *wrapped) gs_memory_retrying_t *rmem = (gs_memory_retrying_t *)wrapped; gs_memory_locked_t *lmem = (gs_memory_locked_t *)gs_memory_retrying_target(rmem); - - return (gs_malloc_memory_t *)gs_memory_locked_target(lmem); + if (lmem) + return (gs_malloc_memory_t *)gs_memory_locked_target(lmem); + return (gs_malloc_memory_t *) wrapped; } /* Free the wrapper, and return the wrapped contents. */ @@ -485,28 +490,28 @@ gs_malloc_unwrap(gs_memory_t *wrapped) return (gs_malloc_memory_t *)contents; } -/* ------ Historical single-instance artifacts ------ */ - -/* Define the default allocator. */ -gs_malloc_memory_t *gs_malloc_memory_default; -gs_memory_t *gs_memory_t_default; -/* Create the default allocator. */ +/* Create the default allocator, and return it. */ gs_memory_t * -gs_malloc_init(void) +gs_malloc_init(const gs_memory_t *parent) { - gs_malloc_memory_default = gs_malloc_memory_init(); - gs_malloc_wrap(&gs_memory_t_default, gs_malloc_memory_default); - gs_memory_t_default->stable_memory = gs_memory_t_default; - return gs_memory_t_default; + gs_malloc_memory_t *malloc_memory_default = gs_malloc_memory_init(); + gs_memory_t *memory_t_default; + + if (parent) + malloc_memory_default->gs_lib_ctx = parent->gs_lib_ctx; + else + gs_lib_ctx_init((gs_memory_t *)malloc_memory_default); + + gs_malloc_wrap(&memory_t_default, malloc_memory_default); + memory_t_default->stable_memory = memory_t_default; + return memory_t_default; } /* Release the default allocator. */ void -gs_malloc_release(void) +gs_malloc_release(gs_memory_t *mem) { - gs_malloc_unwrap(gs_memory_t_default); - gs_memory_t_default = 0; - gs_malloc_memory_release(gs_malloc_memory_default); - gs_malloc_memory_default = 0; + gs_malloc_memory_t * malloc_memory_default = gs_malloc_unwrap(mem); + gs_malloc_memory_release(malloc_memory_default); } diff --git a/gs/src/gsmalloc.h b/gs/src/gsmalloc.h index 181f2c5c8..9c6496f78 100644 --- a/gs/src/gsmalloc.h +++ b/gs/src/gsmalloc.h @@ -40,30 +40,13 @@ gs_malloc_memory_t *gs_malloc_memory_init(void); gs_memory_free_all((gs_memory_t *)mem, FREE_ALL_EVERYTHING,\ "gs_malloc_memory_release") -/* - * Define a default allocator that allocates from the C heap. - * (We would really like to get rid of this.) - */ -extern gs_malloc_memory_t *gs_malloc_memory_default; -extern gs_memory_t *gs_memory_t_default; /* may be locked */ -#define gs_memory_default (*gs_memory_t_default) +gs_memory_t * gs_malloc_init(const gs_memory_t *parent); +void gs_malloc_release(gs_memory_t *mem); -/* - * The following procedures are historical artifacts that we hope to - * get rid of someday. - */ -gs_memory_t * gs_malloc_init(void); -void gs_malloc_release(void); -#define gs_malloc(nelts, esize, cname)\ - (void *)gs_alloc_byte_array(&gs_memory_default, nelts, esize, cname) -#define gs_free(data, nelts, esize, cname)\ - gs_free_object(&gs_memory_default, data, cname) - -/* Define an accessor for the limit on the total allocated heap space. */ -#define gs_malloc_limit (gs_malloc_memory_default->limit) - -/* Define an accessor for the maximum amount ever allocated from the heap. */ -#define gs_malloc_max (gs_malloc_memory_default->max_used) +#define gs_malloc(mem, nelts, esize, cname)\ + (void *)gs_alloc_byte_array(mem->non_gc_memory, nelts, esize, cname) +#define gs_free(mem, data, nelts, esize, cname)\ + gs_free_object(mem->non_gc_memory, data, cname) /* ---------------- Locking ---------------- */ diff --git a/gs/src/gsmemlok.c b/gs/src/gsmemlok.c index 1aee6429a..ebe0799fc 100644 --- a/gs/src/gsmemlok.c +++ b/gs/src/gsmemlok.c @@ -94,6 +94,7 @@ gs_memory_locked_init( lmem->procs = locked_procs; lmem->target = target; + lmem->gs_lib_ctx = target->gs_lib_ctx; /* Allocate a monitor to serialize access to structures within */ lmem->monitor = gx_monitor_alloc(target); diff --git a/gs/src/gsmemory.c b/gs/src/gsmemory.c index 4ef6a7e63..d3fc845c1 100644 --- a/gs/src/gsmemory.c +++ b/gs/src/gsmemory.c @@ -115,9 +115,14 @@ gs_resize_struct_array(gs_memory_t *mem, void *obj, uint num_elements, return gs_resize_object(mem, obj, num_elements, cname); } -/* Allocate a structure using a "raw memory" allocator. */ + +/* Allocate a structure using a "raw memory" allocator. + * really just an alias for gs_alloc_struct_immovable + * with the clients false expectation that it is saving memory + */ + void * -gs_raw_alloc_struct_immovable(gs_raw_memory_t * rmem, +gs_raw_alloc_struct_immovable(gs_memory_t * rmem, gs_memory_type_ptr_t pstype, client_name_t cname) { diff --git a/gs/src/gsmemory.h b/gs/src/gsmemory.h index 2d7f2078e..867d6195d 100644 --- a/gs/src/gsmemory.h +++ b/gs/src/gsmemory.h @@ -40,8 +40,8 @@ #ifndef gsmemory_INCLUDED # define gsmemory_INCLUDED -#include "gsmemraw.h" #include "gstypes.h" /* for gs_bytestring */ +#include "gslibctx.h" /* Define the opaque type for a structure descriptor. */ typedef struct gs_memory_struct_type_s gs_memory_struct_type_t; @@ -75,11 +75,156 @@ struct_name_t gs_struct_type_name(gs_memory_type_ptr_t); ((const char *)gs_struct_type_name(styp)) /* + * Define the structure for reporting memory manager statistics. + */ +typedef struct gs_memory_status_s { + /* + * "Allocated" space is the total amount of space acquired from + * the parent of the memory manager. It includes space used for + * allocated data, space available for allocation, and overhead. + */ + ulong allocated; + /* + * "Used" space is the amount of space used by allocated data + * plus overhead. + */ + ulong used; +} gs_memory_status_t; + + /* + * Allocate bytes. The bytes are always aligned maximally + * if the processor requires alignment. + * + * Note that the object memory level can allocate bytes as + * either movable or immovable: raw memory blocks are + * always immovable. + */ + +#define gs_memory_t_proc_alloc_bytes(proc, mem_t)\ + byte *proc(mem_t *mem, uint nbytes, client_name_t cname) + +#define gs_alloc_bytes_immovable(mem, nbytes, cname)\ + ((mem)->procs.alloc_bytes_immovable(mem, nbytes, cname)) + + /* + * Resize an object to a new number of elements. At the raw + * memory level, the "element" is a byte; for object memory + * (gsmemory.h), the object may be an an array of either + * bytes or structures. The new size may be larger than, + * the same as, or smaller than the old. If the new size is + * the same as the old, resize_object returns the same + * object; otherwise, it preserves the first min(old_size, + * new_size) bytes of the object's contents. + */ + +#define gs_memory_t_proc_resize_object(proc, mem_t)\ + void *proc(mem_t *mem, void *obj, uint new_num_elements,\ + client_name_t cname) + +#define gs_resize_object(mem, obj, newn, cname)\ + ((mem)->procs.resize_object(mem, obj, newn, cname)) + + /* + * Free an object (at the object memory level, this includes + * everything except strings). Note: data == 0 must be + * allowed, and must be a no-op. + */ + +#define gs_memory_t_proc_free_object(proc, mem_t)\ + void proc(mem_t *mem, void *data, client_name_t cname) + +#define gs_free_object(mem, data, cname)\ + ((mem)->procs.free_object(mem, data, cname)) + + /* + * Report status (assigned, used). + */ + +#define gs_memory_t_proc_status(proc, mem_t)\ + void proc(mem_t *mem, gs_memory_status_t *status) + +#define gs_memory_status(mem, pst)\ + ((mem)->procs.status(mem, pst)) + + /* + * Return the stable allocator for this allocator. The + * stable allocator allocates from the same heap and in + * the same VM space, but is not subject to save and restore. + * (It is the client's responsibility to avoid creating + * dangling pointers.) + * + * Note that the stable allocator may be the same allocator + * as this one. + */ + +#define gs_memory_t_proc_stable(proc, mem_t)\ + mem_t *proc(mem_t *mem) + +#define gs_memory_stable(mem)\ + ((mem)->procs.stable(mem)) + + /* + * Free one or more of: data memory acquired by the allocator + * (FREE_ALL_DATA), overhead structures other than the + * allocator itself (FREE_ALL_STRUCTURES), and the allocator + * itself (FREE_ALL_ALLOCATOR). Note that this requires + * allocators to keep track of all the memory they have ever + * acquired, and where they acquired it. Note that this + * operation propagates to the stable allocator (if + * different). + */ + +#define FREE_ALL_DATA 1 +#define FREE_ALL_STRUCTURES 2 +#define FREE_ALL_ALLOCATOR 4 +#define FREE_ALL_EVERYTHING\ + (FREE_ALL_DATA | FREE_ALL_STRUCTURES | FREE_ALL_ALLOCATOR) + +#define gs_memory_t_proc_free_all(proc, mem_t)\ + void proc(mem_t *mem, uint free_mask, client_name_t cname) + +#define gs_memory_free_all(mem, free_mask, cname)\ + ((mem)->procs.free_all(mem, free_mask, cname)) +/* Backward compatibility */ +#define gs_free_all(mem)\ + gs_memory_free_all(mem, FREE_ALL_DATA, "(free_all)") + + /* + * Consolidate free space. This may be used as part of (or + * as an alternative to) garbage collection, or before + * giving up on an attempt to allocate. + */ + +#define gs_memory_t_proc_consolidate_free(proc, mem_t)\ + void proc(mem_t *mem) + +#define gs_consolidate_free(mem)\ + ((mem)->procs.consolidate_free(mem)) + +/* Define the members of the procedure structure. */ +#define gs_raw_memory_procs(mem_t)\ + gs_memory_t_proc_alloc_bytes((*alloc_bytes_immovable), mem_t);\ + gs_memory_t_proc_resize_object((*resize_object), mem_t);\ + gs_memory_t_proc_free_object((*free_object), mem_t);\ + gs_memory_t_proc_stable((*stable), mem_t);\ + gs_memory_t_proc_status((*status), mem_t);\ + gs_memory_t_proc_free_all((*free_all), mem_t);\ + gs_memory_t_proc_consolidate_free((*consolidate_free), mem_t) + + + + + + + + + +/* * Define the memory manager procedural interface. */ typedef struct gs_memory_procs_s { - gs_raw_memory_procs(gs_memory_t); /* defined in gsmemraw.h */ + gs_raw_memory_procs(gs_memory_t); /* Redefine inherited procedures with the new allocator type. */ @@ -186,7 +331,7 @@ typedef struct gs_memory_procs_s { /* * Resize a string. The specification is the same as resize_object - * (in gsmemraw.h), except that the element size is always a byte. + * except that the element size is always a byte. */ #define gs_memory_proc_resize_string(proc)\ @@ -294,18 +439,35 @@ gs_memory_proc_consolidate_free(gs_ignore_consolidate_free); * void *, and does not take the type of the returned pointer as a * parameter. */ -void *gs_raw_alloc_struct_immovable(gs_raw_memory_t * rmem, +void *gs_raw_alloc_struct_immovable(gs_memory_t * rmem, gs_memory_type_ptr_t pstype, client_name_t cname); +typedef struct pl_mem_node_s pl_mem_node_t; + /* * Define an abstract allocator instance. - * Subclasses may have state as well. - * Note that the initial part of this must match gs_raw_memory_t. + * Subclasses may have state as well + * + * stable_memory: no save or restore, maybe gc-ed + * non-gc allocators stable_memory == this + * + * gs_lib_ctx: pointer to a library context + * + * head: is only used by pl_alloc in a pcl/pxl only system to track memory + * + * non_gc_memory: a garabge collecting allocator requires a "parent" who doesn't gc + * non-gc allocators non_gc_memory == this */ #define gs_memory_common\ gs_memory_t *stable_memory;\ - gs_memory_procs_t procs + gs_memory_procs_t procs;\ + gs_lib_ctx_t *gs_lib_ctx;\ + pl_mem_node_t *head;\ + gs_memory_t *non_gc_memory + + + struct gs_memory_s { gs_memory_common; }; diff --git a/gs/src/gsmemraw.h b/gs/src/gsmemraw.h index d45af866d..52451adba 100644 --- a/gs/src/gsmemraw.h +++ b/gs/src/gsmemraw.h @@ -23,6 +23,15 @@ #ifndef gsmemraw_INCLUDED # define gsmemraw_INCLUDED +#if 0 + +/* gsmemraw was an abstract base class. + * it is no longer in use, instead use the concrete base class is gs_memory_t + * since gs_memory_t contains interfaces that must be availiable throughout the system + * is is unadvisable to have a class below it without these. + */ + + /* * This interface provides minimal memory allocation and freeing capability. * It is meant to be used for "wholesale" allocation of blocks -- typically, @@ -214,9 +223,13 @@ typedef struct gs_raw_memory_s gs_raw_memory_t; typedef struct gs_raw_memory_procs_s { gs_raw_memory_procs(gs_raw_memory_t); } gs_raw_memory_procs_t; + + + struct gs_raw_memory_s { gs_raw_memory_t *stable_memory; /* cache the stable allocator */ - gs_raw_memory_procs_t procs; + gs_raw_memory_procs_t procs; }; +#endif /* 0 */ #endif /* gsmemraw_INCLUDED */ diff --git a/gs/src/gsmemret.c b/gs/src/gsmemret.c index 5b1339948..789e25324 100644 --- a/gs/src/gsmemret.c +++ b/gs/src/gsmemret.c @@ -94,6 +94,8 @@ gs_memory_retrying_init( rmem->stable_memory = 0; rmem->procs = retrying_procs; rmem->target = target; + rmem->gs_lib_ctx = target->gs_lib_ctx; + rmem->non_gc_memory = (gs_memory_t *)rmem; gs_memory_retrying_set_recover(rmem, no_recover_proc, NULL); return 0; } diff --git a/gs/src/gsmisc.c b/gs/src/gsmisc.c index 42dd36076..8b0965ff3 100644 --- a/gs/src/gsmisc.c +++ b/gs/src/gsmisc.c @@ -49,16 +49,12 @@ orig_sqrt(double x) #include "gxfarith.h" #include "gxfixed.h" -/* Define private replacements for stdin, stdout, and stderr. */ -FILE *gs_stdio[3]; - - /* ------ Redirected stdout and stderr ------ */ #include <stdarg.h> #define PRINTF_BUF_LENGTH 1024 -int outprintf(const char *fmt, ...) +int outprintf(const gs_memory_t *mem, const char *fmt, ...) { int count; char buf[PRINTF_BUF_LENGTH]; @@ -67,12 +63,12 @@ int outprintf(const char *fmt, ...) va_start(args, fmt); count = vsprintf(buf, fmt, args); - outwrite(buf, count); + outwrite(mem, buf, count); if (count >= PRINTF_BUF_LENGTH) { count = sprintf(buf, "PANIC: printf exceeded %d bytes. Stack has been corrupted.\n", PRINTF_BUF_LENGTH); - outwrite(buf, count); + outwrite(mem, buf, count); } va_end(args); return count; @@ -158,14 +154,14 @@ dprintf_file_only(const char *file) } #endif void -printf_program_ident(const char *program_name, long revision_number) +printf_program_ident(const gs_memory_t *mem, const char *program_name, long revision_number) { if (program_name) - outprintf((revision_number ? "%s " : "%s"), program_name); + outprintf(mem, (revision_number ? "%s " : "%s"), program_name); if (revision_number) { int fpart = revision_number % 100; - outprintf("%d.%02d", (int)(revision_number / 100), fpart); + outprintf(mem, "%d.%02d", (int)(revision_number / 100), fpart); } } void diff --git a/gs/src/gsovrc.c b/gs/src/gsovrc.c index d3b73083e..d38385b3c 100644 --- a/gs/src/gsovrc.c +++ b/gs/src/gsovrc.c @@ -251,7 +251,7 @@ gs_create_overprint( return_error(gs_error_VMerror), "gs_create_overprint" ); pct->type = &gs_composite_overprint_type; - pct->id = gs_next_ids(1); + pct->id = gs_next_ids(mem, 1); pct->params = *pparams; *ppct = (gs_composite_t *)pct; return 0; diff --git a/gs/src/gspcolor.c b/gs/src/gspcolor.c index 10cf164bb..5ddfccb9f 100644 --- a/gs/src/gspcolor.c +++ b/gs/src/gspcolor.c @@ -119,7 +119,7 @@ gs_make_pattern_common(gs_client_color *pcc, gs_newpath(saved); pinst->saved = saved; pcc->pattern = pinst; - pcc->pattern->pattern_id = gs_next_ids(1); + pcc->pattern->pattern_id = gs_next_ids(mem, 1); return 0; } @@ -157,7 +157,7 @@ gs_setpatternspace(gs_state * pgs) if (pgs->color_space->type->index != gs_color_space_index_Pattern) { gs_color_space cs; - gs_cspace_init(&cs, &gs_color_space_type_Pattern, NULL); + gs_cspace_init(&cs, &gs_color_space_type_Pattern, pgs->memory, false); /**************** base_space SETTING IS WRONG ****************/ cs.params.pattern.base_space = *(gs_paint_color_space *) pgs->color_space; diff --git a/gs/src/gsptype1.c b/gs/src/gsptype1.c index d064c9a2a..b21f6cae4 100644 --- a/gs/src/gsptype1.c +++ b/gs/src/gsptype1.c @@ -227,7 +227,7 @@ gs_pattern1_make_pattern(gs_client_color * pcc, code = gx_clip_to_rectangle(saved, &cbox); if (code < 0) goto fsaved; - inst.id = gs_next_ids(1); + inst.id = gs_next_ids(mem, 1); *pinst = inst; return 0; #undef mat @@ -473,7 +473,7 @@ image_PaintProc(const gs_client_color * pcolor, gs_state * pgs) return_error(gs_error_VMerror); if (ppmap->pcspace == 0) { - gs_cspace_init_DeviceGray(&cs); + gs_cspace_init_DeviceGray(pgs->memory, &cs); pcspace = &cs; } else pcspace = ppmap->pcspace; @@ -587,7 +587,7 @@ gs_makepixmappattern( /* set up the client pattern structure */ gs_pattern1_init(&pat); - uid_set_UniqueID(&pat.uid, (id == no_UniqueID) ? gs_next_ids(1) : id); + uid_set_UniqueID(&pat.uid, (id == no_UniqueID) ? gs_next_ids(mem, 1) : id); pat.PaintType = (mask ? 2 : 1); pat.TilingType = 1; pat.BBox.p.x = 0; diff --git a/gs/src/gsstate.c b/gs/src/gsstate.c index e2814a5b9..ad2715b2d 100644 --- a/gs/src/gsstate.c +++ b/gs/src/gsstate.c @@ -251,7 +251,7 @@ gs_state_alloc(gs_memory_t * mem) pgs->effective_clip_path = pgs->clip_path; pgs->effective_clip_shared = true; /* Initialize things so that gx_remap_color won't crash. */ - gs_cspace_init_DeviceGray(pgs->color_space); + gs_cspace_init_DeviceGray(pgs->memory, pgs->color_space); pgs->in_cachedevice = 0; gx_set_device_color_1(pgs); /* sets colorspace and client color */ pgs->device = 0; /* setting device adjusts refcts */ diff --git a/gs/src/gsstruct.h b/gs/src/gsstruct.h index d7bb2876d..932fbd3f5 100644 --- a/gs/src/gsstruct.h +++ b/gs/src/gsstruct.h @@ -336,7 +336,7 @@ struct_proc_reloc_ptrs(basic_reloc_ptrs); /* Begin enumeration */ #define ENUM_PTRS_BEGIN_PROC(proc)\ - gs_ptr_type_t proc(EV_CONST void *vptr, uint size, int index, enum_ptr_t *pep, const gs_memory_struct_type_t *pstype, gc_state_t *gcst) + gs_ptr_type_t proc(const gs_memory_t *mem, EV_CONST void *vptr, uint size, int index, enum_ptr_t *pep, const gs_memory_struct_type_t *pstype, gc_state_t *gcst) #define ENUM_PTRS_BEGIN(proc)\ ENUM_PTRS_BEGIN_PROC(proc)\ { switch ( index ) { default: @@ -457,7 +457,7 @@ extern void reloc_const_bytestring(gs_const_bytestring *pbs, gc_state_t *gcst); /* Subclass support */ #define ENUM_USING(supst, ptr, size, index)\ - (*(supst).enum_ptrs)(ptr, size, index, pep, &(supst), gcst) + (*(supst).enum_ptrs)(mem, ptr, size, index, pep, &(supst), gcst) #define RELOC_USING(supst, ptr, size)\ (*(supst).reloc_ptrs)(ptr, size, &(supst), gcst) @@ -520,7 +520,7 @@ extern void reloc_const_bytestring(gs_const_bytestring *pbs, gc_state_t *gcst); * Boilerplate for clear_marks procedures. */ #define CLEAR_MARKS_PROC(proc)\ - void proc(void *vptr, uint size, const gs_memory_struct_type_t *pstype) + void proc(const gs_memory_t *cmem, void *vptr, uint size, const gs_memory_struct_type_t *pstype) /* Complex structures with their own clear_marks, */ /* enum, reloc, and finalize procedures. */ diff --git a/gs/src/gsstype.h b/gs/src/gsstype.h index 2a4b0a651..f0940cdb8 100644 --- a/gs/src/gsstype.h +++ b/gs/src/gsstype.h @@ -45,13 +45,13 @@ typedef struct enum_ptr_s { /* Clear the marks of a structure. */ #define struct_proc_clear_marks(proc)\ - void proc(void /*obj_header_t*/ *pre, uint size,\ + void proc(const gs_memory_t *cmem, void /*obj_header_t*/ *pre, uint size,\ const gs_memory_struct_type_t *pstype) /* Enumerate the pointers in a structure. */ #define struct_proc_enum_ptrs(proc)\ - gs_ptr_type_t proc(EV_CONST void /*obj_header_t*/ *ptr, uint size,\ + gs_ptr_type_t proc(const gs_memory_t *mem, EV_CONST void /*obj_header_t*/ *ptr, uint size,\ int index, enum_ptr_t *pep, const gs_memory_struct_type_t *pstype,\ gc_state_t *gcst) diff --git a/gs/src/gsutil.c b/gs/src/gsutil.c index c2ec212e6..41cc6b203 100644 --- a/gs/src/gsutil.c +++ b/gs/src/gsutil.c @@ -29,23 +29,12 @@ /* ------ Unique IDs ------ */ -/* Generate a block of unique IDs. */ -static ulong gs_next_id; - -init_proc(gs_gsutil_init); /* check prototype */ -int -gs_gsutil_init(gs_memory_t *mem) -{ - gs_next_id = 1; - return 0; -} - ulong -gs_next_ids(uint count) +gs_next_ids(const gs_memory_t *mem, uint count) { - ulong id = gs_next_id; + ulong id = mem->gs_lib_ctx->gs_next_id; - gs_next_id += count; + mem->gs_lib_ctx->gs_next_id += count; return id; } diff --git a/gs/src/gsutil.h b/gs/src/gsutil.h index 5b5d75484..8b36bfc9e 100644 --- a/gs/src/gsutil.h +++ b/gs/src/gsutil.h @@ -23,7 +23,7 @@ /* ------ Unique IDs ------ */ /* Generate a block of unique IDs. */ -gs_id gs_next_ids(uint count); +gs_id gs_next_ids(const gs_memory_t *mem, uint count); /* ------ Memory utilities ------ */ @@ -61,4 +61,22 @@ bool string_match(const byte * str, uint len, const byte * pstr, uint plen, const string_match_params * psmp); +/* graphical object tags */ +typedef enum { + GS_DEVICE_DOESNT_SUPPORT_TAGS = 0, /* default */ + GS_UNKNOWN_TAG = 0x1, + GS_TEXT_TAG = 0x2, + GS_IMAGE_TAG = 0x4, + GS_PATH_TAG = 0x8, + GS_UNTOUCHED_TAG = 0x10 +} gs_object_tag_type_t; + +/* accessors for object tags */ +gs_object_tag_type_t gs_current_object_tag(void); + +#include "gxstate.h" + +void gs_set_object_tag(gs_state * pgs, const gs_object_tag_type_t tag); +void gs_enable_object_tagging(void); + #endif /* gsutil_INCLUDED */ diff --git a/gs/src/gxacpath.c b/gs/src/gxacpath.c index 939877e78..00e949354 100644 --- a/gs/src/gxacpath.c +++ b/gs/src/gxacpath.c @@ -153,7 +153,7 @@ gx_cpath_accum_end(const gx_device_cpath_accum * padev, gx_clip_path * pcpath) } gx_cpath_set_outer_box(&apath); apath.path_valid = false; - apath.id = gs_next_ids(1); /* path changed => change id */ + apath.id = gs_next_ids(padev->list_memory, 1); /* path changed => change id */ gx_cpath_assign_free(pcpath, &apath); return 0; } diff --git a/gs/src/gxalloc.h b/gs/src/gxalloc.h index dbb18b88b..25bb67b50 100644 --- a/gs/src/gxalloc.h +++ b/gs/src/gxalloc.h @@ -225,7 +225,7 @@ extern_st(st_chunk); if ( pre != end )\ { lprintf2("Chunk parsing error, 0x%lx != 0x%lx\n",\ (ulong)pre, (ulong)end);\ - gs_abort();\ + /*gs_abort((const gs_memory_t *)NULL);*/ \ }\ } #else @@ -333,7 +333,6 @@ typedef struct ref_s ref; struct gs_ref_memory_s { /* The following are set at initialization time. */ gs_memory_common; - gs_raw_memory_t *parent; /* for allocating chunks */ uint chunk_size; uint large_size; /* min size to give large object */ /* its own chunk: must be */ @@ -453,17 +452,17 @@ extern const dump_control_t dump_control_all; /* Print one object with the given options. */ /* Relevant options: type_addresses, no_types, pointers, pointed_strings, */ /* contents. */ -void debug_print_object(const void *obj, const dump_control_t * control); +void debug_print_object(const gs_memory_t *mem, const void *obj, const dump_control_t * control); /* Print the contents of a chunk with the given options. */ /* Relevant options: all. */ -void debug_dump_chunk(const chunk_t * cp, const dump_control_t * control); -void debug_print_chunk(const chunk_t * cp); /* default options */ +void debug_dump_chunk(const gs_memory_t *mem, const chunk_t * cp, const dump_control_t * control); +void debug_print_chunk(const gs_memory_t *mem, const chunk_t * cp); /* default options */ /* Print the contents of all chunks managed by an allocator. */ /* Relevant options: all. */ -void debug_dump_memory(const gs_ref_memory_t * mem, - const dump_control_t * control); +void debug_dump_memory(const gs_ref_memory_t *mem, + const dump_control_t *control); /* Find all the objects that contain a given pointer. */ void debug_find_pointers(const gs_ref_memory_t *mem, const void *target); diff --git a/gs/src/gxccache.c b/gs/src/gxccache.c index ae79b0109..ea47ff785 100644 --- a/gs/src/gxccache.c +++ b/gs/src/gxccache.c @@ -392,7 +392,7 @@ gx_image_cached_char(register gs_show_enum * penum, register cached_char * cc) if (code >= 0) return_check_interrupt(0); /* copy_alpha failed, construct a monobit mask. */ - bits = compress_alpha_bits(cc, &gs_memory_default); + bits = compress_alpha_bits(cc, penum->memory->non_gc_memory); if (bits == 0) return 1; /* VMerror, but recoverable */ } @@ -403,12 +403,12 @@ gx_image_cached_char(register gs_show_enum * penum, register cached_char * cc) } if (depth > 1) { /* Complex color or fill_mask / copy_alpha failed, */ /* construct a monobit mask. */ - bits = compress_alpha_bits(cc, &gs_memory_default); + bits = compress_alpha_bits(cc, penum->memory->non_gc_memory); if (bits == 0) return 1; /* VMerror, but recoverable */ } { /* Use imagemask to render the character. */ - gs_memory_t *mem = &gs_memory_default; + gs_memory_t *mem = penum->memory->non_gc_memory; gs_image_enum *pie = gs_image_enum_alloc(mem, "image_char(image_enum)"); gs_image_t image; @@ -419,7 +419,7 @@ gx_image_cached_char(register gs_show_enum * penum, register cached_char * cc) if (pie == 0) { if (bits != cc_bits(cc)) - gs_free_object(&gs_memory_default, bits, + gs_free_object(mem, bits, "compress_alpha_bits"); return 1; /* VMerror, but recoverable */ } @@ -450,7 +450,7 @@ gx_image_cached_char(register gs_show_enum * penum, register cached_char * cc) gs_free_object(mem, pie, "image_char(image_enum)"); } done:if (bits != cc_bits(cc)) - gs_free_object(&gs_memory_default, bits, "compress_alpha_bits"); + gs_free_object(penum->memory->non_gc_memory, bits, "compress_alpha_bits"); if (code > 0) code = 0; return_check_interrupt(code); diff --git a/gs/src/gxccman.c b/gs/src/gxccman.c index 3d9757459..cd11e9f59 100644 --- a/gs/src/gxccman.c +++ b/gs/src/gxccman.c @@ -696,7 +696,7 @@ gx_add_char_bits(gs_font_dir * dir, cached_char * cc, /* Assign a bitmap id. */ - cc->id = gs_next_ids(1); + cc->id = gs_next_ids(dir->orig_fonts->memory, 1); } /* Purge from the caches all references to a given font. */ diff --git a/gs/src/gxcht.c b/gs/src/gxcht.c index 38b064a5c..505811bb5 100644 --- a/gs/src/gxcht.c +++ b/gs/src/gxcht.c @@ -669,7 +669,7 @@ gx_dc_ht_colored_fill_rectangle(const gx_device_color * pdevc, tiles.raster = raster; tiles.rep_width = tiles.size.x = lw; tiles.rep_height = tiles.size.y = lh; - tiles.id = gs_next_ids(1); + tiles.id = gs_next_ids(dev->memory, 1); tiles.rep_shift = tiles.shift = 0; set_color_ht((byte *)tbits, raster, 0, 0, lw, lh, depth, special, nplanes, pdevc->colors.colored.plane_mask, diff --git a/gs/src/gxclbits.c b/gs/src/gxclbits.c index 34f2d3678..732e9305f 100644 --- a/gs/src/gxclbits.c +++ b/gs/src/gxclbits.c @@ -127,7 +127,7 @@ cmd_put_bits(gx_device_clist_writer * cldev, gx_clist_state * pcls, clist_bitmap_bytes(width_bits, height, compression_mask, &uncompressed_raster, &full_raster); uint max_size = cbuf_size - op_size; - gs_memory_t *mem = (cldev->memory ? cldev->memory : &gs_memory_default); + gs_memory_t *mem = cldev->memory; byte *dp; int compress = 0; diff --git a/gs/src/gxclrast.c b/gs/src/gxclrast.c index 1f4b59f80..ca121a712 100644 --- a/gs/src/gxclrast.c +++ b/gs/src/gxclrast.c @@ -350,7 +350,7 @@ in: /* Initialize for a new page. */ gx_imager_setscreenphase(&imager_state, -x0, -y0, gs_color_select_all); halftone_type = ht_type_none; fill_params.fill_zero_width = false; - gs_cspace_init_DeviceGray(&cs); + gs_cspace_init_DeviceGray(mem, &cs); pcs = &cs; color_unset(&dev_color); color_space.params.indexed.use_proc = 0; @@ -1862,15 +1862,15 @@ read_set_color_space(command_buf_t *pcb, gs_imager_state *pis, (b & 4 ? "(proc)" : "")); switch (index) { case gs_color_space_index_DeviceGray: - gs_cspace_init_DeviceGray(&gray_cs); + gs_cspace_init_DeviceGray(mem, &gray_cs); pcs = &gray_cs; break; case gs_color_space_index_DeviceRGB: - gs_cspace_init_DeviceRGB(&rgb_cs); + gs_cspace_init_DeviceRGB(mem, &rgb_cs); pcs = &rgb_cs; break; case gs_color_space_index_DeviceCMYK: - gs_cspace_init_DeviceCMYK(&cmyk_cs); + gs_cspace_init_DeviceCMYK(mem, &cmyk_cs); pcs = &cmyk_cs; break; default: diff --git a/gs/src/gxclread.c b/gs/src/gxclread.c index 5970e8780..61258a67c 100644 --- a/gs/src/gxclread.c +++ b/gs/src/gxclread.c @@ -474,8 +474,7 @@ clist_playback_file_bands(clist_playback_action action, bool opened_cfile = false; /* We have to pick some allocator for rendering.... */ - gs_memory_t *mem = - (cdev->memory != 0 ? cdev->memory : &gs_memory_default); + gs_memory_t *mem =cdev->memory; stream_band_read_state rs; diff --git a/gs/src/gxclrect.c b/gs/src/gxclrect.c index 881b3efa8..6fb5ddddf 100644 --- a/gs/src/gxclrect.c +++ b/gs/src/gxclrect.c @@ -596,7 +596,7 @@ clist_strip_copy_rop(gx_device * dev, /* Change tile. If there is no id, generate one. */ if (tiles->id == gx_no_bitmap_id) { tile_with_id = *tiles; - tile_with_id.id = gs_next_ids(1); + tile_with_id.id = gs_next_ids(dev->memory, 1); tiles = &tile_with_id; } TRY_RECT { @@ -627,7 +627,7 @@ clist_strip_copy_rop(gx_device * dev, * Allocate enough fake IDs, since the inner call on * clist_strip_copy_rop will need them anyway. */ - ids = gs_next_ids(min(height, rep_height)); + ids = gs_next_ids(dev->memory, min(height, rep_height)); line_tile = *tiles; line_tile.size.y = 1; line_tile.rep_height = 1; diff --git a/gs/src/gxcpath.c b/gs/src/gxcpath.c index 4ce708b52..919d193ec 100644 --- a/gs/src/gxcpath.c +++ b/gs/src/gxcpath.c @@ -112,7 +112,7 @@ cpath_init_rectangle(gx_clip_path * pcpath, gs_fixed_rect * pbox) pcpath->path_valid = false; pcpath->path.bbox = *pbox; gx_cpath_set_outer_box(pcpath); - pcpath->id = gs_next_ids(1); /* path changed => change id */ + pcpath->id = gs_next_ids(pcpath->path.memory, 1); /* path changed => change id */ } private void cpath_init_own_contents(gx_clip_path * pcpath) @@ -665,7 +665,7 @@ gx_cpath_scale_exp2_shared(gx_clip_path * pcpath, int log2_scale_x, #undef SCALE_V } } - pcpath->id = gs_next_ids(1); /* path changed => change id */ + pcpath->id = gs_next_ids(pcpath->path.memory, 1); /* path changed => change id */ return 0; } diff --git a/gs/src/gxcspace.h b/gs/src/gxcspace.h index 256f4f8a3..9e4d2c6aa 100644 --- a/gs/src/gxcspace.h +++ b/gs/src/gxcspace.h @@ -279,7 +279,7 @@ extern_st(st_color_space); */ void gs_cspace_init(gs_color_space *pcs, const gs_color_space_type *pcstype, - gs_memory_t *mem); + gs_memory_t *mem, bool isheap); int gs_cspace_alloc(gs_color_space **ppcspace, const gs_color_space_type *pcstype, gs_memory_t *mem); diff --git a/gs/src/gxdevcli.h b/gs/src/gxdevcli.h index 1479114aa..9a7850df7 100644 --- a/gs/src/gxdevcli.h +++ b/gs/src/gxdevcli.h @@ -692,6 +692,7 @@ typedef struct gx_device_cached_colors_s { gx_device_cached_colors_t cached_colors;\ int width; /* width in pixels */\ int height; /* height in pixels */\ + int TrayOrientation; /* default 0 ( 90 180 270 ) if device supports */\ float MediaSize[2]; /* media dimensions in points */\ float ImagingBBox[4]; /* imageable region in points */\ bool ImagingBBox_set;\ diff --git a/gs/src/gxdevice.h b/gs/src/gxdevice.h index 121c92b48..628969e32 100644 --- a/gs/src/gxdevice.h +++ b/gs/src/gxdevice.h @@ -94,7 +94,8 @@ * unless we use the +/- workaround in the next macro. */ #define std_device_part2_(width, height, x_dpi, y_dpi)\ - { gx_no_color_index, gx_no_color_index }, width, height,\ + { gx_no_color_index, gx_no_color_index },\ + width, height, 0/*TrayOrientation*/,\ { (float)((((width) * 72.0 + 0.5) - 0.5) / (x_dpi))/*MediaSize[0]*/,\ (float)((((height) * 72.0 + 0.5) - 0.5) / (y_dpi))/*MediaSize[1]*/},\ { 0, 0, 0, 0 }/*ImagingBBox*/, 0/*ImagingBBox_set*/,\ diff --git a/gs/src/gxdhtserial.c b/gs/src/gxdhtserial.c index f522f9c14..3005d98fe 100644 --- a/gs/src/gxdhtserial.c +++ b/gs/src/gxdhtserial.c @@ -136,7 +136,7 @@ gx_ht_read_tf( return_error(gs_error_VMerror), "gx_ht_read_tf" ); - pmap->id = gs_next_ids(1); + pmap->id = gs_next_ids(mem, 1); pmap->closure.proc = 0; pmap->closure.data = 0; if (tf_type == gx_ht_tf_identity) { diff --git a/gs/src/gxfcmap.h b/gs/src/gxfcmap.h index e2954dac0..c6eab6903 100644 --- a/gs/src/gxfcmap.h +++ b/gs/src/gxfcmap.h @@ -296,7 +296,7 @@ int gs_cmap_enum_next_entry(gs_cmap_lookups_enum_t *penum); * Initialize a just-allocated CMap, to ensure that all pointers are clean * for the GC. Note that this only initializes the common part. */ -void gs_cmap_init(gs_cmap_t *pcmap, int num_fonts); +void gs_cmap_init(const gs_memory_t *mem, gs_cmap_t *pcmap, int num_fonts); /* * Allocate and initialize (the common part of) a CMap. diff --git a/gs/src/gxfcopy.c b/gs/src/gxfcopy.c index e703332bb..d80fef55c 100644 --- a/gs/src/gxfcopy.c +++ b/gs/src/gxfcopy.c @@ -205,14 +205,14 @@ ENUM_PTRS_WITH(gs_copied_font_data_enum_ptrs, gs_copied_font_data_t *cfdata) gs_copied_glyph_name_t *names = cfdata->names; gs_copied_glyph_extra_name_t *en = cfdata->extra_names; int i; - + if (names != NULL) for (i = 0; i < cfdata->glyphs_size; ++i) if (names[i].glyph < gs_c_min_std_encoding_glyph) - cfdata->dir->ccache.mark_glyph(names[i].glyph, NULL); + cfdata->dir->ccache.mark_glyph(mem, names[i].glyph, NULL); for (; en != NULL; en = en->next) if (en->name.glyph < gs_c_min_std_encoding_glyph) - cfdata->dir->ccache.mark_glyph(en->name.glyph, NULL); + cfdata->dir->ccache.mark_glyph(mem, en->name.glyph, NULL); } return ENUM_USING(st_gs_font_info, &cfdata->info, sizeof(gs_font_info_t), index - 12); ENUM_PTR3(0, gs_copied_font_data_t, glyphs, names, extra_names); diff --git a/gs/src/gxht.c b/gs/src/gxht.c index bdfe1ad66..17869068a 100644 --- a/gs/src/gxht.c +++ b/gs/src/gxht.c @@ -295,7 +295,7 @@ gx_dc_ht_binary_load(gx_device_color * pdevc, const gs_imager_state * pis, gx_ht_cache *pcache = porder->cache; if (pcache->order.bit_data != porder->bit_data) - gx_ht_init_cache(pcache, porder); + gx_ht_init_cache(pis->memory, pcache, porder); /* * We do not load the cache now. Instead we wait until we are ready * to actually render the color. This allows multiple colors to be @@ -705,7 +705,7 @@ gx_dc_ht_binary_get_nonzero_comps( /* Initialize the tile cache for a given screen. */ /* Cache as many different levels as will fit. */ void -gx_ht_init_cache(gx_ht_cache * pcache, const gx_ht_order * porder) +gx_ht_init_cache(const gs_memory_t *mem, gx_ht_cache * pcache, const gx_ht_order * porder) { uint width = porder->width; uint height = porder->height; @@ -758,7 +758,7 @@ gx_ht_init_cache(gx_ht_cache * pcache, const gx_ht_order * porder) raster = bitmap_raster(width_unit); tile_bytes = raster * height; } - pcache->base_id = gs_next_ids(porder->num_levels + 1); + pcache->base_id = gs_next_ids(mem, porder->num_levels + 1); pcache->order = *porder; /* The transfer function is irrelevant, and might become dangling. */ pcache->order.transfer = 0; diff --git a/gs/src/gxht.h b/gs/src/gxht.h index 96ecd9ee5..824e74c8b 100644 --- a/gs/src/gxht.h +++ b/gs/src/gxht.h @@ -166,7 +166,7 @@ extern_st(st_ht_component_element); typedef struct gs_multiple_halftone_s { gs_halftone_component *components; uint num_comp; - int (*get_colorname_string)(gs_separation_name colorname_index, + int (*get_colorname_string)(const gs_memory_t *mem, gs_separation_name colorname_index, unsigned char **ppstr, unsigned int *pname_size); } gs_multiple_halftone; diff --git a/gs/src/gximag3x.c b/gs/src/gximag3x.c index 08f0523bd..985d00331 100644 --- a/gs/src/gximag3x.c +++ b/gs/src/gximag3x.c @@ -220,7 +220,7 @@ gx_begin_image3x_generic(gx_device * dev, "gx_begin_image3x_generic"); if (pmcs == 0) return_error(gs_error_VMerror); - gs_cspace_init_DevicePixel(pmcs, penum->mask[i].depth); + gs_cspace_init_DevicePixel(mem, pmcs, penum->mask[i].depth); mrect.p.x = mrect.p.y = 0; mrect.q.x = penum->mask[i].width; mrect.q.y = penum->mask[i].height; diff --git a/gs/src/gximage.c b/gs/src/gximage.c index 472cd741d..6cd4be137 100644 --- a/gs/src/gximage.c +++ b/gs/src/gximage.c @@ -87,7 +87,7 @@ gx_image_enum_common_init(gx_image_enum_common_t * piec, piec->image_type = pic->type; piec->procs = piep; piec->dev = dev; - piec->id = gs_next_ids(1); + piec->id = gs_next_ids(dev->memory, 1); switch (format) { case gs_image_format_chunky: piec->num_planes = 1; diff --git a/gs/src/gxpcmap.c b/gs/src/gxpcmap.c index e61eca6ce..66a784a79 100644 --- a/gs/src/gxpcmap.c +++ b/gs/src/gxpcmap.c @@ -542,7 +542,7 @@ gx_pattern_cache_add_entry(gs_imager_state * pis, ctile->is_simple = pinst->is_simple; ctile->is_dummy = false; if (mbits != 0) { - make_bitmap(&ctile->tbits, mbits, gs_next_ids(1)); + make_bitmap(&ctile->tbits, mbits, gs_next_ids(pis->memory, 1)); mbits->bitmap_memory = 0; /* don't free the bits */ } else ctile->tbits.data = 0; diff --git a/gs/src/gxttfb.c b/gs/src/gxttfb.c index e39381358..811208f46 100644 --- a/gs/src/gxttfb.c +++ b/gs/src/gxttfb.c @@ -214,7 +214,9 @@ private void DebugPrint(ttfFont *ttf, const char *fmt, ...) if (gs_debug_c('Y')) { va_start(args, fmt); count = vsprintf(buf, fmt, args); - outwrite(buf, count); + /* NB: moved debug output from stdout to stderr + */ + errwrite(buf, count); va_end(args); } } @@ -726,3 +728,4 @@ int gx_ttf_outline(ttfFont *ttf, gx_ttfReader *r, gs_font_type42 *pfont, int gly } } } + diff --git a/gs/src/gzht.h b/gs/src/gzht.h index 0a4cc69b1..7a2247d9d 100644 --- a/gs/src/gzht.h +++ b/gs/src/gzht.h @@ -177,7 +177,7 @@ void gx_ht_free_cache(gs_memory_t *, gx_ht_cache *); (pcache)->ht_tiles[0].tiles.data = 0) /* Initialize a halftone cache with a given order. */ -void gx_ht_init_cache(gx_ht_cache *, const gx_ht_order *); +void gx_ht_init_cache(const gs_memory_t *mem, gx_ht_cache *, const gx_ht_order *); /* Check whether the tile cache corresponds to the current order */ bool gx_check_tile_cache_current(const gs_imager_state * pis); diff --git a/gs/src/ialloc.c b/gs/src/ialloc.c index e94201797..272fe9cf1 100644 --- a/gs/src/ialloc.c +++ b/gs/src/ialloc.c @@ -35,7 +35,7 @@ public_st_gs_dual_memory(); /* Initialize the allocator */ int -ialloc_init(gs_dual_memory_t *dmem, gs_raw_memory_t * rmem, uint chunk_size, +ialloc_init(gs_dual_memory_t *dmem, gs_memory_t * rmem, uint chunk_size, bool level2) { gs_ref_memory_t *ilmem = ialloc_alloc_state(rmem, chunk_size); diff --git a/gs/src/ialloc.h b/gs/src/ialloc.h index 21649c3f9..0e93af835 100644 --- a/gs/src/ialloc.h +++ b/gs/src/ialloc.h @@ -61,7 +61,7 @@ gs_free_const_string(imemory, data, nbytes, cname) /* Initialize the interpreter's allocator. */ -int ialloc_init(gs_dual_memory_t *, gs_raw_memory_t *, uint, bool); +int ialloc_init(gs_dual_memory_t *, gs_memory_t *, uint, bool); /* ------ Internal routines ------ */ diff --git a/gs/src/iapi.c b/gs/src/iapi.c index 01bad190c..a5f6f65fa 100644 --- a/gs/src/iapi.c +++ b/gs/src/iapi.c @@ -27,18 +27,15 @@ #include "iminst.h" #include "imain.h" #include "imainarg.h" +#include "gsmemory.h" +#include "gsmalloc.h" +#include "gslibctx.h" - -/* - * GLOBAL WARNING GLOBAL WARNING GLOBAL WARNING GLOBAL WARNING - * - * The nasty global variables - * - * GLOBAL WARNING GLOBAL WARNING GLOBAL WARNING GLOBAL WARNING +/* number of threads to allow per process + * currently more than 1 is guarenteed to fail */ -int gsapi_instance_counter = 0; -/* extern gs_main_instance *gs_main_instance_default(); */ - +static int gsapi_instance_counter = 0; +static const int gsapi_instance_max = 1; /* Return revision numbers and strings of Ghostscript. */ /* Used for determining if wrong GSDLL loaded. */ @@ -55,27 +52,42 @@ gsapi_revision(gsapi_revision_t *pr, int rvsize) return 0; } -/* Create a new instance of Ghostscript. */ -/* We do not support multiple instances, so make sure - * we use the default instance only once. +/* Create a new instance of Ghostscript. + * First instance per process call with *pinstance == NULL + * next instance in a proces call with *pinstance == copy of valid_instance pointer + * *pinstance is set to a new instance pointer. */ GSDLLEXPORT int GSDLLAPI gsapi_new_instance(gs_main_instance **pinstance, void *caller_handle) { + gs_memory_t *mem = NULL; gs_main_instance *minst; - if (gsapi_instance_counter != 0) { - *pinstance = NULL; + + if (pinstance == NULL) return e_Fatal; + + /* limited to 1 instance, till it works :) */ + if ( gsapi_instance_counter >= gsapi_instance_max ) + return e_Fatal; + ++gsapi_instance_counter; + + if (*pinstance == NULL) + /* first instance in this process */ + mem = gs_malloc_init(NULL); + else { + /* nothing different for second thread initialization + * seperate memory, ids, only stdio is process shared. + */ + mem = gs_malloc_init(NULL); } - gsapi_instance_counter++; - minst = gs_main_instance_default(); - minst->caller_handle = caller_handle; - minst->stdin_fn = NULL; - minst->stdout_fn = NULL; - minst->stderr_fn = NULL; - minst->poll_fn = NULL; - minst->display = NULL; - minst->i_ctx_p = NULL; + minst = gs_main_alloc_instance(mem); + mem->gs_lib_ctx->top_of_system = (void*) minst; + mem->gs_lib_ctx->caller_handle = caller_handle; + mem->gs_lib_ctx->stdin_fn = NULL; + mem->gs_lib_ctx->stdout_fn = NULL; + mem->gs_lib_ctx->stderr_fn = NULL; + mem->gs_lib_ctx->poll_fn = NULL; + *pinstance = minst; return 0; } @@ -87,14 +99,17 @@ gsapi_new_instance(gs_main_instance **pinstance, void *caller_handle) GSDLLEXPORT void GSDLLAPI gsapi_delete_instance(gs_main_instance *minst) { - if ((gsapi_instance_counter > 0) && (minst != NULL)) { - minst->caller_handle = NULL; - minst->stdin_fn = NULL; - minst->stdout_fn = NULL; - minst->stderr_fn = NULL; - minst->poll_fn = NULL; + if ((minst != NULL)) { + minst->heap->gs_lib_ctx->caller_handle = NULL; + minst->heap->gs_lib_ctx->stdin_fn = NULL; + minst->heap->gs_lib_ctx->stdout_fn = NULL; + minst->heap->gs_lib_ctx->stderr_fn = NULL; + minst->heap->gs_lib_ctx->poll_fn = NULL; minst->display = NULL; - gsapi_instance_counter--; + + /* NB: notice how no deletions are occuring, good bet this isn't thread ready + */ + --gsapi_instance_counter; } } @@ -107,9 +122,9 @@ gsapi_set_stdio(gs_main_instance *minst, { if (minst == NULL) return e_Fatal; - minst->stdin_fn = stdin_fn; - minst->stdout_fn = stdout_fn; - minst->stderr_fn = stderr_fn; + minst->heap->gs_lib_ctx->stdin_fn = stdin_fn; + minst->heap->gs_lib_ctx->stdout_fn = stdout_fn; + minst->heap->gs_lib_ctx->stderr_fn = stderr_fn; return 0; } @@ -120,7 +135,7 @@ gsapi_set_poll(gs_main_instance *minst, { if (minst == NULL) return e_Fatal; - minst->poll_fn = poll_fn; + minst->heap->gs_lib_ctx->poll_fn = poll_fn; return 0; } @@ -224,7 +239,8 @@ gsapi_exit(gs_main_instance *minst) if (minst == NULL) return e_Fatal; - return gs_to_exit(0); + gs_to_exit(minst->heap, 0); + return 0; } /* Visual tracer : */ diff --git a/gs/src/ibnum.c b/gs/src/ibnum.c index 1dd16b755..e8c65fb62 100644 --- a/gs/src/ibnum.c +++ b/gs/src/ibnum.c @@ -76,10 +76,10 @@ num_array_size(const ref * op, int format) /* Return t_int if integer, t_real if real, t_null if end of stream, */ /* or an error if the format is invalid. */ int -num_array_get(const ref * op, int format, uint index, ref * np) +num_array_get(const gs_memory_t *mem, const ref * op, int format, uint index, ref * np) { if (format == num_array) { - int code = array_get(op, (long)index, np); + int code = array_get(mem, op, (long)index, np); if (code < 0) return t_null; diff --git a/gs/src/ibnum.h b/gs/src/ibnum.h index e07a209a7..c46b97a18 100644 --- a/gs/src/ibnum.h +++ b/gs/src/ibnum.h @@ -69,7 +69,7 @@ extern const byte enc_num_bytes[]; /* in ibnum.c */ /* Read from an array or encoded number string. */ int num_array_format(const ref *); /* returns format or error */ uint num_array_size(const ref *, int); -int num_array_get(const ref *, int, uint, ref *); +int num_array_get(const gs_memory_t *mem, const ref *, int, uint, ref *); /* Decode a number from a string with appropriate byte swapping. */ int sdecode_number(const byte *, int, ref *); diff --git a/gs/src/ichar.h b/gs/src/ichar.h index eef18c8dc..feb8850ac 100644 --- a/gs/src/ichar.h +++ b/gs/src/ichar.h @@ -64,7 +64,7 @@ int op_show_continue(i_ctx_t *); int op_show_continue_pop(i_ctx_t *, int); int op_show_continue_dispatch(i_ctx_t *, int, int); int op_show_free(i_ctx_t *, int); -void glyph_ref(gs_glyph, ref *); +void glyph_ref(const gs_memory_t *mem, gs_glyph, ref *); int finish_stringwidth(i_ctx_t *); /* Exported by zchar.c for zcharout.c */ diff --git a/gs/src/icharout.h b/gs/src/icharout.h index f915507c6..52f5aa30f 100644 --- a/gs/src/icharout.h +++ b/gs/src/icharout.h @@ -65,6 +65,6 @@ int zchar_charstring_data(gs_font *font, const ref *pgref, * wrapper around dict_first/dict_next to implement the enumerate_glyph * font procedure. */ -int zchar_enumerate_glyph(const ref *prdict, int *pindex, gs_glyph *pglyph); +int zchar_enumerate_glyph(const gs_memory_t *mem, const ref *prdict, int *pindex, gs_glyph *pglyph); #endif /* icharout_INCLUDED */ diff --git a/gs/src/icid.h b/gs/src/icid.h index 1a28028d1..0fb2436e6 100644 --- a/gs/src/icid.h +++ b/gs/src/icid.h @@ -30,11 +30,13 @@ int cid_system_info_param(gs_cid_system_info_t *, const ref *); /* Convert a CID into TT char code or to TT glyph index, using SubstNWP. */ /* Returns 1 if a glyph presents, 0 if not, <0 if error. */ -int cid_to_TT_charcode(const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, +int cid_to_TT_charcode(const gs_memory_t *mem, + const ref *Decoding, const ref *TT_cmap, + const ref *SubstNWP, uint nCID, uint *c, ref *src_type, ref *dst_type); /* Create a CIDMap from a True Type cmap array, Decoding and SubstNWP. */ -int cid_fill_CIDMap(const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, +int cid_fill_CIDMap(const gs_memory_t *mem, const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, int GDBytes, ref *CIDMap); /* <cid9font> <cid> .type9mapcid <charstring> <font_index> */ diff --git a/gs/src/icie.h b/gs/src/icie.h index 118e55ae3..794facb79 100644 --- a/gs/src/icie.h +++ b/gs/src/icie.h @@ -29,27 +29,33 @@ /* Get a range array parameter from a dictionary. */ /* We know that count <= 4. */ -int dict_ranges_param(const ref * pdref, const char *kstr, int count, +int dict_ranges_param(const gs_memory_t *mem, + const ref * pdref, const char *kstr, int count, gs_range * prange); /* Get 3 ranges from a dictionary. */ -int dict_range3_param(const ref *pdref, const char *kstr, +int dict_range3_param(const gs_memory_t *mem, + const ref *pdref, const char *kstr, gs_range3 *prange3); /* Get a 3x3 matrix parameter from a dictionary. */ -int dict_matrix3_param(const ref *pdref, const char *kstr, +int dict_matrix3_param(const gs_memory_t *mem, const ref *pdref, + const char *kstr, gs_matrix3 *pmat3); /* Get an array of procedures from a dictionary. */ /* We know count <= countof(empty_procs). */ -int dict_proc_array_param(const ref * pdict, const char *kstr, +int dict_proc_array_param(const gs_memory_t *mem, const ref *pdict, + const char *kstr, uint count, ref * pparray); /* Get 3 procedures from a dictionary. */ -int dict_proc3_param(const ref *pdref, const char *kstr, ref proc3[3]); +int dict_proc3_param(const gs_memory_t *mem, const ref *pdref, + const char *kstr, ref proc3[3]); /* Get WhitePoint and BlackPoint values. */ -int cie_points_param(const ref * pdref, gs_cie_wb * pwb); +int cie_points_param(const gs_memory_t *mem, + const ref * pdref, gs_cie_wb * pwb); /* Process a 3- or 4-dimensional lookup table from a dictionary. */ /* The caller has set pclt->n and pclt->m. */ diff --git a/gs/src/icstate.h b/gs/src/icstate.h index 9dea073fc..cf39aa8ed 100644 --- a/gs/src/icstate.h +++ b/gs/src/icstate.h @@ -35,6 +35,13 @@ # define gs_context_state_t_DEFINED typedef struct gs_context_state_s gs_context_state_t; #endif + +#ifndef gs_file_path_ptr_DEFINED +# define gs_file_path_ptr_DEFINED +typedef struct gs_file_path_s *gs_file_path_ptr; +#endif + + struct gs_context_state_s { gs_state *pgs; gs_dual_memory_t memory; @@ -51,6 +58,7 @@ struct gs_context_state_s { int scanner_options; /* derived from userparams */ bool LockFilePermissions; /* accessed from userparams */ bool starting_arg_file; /* starting a file specified in command line. */ + gs_file_path_ptr lib_path; /* library search list (GS_LIB) */ ref stdio[3]; /* t_file */ /* Put the stacks at the end to minimize other offsets. */ dict_stack_t dict_stack; diff --git a/gs/src/idebug.c b/gs/src/idebug.c index 65fb8a98b..2ba6da38d 100644 --- a/gs/src/idebug.c +++ b/gs/src/idebug.c @@ -41,25 +41,25 @@ extern const int tx_next_index; /* in interp.c */ /* Print a name. */ void -debug_print_name(const ref * pnref) +debug_print_name(const gs_memory_t *mem, const ref * pnref) { ref sref; - name_string_ref(pnref, &sref); + name_string_ref(mem, pnref, &sref); debug_print_string(sref.value.const_bytes, r_size(&sref)); } void -debug_print_name_index(name_index_t nidx) +debug_print_name_index(const gs_memory_t *mem, name_index_t nidx) { ref nref; - name_index_ref(nidx, &nref); - debug_print_name(&nref); + name_index_ref(mem, nidx, &nref); + debug_print_name(mem, &nref); } /* Print a ref. */ private void -debug_print_full_ref(const ref * pref) +debug_print_full_ref(const gs_memory_t *mem, const ref * pref) { uint size = r_size(pref); ref nref; @@ -99,8 +99,8 @@ debug_print_full_ref(const ref * pref) break; case t_name: dprintf2("name(0x%lx#%u)", (ulong) pref->value.pname, - name_index(pref)); - debug_print_name(pref); + name_index(mem, pref)); + debug_print_name(mem, pref); break; case t_null: dprintf("null"); @@ -110,9 +110,9 @@ debug_print_full_ref(const ref * pref) { const op_array_table *opt = op_index_op_array_table(size); - name_index_ref(opt->nx_table[size - opt->base_index], &nref); + name_index_ref(mem, opt->nx_table[size - opt->base_index], &nref); } - debug_print_name(&nref); + debug_print_name(mem, &nref); break; case t_operator: dprintf1("op(%u", size); @@ -151,7 +151,7 @@ debug_print_full_ref(const ref * pref) } } private void -debug_print_packed_ref(const ref_packed * pref) +debug_print_packed_ref(const gs_memory_t *mem, const ref_packed *pref) { ushort elt = *pref & packed_value_mask; ref nref; @@ -160,7 +160,7 @@ debug_print_packed_ref(const ref_packed * pref) case pt_executable_operator: dprintf("<op_name>"); op_index_ref(elt, &nref); - debug_print_ref(&nref); + debug_print_ref(mem, &nref); break; case pt_integer: dprintf1("<int> %d", (int)elt + packed_min_intval); @@ -170,33 +170,33 @@ debug_print_packed_ref(const ref_packed * pref) goto ptn; case pt_executable_name: dprintf("<exec_name>"); - ptn:name_index_ref(elt, &nref); + ptn: name_index_ref(mem, elt, &nref); dprintf2("(0x%lx#%u)", (ulong) nref.value.pname, elt); - debug_print_name(&nref); + debug_print_name(mem, &nref); break; default: dprintf2("<packed_%d?>0x%x", *pref >> r_packed_type_shift, elt); } } void -debug_print_ref_packed(const ref_packed *rpp) +debug_print_ref_packed(const gs_memory_t *mem, const ref_packed *rpp) { if (r_is_packed(rpp)) - debug_print_packed_ref(rpp); + debug_print_packed_ref(mem, rpp); else - debug_print_full_ref((const ref *)rpp); + debug_print_full_ref(mem, (const ref *)rpp); dflush(); } void -debug_print_ref(const ref * pref) +debug_print_ref(const gs_memory_t *mem, const ref * pref) { - debug_print_ref_packed((const ref_packed *)pref); + debug_print_ref_packed(mem, (const ref_packed *)pref); } /* Dump one ref. */ -private void print_ref_data(const ref *); +private void print_ref_data(const gs_memory_t *mem, const ref *); void -debug_dump_one_ref(const ref * p) +debug_dump_one_ref(const gs_memory_t *mem, const ref * p) { uint attrs = r_type_attrs(p); uint type = r_type(p); @@ -216,18 +216,18 @@ debug_dump_one_ref(const ref * p) if ((attrs & ap->mask) == ap->value) dputc(ap->print); dprintf2(" 0x%04x 0x%08lx", r_size(p), *(const ulong *)&p->value); - print_ref_data(p); + print_ref_data(mem, p); dflush(); } private void -print_ref_data(const ref *p) +print_ref_data(const gs_memory_t *mem, const ref *p) { #define BUF_SIZE 30 byte buf[BUF_SIZE + 1]; const byte *pchars; uint plen; - if (obj_cvs(p, buf, countof(buf) - 1, &plen, &pchars) >= 0 && + if (obj_cvs(mem, p, buf, countof(buf) - 1, &plen, &pchars) >= 0 && pchars == buf && ((buf[plen] = 0), strcmp((char *)buf, "--nostringval--")) ) @@ -237,7 +237,8 @@ print_ref_data(const ref *p) /* Dump a region of memory containing refs. */ void -debug_dump_refs(const ref * from, uint size, const char *msg) +debug_dump_refs(const gs_memory_t *mem, const ref * from, + uint size, const char *msg) { const ref *p = from; uint count = size; @@ -246,7 +247,7 @@ debug_dump_refs(const ref * from, uint size, const char *msg) dprintf2("%s at 0x%lx:\n", msg, (ulong) from); while (count--) { dprintf2("0x%lx: 0x%04x ", (ulong)p, r_type_attrs(p)); - debug_dump_one_ref(p); + debug_dump_one_ref(mem, p); dputc('\n'); p++; } @@ -254,7 +255,8 @@ debug_dump_refs(const ref * from, uint size, const char *msg) /* Dump a stack. */ void -debug_dump_stack(const ref_stack_t * pstack, const char *msg) +debug_dump_stack(const gs_memory_t *mem, + const ref_stack_t * pstack, const char *msg) { uint i; const char *m = msg; @@ -267,14 +269,14 @@ debug_dump_stack(const ref_stack_t * pstack, const char *msg) m = NULL; } dprintf2("0x%lx: 0x%02x ", (ulong)p, r_type(p)); - debug_dump_one_ref(p); + debug_dump_one_ref(mem, p); dputc('\n'); } } /* Dump an array. */ void -debug_dump_array(const ref * array) +debug_dump_array(const gs_memory_t *mem, const ref * array) { const ref_packed *pp; uint type = r_type(array); @@ -290,7 +292,7 @@ debug_dump_array(const ref * array) case t_oparray: /* This isn't really an array, but we'd like to see */ /* its contents anyway. */ - debug_dump_array(array->value.const_refs); + debug_dump_array(mem, array->value.const_refs); return; case t_array: case t_mixedarray: @@ -304,13 +306,13 @@ debug_dump_array(const ref * array) len--, pp = packed_next(pp)) { ref temp; - packed_get(pp, &temp); + packed_get(mem, pp, &temp); if (r_is_packed(pp)) { dprintf2("0x%lx* 0x%04x ", (ulong)pp, (uint)*pp); - print_ref_data(&temp); + print_ref_data(mem, &temp); } else { dprintf2("0x%lx: 0x%02x ", (ulong)pp, r_type(&temp)); - debug_dump_one_ref(&temp); + debug_dump_one_ref(mem, &temp); } dputc('\n'); } diff --git a/gs/src/idebug.h b/gs/src/idebug.h index 1acda2494..51d999c32 100644 --- a/gs/src/idebug.h +++ b/gs/src/idebug.h @@ -21,21 +21,23 @@ # define idebug_INCLUDED /* Print individual values. */ -void debug_print_name(const ref *); -void debug_print_name_index(uint /*name_index_t*/); -void debug_print_ref(const ref *); -void debug_print_ref_packed(const ref_packed *); +void debug_print_name(const gs_memory_t *mem, const ref *); +void debug_print_name_index(const gs_memory_t *mem, uint /*name_index_t*/); +void debug_print_ref(const gs_memory_t *mem, const ref *); +void debug_print_ref_packed(const gs_memory_t *mem, const ref_packed *); /* Dump regions of memory. */ -void debug_dump_one_ref(const ref *); -void debug_dump_refs(const ref * from, uint size, const char *msg); -void debug_dump_array(const ref * array); +void debug_dump_one_ref(const gs_memory_t *mem, const ref *); +void debug_dump_refs(const gs_memory_t *mem, + const ref * from, uint size, const char *msg); +void debug_dump_array(const gs_memory_t *mem, const ref * array); /* Dump a stack. Using this requires istack.h. */ #ifndef ref_stack_DEFINED typedef struct ref_stack_s ref_stack_t; /* also defined in isdata.h */ # define ref_stack_DEFINED #endif -void debug_dump_stack(const ref_stack_t * pstack, const char *msg); +void debug_dump_stack(const gs_memory_t *mem, + const ref_stack_t * pstack, const char *msg); #endif /* idebug_INCLUDED */ diff --git a/gs/src/idict.c b/gs/src/idict.c index 219223c7d..6dfda64f6 100644 --- a/gs/src/idict.c +++ b/gs/src/idict.c @@ -55,9 +55,6 @@ */ const uint dict_max_size = max_array_size - 1; -/* Define whether dictionaries expand automatically when full. */ -bool dict_auto_expand = false; - /* Define whether dictionaries are packed by default. */ bool dict_default_pack = true; @@ -90,7 +87,7 @@ dict_find(const ref * pdref, const ref * pkey, ref ** ppvalue) stats_dict.lookups++; if (r_has_type(pkey, t_name) && dict_is_packed(pdict)) { - uint nidx = name_index(pkey); + uint nidx = name_index(dict_mem(pdict), pkey); uint hash = dict_hash_mod(dict_name_index_hash(nidx), npairs(pdict)) + 1; @@ -254,7 +251,7 @@ dict_unpack(ref * pdref, dict_stack_t *pds) return code; for (nkp = pdict->keys.value.refs; count--; okp++, nkp++) if (r_packed_is_name(okp)) { - packed_get(okp, nkp); + packed_get(mem, okp, nkp); ref_mark_new_in(mem, nkp); } else if (*okp == packed_key_deleted) r_set_attrs(nkp, a_executable); @@ -284,12 +281,13 @@ dict_find(const ref * pdref, const ref * pkey, ref_packed kpack; uint hash; int ktype; + const gs_memory_t *mem = dict_mem(pdict); /* Compute hash. The only types we bother with are strings, */ /* names, and (unlikely, but worth checking for) integers. */ switch (r_type(pkey)) { case t_name: - nidx = name_index(pkey); + nidx = name_index(mem, pkey); nh: hash = dict_name_index_hash(nidx); kpack = packed_name_key(nidx); @@ -302,10 +300,10 @@ dict_find(const ref * pdref, const ref * pkey, if (!r_has_attr(pkey, a_read)) return_error(e_invalidaccess); - code = name_ref(pkey->value.bytes, r_size(pkey), &nref, 1); + code = name_ref(mem, pkey->value.bytes, r_size(pkey), &nref, 1); if (code < 0) return code; - nidx = name_index(&nref); + nidx = name_index(mem, &nref); } goto nh; case t_real: @@ -377,7 +375,7 @@ dict_find(const ref * pdref, const ref * pkey, for (kp = kbot + dict_hash_mod(hash, size) + 2;;) { --kp; if ((etype = r_type(kp)) == ktype) { /* Fast comparison if both keys are names */ - if (name_index(kp) == nidx) { + if (name_index(mem, kp) == nidx) { *ppvalue = pdict->values.value.refs + (kp - kbot); return 1; } @@ -396,7 +394,7 @@ dict_find(const ref * pdref, const ref * pkey, } else /* key not found */ break; } else { - if (obj_eq(kp, pkey)) { + if (obj_eq(mem, kp, pkey)) { *ppvalue = pdict->values.value.refs + (kp - kbot); return 1; } @@ -419,10 +417,15 @@ dict_find_string(const ref * pdref, const char *kstr, ref ** ppvalue) { int code; ref kname; + if ( pdref != 0 ) { + dict *pdict = pdref->value.pdict; - if ((code = name_ref((const byte *)kstr, strlen(kstr), &kname, -1)) < 0) - return code; - return dict_find(pdref, &kname, ppvalue); + if ((code = name_ref(dict_mem(pdict), + (const byte *)kstr, strlen(kstr), &kname, -1)) < 0) + return code; + return dict_find(pdref, &kname, ppvalue); + } + return 0; } /* @@ -435,6 +438,7 @@ dict_put(ref * pdref /* t_dictionary */ , const ref * pkey, const ref * pvalue, { dict *pdict = pdref->value.pdict; gs_ref_memory_t *mem = dict_memory(pdict); + gs_memory_t *pmem = dict_mem(pdict); int rcode = 0; int code; ref *pvslot; @@ -449,7 +453,7 @@ dict_put(ref * pdref /* t_dictionary */ , const ref * pkey, const ref * pvalue, case 0: break; case e_dictfull: - if (!dict_auto_expand) + if (!pmem->gs_lib_ctx->dict_auto_expand) return_error(e_dictfull); code = dict_grow(pdref, pds); if (code < 0) @@ -465,7 +469,7 @@ dict_put(ref * pdref /* t_dictionary */ , const ref * pkey, const ref * pvalue, if (!r_has_attr(pkey, a_read)) return_error(e_invalidaccess); - code = name_from_string(pkey, &kname); + code = name_from_string(pmem, pkey, &kname); if (code < 0) return code; pkey = &kname; @@ -474,7 +478,7 @@ dict_put(ref * pdref /* t_dictionary */ , const ref * pkey, const ref * pvalue, ref_packed *kp; if (!r_has_type(pkey, t_name) || - name_index(pkey) > packed_name_max_index + name_index(pmem, pkey) > packed_name_max_index ) { /* Change to unpacked representation. */ int code = dict_unpack(pdref, pds); @@ -488,7 +492,7 @@ dict_put(ref * pdref /* t_dictionary */ , const ref * pkey, const ref * pvalue, /* array itself is new. */ ref_do_save_in(mem, &pdict->keys, kp, "dict_put(key)"); } - *kp = pt_tag(pt_literal_name) + name_index(pkey); + *kp = pt_tag(pt_literal_name) + name_index(pmem, pkey); } else { ref *kp = pdict->keys.value.refs + index; @@ -536,8 +540,10 @@ dict_put_string(ref * pdref, const char *kstr, const ref * pvalue, { int code; ref kname; + dict *pdict = pdref->value.pdict; - if ((code = name_ref((const byte *)kstr, strlen(kstr), &kname, 0)) < 0) + if ((code = name_ref(dict_mem(pdict), + (const byte *)kstr, strlen(kstr), &kname, 0)) < 0) return code; return dict_put(pdref, &kname, pvalue, pds); } @@ -720,7 +726,7 @@ dict_resize(ref * pdref, uint new_size, dict_stack_t *pds) int code; if (new_size < d_length(pdict)) { - if (!dict_auto_expand) + if (!mem->gs_lib_ctx->dict_auto_expand) return_error(e_dictfull); new_size = d_length(pdict); } @@ -824,7 +830,7 @@ dict_next(const ref * pdref, int index, ref * eltp /* ref eltp[2] */ ) ref *vp = pdict->values.value.refs + index; while (vp--, --index >= 0) { - array_get(&pdict->keys, (long)index, eltp); + array_get(dict_mem(pdict), &pdict->keys, (long)index, eltp); /* Make sure this is a valid entry. */ if (r_has_type(eltp, t_name) || (!dict_is_packed(pdict) && !r_has_type(eltp, t_null)) @@ -854,7 +860,7 @@ dict_index_entry(const ref * pdref, int index, ref * eltp /* ref eltp[2] */ ) { const dict *pdict = pdref->value.pdict; - array_get(&pdict->keys, (long)(index + 1), eltp); + array_get(dict_mem(pdict), &pdict->keys, (long)(index + 1), eltp); if (r_has_type(eltp, t_name) || (!dict_is_packed(pdict) && !r_has_type(eltp, t_null)) ) { diff --git a/gs/src/idict.h b/gs/src/idict.h index 38b731897..5b13ca25a 100644 --- a/gs/src/idict.h +++ b/gs/src/idict.h @@ -38,6 +38,7 @@ struct dict_s { ref memory; /* foreign t_struct, the allocator that */ /* created this dictionary */ #define dict_memory(pdict) r_ptr(&(pdict)->memory, gs_ref_memory_t) +#define dict_mem(pdict) r_ptr(&(pdict)->memory, gs_memory_t) }; /* diff --git a/gs/src/idparam.c b/gs/src/idparam.c index 180e7768f..4cda62a0a 100644 --- a/gs/src/idparam.c +++ b/gs/src/idparam.c @@ -220,7 +220,8 @@ dict_ints_param(const ref * pdict, const char *kstr, /* if defaultvec is not NULL, copy it into fvec (maxlen elements) */ /* and return maxlen. */ int -dict_float_array_check_param(const ref * pdict, const char *kstr, +dict_float_array_check_param(const gs_memory_t *mem, + const ref * pdict, const char *kstr, uint len, float *fvec, const float *defaultvec, int under_error, int over_error) { @@ -240,23 +241,26 @@ dict_float_array_check_param(const ref * pdict, const char *kstr, size = r_size(pdval); if (size > len) return_error(over_error); - code = process_float_array(pdval, size, fvec); + code = process_float_array(mem, pdval, size, fvec); return (code < 0 ? code : size == len || under_error >= 0 ? size : gs_note_error(under_error)); } int -dict_float_array_param(const ref * pdict, const char *kstr, +dict_float_array_param(const gs_memory_t *mem, + const ref * pdict, const char *kstr, uint maxlen, float *fvec, const float *defaultvec) { - return dict_float_array_check_param(pdict, kstr, maxlen, fvec, + return dict_float_array_check_param(mem ,pdict, kstr, maxlen, fvec, defaultvec, 0, e_limitcheck); } int -dict_floats_param(const ref * pdict, const char *kstr, +dict_floats_param(const gs_memory_t *mem, + const ref * pdict, const char *kstr, uint maxlen, float *fvec, const float *defaultvec) { - return dict_float_array_check_param(pdict, kstr, maxlen, fvec, defaultvec, + return dict_float_array_check_param(mem, pdict, kstr, maxlen, + fvec, defaultvec, e_rangecheck, e_rangecheck); } @@ -286,13 +290,13 @@ dict_proc_param(const ref * pdict, const char *kstr, ref * pproc, /* Get a matrix from a dictionary. */ int -dict_matrix_param(const ref * pdict, const char *kstr, gs_matrix * pmat) +dict_matrix_param(const gs_memory_t *mem, const ref * pdict, const char *kstr, gs_matrix * pmat) { ref *pdval; if (pdict == 0 || dict_find_string(pdict, kstr, &pdval) <= 0) return_error(e_typecheck); - return read_matrix(pdval, pmat); + return read_matrix(mem, pdval, pmat); } /* Get a UniqueID or XUID from a dictionary. */ diff --git a/gs/src/idparam.h b/gs/src/idparam.h index bc2d31d4b..b79d2be95 100644 --- a/gs/src/idparam.h +++ b/gs/src/idparam.h @@ -80,14 +80,17 @@ int dict_ints_param(const ref * pdict, const char *kstr, * not NULL, copy (max)len elements from defaultvec to fvec and return * (max)len. */ -int dict_float_array_check_param(const ref * pdict, const char *kstr, +int dict_float_array_check_param(const gs_memory_t *mem, + const ref * pdict, const char *kstr, uint len, float *fvec, const float *defaultvec, int under_error, int over_error); -int dict_float_array_param(const ref * pdict, const char *kstr, +int dict_float_array_param(const gs_memory_t *mem, + const ref * pdict, const char *kstr, uint maxlen, float *fvec, const float *defaultvec); -int dict_floats_param(const ref * pdict, const char *kstr, +int dict_floats_param(const gs_memory_t *mem, + const ref * pdict, const char *kstr, uint len, float *fvec, const float *defaultvec); @@ -99,7 +102,8 @@ int dict_floats_param(const ref * pdict, const char *kstr, */ int dict_proc_param(const ref * pdict, const char *kstr, ref * pproc, bool defaultval); -int dict_matrix_param(const ref * pdict, const char *kstr, +int dict_matrix_param(const gs_memory_t *mem, + const ref * pdict, const char *kstr, gs_matrix * pmat); int dict_uid_param(const ref * pdict, gs_uid * puid, int defaultval, gs_memory_t * mem, const i_ctx_t *i_ctx_p); diff --git a/gs/src/idstack.c b/gs/src/idstack.c index 9098e5b52..38ff2d363 100644 --- a/gs/src/idstack.c +++ b/gs/src/idstack.c @@ -110,14 +110,14 @@ dstack_find_name_by_index(dict_stack_t * pds, uint nidx) do { dict *pdict = pdref->value.pdict; uint size = npairs(pdict); - + const gs_memory_t *mem = dict_mem(pdict); #ifdef DEBUG if (gs_debug_c('D')) { ref dnref; - name_index_ref(nidx, &dnref); + name_index_ref(mem, nidx, &dnref); dlputs("[D]lookup "); - debug_print_name(&dnref); + debug_print_name(mem, &dnref); dprintf3(" in 0x%lx(%u/%u)\n", (ulong) pdict, dict_length(pdref), dict_maxlength(pdref)); @@ -142,7 +142,7 @@ dstack_find_name_by_index(dict_stack_t * pds, uint nidx) for (kp = kbot + dict_hash_mod(hash, size) + 2;;) { --kp; if (r_has_type(kp, t_name)) { - if (name_index(kp) == nidx) { + if (name_index(mem, kp) == nidx) { INCR_DEPTH(pdref); return pdict->values.value.refs + (kp - kbot); } @@ -170,9 +170,12 @@ dstack_find_name_by_index(dict_stack_t * pds, uint nidx) ref key; uint i = pds->stack.p + 1 - pds->stack.bot; uint size = ref_stack_count(&pds->stack); - ref *pvalue; + ref *pvalue; + + dict *pdict = pdref->value.pdict; + const gs_memory_t *mem = dict_mem(pdict); - name_index_ref(nidx, &key); + name_index_ref(mem, nidx, &key); for (; i < size; i++) { if (dict_find(ref_stack_index(&pds->stack, i), &key, &pvalue) > 0 @@ -233,7 +236,7 @@ dstack_gc_cleanup(dict_stack_t * pds) ref key; ref *old_pvalue; - array_get(&pdict->keys, (long)i, &key); + array_get(dict_mem(pdict), &pdict->keys, (long)i, &key); if (r_has_type(&key, t_name) && pv_valid(old_pvalue = key.value.pname->pvalue) ) { /* diff --git a/gs/src/ifapi.h b/gs/src/ifapi.h index 02d4e5493..a91303c48 100644 --- a/gs/src/ifapi.h +++ b/gs/src/ifapi.h @@ -87,6 +87,7 @@ struct FAPI_font_s { void *server_font_data; bool need_decrypt; /* client's data : */ + const gs_memory_t *memory; const char *font_file_path; int subfont; bool is_type1; /* Only for non-disk fonts; dirty for disk fonts. */ diff --git a/gs/src/ifont.h b/gs/src/ifont.h index ad8e93fcf..56fa30277 100644 --- a/gs/src/ifont.h +++ b/gs/src/ifont.h @@ -78,7 +78,7 @@ extern_st(st_font_data); * Get the FontBBox from a font dictionary, if any; if none, or if invalid, * return 4 zeros. */ -int font_bbox_param(const ref * pfdict, double bbox[4]); +int font_bbox_param(const gs_memory_t *mem, const ref *pfdict, double bbox[4]); /* ---------------- Exported by zfont.c ---------------- */ @@ -98,7 +98,7 @@ int font_param(const ref * pfdict, gs_font ** ppfont); * collector. Return true if a mark was just added. This procedure is * intended to be used as the mark_glyph procedure in the character cache. */ -bool zfont_mark_glyph_name(gs_glyph glyph, void *ignore_data); +bool zfont_mark_glyph_name(const gs_memory_t *mem, gs_glyph glyph, void *ignore_data); /* * Return information about a font, including information from the FontInfo diff --git a/gs/src/ifont1.h b/gs/src/ifont1.h index 4ddb322c1..c335e2d4d 100644 --- a/gs/src/ifont1.h +++ b/gs/src/ifont1.h @@ -45,7 +45,8 @@ int charstring_font_get_refs(const_os_ptr op, charstring_font_refs_t *pfr); * CIDFontType 0 font. The client has filled in pdata1->interpret, * subroutineNumberBias, lenIV, and (if applicable) the Type 2 elements. */ -int charstring_font_params(const_os_ptr op, charstring_font_refs_t *pfr, +int charstring_font_params(const gs_memory_t *mem, + const_os_ptr op, charstring_font_refs_t *pfr, gs_type1_data *pdata1); /* diff --git a/gs/src/ifont42.h b/gs/src/ifont42.h index a14841a01..00272d23f 100644 --- a/gs/src/ifont42.h +++ b/gs/src/ifont42.h @@ -29,7 +29,7 @@ int build_gs_TrueType_font(i_ctx_t *, os_ptr, gs_font_type42 **, font_type, * Check a parameter for being an array of strings. Return the parameter * value even if it is of the wrong type. */ -int font_string_array_param(os_ptr, const char *, ref *); +int font_string_array_param(const gs_memory_t *mem, os_ptr, const char *, ref *); /* * Get a GlyphDirectory if present. Return 0 if present, 1 if absent, @@ -41,7 +41,7 @@ int font_GlyphDirectory_param(os_ptr, ref *); * Get a glyph outline from GlyphDirectory. Return an empty string if * the glyph is missing or out of range. */ -int font_gdir_get_outline(const ref *, long, gs_glyph_data_t *); +int font_gdir_get_outline(const gs_memory_t *mem, const ref *, long, gs_glyph_data_t *); /* * Access a given byte offset and length in an array of strings. @@ -50,6 +50,6 @@ int font_gdir_get_outline(const ref *, long, gs_glyph_data_t *); * Return code : 0 - success, <0 - error, * >0 - number of accessible bytes (client must cycle). */ -int string_array_access_proc(const ref *, int, ulong, uint, const byte **); +int string_array_access_proc(const gs_memory_t *mem, const ref *, int, ulong, uint, const byte **); #endif /* ifont42_INCLUDED */ diff --git a/gs/src/igc.c b/gs/src/igc.c index 96cfcd469..9038deac9 100644 --- a/gs/src/igc.c +++ b/gs/src/igc.c @@ -40,9 +40,6 @@ private const bool I_FORCE_GLOBAL_GC = false; /* Define whether to bypass the collector entirely. */ private const bool I_BYPASS_GC = false; -/* Avoid including all of iname.h. */ -extern name_table *the_gs_name_table; - /* Define an entry on the mark stack. */ typedef struct { void *ptr; @@ -70,12 +67,15 @@ struct gc_mark_stack_s { #define ms_size_min 50 /* min size for segment in free block */ /* Forward references */ + +const gs_memory_t * gcst_get_memory_ptr(gc_state_t *gcst); + private void gc_init_mark_stack(gc_mark_stack *, uint); -private void gc_objects_clear_marks(chunk_t *); +private void gc_objects_clear_marks(const gs_memory_t *mem, chunk_t *); private void gc_unmark_names(name_table *); private int gc_trace(gs_gc_root_t *, gc_state_t *, gc_mark_stack *); private int gc_rescan_chunk(chunk_t *, gc_state_t *, gc_mark_stack *); -private int gc_trace_chunk(chunk_t *, gc_state_t *, gc_mark_stack *); +private int gc_trace_chunk(const gs_memory_t *mem, chunk_t *, gc_state_t *, gc_mark_stack *); private bool gc_trace_finish(gc_state_t *); private void gc_clear_reloc(chunk_t *); private void gc_objects_set_reloc(chunk_t *); @@ -174,6 +174,7 @@ gs_gc_reclaim(vm_spaces * pspaces, bool global) ms_entry body[ms_size_default]; } ms_default; gc_mark_stack *mark_stack = &ms_default.stack; + const gs_memory_t *cmem; /* Optionally force global GC for debugging. */ @@ -183,6 +184,7 @@ gs_gc_reclaim(vm_spaces * pspaces, bool global) /* Determine which spaces we are tracing and collecting. */ spaces = *pspaces; + cmem = space_system->stable_memory; space_memories[1] = space_system; space_memories[2] = space_global; min_collect = max_trace = 2; @@ -228,8 +230,8 @@ gs_gc_reclaim(vm_spaces * pspaces, bool global) state.spaces = spaces; state.min_collect = min_collect_vm_space << r_space_shift; state.relocating_untraced = false; - state.heap = state.loc.memory->parent; - state.ntable = the_gs_name_table; + state.heap = state.loc.memory->non_gc_memory; + state.ntable = state.heap->gs_lib_ctx->gs_name_table; /* Register the allocators themselves as roots, */ /* so we mark and relocate the change and save lists properly. */ @@ -260,7 +262,7 @@ gs_gc_reclaim(vm_spaces * pspaces, bool global) for_collected_spaces(ispace) for_space_chunks(ispace, mem, cp) { - gc_objects_clear_marks(cp); + gc_objects_clear_marks((const gs_memory_t *)mem, cp); gc_strings_set_marks(cp, false); } @@ -334,7 +336,7 @@ gs_gc_reclaim(vm_spaces * pspaces, bool global) if (!global) for_chunks(min_collect - 1, mem, cp) - more |= gc_trace_chunk(cp, &state, mark_stack); + more |= gc_trace_chunk((const gs_memory_t *)mem, cp, &state, mark_stack); /* Handle mark stack overflow. */ @@ -379,7 +381,7 @@ gs_gc_reclaim(vm_spaces * pspaces, bool global) /* relocation to wind up as o_untraced, not o_unmarked. */ for_chunks(min_collect - 1, mem, cp) - gc_objects_clear_marks(cp); + gc_objects_clear_marks((const gs_memory_t *)mem, cp); end_phase("post-clear marks"); @@ -574,7 +576,7 @@ ptr_string_unmark(enum_ptr_t *pep, gc_state_t * gcst) /* Unmark the objects in a chunk. */ private void -gc_objects_clear_marks(chunk_t * cp) +gc_objects_clear_marks(const gs_memory_t *mem, chunk_t * cp) { if_debug_chunk('6', "[6]unmarking chunk", cp); SCAN_CHUNK_OBJECTS(cp) @@ -590,7 +592,7 @@ gc_objects_clear_marks(chunk_t * cp) (ulong) size, (ulong) pre); o_set_unmarked(pre); if (proc != 0) - (*proc) (pre + 1, size, pre->o_type); + (*proc) (mem, pre + 1, size, pre->o_type); END_OBJECTS_SCAN } @@ -637,6 +639,7 @@ gc_rescan_chunk(chunk_t * cp, gc_state_t * pstate, gc_mark_stack * pmstack) gs_gc_root_t root; void *comp; int more = 0; + const gs_memory_t *mem = gcst_get_memory_ptr( pstate ); if (sbot > stop) return 0; @@ -684,7 +687,7 @@ gc_rescan_chunk(chunk_t * cp, gc_state_t * pstate, gc_mark_stack * pmstack) if (!o_is_untraced(pre)) o_set_unmarked(pre); if (proc != 0) - (*proc) (comp, size, pre->o_type); + (*proc) (mem, comp, size, pre->o_type); more |= gc_trace(&root, pstate, pmstack); } } @@ -696,7 +699,7 @@ gc_rescan_chunk(chunk_t * cp, gc_state_t * pstate, gc_mark_stack * pmstack) /* We assume that pstate->min_collect > avm_system, */ /* so we don't have to trace names. */ private int -gc_trace_chunk(chunk_t * cp, gc_state_t * pstate, gc_mark_stack * pmstack) +gc_trace_chunk(const gs_memory_t *mem, chunk_t * cp, gc_state_t * pstate, gc_mark_stack * pmstack) { gs_gc_root_t root; void *comp; @@ -739,7 +742,7 @@ gc_trace_chunk(chunk_t * cp, gc_state_t * pstate, gc_mark_stack * pmstack) root.ptype = ptr_struct_type; comp = pre + 1; if (proc != 0) - (*proc) (comp, size, pre->o_type); + (*proc) (mem, comp, size, pre->o_type); more |= gc_trace(&root, pstate, pmstack); } } @@ -825,7 +828,7 @@ gc_trace(gs_gc_root_t * rp, gc_state_t * pstate, gc_mark_stack * pmstack) mproc = ptr[-1].o_type->enum_ptrs; if (mproc == gs_no_struct_enum_ptrs || (ptp = (*mproc) - (ptr, pre_obj_contents_size(ptr - 1), + (gcst_get_memory_ptr(pstate), ptr, pre_obj_contents_size(ptr - 1), sp->index, &nep, ptr[-1].o_type, pstate)) == 0 ) { if_debug0('7', " - done\n"); @@ -1030,7 +1033,7 @@ gc_extend_stack(gc_mark_stack * pms, gc_state_t * pstate) /* storage. This can't happen. */ lprintf1("mark stack overflowed while outside collectible space at 0x%lx!\n", (ulong) cptr); - gs_abort(); + gs_abort(pstate->heap); } if (cptr < cp->rescan_bot) cp->rescan_bot = cptr, new = -1; @@ -1252,7 +1255,7 @@ igc_reloc_struct_ptr(const void /*obj_header_t */ *obj, gc_state_t * gcst) if (back > (cp->ctop - cp->cbase) >> obj_back_shift) { lprintf2("Invalid back pointer %u at 0x%lx!\n", back, (ulong) obj); - gs_abort(); + gs_abort(NULL); } } else { /* Pointed to unknown chunk. Can't check it, sorry. */ @@ -1290,6 +1293,7 @@ gc_objects_compact(chunk_t * cp, gc_state_t * gcst) { chunk_head_t *chead = cp->chead; obj_header_t *dpre = (obj_header_t *) chead->dest; + const gs_memory_t *cmem = gcst->spaces.memories.named.system->stable_memory; SCAN_CHUNK_OBJECTS(cp) DO_ALL @@ -1308,7 +1312,7 @@ gc_objects_compact(chunk_t * cp, gc_state_t * gcst) memmove(dpre, pre, sizeof(obj_header_t) + size); } else - (*procs->compact) (pre, dpre, size); + (*procs->compact) (cmem, pre, dpre, size); dpre = (obj_header_t *) ((byte *) dpre + obj_size_round(size)); } @@ -1344,3 +1348,11 @@ gc_free_empty_chunks(gs_ref_memory_t * mem) } } } + + +const gs_memory_t * gcst_get_memory_ptr(gc_state_t *gcst) +{ + vm_spaces spaces = gcst->spaces; + const gs_memory_t *cmem = space_system->stable_memory; + return cmem; +} diff --git a/gs/src/igc.h b/gs/src/igc.h index b90fed0be..3f74d09a6 100644 --- a/gs/src/igc.h +++ b/gs/src/igc.h @@ -47,7 +47,7 @@ struct struct_shared_procs_s { /* Compact an object. */ #define gc_proc_compact(proc)\ - void proc(obj_header_t *pre, obj_header_t *dpre, uint size) + void proc(const gs_memory_t *cmem, obj_header_t *pre, obj_header_t *dpre, uint size) gc_proc_compact((*compact)); }; @@ -65,7 +65,7 @@ struct gc_state_s { int min_collect; /* avm_space */ bool relocating_untraced; /* if true, we're relocating */ /* pointers from untraced spaces */ - gs_raw_memory_t *heap; /* for extending mark stack */ + gs_memory_t *heap; /* for extending mark stack */ name_table *ntable; /* (implicitly referenced by names) */ #ifdef DEBUG chunk_t *container; diff --git a/gs/src/igcref.c b/gs/src/igcref.c index 29be0c921..f20b74022 100644 --- a/gs/src/igcref.c +++ b/gs/src/igcref.c @@ -79,11 +79,14 @@ ENUM_PTRS_BEGIN_PROC(ref_struct_enum_ptrs) } RELOC_PTRS_BEGIN(ref_struct_reloc_ptrs) { + vm_spaces spaces = gcst->spaces; + const gs_memory_t *cmem = space_system->stable_memory; + ref *beg = vptr; ref *end = (ref *) ((char *)vptr + size); igc_reloc_refs((ref_packed *) beg, (ref_packed *) end, gcst); - ref_struct_clear_marks(vptr, size, pstype); + ref_struct_clear_marks(cmem, vptr, size, pstype); } RELOC_PTRS_END /* ------ Unmarking phase ------ */ @@ -102,7 +105,8 @@ ptr_ref_unmark(enum_ptr_t *pep, gc_state_t * ignored) /* Unmarking routine for ref objects. */ private void -refs_clear_marks(void /*obj_header_t */ *vptr, uint size, +refs_clear_marks(const gs_memory_t *cmem, + void /*obj_header_t */ *vptr, uint size, const gs_memory_struct_type_t * pstype) { ref_packed *rp = (ref_packed *) vptr; @@ -115,7 +119,7 @@ refs_clear_marks(void /*obj_header_t */ *vptr, uint size, #ifdef DEBUG if (gs_debug_c('8')) { dlprintf1(" [8]unmark packed 0x%lx ", (ulong) rp); - debug_print_ref((const ref *)rp); + debug_print_ref(cmem, (const ref *)rp); dputs("\n"); } #endif @@ -127,7 +131,7 @@ refs_clear_marks(void /*obj_header_t */ *vptr, uint size, #ifdef DEBUG if (gs_debug_c('8')) { dlprintf1(" [8]unmark ref 0x%lx ", (ulong) rp); - debug_print_ref(pref); + debug_print_ref(cmem, pref); dputs("\n"); } #endif @@ -173,7 +177,7 @@ ptr_ref_mark(enum_ptr_t *pep, gc_state_t * ignored) /* Clear the relocation for a ref object. */ private void -refs_clear_reloc(obj_header_t * hdr, uint size) +refs_clear_reloc(obj_header_t *hdr, uint size) { ref_packed *rp = (ref_packed *) (hdr + 1); ref_packed *end = (ref_packed *) ((byte *) rp + size); @@ -383,7 +387,10 @@ igc_reloc_refs(ref_packed * from, ref_packed * to, gc_state_t * gcst) { int min_trace = gcst->min_collect; ref_packed *rp = from; - bool do_all = gcst->relocating_untraced; + bool do_all = gcst->relocating_untraced; + + vm_spaces spaces = gcst->spaces; + const gs_memory_t *cmem = space_system->stable_memory; while (rp < to) { ref *pref; @@ -507,7 +514,7 @@ igc_reloc_refs(ref_packed * from, ref_packed * to, gc_state_t * gcst) break; case t_name: { - void *psub = name_ref_sub_table(pref); + void *psub = name_ref_sub_table(cmem, pref); void *rsub = RELOC_OBJ(psub); /* gcst implicit */ SET_RELOC(pref->value.pname, @@ -545,7 +552,7 @@ no_reloc: /* Relocate a pointer to a ref. */ /* See gsmemory.h for why the argument is const and the result is not. */ ref_packed * -igc_reloc_ref_ptr(const ref_packed * prp, gc_state_t * ignored) +igc_reloc_ref_ptr(const ref_packed * prp, gc_state_t *gcst) { /* * Search forward for relocation. This algorithm is intrinsically very @@ -559,7 +566,6 @@ igc_reloc_ref_ptr(const ref_packed * prp, gc_state_t * ignored) #else # define RP_REF(rp) ((const ref *)rp) #endif - /* * Iff this pointer points into a space that wasn't traced, * the referent won't be marked. In this case, we shouldn't @@ -633,7 +639,7 @@ ret_rp: /* Compact a ref object. */ /* Remove the marks at the same time. */ private void -refs_compact(obj_header_t * pre, obj_header_t * dpre, uint size) +refs_compact(const gs_memory_t *mem, obj_header_t * pre, obj_header_t * dpre, uint size) { ref_packed *dest; ref_packed *src; @@ -705,7 +711,7 @@ refs_compact(obj_header_t * pre, obj_header_t * dpre, uint size) lprintf3("Reloc error for refs 0x%lx: reloc = %lu, stored = %u\n", (ulong) dpre, (ulong) ((byte *) src - (byte *) dest), (uint) r_size((ref *) src - 1)); - gs_abort(); + gs_abort(mem); } #endif /* Pad to a multiple of sizeof(ref). */ diff --git a/gs/src/iimage.h b/gs/src/iimage.h index b9d8aadcb..1a9578189 100644 --- a/gs/src/iimage.h +++ b/gs/src/iimage.h @@ -34,7 +34,8 @@ typedef struct image_params_s { } image_params; /* Extract and check parameters for an image. */ -int data_image_params(const ref *op, gs_data_image_t *pim, +int data_image_params(const gs_memory_t *mem, + const ref *op, gs_data_image_t *pim, image_params *pip, bool require_DataSource, int num_components, int max_bits_per_component, bool has_alpha); diff --git a/gs/src/iinit.c b/gs/src/iinit.c index 2ce77962f..b51889b63 100644 --- a/gs/src/iinit.c +++ b/gs/src/iinit.c @@ -113,7 +113,7 @@ i_initial_remove_name(i_ctx_t *i_ctx_p, const char *nstr) { ref nref; - if (name_ref((const byte *)nstr, strlen(nstr), &nref, -1) >= 0) + if (name_ref(imemory, (const byte *)nstr, strlen(nstr), &nref, -1) >= 0) idict_undef(systemdict, &nref); } @@ -348,7 +348,7 @@ obj_init(i_ctx_t **pi_ctx_p, gs_dual_memory_t *idmem) if (code < 0) return code; for (i = 0; i < n; i++) - if ((code = name_enter_string((const char *)gs_error_names[i], + if ((code = name_enter_string(imemory, (const char *)gs_error_names[i], era.value.refs + i)) < 0) return code; return initial_enter_name("ErrorNames", &era); @@ -448,7 +448,7 @@ op_init(i_ctx_t *i_ctx_p) if (op_def_is_begin_dict(def)) { ref nref; - code = name_ref((const byte *)nstr, strlen(nstr), &nref, -1); + code = name_ref(imemory, (const byte *)nstr, strlen(nstr), &nref, -1); if (code < 0) return code; if (!dict_find(systemdict, &nref, &pdict)) diff --git a/gs/src/ilocate.c b/gs/src/ilocate.c index b58dd4db2..0a02f435a 100644 --- a/gs/src/ilocate.c +++ b/gs/src/ilocate.c @@ -317,7 +317,9 @@ ialloc_validate_chunk(const chunk_t * cp, gc_state_t * gcst) gs_ptr_type_t ptype; if (proc != gs_no_struct_enum_ptrs) - for (; (ptype = (*proc) (pre + 1, size, index, &eptr, pre->o_type, NULL)) != 0; ++index) { + for (; (ptype = (*proc) (gcst_get_memory_ptr(gcst), + pre + 1, size, index, &eptr, + pre->o_type, gcst)) != 0; ++index) { if (eptr.ptr == 0) DO_NOTHING; else if (ptype == ptr_struct_type) @@ -332,10 +334,12 @@ ialloc_validate_chunk(const chunk_t * cp, gc_state_t * gcst) private void ialloc_validate_ref_packed(const ref_packed * rp, gc_state_t * gcst) { + const gs_memory_t *cmem = gcst->spaces.memories.named.system->stable_memory; + if (r_is_packed(rp)) { ref unpacked; - packed_get(rp, &unpacked); + packed_get(cmem, rp, &unpacked); ialloc_validate_ref(&unpacked, gcst); } else { ialloc_validate_ref((const ref *)rp, gcst); @@ -348,6 +352,7 @@ ialloc_validate_ref(const ref * pref, gc_state_t * gcst) const ref *rptr; const char *tname; uint size; + const gs_memory_t *cmem = gcst->spaces.memories.named.system->stable_memory; if (!gs_debug_c('?')) return; /* no check */ @@ -368,15 +373,15 @@ cks: if (optr != 0) ialloc_validate_object(optr, NULL, gcst); break; case t_name: - if (name_index_ptr(name_index(pref)) != pref->value.pname) { + if (name_index_ptr(cmem, name_index(cmem, pref)) != pref->value.pname) { lprintf3("At 0x%lx, bad name %u, pname = 0x%lx\n", - (ulong) pref, (uint)name_index(pref), + (ulong) pref, (uint)name_index(cmem, pref), (ulong) pref->value.pname); break; } { ref sref; - name_string_ref(pref, &sref); + name_string_ref(cmem, pref, &sref); if (r_space(&sref) != avm_foreign && !gc_locate(sref.value.const_bytes, gcst) ) { @@ -468,7 +473,7 @@ ialloc_validate_object(const obj_header_t * ptr, const chunk_t * cp, if (otype == &st_free) { lprintf3("Reference to free object 0x%lx(%lu), in chunk 0x%lx!\n", (ulong) ptr, (ulong) size, (ulong) cp); - gs_abort(); + gs_abort(gcst->heap); } if ((cp != 0 && !object_size_valid(pre, size, cp)) || otype->ssize == 0 || @@ -480,7 +485,7 @@ ialloc_validate_object(const obj_header_t * ptr, const chunk_t * cp, (ulong) ptr, (ulong) size); dprintf2(" ssize = %u, in chunk 0x%lx!\n", otype->ssize, (ulong) cp); - gs_abort(); + gs_abort(gcst->heap); } } diff --git a/gs/src/imain.c b/gs/src/imain.c index efa4ce113..227ec3755 100644 --- a/gs/src/imain.c +++ b/gs/src/imain.c @@ -18,16 +18,6 @@ /* Common support for interpreter front ends */ #include "memory_.h" #include "string_.h" -/* Capture stdin/out/err before gs.h redefines them. */ -#include <stdio.h> -#include <stdlib.h> -private void -set_stdfiles(FILE * stdfiles[3]) -{ - stdfiles[0] = stdin; - stdfiles[1] = stdout; - stdfiles[2] = stderr; -} #include "ghost.h" #include "gp.h" #include "gscdefs.h" /* for gs_init_file */ @@ -58,27 +48,43 @@ set_stdfiles(FILE * stdfiles[3]) #include "isave.h" /* for prototypes */ #include "interp.h" #include "ivmspace.h" -#include "idisp.h" /* for setting display device callback */ #include "iplugin.h" /* ------ Exported data ------ */ -/* Define the default instance of the interpreter. */ -/* Currently, this is the *only possible* instance, because most of */ -/* the places that need to take an explicit instance argument don't. */ -private gs_main_instance the_gs_main_instance; -gs_main_instance * -gs_main_instance_default(void) +/** using backpointers retrieve minst from any memory pointer + * + */ +gs_main_instance* +get_minst_from_memory(const gs_memory_t *mem) { - /* Determine whether the instance has been initialized. */ - if (the_gs_main_instance.memory_chunk_size == 0) - the_gs_main_instance = gs_main_instance_init_values; - return &the_gs_main_instance; +#ifdef PSI_INCLUDED + extern gs_main_instance *ps_impl_get_minst( const gs_memory_t *mem ); + return ps_impl_get_minst(mem); +#else + return (gs_main_instance*)mem->gs_lib_ctx->top_of_system; +#endif } -/* Define the interpreter's name table. We'll move it somewhere better */ -/* eventually.... */ -name_table *the_gs_name_table; +/** construct main instance caller needs to retain */ +gs_main_instance * +gs_main_alloc_instance(gs_memory_t *mem) +{ + gs_main_instance *minst = 0; + if (mem) { + minst = (gs_main_instance *) gs_alloc_bytes_immovable(mem, + sizeof(gs_main_instance), + "init_main_instance"); + memcpy(minst, &gs_main_instance_init_values, sizeof(gs_main_instance_init_values)); + minst->heap = mem; + +# ifndef PSI_INCLUDED + mem->gs_lib_ctx->top_of_system = minst; + /* else top of system is pl_universe */ +# endif + } + return minst; +} /* ------ Forward references ------ */ @@ -88,45 +94,38 @@ private void print_resource_usage(const gs_main_instance *, /* ------ Initialization ------ */ -/* Save the real stdio files. */ -void -gs_get_real_stdio(FILE * stdfiles[3]) -{ - set_stdfiles(stdfiles); -} - /* Initialization to be done before anything else. */ int gs_main_init0(gs_main_instance * minst, FILE * in, FILE * out, FILE * err, int max_lib_paths) { - gs_memory_t *heap; ref *paths; - /* Set our versions of stdin/out/err. */ - gs_stdin = minst->fstdin = in; - gs_stdout = minst->fstdout = out; - gs_stderr = minst->fstderr = err; /* Do platform-dependent initialization. */ /* We have to do this as the very first thing, */ /* because it detects attempts to run 80N86 executables (N>0) */ /* on incompatible processors. */ gp_init(); + + /* Initialize the imager. */ +# ifndef PSI_INCLUDED + /* Reset debugging flags */ + memset(gs_debug, 0, 128); + gs_log_errors = 0; /* gs_debug['#'] = 0 */ +# else + /* plmain settings remain in effect */ +# endif gp_get_usertime(minst->base_time); - /* Initialize the imager. */ - heap = gs_lib_init0(gs_stdout); - if (heap == 0) - return_error(e_VMerror); - minst->heap = heap; + /* Initialize the file search paths. */ - paths = (ref *) gs_alloc_byte_array(heap, max_lib_paths, sizeof(ref), + paths = (ref *) gs_alloc_byte_array(minst->heap, max_lib_paths, sizeof(ref), "lib_path array"); if (paths == 0) { - gs_lib_finit(1, e_VMerror); + gs_lib_finit(1, e_VMerror, minst->heap); return_error(e_VMerror); } make_array(&minst->lib_path.container, avm_foreign, max_lib_paths, - (ref *) gs_alloc_byte_array(heap, max_lib_paths, sizeof(ref), + (ref *) gs_alloc_byte_array(minst->heap, max_lib_paths, sizeof(ref), "lib_path array")); make_array(&minst->lib_path.list, avm_foreign | a_readonly, 0, minst->lib_path.container.value.refs); @@ -145,7 +144,7 @@ gs_main_init1(gs_main_instance * minst) if (minst->init_done < 1) { gs_dual_memory_t idmem; int code = - ialloc_init(&idmem, (gs_raw_memory_t *)&gs_memory_default, + ialloc_init(&idmem, minst->heap, minst->memory_chunk_size, gs_have_level2()); if (code < 0) @@ -161,9 +160,9 @@ gs_main_init1(gs_main_instance * minst) if (nt == 0) return_error(e_VMerror); - the_gs_name_table = nt; + mem->gs_lib_ctx->gs_name_table = nt; code = gs_register_struct_root(mem, NULL, - (void **)&the_gs_name_table, + (void **)&mem->gs_lib_ctx->gs_name_table, "the_gs_name_table"); if (code < 0) return code; @@ -207,6 +206,9 @@ gs_main_interpret(gs_main_instance *minst, ref * pref, int user_errors, ref refpop; int code; + /* set interpreter pointer to lib_path */ + minst->i_ctx_p->lib_path = &minst->lib_path; + code = gs_interpret(&minst->i_ctx_p, pref, user_errors, pexit_code, perror_object); while ((code == e_NeedStdin) || (code == e_NeedStdout) || @@ -226,7 +228,7 @@ gs_main_interpret(gs_main_instance *minst, ref * pref, int user_errors, int count = esp[0].tas.rsize; int rcode = 0; if (str != NULL) - rcode = gs_main_outwrite(minst, str, count); + rcode = outwrite(imemory, str, count); if (rcode < 0) return_error(e_ioerror); } @@ -248,7 +250,7 @@ gs_main_interpret(gs_main_instance *minst, ref * pref, int user_errors, int count = esp[0].tas.rsize; int rcode = 0; if (str != NULL) - rcode = gs_main_errwrite(minst, str, count); + rcode = errwrite(str, count); if (rcode < 0) return_error(e_ioerror); } @@ -266,12 +268,14 @@ gs_main_interpret(gs_main_instance *minst, ref * pref, int user_errors, * esp[-1] = file, stdin stream * We read from stdin then pop these 2 items. */ - if (minst->stdin_fn) - count = (*minst->stdin_fn)(minst->caller_handle, - minst->stdin_buf, count); + if (minst->heap->gs_lib_ctx->stdin_fn) + count = (*minst->heap->gs_lib_ctx->stdin_fn) + (minst->heap->gs_lib_ctx->caller_handle, + minst->stdin_buf, count); else count = gp_stdin_read(minst->stdin_buf, count, - minst->stdin_is_interactive, minst->fstdin); + minst->heap->gs_lib_ctx->stdin_is_interactive, + minst->heap->gs_lib_ctx->fstdin); if (count < 0) return_error(e_ioerror); @@ -348,8 +352,12 @@ gs_main_init2(gs_main_instance * minst) return code; minst->init_done = 2; i_ctx_p = minst->i_ctx_p; /* init file may change it */ + /* NB this is to be done with device parameters + * both minst->display and display_set_callback() are going away + */ if (minst->display) code = display_set_callback(minst, minst->display); + if (code < 0) return code; } @@ -465,10 +473,11 @@ gs_main_lib_open(gs_main_instance * minst, const char *file_name, ref * pfile) byte fn[maxfn]; uint len; - return lib_file_open(NULL /* Don't check permissions here, because permlist - isn't ready running init files. */ - , file_name, strlen(file_name), fn, maxfn, - &len, pfile, imemory); + return lib_file_open( &minst->lib_path, + NULL /* Don't check permissions here, because permlist + isn't ready running init files. */ + , file_name, strlen(file_name), fn, maxfn, + &len, pfile, imemory); } /* Open and execute a file. */ @@ -728,7 +737,7 @@ gs_pop_string(gs_main_instance * minst, gs_string * result) return code; switch (r_type(&vref)) { case t_name: - name_string_ref(&vref, &vref); + name_string_ref(minst->heap, &vref, &vref); code = 1; goto rstr; case t_string: @@ -771,7 +780,7 @@ private char *gs_main_tempnames(gs_main_instance *minst) /* get lengths of temporary filenames */ idict = dict_first(tempfiles); while ((idict = dict_next(tempfiles, idict, &keyval[0])) >= 0) { - if (obj_string_data(&keyval[0], &data, &size) >= 0) + if (obj_string_data(minst->heap, &keyval[0], &data, &size) >= 0) len += size + 1; } if (len != 0) @@ -782,7 +791,7 @@ private char *gs_main_tempnames(gs_main_instance *minst) idict = dict_first(tempfiles); i = 0; while ((idict = dict_next(tempfiles, idict, &keyval[0])) >= 0) { - if (obj_string_data(&keyval[0], &data, &size) >= 0) { + if (obj_string_data(minst->heap, &keyval[0], &data, &size) >= 0) { memcpy(tempnames+i, (const char *)data, size); i+= size; tempnames[i++] = '\0'; @@ -801,6 +810,10 @@ gs_main_finit(gs_main_instance * minst, int exit_status, int code) int exit_code; ref error_object; char *tempnames; + + /* NB: need to free gs_name_table + */ + /* * Previous versions of this code closed the devices in the * device list here. Since these devices are now prototypes, @@ -851,19 +864,20 @@ gs_main_finit(gs_main_instance * minst, int exit_status, int code) /* Do the equivalent of a restore "past the bottom". */ /* This will release all memory, close all open files, etc. */ if (minst->init_done >= 1) { - gs_raw_memory_t *mem_raw = i_ctx_p->memory.current->parent; + gs_memory_t *mem_raw = i_ctx_p->memory.current->non_gc_memory; i_plugin_holder *h = i_ctx_p->plugin_list; alloc_restore_all(idmemory); i_plugin_finit(mem_raw, h); } /* clean up redirected stdout */ - if (minst->fstdout2 && (minst->fstdout2 != minst->fstdout) - && (minst->fstdout2 != minst->fstderr)) { - fclose(minst->fstdout2); - minst->fstdout2 = (FILE *)NULL; + if (minst->heap->gs_lib_ctx->fstdout2 + && (minst->heap->gs_lib_ctx->fstdout2 != minst->heap->gs_lib_ctx->fstdout) + && (minst->heap->gs_lib_ctx->fstdout2 != minst->heap->gs_lib_ctx->fstderr)) { + fclose(minst->heap->gs_lib_ctx->fstdout2); + minst->heap->gs_lib_ctx->fstdout2 = (FILE *)NULL; } - minst->stdout_is_redirected = 0; - minst->stdout_to_stderr = 0; + minst->heap->gs_lib_ctx->stdout_is_redirected = 0; + minst->heap->gs_lib_ctx->stdout_to_stderr = 0; /* remove any temporary files, after ghostscript has closed files */ if (tempnames) { char *p = tempnames; @@ -873,23 +887,23 @@ gs_main_finit(gs_main_instance * minst, int exit_status, int code) } free(tempnames); } - gs_lib_finit(exit_status, code); + gs_lib_finit(exit_status, code, minst->heap); return exit_status; } int -gs_to_exit_with_code(int exit_status, int code) +gs_to_exit_with_code(const gs_memory_t *mem, int exit_status, int code) { - return gs_finit(exit_status, code); + return gs_main_finit(get_minst_from_memory(mem), exit_status, code); } int -gs_to_exit(int exit_status) +gs_to_exit(const gs_memory_t *mem, int exit_status) { - return gs_to_exit_with_code(exit_status, 0); + return gs_to_exit_with_code(mem, exit_status, 0); } void -gs_abort(void) +gs_abort(const gs_memory_t *mem) { - gs_to_exit(1); + gs_to_exit(mem, 1); /* it's fatal calling OS independent exit() */ gp_do_exit(1); } @@ -943,93 +957,11 @@ gs_main_dump_stack(gs_main_instance *minst, int code, ref * perror_object) dprintf1("\nUnexpected interpreter error %d.\n", code); if (perror_object != 0) { dputs("Error object: "); - debug_print_ref(perror_object); + debug_print_ref(minst->heap, perror_object); dputc('\n'); } - debug_dump_stack(&o_stack, "Operand stack"); - debug_dump_stack(&e_stack, "Execution stack"); - debug_dump_stack(&d_stack, "Dictionary stack"); -} -/* Backward compatibility */ -void -gs_debug_dump_stack(int code, ref * perror_object) -{ - gs_main_dump_stack(gs_main_instance_default(), code, perror_object); -} - - -/* Provide a single point for all "C" stdout and stderr. - * Eventually these will always be referenced through an instance structure. - * We don't know which instance is running (and currently only one - * instance is possible) so use the default instance. - */ - -int -gs_main_outwrite(gs_main_instance *minst, const char *str, int len) -{ - int code; - FILE *fout; - if (len == 0) - return 0; - if (minst->stdout_is_redirected) { - if (minst->stdout_to_stderr) - return gs_main_errwrite(minst, str, len); - fout = minst->fstdout2; - } - else if (minst->stdout_fn) { - return (*minst->stdout_fn)(minst->caller_handle, str, len); - } - else { - fout = minst->fstdout; - } - code = fwrite(str, 1, len, fout); - fflush(fout); - return code; + debug_dump_stack(minst->heap, &o_stack, "Operand stack"); + debug_dump_stack(minst->heap, &e_stack, "Execution stack"); + debug_dump_stack(minst->heap, &d_stack, "Dictionary stack"); } -int -gs_main_errwrite(gs_main_instance *minst, const char *str, int len) -{ - int code; - if (len == 0) - return 0; - if (minst->stderr_fn) - return (*minst->stderr_fn)(minst->caller_handle, str, len); - code = fwrite(str, 1, len, minst->fstderr); - fflush(minst->fstderr); - return code; -} - -int outwrite(const char *str, int len) -{ - return gs_main_outwrite(gs_main_instance_default(), str, len); -} - -int errwrite(const char *str, int len) -{ - return gs_main_errwrite(gs_main_instance_default(), str, len); -} - -void outflush(void) -{ - gs_main_instance * minst = gs_main_instance_default(); - if (minst->stdout_is_redirected) { - if (minst->stdout_to_stderr) { - if (!minst->stderr_fn) - fflush(minst->fstderr); - } - else - fflush(minst->fstdout2); - } - else if (!minst->stdout_fn) - fflush(minst->fstdout); -} - -void errflush(void) -{ - gs_main_instance * minst = gs_main_instance_default(); - if (!minst->stderr_fn) - fflush(minst->fstderr); -} - - diff --git a/gs/src/imainarg.c b/gs/src/imainarg.c index ee8802cfb..a5aa61b84 100644 --- a/gs/src/imainarg.c +++ b/gs/src/imainarg.c @@ -79,7 +79,7 @@ extern int zflushpage(i_ctx_t *); /* Redefine puts to use outprintf, */ /* so it will work even without stdio. */ #undef puts -#define puts(str) outprintf("%s\n", str) +#define puts(mem, str) outprintf(mem, "%s\n", str) /* Forward references */ #define runInit 1 @@ -113,7 +113,8 @@ private FILE * gs_main_arg_fopen(const char *fname, void *vminst) { gs_main_set_lib_paths((gs_main_instance *) vminst); - return lib_fopen(fname); + return lib_fopen(&((gs_main_instance *)vminst)->lib_path, + ((gs_main_instance *)vminst)->heap, fname); } private void set_debug_flags(const char *arg, char *flags) @@ -123,20 +124,17 @@ set_debug_flags(const char *arg, char *flags) while (*arg) flags[*arg++ & 127] = value; } -#define arg_heap_copy(str) arg_copy(str, &gs_memory_default) + int gs_main_init_with_args(gs_main_instance * minst, int argc, char *argv[]) { const char *arg; arg_list args; - FILE *stdfiles[3]; int code; - gs_get_real_stdio(stdfiles); arg_init(&args, (const char **)argv, argc, gs_main_arg_fopen, (void *)minst); - code = gs_main_init0(minst, stdfiles[0], stdfiles[1], stdfiles[2], - GS_MAX_LIB_DIRS); + code = gs_main_init0(minst, 0, 0, 0, GS_MAX_LIB_DIRS); if (code < 0) return code; /* This first check is not needed on VMS since GS_LIB evaluates to the same @@ -178,7 +176,7 @@ gs_main_init_with_args(gs_main_instance * minst, int argc, char *argv[]) helping = true; } else if (!strcmp(argv[i], "--version")) { print_version(minst); - puts(""); /* \n */ + puts(minst->heap, ""); /* \n */ helping = true; } if (helping) @@ -210,7 +208,7 @@ gs_main_init_with_args(gs_main_instance * minst, int argc, char *argv[]) if (code < 0) return code; if (code > 0) - outprintf("Unknown switch %s - ignoring\n", arg); + outprintf(minst->heap, "Unknown switch %s - ignoring\n", arg); break; default: code = argproc(minst, arg); @@ -259,10 +257,10 @@ swproc(gs_main_instance * minst, const char *arg, arg_list * pal) return 1; case 0: /* read stdin as a file char-by-char */ /* This is a ******HACK****** for Ghostview. */ - minst->stdin_is_interactive = true; + minst->heap->gs_lib_ctx->stdin_is_interactive = true; goto run_stdin; case '_': /* read stdin with normal buffering */ - minst->stdin_is_interactive = false; + minst->heap->gs_lib_ctx->stdin_is_interactive = false; run_stdin: minst->run_start = false; /* don't run 'start' */ /* Set NOPAUSE so showpage won't try to read from stdin. */ @@ -272,7 +270,7 @@ run_stdin: code = gs_main_init2(minst); /* Finish initialization */ if (code < 0) return code; - gs_stdin_is_interactive = minst->stdin_is_interactive; + code = run_string(minst, ".runstdin", runFlush); if (code < 0) return code; @@ -287,11 +285,11 @@ run_stdin: if (code < 0) return e_Fatal; if (psarg == 0) { - outprintf("Usage: gs ... -%c file.ps arg1 ... argn\n", sw); + outprintf(minst->heap, "Usage: gs ... -%c file.ps arg1 ... argn\n", sw); arg_finit(pal); return e_Fatal; } - psarg = arg_heap_copy(psarg); + psarg = arg_copy(psarg, minst->heap); if (psarg == NULL) return e_Fatal; code = gs_main_init2(minst); @@ -301,7 +299,7 @@ run_stdin: if (code < 0) return code; while ((arg = arg_next(pal, &code)) != 0) { - char *fname = arg_heap_copy(arg); + char *fname = arg_copy(arg, minst->heap); if (fname == NULL) return e_Fatal; code = runarg(minst, "", fname, "", runInit); @@ -322,7 +320,7 @@ run_stdin: gs_alloc_debug = 0; break; default: - puts("-A may only be followed by -"); + puts(minst->heap, "-A may only be followed by -"); return e_Fatal; } break; @@ -335,7 +333,9 @@ run_stdin: if (sscanf((const char *)arg, "%u", &bsize) != 1 || bsize <= 0 || bsize > MAX_BUFFERED_SIZE ) { - outprintf("-B must be followed by - or size between 1 and %u\n", MAX_BUFFERED_SIZE); + outprintf(minst->heap, + "-B must be followed by - or size between 1 and %u\n", + MAX_BUFFERED_SIZE); return e_Fatal; } minst->run_buffer_size = bsize; @@ -356,7 +356,7 @@ run_stdin: (arg[0] == '-' && !isdigit(arg[1])) ) break; - sarg = arg_heap_copy(arg); + sarg = arg_copy(arg, minst->heap); if (sarg == NULL) return e_Fatal; code = runarg(minst, "", sarg, ".runstring", 0); @@ -366,7 +366,7 @@ run_stdin: if (code < 0) return e_Fatal; if (arg != 0) { - char *p = arg_heap_copy(arg); + char *p = arg_copy(arg, minst->heap); if (p == NULL) return e_Fatal; arg_push_string(pal, p); @@ -383,7 +383,7 @@ run_stdin: gs_log_errors = 0; break; default: - puts("-E may only be followed by -"); + puts(minst->heap, "-E may only be followed by -"); return e_Fatal; } break; @@ -393,7 +393,7 @@ run_stdin: break; case 'F': /* run file with buffer_size = 1 */ if (!*arg) { - puts("-F requires a file name"); + puts(minst->heap, "-F requires a file name"); return e_Fatal; } { uint bsize = minst->run_buffer_size; @@ -411,7 +411,7 @@ run_stdin: if ((code = gs_main_init1(minst)) < 0) return code; if (sscanf((const char *)arg, "%ldx%ld", &width, &height) != 2) { - puts("-g must be followed by <width>x<height>"); + puts(minst->heap, "-g must be followed by <width>x<height>"); return e_Fatal; } make_int(&value, width); @@ -427,7 +427,7 @@ run_stdin: return e_Info; /* show usage info on exit */ case 'I': /* specify search path */ { - char *path = arg_heap_copy(arg); + char *path = arg_copy(arg, minst->heap); if (path == NULL) return e_Fatal; gs_main_add_lib_path(minst, path); @@ -436,14 +436,15 @@ run_stdin: case 'K': /* set malloc limit */ { long msize = 0; + gs_malloc_memory_t *rawheap = gs_malloc_wrapped_contents(minst->heap); sscanf((const char *)arg, "%ld", &msize); if (msize <= 0 || msize > max_long >> 10) { - outprintf("-K<numK> must have 1 <= numK <= %ld\n", - max_long >> 10); + outprintf(minst->heap, "-K<numK> must have 1 <= numK <= %ld\n", + max_long >> 10); return e_Fatal; } - gs_malloc_limit = msize << 10; + rawheap->limit = msize << 10; } break; case 'M': /* set memory allocation increment */ @@ -453,7 +454,7 @@ run_stdin: sscanf((const char *)arg, "%u", &msize); #if arch_ints_are_short if (msize <= 0 || msize >= 64) { - puts("-M must be between 1 and 63"); + puts(minst->heap, "-M must be between 1 and 63"); return e_Fatal; } #endif @@ -467,7 +468,7 @@ run_stdin: sscanf((const char *)arg, "%d", &nsize); #if arch_ints_are_short if (nsize < 2 || nsize > 64) { - puts("-N must be between 2 and 64"); + puts(minst->heap, "-N must be between 2 and 64"); return e_Fatal; } #endif @@ -480,7 +481,7 @@ run_stdin: else if (!strcmp(arg, "-")) minst->search_here_first = false; else { - puts("Only -P or -P- is allowed."); + puts(minst->heap, "Only -P or -P- is allowed."); return e_Fatal; } break; @@ -498,7 +499,7 @@ run_stdin: return code; switch (sscanf((const char *)arg, "%fx%f", &xres, &yres)) { default: - puts("-r must be followed by <res> or <xres>x<yres>"); + puts(minst->heap, "-r must be followed by <res> or <xres>x<yres>"); return e_Fatal; case 1: /* -r<res> */ yres = xres; @@ -516,7 +517,7 @@ run_stdin: case 'S': /* define name as string */ case 's': { - char *adef = arg_heap_copy(arg); + char *adef = arg_copy(arg, minst->heap); char *eqp; bool isd = (sw == 'D' || sw == 'd'); ref value; @@ -532,7 +533,7 @@ run_stdin: if ((code = gs_main_init1(minst)) < 0) return code; if (eqp == adef) { - puts("Usage: -dname, -dname=token, -sname=string"); + puts(minst->heap, "Usage: -dname, -dname=token, -sname=string"); return e_Fatal; } if (eqp == NULL) { @@ -557,14 +558,14 @@ run_stdin: code = scan_token(minst->i_ctx_p, &astream, &value, &state); if (code) { - puts("-dname= must be followed by a valid token"); + puts(minst->heap, "-dname= must be followed by a valid token"); return e_Fatal; } if (r_has_type_attrs(&value, t_name, a_executable)) { ref nsref; - name_string_ref(&value, &nsref); + name_string_ref(minst->heap, &value, &nsref); #define string_is(nsref, str, len)\ (r_size(&(nsref)) == (len) &&\ !strncmp((const char *)(nsref).value.const_bytes, str, (len))) @@ -575,7 +576,8 @@ run_stdin: else if (string_is(nsref, "false", 5)) make_false(&value); else { - puts("-dvar=name requires name=null, true, or false"); + puts(minst->heap, + "-dvar=name requires name=null, true, or false"); return e_Fatal; } #undef name_is_string @@ -608,7 +610,7 @@ run_stdin: break; case 'u': /* undefine name */ if (!*arg) { - puts("-u requires a name to undefine."); + puts(minst->heap, "-u requires a name to undefine."); return e_Fatal; } if ((code = gs_main_init1(minst)) < 0) @@ -687,7 +689,7 @@ argproc(gs_main_instance * minst, const char *arg) if (code < 0) return code; - filearg = arg_heap_copy(arg); + filearg = arg_copy(arg, minst->heap); if (filearg == NULL) return e_Fatal; if (minst->run_buffer_size) { @@ -707,7 +709,7 @@ run_buffered(gs_main_instance * minst, const char *arg) int code; if (in == 0) { - outprintf("Unable to open %s for reading", arg); + outprintf(minst->heap, "Unable to open %s for reading", arg); return_error(e_invalidfileaccess); } code = gs_main_init2(minst); @@ -809,25 +811,27 @@ try_stdout_redirect(gs_main_instance * minst, const char *command, const char *filename) { if (strcmp(command, "stdout") == 0) { - minst->stdout_to_stderr = 0; - minst->stdout_is_redirected = 0; + minst->heap->gs_lib_ctx->stdout_to_stderr = 0; + minst->heap->gs_lib_ctx->stdout_is_redirected = 0; /* If stdout already being redirected and it is not stdout * or stderr, close it */ - if (minst->fstdout2 && (minst->fstdout2 != minst->fstdout) - && (minst->fstdout2 != minst->fstderr)) { - fclose(minst->fstdout2); - minst->fstdout2 = (FILE *)NULL; + if (minst->heap->gs_lib_ctx->fstdout2 + && (minst->heap->gs_lib_ctx->fstdout2 != minst->heap->gs_lib_ctx->fstdout) + && (minst->heap->gs_lib_ctx->fstdout2 != minst->heap->gs_lib_ctx->fstderr)) { + fclose(minst->heap->gs_lib_ctx->fstdout2); + minst->heap->gs_lib_ctx->fstdout2 = (FILE *)NULL; } /* If stdout is being redirected, set minst->fstdout2 */ if ( (filename != 0) && strlen(filename) && strcmp(filename, "-") && strcmp(filename, "%stdout") ) { if (strcmp(filename, "%stderr") == 0) { - minst->stdout_to_stderr = 1; + minst->heap->gs_lib_ctx->stdout_to_stderr = 1; } - else if ((minst->fstdout2 = fopen(filename, "w")) == (FILE *)NULL) + else if ((minst->heap->gs_lib_ctx->fstdout2 = + fopen(filename, "w")) == (FILE *)NULL) return_error(e_invalidfileaccess); - minst->stdout_is_redirected = 1; + minst->heap->gs_lib_ctx->stdout_is_redirected = 1; } return 0; } @@ -868,7 +872,7 @@ print_help(gs_main_instance * minst) print_devices(minst); print_paths(minst); if (gs_init_string_sizeof > 0) { - outprintf("Initialization files are compiled into the executable.\n"); + outprintf(minst->heap, "Initialization files are compiled into the executable.\n"); } print_help_trailer(minst); } @@ -877,8 +881,8 @@ print_help(gs_main_instance * minst) private void print_revision(const gs_main_instance *minst) { - printf_program_ident(gs_product, gs_revision); - outprintf(" (%d-%02d-%02d)\n%s\n", + printf_program_ident(minst->heap, gs_product, gs_revision); + outprintf(minst->heap, " (%d-%02d-%02d)\n%s\n", (int)(gs_revisiondate / 10000), (int)(gs_revisiondate / 100 % 100), (int)(gs_revisiondate % 100), @@ -889,15 +893,15 @@ print_revision(const gs_main_instance *minst) private void print_version(const gs_main_instance *minst) { - printf_program_ident(NULL, gs_revision); + printf_program_ident(minst->heap, NULL, gs_revision); } /* Print usage information. */ private void print_usage(const gs_main_instance *minst) { - outprintf("%s", help_usage1); - outprintf("%s", help_usage2); + outprintf(minst->heap, "%s", help_usage1); + outprintf(minst->heap, "%s", help_usage2); } /* compare function for qsort */ @@ -911,9 +915,9 @@ cmpstr(const void *v1, const void *v2) private void print_devices(const gs_main_instance *minst) { - outprintf("%s", help_default_device); - outprintf(" %s\n", gs_devicename(gs_getdevice(0))); - outprintf("%s", help_devices); + outprintf(minst->heap, "%s", help_default_device); + outprintf(minst->heap, " %s\n", gs_devicename(gs_getdevice(0))); + outprintf(minst->heap, "%s", help_devices); { int i; int pos = 100; @@ -931,8 +935,8 @@ print_devices(const gs_main_instance *minst) int len = strlen(dname); if (pos + 1 + len > 76) - outprintf("\n "), pos = 2; - outprintf(" %s", dname); + outprintf(minst->heap, "\n "), pos = 2; + outprintf(minst->heap, " %s", dname); pos += 1 + len; } } @@ -944,21 +948,21 @@ print_devices(const gs_main_instance *minst) int len = strlen(names[i]); if (pos + 1 + len > 76) - outprintf("\n "), pos = 2; - outprintf(" %s", names[i]); + outprintf(minst->heap, "\n "), pos = 2; + outprintf(minst->heap, " %s", names[i]); pos += 1 + len; } - gs_free((char *)names, ndev * sizeof(const char*), 1, "print_devices"); + gs_free(minst->heap, (char *)names, ndev * sizeof(const char*), 1, "print_devices"); } } - outprintf("\n"); + outprintf(minst->heap, "\n"); } /* Print the list of language emulators. */ private void print_emulators(const gs_main_instance *minst) { - outprintf("%s", help_emulators); + outprintf(minst->heap, "%s", help_emulators); { const ref *pes; @@ -970,16 +974,16 @@ print_emulators(const gs_main_instance *minst) * an array of string refs, each string is actually a * (null terminated) C string. */ - outprintf(" %s", (const char *)pes->value.const_bytes); + outprintf(minst->heap, " %s", (const char *)pes->value.const_bytes); } - outprintf("\n"); + outprintf(minst->heap, "\n"); } /* Print the search paths. */ private void print_paths(gs_main_instance * minst) { - outprintf("%s", help_paths); + outprintf(minst->heap, "%s", help_paths); gs_main_set_lib_paths(minst); { uint count = r_size(&minst->lib_path.list); @@ -996,8 +1000,8 @@ print_paths(gs_main_instance * minst) const char *sepr = (i == count - 1 ? "" : fsepr); if (1 + pos + strlen(sepr) + len > 76) - outprintf("\n "), pos = 2; - outprintf(" "); + outprintf(minst->heap, "\n "), pos = 2; + outprintf(minst->heap, " "); /* * This is really ugly, but it's necessary because some * platforms rely on all console output being funneled through @@ -1009,13 +1013,13 @@ print_paths(gs_main_instance * minst) uint j; for (j = len; j; j--) - outprintf("%c", *p++); + outprintf(minst->heap, "%c", *p++); } - outprintf("%s", sepr); + outprintf(minst->heap, "%s", sepr); pos += 1 + len + strlen(sepr); } } - outprintf("\n"); + outprintf(minst->heap, "\n"); } /* Print the help trailer. */ @@ -1029,5 +1033,5 @@ print_help_trailer(const gs_main_instance *minst) if (gp_file_name_combine(gs_doc_directory, strlen(gs_doc_directory), use_htm, strlen(use_htm), false, buffer, &blen) != gp_combine_success) p = use_htm; - outprintf(help_trailer, p, GS_BUG_MAILBOX); + outprintf(minst->heap, help_trailer, p, GS_BUG_MAILBOX); } diff --git a/gs/src/iminst.h b/gs/src/iminst.h index e2be631e3..53e74ec17 100644 --- a/gs/src/iminst.h +++ b/gs/src/iminst.h @@ -63,13 +63,6 @@ typedef struct gs_file_path_s { */ struct gs_main_instance_s { /* The following are set during initialization. */ - FILE *fstdin; - FILE *fstdout; - FILE *fstderr; - FILE *fstdout2; /* for redirecting %stdout and diagnostics */ - bool stdout_is_redirected; /* to stderr or fstdout2 */ - bool stdout_to_stderr; - bool stdin_is_interactive; gs_memory_t *heap; /* (C) heap allocator */ uint memory_chunk_size; /* 'wholesale' allocation unit */ ulong name_table_size; @@ -86,12 +79,11 @@ struct gs_main_instance_s { char stdout_buf[STDOUT_BUF_SIZE]; /* for e_NeedStdout callout */ char stderr_buf[STDERR_BUF_SIZE]; /* for e_NeedStderr callout */ ref error_object; /* Use by gsapi_*() */ - void *caller_handle; /* identifies caller of GS DLL/shared object */ - int (GSDLLCALL *stdin_fn)(void *caller_handle, char *buf, int len); - int (GSDLLCALL *stdout_fn)(void *caller_handle, const char *str, int len); - int (GSDLLCALL *stderr_fn)(void *caller_handle, const char *str, int len); - int (GSDLLCALL *poll_fn)(void *caller_handle); +#if 1 + /* needs to be removed */ display_callback *display; /* callback structure for display device */ +#endif + /* The following are updated dynamically. */ i_ctx_t *i_ctx_p; /* current interpreter context state */ }; @@ -101,7 +93,7 @@ struct gs_main_instance_s { * must include gconfig.h, because of SEARCH_HERE_FIRST. */ #define gs_main_instance_default_init_values\ - 0, 0, 0, 0, 0, 0 ,1 /*true*/, 0, 20000, 0, 0, -1, 0, SEARCH_HERE_FIRST, 1 + 0, 20000, 0, 0, -1, 0, SEARCH_HERE_FIRST, 1 extern const gs_main_instance gs_main_instance_init_values; #endif /* iminst_INCLUDED */ diff --git a/gs/src/iname.h b/gs/src/iname.h index 623df824b..47966d041 100644 --- a/gs/src/iname.h +++ b/gs/src/iname.h @@ -30,66 +30,61 @@ /* ---------------- Procedural interface ---------------- */ -/* Define the interpreter's name table. */ -extern name_table *the_gs_name_table; - -/* Backward compatibility */ -#define the_name_table() ((const name_table *)the_gs_name_table) /* Get the allocator for the name table. */ -#define name_memory()\ - names_memory(the_gs_name_table) +#define name_memory(mem)\ + names_memory(mem->gs_lib_ctx->gs_name_table) /* * Look up and/or enter a name in the name table. * See inames.h for the values of enterflag, and the possible return values. */ -#define name_ref(ptr, size, pnref, enterflag)\ - names_ref(the_gs_name_table, ptr, size, pnref, enterflag) -#define name_string_ref(pnref, psref)\ - names_string_ref(the_gs_name_table, pnref, psref) +#define name_ref(mem, ptr, size, pnref, enterflag)\ + names_ref(mem->gs_lib_ctx->gs_name_table, ptr, size, pnref, enterflag) +#define name_string_ref(mem, pnref, psref)\ + names_string_ref(mem->gs_lib_ctx->gs_name_table, pnref, psref) /* * name_enter_string calls name_ref with a (permanent) C string. */ -#define name_enter_string(str, pnref)\ - names_enter_string(the_gs_name_table,str, pnref) +#define name_enter_string(mem, str, pnref)\ + names_enter_string(mem->gs_lib_ctx->gs_name_table, str, pnref) /* * name_from_string essentially implements cvn. * It always enters the name, and copies the executable attribute. */ -#define name_from_string(psref, pnref)\ - names_from_string(the_gs_name_table, psref, pnref) +#define name_from_string(mem, psref, pnref)\ + names_from_string(mem->gs_lib_ctx->gs_name_table, psref, pnref) /* Compare two names for equality. */ #define name_eq(pnref1, pnref2)\ names_eq(pnref1, pnref2) /* Invalidate the value cache for a name. */ -#define name_invalidate_value_cache(pnref)\ - names_invalidate_value_cache(the_gs_name_table, pnref) +#define name_invalidate_value_cache(mem, pnref)\ + names_invalidate_value_cache(mem->gs_lib_ctx->gs_name_table, pnref) /* Convert between names and indices. */ -#define name_index(pnref) /* ref => index */\ - names_index(the_gs_name_table, pnref) -#define name_index_ptr(nidx) /* index => name */\ - names_index_ptr(the_gs_name_table, nidx) -#define name_index_ref(nidx, pnref) /* index => ref */\ - names_index_ref(the_gs_name_table, nidx, pnref) +#define name_index(mem, pnref) /* ref => index */\ + names_index(mem->gs_lib_ctx->gs_name_table, pnref) +#define name_index_ptr(mem, nidx) /* index => name */\ + names_index_ptr(mem->gs_lib_ctx->gs_name_table, nidx) +#define name_index_ref(mem, nidx, pnref) /* index => ref */\ + names_index_ref(mem->gs_lib_ctx->gs_name_table, nidx, pnref) /* Get the index of the next valid name. */ /* The argument is 0 or a valid index. */ /* Return 0 if there are no more. */ -#define name_next_valid_index(nidx)\ - names_next_valid_index(the_gs_name_table, nidx) +#define name_next_valid_index(mem, nidx)\ + names_next_valid_index(mem->gs_lib_ctx->gs_name_table, nidx) /* Mark a name for the garbage collector. */ /* Return true if this is a new mark. */ -#define name_mark_index(nidx)\ - names_mark_index(the_gs_name_table, nidx) +#define name_mark_index(mem, nidx)\ + names_mark_index(mem->gs_lib_ctx->gs_name_table, nidx) /* Get the object (sub-table) containing a name. */ /* The garbage collector needs this so it can relocate pointers to names. */ -#define name_ref_sub_table(pnref)\ - names_ref_sub_table(the_gs_name_table, pnref) +#define name_ref_sub_table(mem, pnref)\ + names_ref_sub_table(mem->gs_lib_ctx->gs_name_table, pnref) #endif /* iname_INCLUDED */ diff --git a/gs/src/interp.c b/gs/src/interp.c index 07227ad3d..40f856de3 100644 --- a/gs/src/interp.c +++ b/gs/src/interp.c @@ -696,7 +696,7 @@ gs_errorname(i_ctx_t *i_ctx_p, int code, ref * perror_name) dict_find_string(systemdict, "ErrorNames", &pErrorNames) <= 0 ) return_error(e_undefined); /* errordict or ErrorNames not found?! */ - return array_get(pErrorNames, (long)(-code - 1), perror_name); + return array_get(imemory, pErrorNames, (long)(-code - 1), perror_name); } /* Store an error string in $error.errorinfo. */ @@ -781,7 +781,7 @@ interp(i_ctx_t **pi_ctx_p /* context for execution, updated if resched */, * Get a pointer to the name table so that we can use the * inline version of name_index_ref. */ - const name_table *const int_nt = the_name_table(); + const name_table *const int_nt = imemory->gs_lib_ctx->gs_name_table; #define set_error(ecode)\ { ierror.code = ecode; ierror.line = __LINE__; } @@ -800,7 +800,7 @@ interp(i_ctx_t **pi_ctx_p /* context for execution, updated if resched */, int ticks_left = gs_interp_time_slice_ticks; /* - * If we exceed the VMThreshold, set ticks_left to -1 + * If we exceed the VMThreshold, set ticks_left to -100 * to alert the interpreter that we need to garbage collect. */ set_gc_signal(i_ctx_p, &ticks_left, -100); @@ -1149,7 +1149,7 @@ remap: if (iesp + 2 >= estop) { return_with_error_iref(code); iesp = esp; } - packed_get(iref_packed, iesp + 1); + packed_get(imemory, iref_packed, iesp + 1); make_oper(iesp + 2, 0, r_ptr(&istate->remap_color_info, int_remap_color_info_t)->proc); @@ -1667,7 +1667,7 @@ res: * We need a real object to return as the error object. * (It only has to last long enough to store in *perror_object.) */ - packed_get((const ref_packed *)ierror.obj, &ierror.full); + packed_get(imemory, (const ref_packed *)ierror.obj, &ierror.full); store_state_short(iesp); if (IREF == ierror.obj) SET_IREF(&ierror.full); diff --git a/gs/src/iparam.c b/gs/src/iparam.c index 8f492d9db..2ba4525c1 100644 --- a/gs/src/iparam.c +++ b/gs/src/iparam.c @@ -46,7 +46,7 @@ ref_param_key(const iparam_list * plist, gs_param_name pkey, ref * pkref) make_int(pkref, key); return 0; } else - return name_ref((const byte *)pkey, strlen(pkey), pkref, 0); + return name_ref(plist->memory, (const byte *)pkey, strlen(pkey), pkref, 0); } /* Fill in a gs_param_key_t from a name or int ref. */ @@ -56,7 +56,7 @@ ref_to_key(const ref * pref, gs_param_key_t * key, iparam_list *plist) if (r_has_type(pref, t_name)) { ref nref; - name_string_ref(pref, &nref); + name_string_ref(plist->memory, pref, &nref); key->data = nref.value.const_bytes; key->size = r_size(&nref); key->persistent = false; /* names may be freed */ @@ -107,7 +107,7 @@ private int ref_array_param_requested(const iparam_list *, gs_param_name, private int ref_param_write(iparam_list *, gs_param_name, const ref *); private int ref_param_write_string_value(ref *, const gs_param_string *, gs_ref_memory_t *); -private int ref_param_write_name_value(ref *, const gs_param_string *); +private int ref_param_write_name_value(const gs_memory_t *mem, ref *, const gs_param_string *); private int ref_param_make_int(ref *pe, const void *pvalue, uint i, gs_ref_memory_t *imem) { @@ -132,7 +132,7 @@ ref_param_make_string(ref *pe, const void *pvalue, uint i, gs_ref_memory_t *imem private int ref_param_make_name(ref * pe, const void *pvalue, uint i, gs_ref_memory_t *imem) { - return ref_param_write_name_value(pe, + return ref_param_write_name_value((const gs_memory_t *)imem, pe, &((const gs_param_string_array *)pvalue)->data[i]); } private int @@ -235,7 +235,7 @@ ref_param_write_typed(gs_param_list * plist, gs_param_name pkey, case gs_param_type_name: if (!ref_param_requested(plist, pkey)) return 0; - code = ref_param_write_name_value(&value, &pvalue->value.n); + code = ref_param_write_name_value(iplist->memory, &value, &pvalue->value.n); break; case gs_param_type_int_array: return ref_param_write_typed_array(plist, pkey, &pvalue->value.ia, @@ -322,9 +322,9 @@ ref_param_write_string_value(ref * pref, const gs_param_string * pvalue, /* Prepare to write a name value. */ private int -ref_param_write_name_value(ref * pref, const gs_param_string * pvalue) +ref_param_write_name_value(const gs_memory_t *mem, ref * pref, const gs_param_string * pvalue) { - return name_ref(pvalue->data, pvalue->size, pref, + return name_ref(mem, pvalue->data, pvalue->size, pref, (pvalue->persistent ? 0 : 1)); } @@ -520,7 +520,8 @@ private const gs_param_list_procs ref_read_procs = }; private int ref_param_read(iparam_list *, gs_param_name, iparam_loc *, int); -private int ref_param_read_string_value(const iparam_loc *, +private int ref_param_read_string_value(const gs_memory_t *mem, + const iparam_loc *, gs_param_string *); private int ref_param_read_array(iparam_list *, gs_param_name, iparam_loc *); @@ -556,7 +557,7 @@ ref_param_read_int_array(gs_param_list * plist, gs_param_name pkey, for (i = 0; i < size; i++) { ref elt; - array_get(loc.pvalue, i, &elt); + array_get(plist->memory, loc.pvalue, i, &elt); if (!r_has_type(&elt, t_integer)) { code = gs_note_error(e_typecheck); break; @@ -601,7 +602,7 @@ ref_param_read_float_array(gs_param_list * plist, gs_param_name pkey, aref = *loc.pvalue; loc.pvalue = &elt; for (i = 0; code >= 0 && i < size; i++) { - array_get(&aref, i, &elt); + array_get(plist->memory, &aref, i, &elt); code = float_param(&elt, pfv + i); } if (code < 0) { @@ -637,15 +638,15 @@ ref_param_read_string_array(gs_param_list * plist, gs_param_name pkey, if (r_has_type(&aref, t_array)) { for (i = 0; code >= 0 && i < size; i++) { loc.pvalue = aref.value.refs + i; - code = ref_param_read_string_value(&loc, psv + i); + code = ref_param_read_string_value(plist->memory, &loc, psv + i); } } else { ref elt; loc.pvalue = &elt; for (i = 0; code >= 0 && i < size; i++) { - array_get(&aref, i, &elt); - code = ref_param_read_string_value(&loc, psv + i); + array_get(plist->memory, &aref, i, &elt); + code = ref_param_read_string_value(plist->memory, &loc, psv + i); } } if (code < 0) { @@ -732,7 +733,7 @@ ref_param_read_typed(gs_param_list * plist, gs_param_name pkey, * on the type of the first element of the array. If that * fails, we try again with more general types. */ - array_get(loc.pvalue, 0, &elt); + array_get(plist->memory, loc.pvalue, 0, &elt); switch (r_type(&elt)) { case t_integer: pvalue->type = gs_param_type_int_array; @@ -790,7 +791,7 @@ ref_param_read_typed(gs_param_list * plist, gs_param_name pkey, return 0; case t_name: pvalue->type = gs_param_type_name; - return ref_param_read_string_value(&loc, &pvalue->value.n); + return ref_param_read_string_value(plist->memory, &loc, &pvalue->value.n); case t_null: pvalue->type = gs_param_type_null; return 0; @@ -800,7 +801,7 @@ ref_param_read_typed(gs_param_list * plist, gs_param_name pkey, return 0; case t_string: pvalue->type = gs_param_type_string; - return ref_param_read_string_value(&loc, &pvalue->value.s); + return ref_param_read_string_value(plist->memory, &loc, &pvalue->value.s); default: break; } @@ -866,7 +867,7 @@ ref_param_get_next_key(gs_param_list * plist, gs_param_enumerator_t * penum, /* Read a string value. */ private int -ref_param_read_string_value(const iparam_loc * ploc, gs_param_string * pvalue) +ref_param_read_string_value(const gs_memory_t *mem, const iparam_loc * ploc, gs_param_string * pvalue) { const ref *pref = ploc->pvalue; @@ -874,7 +875,7 @@ ref_param_read_string_value(const iparam_loc * ploc, gs_param_string * pvalue) case t_name: { ref nref; - name_string_ref(pref, &nref); + name_string_ref(mem, pref, &nref); pvalue->data = nref.value.const_bytes; pvalue->size = r_size(&nref); pvalue->persistent = true; diff --git a/gs/src/iplugin.c b/gs/src/iplugin.c index 7bdf8ce2c..9d6d790bc 100644 --- a/gs/src/iplugin.c +++ b/gs/src/iplugin.c @@ -35,23 +35,23 @@ extern_i_plugin_table(); private void *i_plugin_mem_alloc(i_plugin_client_memory *mem, unsigned int nbytes, const char *cname) -{ gs_raw_memory_t *mem_raw = (gs_raw_memory_t *)mem->client_data; +{ gs_memory_t *mem_raw = mem->client_data; return mem_raw->procs.alloc_bytes_immovable(mem_raw, nbytes, cname); } private void i_plugin_mem_free(i_plugin_client_memory *mem, void *data, const char *cname) -{ gs_raw_memory_t *mem_raw = (gs_raw_memory_t *)mem->client_data; +{ gs_memory_t *mem_raw = mem->client_data; mem_raw->procs.free_object(mem_raw, data, cname); } -void i_plugin_make_memory(i_plugin_client_memory *mem, gs_raw_memory_t *mem_raw) +void i_plugin_make_memory(i_plugin_client_memory *mem, gs_memory_t *mem_raw) { mem->client_data = mem_raw; mem->alloc = i_plugin_mem_alloc; mem->free = i_plugin_mem_free; } int i_plugin_init(i_ctx_t *i_ctx_p) -{ gs_raw_memory_t *mem_raw = i_ctx_p->memory.current->parent; +{ gs_memory_t *mem_raw = i_ctx_p->memory.current->non_gc_memory; const i_plugin_instantiation_proc *p = i_plugin_table; i_plugin_holder *h; int code; @@ -72,7 +72,7 @@ int i_plugin_init(i_ctx_t *i_ctx_p) return 0; } -void i_plugin_finit(gs_raw_memory_t *mem_raw, i_plugin_holder *list) +void i_plugin_finit(gs_memory_t *mem_raw, i_plugin_holder *list) { i_plugin_client_memory client_mem; i_plugin_make_memory(&client_mem, mem_raw); while (list != 0) { diff --git a/gs/src/iplugin.h b/gs/src/iplugin.h index c39424ff0..66f91a003 100644 --- a/gs/src/iplugin.h +++ b/gs/src/iplugin.h @@ -25,9 +25,9 @@ typedef struct gs_context_state_s i_ctx_t; #endif -#ifndef gs_raw_memory_t_DEFINED -#define gs_raw_memory_t_DEFINED -typedef struct gs_raw_memory_s gs_raw_memory_t; +#ifndef gs_memory_DEFINED +#define gs_memory_DEFINED +typedef struct gs_memory_s gs_memory_t; #endif typedef struct i_plugin_holder_s i_plugin_holder; @@ -63,9 +63,9 @@ struct i_plugin_client_memory_s { /* must be copying */ typedef plugin_instantiation_proc((*i_plugin_instantiation_proc));\ extern const i_plugin_instantiation_proc i_plugin_table[] -void i_plugin_make_memory(i_plugin_client_memory *mem, gs_raw_memory_t *mem_raw); +void i_plugin_make_memory(i_plugin_client_memory *mem, gs_memory_t *mem_raw); int i_plugin_init(i_ctx_t *); -void i_plugin_finit(gs_raw_memory_t *mem, i_plugin_holder *list); +void i_plugin_finit(gs_memory_t *mem, i_plugin_holder *list); i_plugin_instance *i_plugin_find(i_ctx_t *i_ctx_p, const char *type, const char *subtype); i_plugin_holder * i_plugin_get_list(i_ctx_t *i_ctx_p); diff --git a/gs/src/isave.c b/gs/src/isave.c index 24ae337d9..052a47c1c 100644 --- a/gs/src/isave.c +++ b/gs/src/isave.c @@ -309,7 +309,7 @@ alloc_save_state(gs_dual_memory_t * dmem, void *cdata) { gs_ref_memory_t *lmem = dmem->space_local; gs_ref_memory_t *gmem = dmem->space_global; - ulong sid = gs_next_ids(2); + ulong sid = gs_next_ids((const gs_memory_t *)lmem->stable_memory, 2); bool global = lmem->save_level == 0 && gmem != lmem && gmem->num_contexts == 1; @@ -385,7 +385,7 @@ alloc_save_space(gs_ref_memory_t * mem, gs_dual_memory_t * dmem, ulong sid) if (cp->ctop - cp->cbot > min_inner_chunk_space) { /* Create an inner chunk to cover only the unallocated part. */ chunk_t *inner = - gs_raw_alloc_struct_immovable(mem->parent, &st_chunk, + gs_raw_alloc_struct_immovable(mem->non_gc_memory, &st_chunk, "alloc_save_space(inner)"); if (inner == 0) @@ -413,7 +413,7 @@ alloc_save_space(gs_ref_memory_t * mem, gs_dual_memory_t * dmem, ulong sid) } save->state = save_mem; save->spaces = dmem->spaces; - save->restore_names = (name_memory() == (gs_memory_t *) mem); + save->restore_names = (name_memory(mem) == (gs_memory_t *) mem); save->is_current = (dmem->current == mem); save->id = sid; mem->saved = save; @@ -451,7 +451,7 @@ alloc_save_change_in(gs_ref_memory_t *mem, const ref * pcont, else { lprintf3("Bad type %u for save! pcont = 0x%lx, where = 0x%lx\n", r_type(pcont), (ulong) pcont, (ulong) where); - gs_abort(); + gs_abort((const gs_memory_t *)mem); } if (r_is_packed(where)) *(ref_packed *)&cp->contents = *where; @@ -561,25 +561,27 @@ alloc_is_since_save(const void *vptr, const alloc_save_t * save) /* Test whether a name would be invalidated by a restore. */ bool -alloc_name_is_since_save(const ref * pnref, const alloc_save_t * save) +alloc_name_is_since_save(const gs_memory_t *mem, + const ref * pnref, const alloc_save_t * save) { const name_string_t *pnstr; if (!save->restore_names) return false; - pnstr = names_string_inline(the_gs_name_table, pnref); + pnstr = names_string_inline(mem->gs_lib_ctx->gs_name_table, pnref); if (pnstr->foreign_string) return false; return alloc_is_since_save(pnstr->string_bytes, save); } bool -alloc_name_index_is_since_save(uint nidx, const alloc_save_t * save) +alloc_name_index_is_since_save(const gs_memory_t *mem, + uint nidx, const alloc_save_t *save) { const name_string_t *pnstr; if (!save->restore_names) return false; - pnstr = names_index_string_inline(the_gs_name_table, nidx); + pnstr = names_index_string_inline(mem->gs_lib_ctx->gs_name_table, nidx); if (pnstr->foreign_string) return false; return alloc_is_since_save(pnstr->string_bytes, save); @@ -838,7 +840,7 @@ restore_resources(alloc_save_t * sprev, gs_ref_memory_t * mem) /* Adjust the name table. */ if (sprev->restore_names) - names_restore(the_gs_name_table, sprev); + names_restore(mem->gs_lib_ctx->gs_name_table, sprev); } /* Release memory for a restore. */ @@ -945,7 +947,7 @@ combine_space(gs_ref_memory_t * mem) outer->rtop = cp->rtop; outer->ctop = cp->ctop; outer->has_refs |= cp->has_refs; - gs_free_object(mem->parent, cp, + gs_free_object(mem->non_gc_memory, cp, "combine_space(inner)"); } } diff --git a/gs/src/isave.h b/gs/src/isave.h index 8f7ffa2de..106ae7531 100644 --- a/gs/src/isave.h +++ b/gs/src/isave.h @@ -63,8 +63,8 @@ alloc_save_t *alloc_save_current(const gs_dual_memory_t *); bool alloc_is_since_save(const void *, const alloc_save_t *); /* Check whether a name was created since a given save. */ -bool alloc_name_is_since_save(const ref *, const alloc_save_t *); -bool alloc_name_index_is_since_save(uint, const alloc_save_t *); +bool alloc_name_is_since_save(const gs_memory_t *mem, const ref *, const alloc_save_t *); +bool alloc_name_index_is_since_save(const gs_memory_t *mem, uint, const alloc_save_t *); /* * Check whether any names have been created since a given save diff --git a/gs/src/iscan.c b/gs/src/iscan.c index 5a17cad90..af24958c9 100644 --- a/gs/src/iscan.c +++ b/gs/src/iscan.c @@ -506,7 +506,7 @@ scan_token(i_ctx_t *i_ctx_p, stream * s, ref * pref, scanner_state * pstate) case '[': case ']': s1[0] = (byte) c; - retcode = name_ref(s1, 1, myref, 1); /* can't fail */ + retcode = name_ref(imemory, s1, 1, myref, 1); /* can't fail */ r_set_attrs(myref, a_executable); break; case '<': @@ -806,7 +806,7 @@ scan_token(i_ctx_t *i_ctx_p, stream * s, ref * pref, scanner_state * pstate) if (c1 == c) { s1[0] = s1[1] = c; - name_ref(s1, 2, myref, 1); /* can't fail */ + name_ref(imemory, s1, 2, myref, 1); /* can't fail */ goto have_name; } scan_putback(); @@ -872,7 +872,7 @@ scan_token(i_ctx_t *i_ctx_p, stream * s, ref * pref, scanner_state * pstate) /* The default is a name. */ default: if (c < 0) { - dynamic_init(&da, name_memory()); /* da state must be clean */ + dynamic_init(&da, name_memory(imemory)); /* da state must be clean */ scan_type = scanning_none; goto pause; } @@ -980,7 +980,7 @@ scan_token(i_ctx_t *i_ctx_p, stream * s, ref * pref, scanner_state * pstate) /* We have to do this before the next */ /* sgetc, which will overwrite the buffer. */ da.limit = (byte *)++ sptr; - da.memory = name_memory(); + da.memory = name_memory(imemory); retcode = dynamic_grow(&da, da.limit, name_max_string); if (retcode < 0) { dynamic_save(&da); @@ -1058,7 +1058,7 @@ scan_token(i_ctx_t *i_ctx_p, stream * s, ref * pref, scanner_state * pstate) if (da.is_dynamic) { /* We've already allocated the string on the heap. */ uint size = daptr - da.base; - retcode = name_ref(da.base, size, myref, -1); + retcode = name_ref(imemory, da.base, size, myref, -1); if (retcode >= 0) { dynamic_free(&da); } else { @@ -1069,10 +1069,10 @@ scan_token(i_ctx_t *i_ctx_p, stream * s, ref * pref, scanner_state * pstate) scan_type = scanning_name; goto pause_ret; } - retcode = name_ref(da.base, size, myref, 2); + retcode = name_ref(imemory, da.base, size, myref, 2); } } else { - retcode = name_ref(da.base, (uint) (daptr - da.base), + retcode = name_ref(imemory, da.base, (uint) (daptr - da.base), myref, !s->foreign); } /* Done scanning. Check for preceding /'s. */ diff --git a/gs/src/iscanbin.c b/gs/src/iscanbin.c index 425a7d08a..6cb45b9b9 100644 --- a/gs/src/iscanbin.c +++ b/gs/src/iscanbin.c @@ -135,7 +135,7 @@ typedef enum { #define SIZEOF_BIN_SEQ_OBJ ((uint)8) /* Forward references */ -private int scan_bin_get_name(const ref *, int, ref *); +private int scan_bin_get_name(const gs_memory_t *mem, const ref *, int, ref *); private int scan_bin_num_array_continue(i_ctx_t *, stream *, ref *, scanner_state *); private int scan_bin_string_continue(i_ctx_t *, stream *, ref *, scanner_state *); private int scan_bos_continue(i_ctx_t *, stream *, ref *, scanner_state *); @@ -305,13 +305,13 @@ scan_binary_token(i_ctx_t *i_ctx_p, stream *s, ref *pref, return code; } case BT_LITNAME_SYSTEM: - code = scan_bin_get_name(system_names_p, p[1], pref); + code = scan_bin_get_name(imemory, system_names_p, p[1], pref); goto lname; case BT_EXECNAME_SYSTEM: - code = scan_bin_get_name(system_names_p, p[1], pref); + code = scan_bin_get_name(imemory, system_names_p, p[1], pref); goto xname; case BT_LITNAME_USER: - code = scan_bin_get_name(user_names_p, p[1], pref); + code = scan_bin_get_name(imemory, user_names_p, p[1], pref); lname: if (code < 0) return code; @@ -320,7 +320,7 @@ scan_binary_token(i_ctx_t *i_ctx_p, stream *s, ref *pref, s_end_inline(s, p + 1, rlimit); return 0; case BT_EXECNAME_USER: - code = scan_bin_get_name(user_names_p, p[1], pref); + code = scan_bin_get_name(imemory, user_names_p, p[1], pref); xname: if (code < 0) return code; @@ -356,11 +356,11 @@ scan_binary_token(i_ctx_t *i_ctx_p, stream *s, ref *pref, /* Get a system or user name. */ private int -scan_bin_get_name(const ref *pnames /*t_array*/, int index, ref *pref) +scan_bin_get_name(const gs_memory_t *mem, const ref *pnames /*t_array*/, int index, ref *pref) { if (pnames == 0) return_error(e_rangecheck); - return array_get(pnames, (long)index, pref); + return array_get(mem, pnames, (long)index, pref); } /* Continue collecting a binary string. */ @@ -535,10 +535,10 @@ scan_bos_continue(i_ctx_t *i_ctx_p, register stream * s, ref * pref, value = sdecodelong(p + 5, num_format); switch (osize) { case 0: - code = array_get(user_names_p, value, op); + code = array_get(imemory, user_names_p, value, op); goto usn; case 0xffff: - code = array_get(system_names_p, value, op); + code = array_get(imemory, system_names_p, value, op); usn: if (code < 0) return code; @@ -651,7 +651,7 @@ scan_bos_string_continue(i_ctx_t *i_ctx_p, register stream * s, ref * pref, uint attrs = (r_has_attr(op, a_executable) ? a_executable : 0); - code = name_ref(op->value.bytes, r_size(op), op, 1); + code = name_ref(imemory, op->value.bytes, r_size(op), op, 1); if (code < 0) return code; r_set_attrs(op, attrs); @@ -795,7 +795,7 @@ nos: break; case t_name: type = BS_TYPE_NAME; - name_string_ref(obj, &nstr); + name_string_ref(imemory, obj, &nstr); r_copy_attrs(&nstr, a_executable, obj); obj = &nstr; goto nos; diff --git a/gs/src/iutil.c b/gs/src/iutil.c index 00f9dc97a..12b14f35d 100644 --- a/gs/src/iutil.c +++ b/gs/src/iutil.c @@ -87,7 +87,7 @@ refset_null_new(ref * to, uint size, uint new_mask) /* Compare two objects for equality. */ bool -obj_eq(const ref * pref1, const ref * pref2) +obj_eq(const gs_memory_t *mem, const ref * pref1, const ref * pref2) { ref nref; @@ -107,13 +107,13 @@ obj_eq(const ref * pref1, const ref * pref2) case t_name: if (!r_has_type(pref2, t_string)) return false; - name_string_ref(pref1, &nref); + name_string_ref(mem, pref1, &nref); pref1 = &nref; break; case t_string: if (!r_has_type(pref2, t_name)) return false; - name_string_ref(pref2, &nref); + name_string_ref(mem, pref2, &nref); pref2 = &nref; break; @@ -191,14 +191,14 @@ obj_eq(const ref * pref1, const ref * pref2) /* Compare two objects for identity. */ bool -obj_ident_eq(const ref * pref1, const ref * pref2) +obj_ident_eq(const gs_memory_t *mem, const ref * pref1, const ref * pref2) { if (r_type(pref1) != r_type(pref2)) return false; if (r_has_type(pref1, t_string)) return (pref1->value.bytes == pref2->value.bytes && r_size(pref1) == r_size(pref2)); - return obj_eq(pref1, pref2); + return obj_eq(mem, pref1, pref2); } /* @@ -207,13 +207,13 @@ obj_ident_eq(const ref * pref1, const ref * pref2) * If the object is a string without read access, return e_invalidaccess. */ int -obj_string_data(const ref *op, const byte **pchars, uint *plen) +obj_string_data(const gs_memory_t *mem, const ref *op, const byte **pchars, uint *plen) { switch (r_type(op)) { case t_name: { ref nref; - name_string_ref(op, &nref); + name_string_ref(mem, op, &nref); *pchars = nref.value.bytes; *plen = r_size(&nref); return 0; @@ -298,7 +298,7 @@ obj_cvp(const ref * op, byte * str, uint len, uint * prlen, goto nl; case t_name: if (r_has_attr(op, a_executable)) { - code = obj_string_data(op, &data, &size); + code = obj_string_data(mem, op, &data, &size); if (code < 0) return code; goto nl; @@ -441,7 +441,7 @@ other: check_read(*op); /* falls through */ case t_name: - code = obj_string_data(op, &data, &size); + code = obj_string_data(mem, op, &data, &size); if (code < 0) return code; goto nl; @@ -449,9 +449,9 @@ other: uint index = op_index(op); const op_array_table *opt = op_index_op_array_table(index); - name_index_ref(opt->nx_table[index - opt->base_index], &nref); - name_string_ref(&nref, &nref); - code = obj_string_data(&nref, &data, &size); + name_index_ref(mem, opt->nx_table[index - opt->base_index], &nref); + name_string_ref(mem, &nref, &nref); + code = obj_string_data(mem, &nref, &data, &size); if (code < 0) return code; goto nl; @@ -520,16 +520,16 @@ ensure_dot(char *buf) * str. In any case, store the length in *prlen. */ int -obj_cvs(const ref * op, byte * str, uint len, uint * prlen, +obj_cvs(const gs_memory_t *mem, const ref * op, byte * str, uint len, uint * prlen, const byte ** pchars) { - int code = obj_cvp(op, str, len, prlen, 0, 0, NULL); + int code = obj_cvp(op, str, len, prlen, 0, 0, mem); /* NB: NULL memptr */ if (code != 1 && pchars) { *pchars = str; return code; } - obj_string_data(op, pchars, prlen); + obj_string_data(mem, op, pchars, prlen); return gs_note_error(e_rangecheck); } @@ -576,7 +576,7 @@ op_index_ref(uint index, ref * pref) /* This is also used to index into Encoding vectors, */ /* the error name vector, etc. */ int -array_get(const ref * aref, long index_long, ref * pref) +array_get(const gs_memory_t *mem, const ref * aref, long index_long, ref * pref) { if ((ulong)index_long >= r_size(aref)) return_error(e_rangecheck); @@ -595,14 +595,14 @@ array_get(const ref * aref, long index_long, ref * pref) for (; index--;) packed = packed_next(packed); - packed_get(packed, pref); + packed_get(mem, packed, pref); } break; case t_shortarray: { const ref_packed *packed = aref->value.packed + index_long; - packed_get(packed, pref); + packed_get(mem, packed, pref); } break; default: @@ -616,7 +616,7 @@ array_get(const ref * aref, long index_long, ref * pref) /* Source and destination are allowed to overlap if the source is packed, */ /* or if they are identical. */ void -packed_get(const ref_packed * packed, ref * pref) +packed_get(const gs_memory_t *mem, const ref_packed * packed, ref * pref) { const ref_packed elt = *packed; uint value = elt & packed_value_mask; @@ -632,10 +632,10 @@ packed_get(const ref_packed * packed, ref * pref) make_int(pref, (int)value + packed_min_intval); break; case pt_literal_name: - name_index_ref(value, pref); + name_index_ref(mem, value, pref); break; case pt_executable_name: - name_index_ref(value, pref); + name_index_ref(mem, value, pref); r_set_attrs(pref, a_executable); break; case pt_full_ref: @@ -744,7 +744,7 @@ float_params(const ref * op, int count, float *pval) /* Get N numeric parameters (as floating point numbers) from an array */ int -process_float_array(const ref * parray, int count, float * pval) +process_float_array(const gs_memory_t *mem, const ref * parray, int count, float * pval) { int code = 0, indx0 = 0; @@ -759,7 +759,7 @@ process_float_array(const ref * parray, int count, float * pval) subcount = (count > countof(ref_buff) ? countof(ref_buff) : count); for (i = 0; i < subcount && code >= 0; i++) - code = array_get(parray, (long)(i + indx0), &ref_buff[i]); + code = array_get(mem, parray, (long)(i + indx0), &ref_buff[i]); if (code >= 0) code = float_params(ref_buff + subcount - 1, subcount, pval); count -= subcount; @@ -851,7 +851,7 @@ check_type_failed(const ref * op) /* Read a matrix operand. */ /* Return 0 if OK, error code if not. */ int -read_matrix(const ref * op, gs_matrix * pmat) +read_matrix(const gs_memory_t *mem, const ref * op, gs_matrix * pmat) { int code; ref values[6]; @@ -863,7 +863,7 @@ read_matrix(const ref * op, gs_matrix * pmat) int i; for (i = 0; i < 6; ++i) { - code = array_get(op, (long)i, &values[i]); + code = array_get(mem, op, (long)i, &values[i]); if (code < 0) return code; } diff --git a/gs/src/iutil.h b/gs/src/iutil.h index 224085eff..84c6936a9 100644 --- a/gs/src/iutil.h +++ b/gs/src/iutil.h @@ -38,18 +38,18 @@ void refset_null_new(ref * to, uint size, uint new_mask); #define refset_null(to, size) refset_null_new(to, size, ialloc_new_mask) /* Compare two objects for equality. */ -bool obj_eq(const ref *, const ref *); +bool obj_eq(const gs_memory_t *mem, const ref *, const ref *); /* Compare two objects for identity. */ /* (This is not a standard PostScript concept.) */ -bool obj_ident_eq(const ref *, const ref *); +bool obj_ident_eq(const gs_memory_t *mem, const ref *, const ref *); /* * Set *pchars and *plen to point to the data of a name or string, and * return 0. If the object isn't a name or string, return e_typecheck. * If the object is a string without read access, return e_invalidaccess. */ -int obj_string_data(const ref *op, const byte **pchars, uint *plen); +int obj_string_data(const gs_memory_t *mem, const ref *op, const byte **pchars, uint *plen); /* * Create a printable representation of an object, a la cvs and = @@ -80,17 +80,17 @@ int obj_cvp(const ref * op, byte *str, uint len, uint * prlen, * and it can return a pointer to the data for names and strings, like * obj_string_data. */ -int obj_cvs(const ref * op, byte * str, uint len, uint * prlen, +int obj_cvs(const gs_memory_t *mem, const ref * op, byte * str, uint len, uint * prlen, const byte ** pchars); /* Get an element from an array (packed or not). */ -int array_get(const ref *, long, ref *); +int array_get(const gs_memory_t *mem, const ref *, long, ref *); /* Get an element from a packed array. */ /* (This works for ordinary arrays too.) */ /* Source and destination are allowed to overlap if the source is packed, */ /* or if they are identical. */ -void packed_get(const ref_packed *, ref *); +void packed_get(const gs_memory_t *mem, const ref_packed *, ref *); /* Check to make sure an interval contains no object references */ /* to a space younger than a given one. */ @@ -115,7 +115,7 @@ int num_params(const ref *, int, double *); int float_params(const ref *, int, float *); /* process_float_array can lose accuracy for large integers */ -int process_float_array(const ref *, int, float *); +int process_float_array(const gs_memory_t *mem, const ref *, int, float *); /* Get a single real parameter. */ /* The only possible error is e_typecheck. */ @@ -139,7 +139,7 @@ typedef struct gs_matrix_s gs_matrix; #endif /* Read a matrix operand. */ -int read_matrix(const ref *, gs_matrix *); +int read_matrix(const gs_memory_t *mem, const ref *, gs_matrix *); /* Write a matrix operand. */ /* If dmem is NULL, the array is guaranteed newly allocated in imem. */ diff --git a/gs/src/lib.mak b/gs/src/lib.mak index a5432201d..cecaca6b6 100644 --- a/gs/src/lib.mak +++ b/gs/src/lib.mak @@ -252,6 +252,10 @@ $(GLOBJ)gsmisc.$(OBJ) : $(GLSRC)gsmisc.c $(GXERR)\ $(gpcheck_h) $(gserror_h) $(gxfarith_h) $(gxfixed_h) $(GLCC) $(GLO_)gsmisc.$(OBJ) $(C_) $(GLSRC)gsmisc.c +$(GLOBJ)gslibctx.$(OBJ) : $(GLSRC)gslibctx.c $(GLSRC)gslibctx.h $(GXERR)\ + $(std_h) + $(GLCC) $(GLO_)gslibctx.$(OBJ) $(C_) $(GLSRC)gslibctx.c + $(GLOBJ)gsnotify.$(OBJ) : $(GLSRC)gsnotify.c $(GXERR)\ $(gsnotify_h) $(gsstruct_h) $(GLCC) $(GLO_)gsnotify.$(OBJ) $(C_) $(GLSRC)gsnotify.c @@ -1065,7 +1069,7 @@ LIB7s=$(GLOBJ)gsht.$(OBJ) $(GLOBJ)gshtscr.$(OBJ) $(GLOBJ)gswts.$(OBJ) LIB8s=$(GLOBJ)gsimage.$(OBJ) $(GLOBJ)gsimpath.$(OBJ) $(GLOBJ)gsinit.$(OBJ) LIB9s=$(GLOBJ)gsiodev.$(OBJ) $(GLOBJ)gsistate.$(OBJ) $(GLOBJ)gsline.$(OBJ) LIB10s=$(GLOBJ)gsmalloc.$(OBJ) $(GLOBJ)gsmatrix.$(OBJ) $(GLOBJ)gsmemlok.$(OBJ) -LIB11s=$(GLOBJ)gsmemory.$(OBJ) $(GLOBJ)gsmemret.$(OBJ) $(GLOBJ)gsmisc.$(OBJ) $(GLOBJ)gsnotify.$(OBJ) +LIB11s=$(GLOBJ)gsmemory.$(OBJ) $(GLOBJ)gsmemret.$(OBJ) $(GLOBJ)gsmisc.$(OBJ) $(GLOBJ)gsnotify.$(OBJ) $(GLOBJ)gslibctx.$(OBJ) LIB12s=$(GLOBJ)gspaint.$(OBJ) $(GLOBJ)gsparam.$(OBJ) $(GLOBJ)gspath.$(OBJ) LIB13s=$(GLOBJ)gsserial.$(OBJ) $(GLOBJ)gsstate.$(OBJ) $(GLOBJ)gstext.$(OBJ)\ $(GLOBJ)gsutil.$(OBJ) @@ -1109,7 +1113,7 @@ $(GLD)libs.dev : $(LIB_MAK) $(ECHOGS_XE) $(LIBs) $(LIB_O) $(GLD)gsiodevs.dev $(ADDMOD) $(GLD)libs $(LIB12s) $(ADDMOD) $(GLD)libs $(LIB13s) $(ADDCOMP) $(GLD)libs overprint - $(ADDMOD) $(GLD)libs -init gshtscr gsutil + $(ADDMOD) $(GLD)libs -init gshtscr $(ADDMOD) $(GLD)libs -include $(GLD)gsiodevs $(GLD)libx.dev : $(LIB_MAK) $(ECHOGS_XE) $(LIBx) diff --git a/gs/src/sdctc.c b/gs/src/sdctc.c index cb8cf7ea9..530cf6866 100644 --- a/gs/src/sdctc.c +++ b/gs/src/sdctc.c @@ -31,7 +31,7 @@ s_DCT_set_defaults(stream_state * st) { stream_DCT_state *const ss = (stream_DCT_state *) st; - ss->jpeg_memory = &gs_memory_default; + ss->jpeg_memory = gs_lib_ctx_get_non_gc_memory_t(); ss->data.common = 0; /**************** ss->data.common->Picky = 0; diff --git a/gs/src/std.h b/gs/src/std.h index 0ae5f626d..dd2f2103f 100644 --- a/gs/src/std.h +++ b/gs/src/std.h @@ -163,6 +163,18 @@ typedef ulong bits32; */ #include <stdio.h> +/* + * Not a very good place to define this, but we can't find a better one. + */ +#ifndef gs_memory_DEFINED +# define gs_memory_DEFINED +typedef struct gs_memory_s gs_memory_t; +#endif + +#define init_proc(proc)\ + int proc(gs_memory_t *) + + /* dpf and epf may be redefined */ #define dpf errprintf #define epf errprintf @@ -170,15 +182,15 @@ typedef ulong bits32; /* To allow stdout and stderr to be redirected, all stdout goes * though outwrite and all stderr goes through errwrite. */ -int outwrite(const char *str, int len); +int outwrite(const gs_memory_t *mem, const char *str, int len); int errwrite(const char *str, int len); -void outflush(void); +void outflush(const gs_memory_t *mem); void errflush(void); /* Formatted output to outwrite and errwrite. * The maximum string length is 1023 characters. */ #ifdef __PROTOTYPES__ -int outprintf(const char *fmt, ...); +int outprintf(const gs_memory_t *mem, const char *fmt, ...); int errprintf(const char *fmt, ...); #else int outprintf(); @@ -252,7 +264,7 @@ void dflush(void); /* flush stderr */ #define dlprintf12(str,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12)\ (_dpl dprintf12(str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)) -void printf_program_ident(const char *program_name, long revision_number); +void printf_program_ident(const gs_memory_t *mem, const char *program_name, long revision_number); void eprintf_program_ident(const char *program_name, long revision_number); const char *gs_program_name(void); long gs_revision_number(void); diff --git a/gs/src/szlibc.c b/gs/src/szlibc.c index aa0bdb901..462003433 100644 --- a/gs/src/szlibc.c +++ b/gs/src/szlibc.c @@ -52,7 +52,7 @@ s_zlib_set_defaults(stream_state * st) int s_zlib_alloc_dynamic_state(stream_zlib_state *ss) { - gs_memory_t *mem = (ss->memory ? ss->memory : &gs_memory_default); + gs_memory_t *mem = ss->memory; zlib_dynamic_state_t *zds = gs_alloc_struct_immovable(mem, zlib_dynamic_state_t, &st_zlib_dynamic_state, diff --git a/gs/src/ttload.c b/gs/src/ttload.c index 97fe284dd..2773baec8 100644 --- a/gs/src/ttload.c +++ b/gs/src/ttload.c @@ -138,9 +138,11 @@ face->cvtSize = 300; /* Work around DynaLab bug in DingBat1. */ #endif - face->cvt = mem->alloc_bytes(mem, face->cvtSize * sizeof(Short), "Load_TrueType_CVT"); - if (!face->cvt) - return TT_Err_Out_Of_Memory; + if(face->cvtSize > 0) { /* allow fonts with a CVT table */ + face->cvt = mem->alloc_bytes(mem, face->cvtSize * sizeof(Short), "Load_TrueType_CVT"); + if (!face->cvt) + return TT_Err_Out_Of_Memory; + } limit = face->cvtSize; diff --git a/gs/src/zarray.c b/gs/src/zarray.c index 8e8ac0301..d709a8548 100644 --- a/gs/src/zarray.c +++ b/gs/src/zarray.c @@ -64,7 +64,7 @@ zaload(i_ctx_t *i_ctx_p) if (code < 0) return code; for (i = asize; i > 0; i--, packed = packed_next(packed)) - packed_get(packed, ref_stack_index(&o_stack, i)); + packed_get(imemory, packed, ref_stack_index(&o_stack, i)); *osp = aref; return 0; } @@ -76,7 +76,7 @@ zaload(i_ctx_t *i_ctx_p) os_ptr pdest = op; for (i = 0; i < asize; i++, pdest++, packed = packed_next(packed)) - packed_get(packed, pdest); + packed_get(imemory, packed, pdest); } push(asize); ref_assign(op, &aref); diff --git a/gs/src/zbfont.c b/gs/src/zbfont.c index 2d2c34fbb..6c7ef5753 100644 --- a/gs/src/zbfont.c +++ b/gs/src/zbfont.c @@ -69,14 +69,14 @@ zfont_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t gspace) const ref *pencoding = &pdata->Encoding; ulong index = chr; /* work around VAX widening bug */ ref cname; - int code = array_get(pencoding, (long)index, &cname); + int code = array_get(pfont->memory, pencoding, (long)index, &cname); if (code < 0 || !r_has_type(&cname, t_name)) return gs_no_glyph; if (pfont->FontType == ft_user_defined && r_type(&pdata->BuildGlyph) == t_null) { ref nsref, tname; - name_string_ref(&cname, &nsref); + name_string_ref(pfont->memory, &cname, &nsref); if (r_size(&nsref) == 7 && !memcmp(nsref.value.const_bytes, ".notdef", r_size(&nsref))) { /* A special support for high level devices. @@ -94,7 +94,7 @@ zfont_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t gspace) if (gspace == GLYPH_SPACE_NOGEN) return gs_no_glyph; sprintf(buf, "j%ld", chr); /* 'j' is arbutrary. */ - code = name_ref((const byte *)buf, strlen(buf), &tname, 1); + code = name_ref(pfont->memory, (const byte *)buf, strlen(buf), &tname, 1); if (code < 0) { /* Can't propagate the error due to interface limitation, return with .notdef */ @@ -102,7 +102,7 @@ zfont_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t gspace) cname = tname; } } - return (gs_glyph)name_index(&cname); + return (gs_glyph)name_index(pfont->memory, &cname); } /* Get the name of a glyph. */ @@ -116,20 +116,20 @@ zfont_glyph_name(gs_font *font, gs_glyph index, gs_const_string *pstr) int code; sprintf(cid_name, "%lu", (ulong) index); - code = name_ref((const byte *)cid_name, strlen(cid_name), + code = name_ref(font->memory, (const byte *)cid_name, strlen(cid_name), &nref, 1); if (code < 0) return code; } else - name_index_ref(index, &nref); - name_string_ref(&nref, &sref); + name_index_ref(font->memory, index, &nref); + name_string_ref(font->memory, &nref, &sref); pstr->data = sref.value.const_bytes; pstr->size = r_size(&sref); return 0; } private gs_char -gs_font_map_glyph_by_dict(const ref *map, gs_glyph glyph) +gs_font_map_glyph_by_dict(const gs_memory_t *mem, const ref *map, gs_glyph glyph) { ref *v, n; if (glyph >= gs_min_cid_glyph) { @@ -141,7 +141,7 @@ gs_font_map_glyph_by_dict(const ref *map, gs_glyph glyph) if (dict_find(map, &n, &v) > 0) { ref vv; - if (array_get(v, cid % 256, &vv) == 0 && r_type(&vv) == t_integer) + if (array_get(mem, v, cid % 256, &vv) == 0 && r_type(&vv) == t_integer) return vv.value.intval; } return GS_NO_CHAR; /* Absent in the map. */ @@ -149,7 +149,7 @@ gs_font_map_glyph_by_dict(const ref *map, gs_glyph glyph) /* This is GlyphNames2Unicode dictionary. */ make_int(&n, cid); } else - name_index_ref(glyph, &n); + name_index_ref(mem, glyph, &n); if (dict_find(map, &n, &v) > 0) { if (r_has_type(v, t_string)) { int i, l = r_size(v); @@ -173,7 +173,8 @@ gs_font_map_glyph_to_unicode(gs_font *font, gs_glyph glyph) const ref *UnicodeDecoding; if (r_type(&pdata->GlyphNames2Unicode) == t_dictionary) { - gs_char c = gs_font_map_glyph_by_dict(&pdata->GlyphNames2Unicode, glyph); + gs_char c = gs_font_map_glyph_by_dict(font->memory, + &pdata->GlyphNames2Unicode, glyph); if (c != GS_NO_CHAR) return c; @@ -185,7 +186,7 @@ gs_font_map_glyph_to_unicode(gs_font *font, gs_glyph glyph) } UnicodeDecoding = zfont_get_to_unicode_map(font->dir); if (UnicodeDecoding != NULL && r_type(UnicodeDecoding) == t_dictionary) - return gs_font_map_glyph_by_dict(UnicodeDecoding, glyph); + return gs_font_map_glyph_by_dict(font->memory, UnicodeDecoding, glyph); return GS_NO_CHAR; /* No map. */ } @@ -201,7 +202,7 @@ const op_def zbfont_op_defs[] = /* Convert strings to executable names for build_proc_refs. */ int -build_proc_name_refs(build_proc_refs * pbuild, +build_proc_name_refs(const gs_memory_t *mem, build_proc_refs * pbuild, const char *bcstr, const char *bgstr) { int code; @@ -209,14 +210,16 @@ build_proc_name_refs(build_proc_refs * pbuild, if (!bcstr) make_null(&pbuild->BuildChar); else { - if ((code = name_ref((const byte *)bcstr, strlen(bcstr), &pbuild->BuildChar, 0)) < 0) + if ((code = name_ref(mem, (const byte *)bcstr, + strlen(bcstr), &pbuild->BuildChar, 0)) < 0) return code; r_set_attrs(&pbuild->BuildChar, a_executable); } if (!bgstr) make_null(&pbuild->BuildGlyph); else { - if ((code = name_ref((const byte *)bgstr, strlen(bgstr), &pbuild->BuildGlyph, 0)) < 0) + if ((code = name_ref(mem, (const byte *)bgstr, + strlen(bgstr), &pbuild->BuildGlyph, 0)) < 0) return code; r_set_attrs(&pbuild->BuildGlyph, a_executable); } @@ -400,7 +403,7 @@ build_gs_simple_font(i_ctx_t *i_ctx_p, os_ptr op, gs_font_base ** ppfont, dict_find_string(pfontinfo, "GlyphNames2Unicode", &g2u) <= 0 || !r_has_type(pfontinfo, t_dictionary)) g2u = NULL; - code = font_bbox_param(op, bbox); + code = font_bbox_param(imemory, op, bbox); if (code < 0) return code; code = dict_uid_param(op, &uid, 0, imemory, i_ctx_p); @@ -462,14 +465,14 @@ lookup_gs_simple_font_encoding(gs_font_base * pfont) for (i = 0; i < esize; ++i) { ref fchar; - if (array_get(pfe, (long)i, &fchar) < 0 || + if (array_get(pfont->memory, pfe, (long)i, &fchar) < 0 || !r_has_type(&fchar, t_name) ) fstrs[i].data = 0, fstrs[i].size = 0; else { ref nsref; - name_string_ref(&fchar, &nsref); + name_string_ref(pfont->memory, &fchar, &nsref); fstrs[i].data = nsref.value.const_bytes; fstrs[i].size = r_size(&nsref); } @@ -506,14 +509,14 @@ lookup_gs_simple_font_encoding(gs_font_base * pfont) /* Get FontMatrix and FontName parameters. */ private int -sub_font_params(const ref *op, gs_matrix *pmat, gs_matrix *pomat, ref *pfname) +sub_font_params(const gs_memory_t *mem, const ref *op, gs_matrix *pmat, gs_matrix *pomat, ref *pfname) { ref *pmatrix; ref *pfontname; ref *porigfont; if (dict_find_string(op, "FontMatrix", &pmatrix) <= 0 || - read_matrix(pmatrix, pmat) < 0 + read_matrix(mem, pmatrix, pmat) < 0 ) return_error(e_invalidfont); if (dict_find_string(op, ".OrigFont", &porigfont) <= 0) @@ -521,15 +524,15 @@ sub_font_params(const ref *op, gs_matrix *pmat, gs_matrix *pomat, ref *pfname) if (pomat!= NULL) { if (porigfont == NULL || dict_find_string(porigfont, "FontMatrix", &pmatrix) <= 0 || - read_matrix(pmatrix, pomat) < 0 + read_matrix(mem, pmatrix, pomat) < 0 ) memset(pomat, 0, sizeof(*pomat)); } if (dict_find_string((porigfont != NULL ? porigfont : op), ".Alias", &pfontname) > 0) { /* If we emulate the font, we want the requested name rather than a substitute. */ - get_font_name(pfname, pfontname); + get_font_name(mem, pfname, pfontname); } else if (dict_find_string((porigfont != NULL ? porigfont : op), "FontName", &pfontname) > 0) { - get_font_name(pfname, pfontname); + get_font_name(mem, pfname, pfontname); } else make_empty_string(pfname, a_readonly); return 0; @@ -557,7 +560,7 @@ build_gs_font(i_ctx_t *i_ctx_p, os_ptr op, gs_font ** ppfont, font_type ftype, ref *pfid; ref *aop = dict_access_ref(op); - get_font_name(&kname, op - 1); + get_font_name(imemory, &kname, op - 1); if (dict_find_string(op, "FontType", &pftype) <= 0 || !r_has_type(pftype, t_integer) || pftype->value.intval != (int)ftype @@ -593,7 +596,7 @@ build_gs_font(i_ctx_t *i_ctx_p, os_ptr op, gs_font ** ppfont, font_type ftype, if (pfont->base == pfont) { /* original font */ if (!level2_enabled) return_error(e_invalidfont); - if (obj_eq(pfont_dict(pfont), op)) { + if (obj_eq(pfont->memory, pfont_dict(pfont), op)) { *ppfont = pfont; return 1; } @@ -607,7 +610,7 @@ build_gs_font(i_ctx_t *i_ctx_p, os_ptr op, gs_font ** ppfont, font_type ftype, gs_matrix mat; ref fname; /* t_string */ - code = sub_font_params(op, &mat, NULL, &fname); + code = sub_font_params(imemory, op, &mat, NULL, &fname); if (code < 0) return code; code = 1; @@ -666,7 +669,7 @@ build_gs_sub_font(i_ctx_t *i_ctx_p, const ref *op, gs_font **ppfont, * in the same VM as the font dictionary. */ uint space = ialloc_space(idmemory); - int code = sub_font_params(op, &mat, &omat, &fname); + int code = sub_font_params(imemory, op, &mat, &omat, &fname); if (code < 0) return code; @@ -711,14 +714,14 @@ build_gs_sub_font(i_ctx_t *i_ctx_p, const ref *op, gs_font **ppfont, /* Get the string corresponding to a font name. */ /* If the font name isn't a name or a string, return an empty string. */ void -get_font_name(ref * pfname, const ref * op) +get_font_name(const gs_memory_t *mem, ref * pfname, const ref * op) { switch (r_type(op)) { case t_string: *pfname = *op; break; case t_name: - name_string_ref(op, pfname); + name_string_ref(mem, op, pfname); break; default: /* This is weird, but legal.... */ diff --git a/gs/src/zchar.c b/gs/src/zchar.c index 7154e5691..6e006861f 100644 --- a/gs/src/zchar.c +++ b/gs/src/zchar.c @@ -41,7 +41,8 @@ #include "zchar42.h" /* Forward references */ -private bool map_glyph_to_char(const ref *, const ref *, ref *); +private bool map_glyph_to_char(const gs_memory_t *mem, + const ref *, const ref *, ref *); private int finish_show(i_ctx_t *); private int op_show_cleanup(i_ctx_t *); private int op_show_return_width(i_ctx_t *, uint, double *); @@ -319,7 +320,7 @@ zfontbbox(i_ctx_t *i_ctx_p) check_type(*op, t_dictionary); check_dict_read(*op); - code = font_bbox_param(op, bbox); + code = font_bbox_param(imemory, op, bbox); if (code < 0) return code; if (bbox[0] < bbox[2] && bbox[1] < bbox[3]) { @@ -362,10 +363,10 @@ const op_def zchar_op_defs[] = /* Convert a glyph to a ref. */ void -glyph_ref(gs_glyph glyph, ref * gref) +glyph_ref(const gs_memory_t *mem, gs_glyph glyph, ref * gref) { if (glyph < gs_min_cid_glyph) - name_index_ref(glyph, gref); + name_index_ref(mem, glyph, gref); else make_int(gref, glyph - gs_min_cid_glyph); } @@ -516,7 +517,7 @@ op_show_continue_dispatch(i_ctx_t *i_ctx_p, int npop, int code) !r_has_type(&pfdata->BuildGlyph, t_null) && glyph != gs_no_glyph ) { - glyph_ref(glyph, op); + glyph_ref(imemory, glyph, op); esp[2] = pfdata->BuildGlyph; } else if (r_has_type(&pfdata->BuildChar, t_null)) goto err; @@ -526,12 +527,12 @@ op_show_continue_dispatch(i_ctx_t *i_ctx_p, int npop, int code) ref gref; const ref *pencoding = &pfdata->Encoding; - glyph_ref(glyph, &gref); - if (!map_glyph_to_char(&gref, pencoding, + glyph_ref(imemory, glyph, &gref); + if (!map_glyph_to_char(imemory, &gref, pencoding, (ref *) op) ) { /* Not found, try .notdef */ - name_enter_string(".notdef", &gref); - if (!map_glyph_to_char(&gref, + name_enter_string(imemory, ".notdef", &gref); + if (!map_glyph_to_char(imemory, &gref, pencoding, (ref *) op) ) @@ -554,8 +555,8 @@ op_show_continue_dispatch(i_ctx_t *i_ctx_p, int npop, int code) if (chr != gs_no_char && !r_has_type(&pfdata->BuildChar, t_null) && (glyph == gs_no_glyph || - (array_get(&pfdata->Encoding, (long)(chr & 0xff), &eref) >= 0 && - (glyph_ref(glyph, &gref), obj_eq(&gref, &eref)))) + (array_get(imemory, &pfdata->Encoding, (long)(chr & 0xff), &eref) >= 0 && + (glyph_ref(imemory, glyph, &gref), obj_eq(imemory, &gref, &eref)))) ) { make_int(op, chr & 0xff); esp[2] = pfdata->BuildChar; @@ -564,7 +565,7 @@ op_show_continue_dispatch(i_ctx_t *i_ctx_p, int npop, int code) if (glyph == gs_no_glyph) make_int(op, 0); else - glyph_ref(glyph, op); + glyph_ref(imemory, glyph, op); esp[2] = pfdata->BuildGlyph; } } @@ -584,7 +585,7 @@ op_show_continue_dispatch(i_ctx_t *i_ctx_p, int npop, int code) pop(npop); op = osp; - glyph_ref(glyph, &cnref); + glyph_ref(imemory, glyph, &cnref); if (pfont->FontType == ft_CID_TrueType) { gs_font_type42 *pfont42 = (gs_font_type42 *)pfont; uint glyph_index = pfont42->data.get_glyph_index(pfont42, glyph); @@ -606,15 +607,15 @@ err: } /* Reverse-map a glyph name to a character code for glyphshow. */ private bool -map_glyph_to_char(const ref * pgref, const ref * pencoding, ref * pch) +map_glyph_to_char(const gs_memory_t *mem, const ref * pgref, const ref * pencoding, ref * pch) { uint esize = r_size(pencoding); uint ch; ref eref; for (ch = 0; ch < esize; ch++) { - array_get(pencoding, (long)ch, &eref); - if (obj_eq(pgref, &eref)) { + array_get(mem, pencoding, (long)ch, &eref); + if (obj_eq(mem, pgref, &eref)) { make_int(pch, ch); return true; } @@ -782,7 +783,7 @@ op_show_free(i_ctx_t *i_ctx_p, int code) /* Get a FontBBox parameter from a font dictionary. */ int -font_bbox_param(const ref * pfdict, double bbox[4]) +font_bbox_param(const gs_memory_t *mem, const ref * pfdict, double bbox[4]) { ref *pbbox; @@ -807,7 +808,7 @@ font_bbox_param(const ref * pfdict, double bbox[4]) const float max_ratio = 12; /* From the bug 687594. */ for (i = 0; i < 4; i++) { - packed_get(pbe, rbe + i); + packed_get(mem, pbe, rbe + i); pbe = packed_next(pbe); } if ((code = num_params(rbe + 3, 4, bbox)) < 0) diff --git a/gs/src/zchar1.c b/gs/src/zchar1.c index 530059fc8..2708cdc98 100644 --- a/gs/src/zchar1.c +++ b/gs/src/zchar1.c @@ -665,7 +665,7 @@ type1_continue_dispatch(i_ctx_t *i_ctx_p, gs_type1exec_state *pcxs, */ const font_data *pfdata = pfont_data(gs_currentfont(igs)); - code = array_get(&pfdata->u.type1.OtherSubrs, (long)value, pos); + code = array_get(imemory, &pfdata->u.type1.OtherSubrs, (long)value, pos); if (code >= 0) return type1_result_callothersubr; } @@ -888,7 +888,7 @@ zsetweightvector(i_ctx_t *i_ctx_p) size = r_size(op); if (size != pfont1->data.WeightVector.count) return_error(e_invalidfont); - code = process_float_array(op, size, pfont1->data.WeightVector.values); + code = process_float_array(imemory, op, size, pfont1->data.WeightVector.values); if (code < 0) return code; pop(2); @@ -919,7 +919,7 @@ z1_glyph_data(gs_font_type1 * pfont, gs_glyph glyph, gs_glyph_data_t *pgd) { ref gref; - glyph_ref(glyph, &gref); + glyph_ref(pfont->memory, glyph, &gref); return zchar_charstring_data((gs_font *)pfont, &gref, pgd); } @@ -931,7 +931,7 @@ z1_subr_data(gs_font_type1 * pfont, int index, bool global, ref subr; int code; - code = array_get((global ? &pfdata->u.type1.GlobalSubrs : + code = array_get(pfont->memory, (global ? &pfdata->u.type1.GlobalSubrs : &pfdata->u.type1.Subrs), index, &subr); if (code < 0) @@ -954,11 +954,11 @@ z1_seac_data(gs_font_type1 *pfont, int ccode, gs_glyph *pglyph, if (glyph == GS_NO_GLYPH) return_error(e_rangecheck); if ((code = gs_c_glyph_name(glyph, gstr)) < 0 || - (code = name_ref(gstr->data, gstr->size, &rglyph, 0)) < 0 + (code = name_ref(pfont->memory, gstr->data, gstr->size, &rglyph, 0)) < 0 ) return code; if (pglyph) - *pglyph = name_index(&rglyph); + *pglyph = name_index(pfont->memory, &rglyph); if (pgd) code = zchar_charstring_data((gs_font *)pfont, &rglyph, pgd); return code; @@ -1015,7 +1015,7 @@ zchar1_glyph_outline(gs_font *font, int WMode, gs_glyph glyph, const gs_matrix * gs_glyph_data_t gdata; int code; - glyph_ref(glyph, &gref); + glyph_ref(font->memory, glyph, &gref); code = zchar_charstring_data(font, &gref, &gdata); if (code < 0) return code; @@ -1141,7 +1141,7 @@ z1_glyph_info_generic(gs_font *font, gs_glyph glyph, const gs_matrix *pmat, /* Ignore CDevProc. Used to compure MissingWidth.*/ } } - glyph_ref(glyph, &gref); + glyph_ref(pbfont->memory, glyph, &gref); if (width_members == GLYPH_INFO_WIDTH1) { double wv[4]; code = zchar_get_metrics2(pbfont, &gref, wv); diff --git a/gs/src/zcharout.c b/gs/src/zcharout.c index 5471aa673..3ecfcb020 100644 --- a/gs/src/zcharout.c +++ b/gs/src/zcharout.c @@ -274,7 +274,7 @@ zchar_set_cache(i_ctx_t *i_ctx_p, const gs_font_base * pbfont, * Get the CharString data corresponding to a glyph. Return typecheck * if it isn't a string. */ -private bool charstring_is_notdef_proc(const ref *); +private bool charstring_is_notdef_proc(const gs_memory_t *mem, const ref *); private int charstring_make_notdef(gs_glyph_data_t *, gs_font *); int zchar_charstring_data(gs_font *font, const ref *pgref, gs_glyph_data_t *pgd) @@ -294,7 +294,7 @@ zchar_charstring_data(gs_font *font, const ref *pgref, gs_glyph_data_t *pgd) * 0 0 hsbw endchar */ if (font->FontType == ft_encrypted && - charstring_is_notdef_proc(pcstr) + charstring_is_notdef_proc(font->memory, pcstr) ) return charstring_make_notdef(pgd, font); else @@ -305,14 +305,14 @@ zchar_charstring_data(gs_font *font, const ref *pgref, gs_glyph_data_t *pgd) return 0; } private bool -charstring_is_notdef_proc(const ref *pcstr) +charstring_is_notdef_proc(const gs_memory_t *mem, const ref *pcstr) { if (r_is_array(pcstr) && r_size(pcstr) == 4) { ref elts[4]; long i; for (i = 0; i < 4; ++i) - array_get(pcstr, i, &elts[i]); + array_get(mem, pcstr, i, &elts[i]); if (r_has_type(&elts[0], t_name) && r_has_type(&elts[1], t_integer) && elts[1].value.intval == 0 && r_has_type(&elts[2], t_integer) && elts[2].value.intval == 0 && @@ -320,9 +320,9 @@ charstring_is_notdef_proc(const ref *pcstr) ) { ref nref; - name_enter_string("pop", &nref); + name_enter_string(mem, "pop", &nref); if (name_eq(&elts[0], &nref)) { - name_enter_string("setcharwidth", &nref); + name_enter_string(mem, "setcharwidth", &nref); if (name_eq(&elts[3], &nref)) return true; } @@ -366,7 +366,7 @@ charstring_make_notdef(gs_glyph_data_t *pgd, gs_font *font) * CIDFontType 0 CIDFont. */ int -zchar_enumerate_glyph(const ref *prdict, int *pindex, gs_glyph *pglyph) +zchar_enumerate_glyph(const gs_memory_t *mem, const ref *prdict, int *pindex, gs_glyph *pglyph) { int index = *pindex - 1; ref elt[2]; @@ -384,7 +384,7 @@ next: *pglyph = gs_min_cid_glyph + elt[0].value.intval; break; case t_name: - *pglyph = name_index(elt); + *pglyph = name_index(mem, elt); break; default: /* can't handle it */ goto next; diff --git a/gs/src/zcharx.c b/gs/src/zcharx.c index ac2d47ac8..f7d251a19 100644 --- a/gs/src/zcharx.c +++ b/gs/src/zcharx.c @@ -44,7 +44,7 @@ glyph_show_setup(i_ctx_t *i_ctx_p, gs_glyph *pglyph) break; default: check_type(*op, t_name); - *pglyph = name_index(op); + *pglyph = name_index(imemory, op); } return op_show_enum_setup(i_ctx_p); } @@ -110,7 +110,7 @@ moveshow(i_ctx_t *i_ctx_p, bool have_x, bool have_y) for (i = 0; i < size; ++i) { ref value; - switch (code = num_array_get(op, format, i, &value)) { + switch (code = num_array_get(imemory, op, format, i, &value)) { case t_integer: values[i] = (float)value.value.intval; break; case t_real: diff --git a/gs/src/zcid.c b/gs/src/zcid.c index f148c8c2e..81bcc8a02 100644 --- a/gs/src/zcid.c +++ b/gs/src/zcid.c @@ -52,13 +52,14 @@ cid_system_info_param(gs_cid_system_info_t *pcidsi, const ref *prcidsi) /* Convert a CID into TT char code or to TT glyph index. */ private bool -TT_char_code_from_CID_no_subst(const ref *Decoding, const ref *TT_cmap, uint nCID, uint *c) +TT_char_code_from_CID_no_subst(const gs_memory_t *mem, + const ref *Decoding, const ref *TT_cmap, uint nCID, uint *c) { ref *DecodingArray, char_code, ih, glyph_index; make_int(&ih, nCID / 256); if (dict_find(Decoding, &ih, &DecodingArray) <= 0 || !r_has_type(DecodingArray, t_array) || - array_get(DecodingArray, nCID % 256, &char_code) < 0 || + array_get(mem, DecodingArray, nCID % 256, &char_code) < 0 || !r_has_type(&char_code, t_integer)) { /* fixme : Generally, a single char_code can be insufficient. It could be an array. Fix lib/gs_ciddc.ps as well. */ @@ -68,7 +69,7 @@ TT_char_code_from_CID_no_subst(const ref *Decoding, const ref *TT_cmap, uint nCI *c = char_code.value.intval; return true; } - if (array_get(TT_cmap, char_code.value.intval, &glyph_index) < 0 || + if (array_get(mem, TT_cmap, char_code.value.intval, &glyph_index) < 0 || !r_has_type(&glyph_index, t_integer)) return false; *c = glyph_index.value.intval; @@ -78,12 +79,13 @@ TT_char_code_from_CID_no_subst(const ref *Decoding, const ref *TT_cmap, uint nCI /* Convert a CID into a TT char code or into a TT glyph index, using SubstNWP. */ /* Returns 1 if a glyph presents, 0 if not, <0 if error. */ int -cid_to_TT_charcode(const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, +cid_to_TT_charcode(const gs_memory_t *mem, + const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, uint nCID, uint *c, ref *src_type, ref *dst_type) { int SubstNWP_length = r_size(SubstNWP), i, code; - if (TT_char_code_from_CID_no_subst(Decoding, TT_cmap, nCID, c)) { + if (TT_char_code_from_CID_no_subst(mem, Decoding, TT_cmap, nCID, c)) { make_null(src_type); /* Leaving dst_type uninitialized. */ return 1; @@ -92,28 +94,28 @@ cid_to_TT_charcode(const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, ref rb, re, rs; int nb, ne, ns; - if ((code = array_get(SubstNWP, i + 1, &rb)) < 0) + if ((code = array_get(mem, SubstNWP, i + 1, &rb)) < 0) return code; - if ((code = array_get(SubstNWP, i + 2, &re)) < 0) + if ((code = array_get(mem, SubstNWP, i + 2, &re)) < 0) return code; - if ((code = array_get(SubstNWP, i + 3, &rs)) < 0) + if ((code = array_get(mem, SubstNWP, i + 3, &rs)) < 0) return code; nb = rb.value.intval; ne = re.value.intval; ns = rs.value.intval; if (nCID >= nb && nCID <= ne) - if (TT_char_code_from_CID_no_subst(Decoding, TT_cmap, ns + (nCID - nb), c)) { - if ((code = array_get(SubstNWP, i + 0, src_type)) < 0) + if (TT_char_code_from_CID_no_subst(mem, Decoding, TT_cmap, ns + (nCID - nb), c)) { + if ((code = array_get(mem, SubstNWP, i + 0, src_type)) < 0) return code; - if ((code = array_get(SubstNWP, i + 4, dst_type)) < 0) + if ((code = array_get(mem, SubstNWP, i + 4, dst_type)) < 0) return code; return 1; } if (nCID >= ns && nCID <= ns + (ne - nb)) - if (TT_char_code_from_CID_no_subst(Decoding, TT_cmap, nb + (nCID - ns), c)) { - if ((code = array_get(SubstNWP, i + 0, dst_type)) < 0) + if (TT_char_code_from_CID_no_subst(mem, Decoding, TT_cmap, nb + (nCID - ns), c)) { + if ((code = array_get(mem, SubstNWP, i + 0, dst_type)) < 0) return code; - if ((code = array_get(SubstNWP, i + 4, src_type)) < 0) + if ((code = array_get(mem, SubstNWP, i + 4, src_type)) < 0) return code; return 1; } @@ -124,7 +126,7 @@ cid_to_TT_charcode(const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, /* Set a CIDMap element. */ private int -set_CIDMap_element(ref *CIDMap, uint cid, uint glyph_index) +set_CIDMap_element(const gs_memory_t *mem, ref *CIDMap, uint cid, uint glyph_index) { /* Assuming the CIDMap is already type-checked. */ /* Assuming GDBytes == 2. */ int offset = cid * 2; @@ -135,7 +137,7 @@ set_CIDMap_element(ref *CIDMap, uint cid, uint glyph_index) if (glyph_index >= 65536) return_error(e_rangecheck); /* Can't store with GDBytes == 2. */ for (i = 0; i < count; i++) { - array_get(CIDMap, i, &s); + array_get(mem, CIDMap, i, &s); size = r_size(&s) & ~1; if (offset < size) { c = s.value.bytes + offset; @@ -152,7 +154,8 @@ set_CIDMap_element(ref *CIDMap, uint cid, uint glyph_index) /* Create a CIDMap from a True Type cmap array, Decoding and SubstNWP. */ int -cid_fill_CIDMap(const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, int GDBytes, +cid_fill_CIDMap(const gs_memory_t *mem, + const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, int GDBytes, ref *CIDMap) { int dict_enum; ref el[2]; @@ -166,7 +169,7 @@ cid_fill_CIDMap(const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, in /* Checking the CIDMap structure correctness : */ for (i = 0; i < count; i++) { ref s; - int code = array_get(CIDMap, i, &s); + int code = array_get(mem, CIDMap, i, &s); if (code < 0) return code; @@ -188,13 +191,13 @@ cid_fill_CIDMap(const ref *Decoding, const ref *TT_cmap, const ref *SubstNWP, in for (i = 0; i < count; i++) { uint cid = index * 256 + i, glyph_index; ref src_type, dst_type; - int code = cid_to_TT_charcode(Decoding, TT_cmap, SubstNWP, + int code = cid_to_TT_charcode(mem, Decoding, TT_cmap, SubstNWP, cid, &glyph_index, &src_type, &dst_type); if (code < 0) return code; if (code > 0) { - code = set_CIDMap_element(CIDMap, cid, glyph_index); + code = set_CIDMap_element(mem, CIDMap, cid, glyph_index); if (code < 0) return code; } diff --git a/gs/src/zcie.c b/gs/src/zcie.c index 9b2d66a40..f6cd3b3ad 100644 --- a/gs/src/zcie.c +++ b/gs/src/zcie.c @@ -48,10 +48,11 @@ static const ref empty_procs[4] = /* Get a range array parameter from a dictionary. */ /* We know that count <= 4. */ int -dict_ranges_param(const ref * pdref, const char *kstr, int count, +dict_ranges_param(const gs_memory_t *mem, + const ref * pdref, const char *kstr, int count, gs_range * prange) { - int code = dict_floats_param(pdref, kstr, count * 2, + int code = dict_floats_param(mem, pdref, kstr, count * 2, (float *)prange, NULL); if (code < 0) @@ -64,8 +65,9 @@ dict_ranges_param(const ref * pdref, const char *kstr, int count, /* Get an array of procedures from a dictionary. */ /* We know count <= countof(empty_procs). */ int -dict_proc_array_param(const ref * pdict, const char *kstr, - uint count, ref * pparray) +dict_proc_array_param(const gs_memory_t *mem, + const ref *pdict, const char *kstr, + uint count, ref *pparray) { ref *pvalue; @@ -78,7 +80,7 @@ dict_proc_array_param(const ref * pdict, const char *kstr, for (i = 0; i < count; i++) { ref proc; - array_get(pvalue, (long)i, &proc); + array_get(mem, pvalue, (long)i, &proc); check_proc_only(proc); } *pparray = *pvalue; @@ -90,14 +92,17 @@ dict_proc_array_param(const ref * pdict, const char *kstr, /* Get 3 ranges from a dictionary. */ int -dict_range3_param(const ref *pdref, const char *kstr, gs_range3 *prange3) +dict_range3_param(const gs_memory_t *mem, + const ref *pdref, const char *kstr, + gs_range3 *prange3) { - return dict_ranges_param(pdref, kstr, 3, prange3->ranges); + return dict_ranges_param(mem, pdref, kstr, 3, prange3->ranges); } /* Get a 3x3 matrix from a dictionary. */ int -dict_matrix3_param(const ref *pdref, const char *kstr, gs_matrix3 *pmat3) +dict_matrix3_param(const gs_memory_t *mem, + const ref *pdref, const char *kstr, gs_matrix3 *pmat3) { /* * We can't simply call dict_float_array_param with the matrix @@ -111,7 +116,7 @@ dict_matrix3_param(const ref *pdref, const char *kstr, gs_matrix3 *pmat3) memcpy(&values[0], &Matrix3_default.cu, 3 * sizeof(float)); memcpy(&values[3], &Matrix3_default.cv, 3 * sizeof(float)); memcpy(&values[6], &Matrix3_default.cw, 3 * sizeof(float)); - code = dict_floats_param(pdref, kstr, 9, values, values); + code = dict_floats_param(mem, pdref, kstr, 9, values, values); if (code < 0) return code; memcpy(&pmat3->cu, &values[0], 3 * sizeof(float)); @@ -122,19 +127,20 @@ dict_matrix3_param(const ref *pdref, const char *kstr, gs_matrix3 *pmat3) /* Get 3 procedures from a dictionary. */ int -dict_proc3_param(const ref *pdref, const char *kstr, ref proc3[3]) +dict_proc3_param(const gs_memory_t *mem, const ref *pdref, const char *kstr, ref proc3[3]) { - return dict_proc_array_param(pdref, kstr, 3, proc3); + return dict_proc_array_param(mem, pdref, kstr, 3, proc3); } /* Get WhitePoint and BlackPoint values. */ int -cie_points_param(const ref * pdref, gs_cie_wb * pwb) +cie_points_param(const gs_memory_t *mem, + const ref * pdref, gs_cie_wb * pwb) { int code; - if ((code = dict_floats_param(pdref, "WhitePoint", 3, (float *)&pwb->WhitePoint, NULL)) < 0 || - (code = dict_floats_param(pdref, "BlackPoint", 3, (float *)&pwb->BlackPoint, (const float *)&BlackPoint_default)) < 0 + if ((code = dict_floats_param(mem, pdref, "WhitePoint", 3, (float *)&pwb->WhitePoint, NULL)) < 0 || + (code = dict_floats_param(mem, pdref, "BlackPoint", 3, (float *)&pwb->BlackPoint, (const float *)&BlackPoint_default)) < 0 ) return code; if (pwb->WhitePoint.u <= 0 || @@ -236,14 +242,14 @@ cie_3d_table_param(const ref * ptable, uint count, uint nbytes, /* Common code for the CIEBased* cases of setcolorspace. */ private int -cie_lmnp_param(const ref * pdref, gs_cie_common * pcie, ref_cie_procs * pcprocs) +cie_lmnp_param(const gs_memory_t *mem, const ref * pdref, gs_cie_common * pcie, ref_cie_procs * pcprocs) { int code; - if ((code = dict_range3_param(pdref, "RangeLMN", &pcie->RangeLMN)) < 0 || - (code = dict_proc3_param(pdref, "DecodeLMN", &pcprocs->DecodeLMN)) < 0 || - (code = dict_matrix3_param(pdref, "MatrixLMN", &pcie->MatrixLMN)) < 0 || - (code = cie_points_param(pdref, &pcie->points)) < 0 + if ((code = dict_range3_param(mem, pdref, "RangeLMN", &pcie->RangeLMN)) < 0 || + (code = dict_proc3_param(mem, pdref, "DecodeLMN", &pcprocs->DecodeLMN)) < 0 || + (code = dict_matrix3_param(mem, pdref, "MatrixLMN", &pcie->MatrixLMN)) < 0 || + (code = cie_points_param(mem, pdref, &pcie->points)) < 0 ) return code; pcie->DecodeLMN = DecodeLMN_default; @@ -252,14 +258,14 @@ cie_lmnp_param(const ref * pdref, gs_cie_common * pcie, ref_cie_procs * pcprocs) /* Common code for the CIEBasedABC/DEF[G] cases of setcolorspace. */ private int -cie_abc_param(const ref * pdref, gs_cie_abc * pcie, ref_cie_procs * pcprocs) +cie_abc_param(const gs_memory_t *mem, const ref * pdref, gs_cie_abc * pcie, ref_cie_procs * pcprocs) { int code; - if ((code = dict_range3_param(pdref, "RangeABC", &pcie->RangeABC)) < 0 || - (code = dict_proc3_param(pdref, "DecodeABC", &pcprocs->Decode.ABC)) < 0 || - (code = dict_matrix3_param(pdref, "MatrixABC", &pcie->MatrixABC)) < 0 || - (code = cie_lmnp_param(pdref, &pcie->common, pcprocs)) < 0 + if ((code = dict_range3_param(mem, pdref, "RangeABC", &pcie->RangeABC)) < 0 || + (code = dict_proc3_param(mem, pdref, "DecodeABC", &pcprocs->Decode.ABC)) < 0 || + (code = dict_matrix3_param(mem, pdref, "MatrixABC", &pcie->MatrixABC)) < 0 || + (code = cie_lmnp_param(mem, pdref, &pcie->common, pcprocs)) < 0 ) return code; pcie->DecodeABC = DecodeABC_default; @@ -321,11 +327,11 @@ zsetciedefgspace(i_ctx_t *i_ctx_p) pcie = pcs->params.defg; pcie->Table.n = 4; pcie->Table.m = 3; - if ((code = dict_ranges_param(op, "RangeDEFG", 4, pcie->RangeDEFG.ranges)) < 0 || - (code = dict_proc_array_param(op, "DecodeDEFG", 4, &procs.PreDecode.DEFG)) < 0 || - (code = dict_ranges_param(op, "RangeHIJK", 4, pcie->RangeHIJK.ranges)) < 0 || + if ((code = dict_ranges_param(mem, op, "RangeDEFG", 4, pcie->RangeDEFG.ranges)) < 0 || + (code = dict_proc_array_param(mem, op, "DecodeDEFG", 4, &procs.PreDecode.DEFG)) < 0 || + (code = dict_ranges_param(mem, op, "RangeHIJK", 4, pcie->RangeHIJK.ranges)) < 0 || (code = cie_table_param(ptref, &pcie->Table, mem)) < 0 || - (code = cie_abc_param(op, (gs_cie_abc *) pcie, &procs)) < 0 || + (code = cie_abc_param(imemory, op, (gs_cie_abc *) pcie, &procs)) < 0 || (code = cie_cache_joint(i_ctx_p, &istate->colorrendering.procs, (gs_cie_common *)pcie, igs)) < 0 || /* do this last */ (code = cie_cache_push_finish(i_ctx_p, cie_defg_finish, imem, pcie)) < 0 || (code = cie_prepare_cache4(i_ctx_p, &pcie->RangeDEFG, @@ -380,11 +386,11 @@ zsetciedefspace(i_ctx_t *i_ctx_p) pcie = pcs->params.def; pcie->Table.n = 3; pcie->Table.m = 3; - if ((code = dict_range3_param(op, "RangeDEF", &pcie->RangeDEF)) < 0 || - (code = dict_proc3_param(op, "DecodeDEF", &procs.PreDecode.DEF)) < 0 || - (code = dict_range3_param(op, "RangeHIJ", &pcie->RangeHIJ)) < 0 || + if ((code = dict_range3_param(mem, op, "RangeDEF", &pcie->RangeDEF)) < 0 || + (code = dict_proc3_param(mem, op, "DecodeDEF", &procs.PreDecode.DEF)) < 0 || + (code = dict_range3_param(mem, op, "RangeHIJ", &pcie->RangeHIJ)) < 0 || (code = cie_table_param(ptref, &pcie->Table, mem)) < 0 || - (code = cie_abc_param(op, (gs_cie_abc *) pcie, &procs)) < 0 || + (code = cie_abc_param(imemory, op, (gs_cie_abc *) pcie, &procs)) < 0 || (code = cie_cache_joint(i_ctx_p, &istate->colorrendering.procs, (gs_cie_common *)pcie, igs)) < 0 || /* do this last */ (code = cie_cache_push_finish(i_ctx_p, cie_def_finish, imem, pcie)) < 0 || (code = cie_prepare_cache3(i_ctx_p, &pcie->RangeDEF, @@ -431,7 +437,7 @@ zsetcieabcspace(i_ctx_t *i_ctx_p) if (code < 0) return code; pcie = pcs->params.abc; - code = cie_abc_param(op, pcie, &procs); + code = cie_abc_param(imemory, op, pcie, &procs); if (code < 0 || (code = cie_cache_joint(i_ctx_p, &istate->colorrendering.procs, (gs_cie_common *)pcie, igs)) < 0 || /* do this last */ (code = cie_cache_push_finish(i_ctx_p, cie_abc_finish, imem, pcie)) < 0 || @@ -476,9 +482,9 @@ zsetcieaspace(i_ctx_t *i_ctx_p) if (code < 0) return code; pcie = pcs->params.a; - if ((code = dict_floats_param(op, "RangeA", 2, (float *)&pcie->RangeA, (const float *)&RangeA_default)) < 0 || - (code = dict_floats_param(op, "MatrixA", 3, (float *)&pcie->MatrixA, (const float *)&MatrixA_default)) < 0 || - (code = cie_lmnp_param(op, &pcie->common, &procs)) < 0 || + if ((code = dict_floats_param(imemory, op, "RangeA", 2, (float *)&pcie->RangeA, (const float *)&RangeA_default)) < 0 || + (code = dict_floats_param(imemory, op, "MatrixA", 3, (float *)&pcie->MatrixA, (const float *)&MatrixA_default)) < 0 || + (code = cie_lmnp_param(imemory, op, &pcie->common, &procs)) < 0 || (code = cie_cache_joint(i_ctx_p, &istate->colorrendering.procs, (gs_cie_common *)pcie, igs)) < 0 || /* do this last */ (code = cie_cache_push_finish(i_ctx_p, cie_a_finish, imem, pcie)) < 0 || (code = cie_prepare_cache(i_ctx_p, &pcie->RangeA, &procs.Decode.A, &pcie->caches.DecodeA.floats, pcie, imem, "Decode.A")) < 0 || diff --git a/gs/src/zcolor.c b/gs/src/zcolor.c index 95be7e2ac..c59da156f 100644 --- a/gs/src/zcolor.c +++ b/gs/src/zcolor.c @@ -131,9 +131,9 @@ zcurrentcolorspace(i_ctx_t * i_ctx_p) if ( gs_color_space_get_index(igs->color_space) == gs_color_space_index_DeviceGray ) { ref gray, graystr; ref csa = istate->colorspace.array; - if (array_get(&csa, 0, &gray) >= 0 && + if (array_get(imemory, &csa, 0, &gray) >= 0 && r_has_type(&gray, t_name) && - (name_string_ref(&gray, &graystr), + (name_string_ref(imemory, &gray, &graystr), r_size(&graystr) == 10 && !memcmp(graystr.value.bytes, "DeviceGray", 10))) { @@ -142,7 +142,7 @@ zcurrentcolorspace(i_ctx_t * i_ctx_p) int code = ialloc_ref_array(op, a_all, 1, "currentcolorspace"); if (code < 0) return code; - return name_enter_string("DeviceGray", op->value.refs); + return name_enter_string(imemory, "DeviceGray", op->value.refs); } } else *op = istate->colorspace.array; @@ -273,7 +273,7 @@ zincludecolorspace(i_ctx_t * i_ctx_p) int code; check_type(*op, t_name); - name_string_ref(op, &nsref); + name_string_ref(imemory, op, &nsref); code = gs_includecolorspace(igs, nsref.value.const_bytes, r_size(&nsref)); if (!code) pop(1); @@ -308,15 +308,15 @@ zsetdevcspace(i_ctx_t * i_ctx_p) switch((gs_color_space_index)osp->value.intval) { default: /* can't happen */ case gs_color_space_index_DeviceGray: - gs_cspace_init_DeviceGray(&cs); + gs_cspace_init_DeviceGray(imemory, &cs); break; case gs_color_space_index_DeviceRGB: - gs_cspace_init_DeviceRGB(&cs); + gs_cspace_init_DeviceRGB(imemory, &cs); break; case gs_color_space_index_DeviceCMYK: - gs_cspace_init_DeviceCMYK(&cs); + gs_cspace_init_DeviceCMYK(imemory, &cs); break; } if ((code = gs_setcolorspace(igs, &cs)) >= 0) diff --git a/gs/src/zcontext.c b/gs/src/zcontext.c index df7c1409f..3b40383cb 100644 --- a/gs/src/zcontext.c +++ b/gs/src/zcontext.c @@ -112,7 +112,7 @@ CLEAR_MARKS_PROC(context_clear_marks) gs_context_t *const pctx = vptr; (*st_context_state.clear_marks) - (&pctx->state, sizeof(pctx->state), &st_context_state); + (cmem, &pctx->state, sizeof(pctx->state), &st_context_state); } private ENUM_PTRS_WITH(context_enum_ptrs, gs_context_t *pctx) @@ -278,7 +278,7 @@ context_reclaim(vm_spaces * pspaces, bool global) #ifdef DEBUG if (!psched->current->visible) { lprintf("Current context is invisible!\n"); - gs_abort(); + gs_abort((gs_memory_t *)lmem); } #endif @@ -370,7 +370,7 @@ ctx_initialize(i_ctx_t **pi_ctx_p) /* Create an initial context. */ if (context_create(psched, &psched->current, &gs_imemory, *pi_ctx_p, true) < 0) { lprintf("Can't create initial context!"); - gs_abort(); + gs_abort(imemory); } psched->current->scheduler = psched; /* Hook into the interpreter. */ @@ -601,7 +601,7 @@ do_fork(i_ctx_t *i_ctx_p, os_ptr op, const ref * pstdin, const ref * pstdout, /* Share global VM, private local VM. */ ref *puserdict; uint userdict_size; - gs_raw_memory_t *parent = iimemory_local->parent; + gs_memory_t *parent = iimemory_local->non_gc_memory; gs_ref_memory_t *lmem; gs_ref_memory_t *lmem_stable; @@ -695,7 +695,7 @@ do_fork(i_ctx_t *i_ctx_p, os_ptr op, const ref * pstdin, const ref * pstdout, for (i = 0; i < copy; ++i) { ref *pdref = ref_stack_index(dstack, i); - if (obj_eq(pdref, &old_userdict)) + if (obj_eq(imemory, pdref, &old_userdict)) *pdref = new_userdict; } } @@ -1165,7 +1165,7 @@ context_create(gs_scheduler_t * psched, gs_context_t ** ppctx, return code; } } - ctx_index = gs_next_ids(1); + ctx_index = gs_next_ids(mem, 1); pctx->scheduler = psched; pctx->status = cs_active; pctx->index = ctx_index; diff --git a/gs/src/zcontrol.c b/gs/src/zcontrol.c index 0924fd9a2..f236f5c0a 100644 --- a/gs/src/zcontrol.c +++ b/gs/src/zcontrol.c @@ -55,7 +55,7 @@ zcond(i_ctx_t *i_ctx_p) esp = ep += 3; ref_assign(ep - 2, op); /* the cond body */ make_op_estack(ep - 1, cond_continue); - array_get(op, 0L, ep); + array_get(imemory, op, 0L, ep); esfile_check_cache(); pop(1); return o_push_estack; @@ -73,7 +73,7 @@ cond_continue(i_ctx_t *i_ctx_p) /* of the tail. */ check_type(*op, t_boolean); if (op->value.boolval) { /* true */ - array_get(ep, 1L, ep); + array_get(imemory, ep, 1L, ep); esfile_check_cache(); code = o_pop_estack; } else if (r_size(ep) > 2) { /* false */ @@ -84,7 +84,7 @@ cond_continue(i_ctx_t *i_ctx_p) elts = packed_next(elts); elts = packed_next(elts); ep->value.packed = elts; - array_get(ep, 0L, ep + 2); + array_get(imemory, ep, 0L, ep + 2); make_op_estack(ep + 1, cond_continue); esp = ep + 2; esfile_check_cache(); diff --git a/gs/src/zcrd.c b/gs/src/zcrd.c index 771fa8f7e..70f1725a1 100644 --- a/gs/src/zcrd.c +++ b/gs/src/zcrd.c @@ -35,7 +35,7 @@ #include "store.h" /* for make_null */ /* Forward references */ -private int zcrd1_proc_params(os_ptr op, ref_cie_render_procs * pcprocs); +private int zcrd1_proc_params(const gs_memory_t *mem, os_ptr op, ref_cie_render_procs * pcprocs); private int zcrd1_params(os_ptr op, gs_cie_render * pcrd, ref_cie_render_procs * pcprocs, gs_memory_t * mem); private int cache_colorrendering1(i_ctx_t *i_ctx_p, gs_cie_render * pcrd, @@ -129,7 +129,7 @@ zsetcolorrendering1(i_ctx_t *i_ctx_p) check_type(op[-1], t_dictionary); check_stype(*op, st_cie_render1); - code = zcrd1_proc_params(op - 1, &procs); + code = zcrd1_proc_params(imemory, op - 1, &procs); if (code < 0) return code; code = gs_setcolorrendering(igs, r_ptr(op, gs_cie_render)); @@ -172,14 +172,15 @@ zsetdevicecolorrendering1(i_ctx_t *i_ctx_p) /* Get ColorRenderingType 1 procedures from the PostScript dictionary. */ private int -zcrd1_proc_params(os_ptr op, ref_cie_render_procs * pcprocs) +zcrd1_proc_params(const gs_memory_t *mem, + os_ptr op, ref_cie_render_procs * pcprocs) { int code; ref *pRT; - if ((code = dict_proc3_param(op, "EncodeLMN", &pcprocs->EncodeLMN)) < 0 || - (code = dict_proc3_param(op, "EncodeABC", &pcprocs->EncodeABC)) < 0 || - (code = dict_proc3_param(op, "TransformPQR", &pcprocs->TransformPQR)) < 0 + if ((code = dict_proc3_param(mem, op, "EncodeLMN", &pcprocs->EncodeLMN)) < 0 || + (code = dict_proc3_param(mem, op, "EncodeABC", &pcprocs->EncodeABC)) < 0 || + (code = dict_proc3_param(mem, op, "TransformPQR", &pcprocs->TransformPQR)) < 0 ) return (code < 0 ? code : gs_note_error(e_rangecheck)); if (dict_find_string(op, "RenderTable", &pRT) > 0) { @@ -212,14 +213,14 @@ zcrd1_params(os_ptr op, gs_cie_render * pcrd, ref *pRT; if ((code = dict_int_param(op, "ColorRenderingType", 1, 1, 0, &ignore)) < 0 || - (code = zcrd1_proc_params(op, pcprocs)) < 0 || - (code = dict_matrix3_param(op, "MatrixLMN", &pcrd->MatrixLMN)) < 0 || - (code = dict_range3_param(op, "RangeLMN", &pcrd->RangeLMN)) < 0 || - (code = dict_matrix3_param(op, "MatrixABC", &pcrd->MatrixABC)) < 0 || - (code = dict_range3_param(op, "RangeABC", &pcrd->RangeABC)) < 0 || - (code = cie_points_param(op, &pcrd->points)) < 0 || - (code = dict_matrix3_param(op, "MatrixPQR", &pcrd->MatrixPQR)) < 0 || - (code = dict_range3_param(op, "RangePQR", &pcrd->RangePQR)) < 0 + (code = zcrd1_proc_params(mem, op, pcprocs)) < 0 || + (code = dict_matrix3_param(mem, op, "MatrixLMN", &pcrd->MatrixLMN)) < 0 || + (code = dict_range3_param(mem, op, "RangeLMN", &pcrd->RangeLMN)) < 0 || + (code = dict_matrix3_param(mem, op, "MatrixABC", &pcrd->MatrixABC)) < 0 || + (code = dict_range3_param(mem, op, "RangeABC", &pcrd->RangeABC)) < 0 || + (code = cie_points_param(mem, op, &pcrd->points)) < 0 || + (code = dict_matrix3_param(mem, op, "MatrixPQR", &pcrd->MatrixPQR)) < 0 || + (code = dict_range3_param(mem,op, "RangePQR", &pcrd->RangePQR)) < 0 ) return code; if (dict_find_string(op, "RenderTable", &pRT) > 0) { @@ -456,7 +457,7 @@ ztpqr_scale_wb_common(i_ctx_t *i_ctx_p, int idx) for (i = 0; i < 4; i++) { ref tmp; - code = array_get(op - 4 + i, idx, &tmp); + code = array_get(imemory, op - 4 + i, idx, &tmp); if (code >= 0) code = real_param(&tmp, &a[i]); if (code < 0) return code; diff --git a/gs/src/zcsdevn.c b/gs/src/zcsdevn.c index 549bdadda..80323667e 100644 --- a/gs/src/zcsdevn.c +++ b/gs/src/zcsdevn.c @@ -75,7 +75,7 @@ zsetdevicenspace(i_ctx_t *i_ctx_p) /* See zcsindex.c for why we use memmove here. */ memmove(&cs.params.device_n.alt_space, &cs, sizeof(cs.params.device_n.alt_space)); - gs_cspace_init(&cs, &gs_color_space_type_DeviceN, NULL); + gs_cspace_init(&cs, &gs_color_space_type_DeviceN, imemory, false); code = gs_build_DeviceN(&cs, num_components, pacs, imemory); if (code < 0) return code; @@ -89,10 +89,10 @@ zsetdevicenspace(i_ctx_t *i_ctx_p) ref sname; for (i = 0; i < num_components; ++i) { - array_get(pcsa, (long)i, &sname); + array_get(imemory, pcsa, (long)i, &sname); switch (r_type(&sname)) { case t_string: - code = name_from_string(&sname, &sname); + code = name_from_string(imemory, &sname, &sname); if (code < 0) { ifree_object(names, ".setdevicenspace(names)"); ifree_object(pmap, ".setdevicenspace(map)"); @@ -100,7 +100,7 @@ zsetdevicenspace(i_ctx_t *i_ctx_p) } /* falls through */ case t_name: - names[i] = name_index(&sname); + names[i] = name_index(imemory, &sname); break; default: ifree_object(names, ".setdevicenspace(names)"); diff --git a/gs/src/zcsindex.c b/gs/src/zcsindex.c index 1bada4591..ca8175e00 100644 --- a/gs/src/zcsindex.c +++ b/gs/src/zcsindex.c @@ -83,7 +83,7 @@ zsetindexedspace(i_ctx_t *i_ctx_p) return_error(e_rangecheck); memmove(&cs.params.indexed.base_space, &cs, sizeof(cs.params.indexed.base_space)); - gs_cspace_init(&cs, &gs_color_space_type_Indexed, NULL); + gs_cspace_init(&cs, &gs_color_space_type_Indexed, imemory, false); cs.params.indexed.lookup.table.data = pcsa[2].value.const_bytes; cs.params.indexed.lookup.table.size = num_values; cs.params.indexed.use_proc = 0; @@ -105,7 +105,7 @@ zsetindexedspace(i_ctx_t *i_ctx_p) return code; memmove(&cs.params.indexed.base_space, &cs, sizeof(cs.params.indexed.base_space)); - gs_cspace_init(&cs, &gs_color_space_type_Indexed, NULL); + gs_cspace_init(&cs, &gs_color_space_type_Indexed, imemory, false); cs.params.indexed.use_proc = 1; *pproc = pcsa[2]; map->proc.lookup_index = lookup_indexed_map; diff --git a/gs/src/zcspixel.c b/gs/src/zcspixel.c index 54e1b52c3..3dbb68957 100644 --- a/gs/src/zcspixel.c +++ b/gs/src/zcspixel.c @@ -23,6 +23,7 @@ #include "gsmatrix.h" /* for gscolor2.h */ #include "gscolor2.h" #include "gscpixel.h" +#include "ialloc.h" /* <array> .setdevicepixelspace - */ private int @@ -36,9 +37,9 @@ zsetdevicepixelspace(i_ctx_t *i_ctx_p) check_read_type(*op, t_array); if (r_size(op) != 2) return_error(e_rangecheck); - array_get(op, 1L, &depth); + array_get(imemory, op, 1L, &depth); check_type_only(depth, t_integer); - code = gs_cspace_init_DevicePixel(&cs, (int)depth.value.intval); + code = gs_cspace_init_DevicePixel(imemory, &cs, (int)depth.value.intval); if (code < 0) return code; code = gs_setcolorspace(igs, &cs); diff --git a/gs/src/zcssepr.c b/gs/src/zcssepr.c index 605395285..de24723d5 100644 --- a/gs/src/zcssepr.c +++ b/gs/src/zcssepr.c @@ -66,6 +66,7 @@ zsetseparationspace(i_ctx_t *i_ctx_p) gs_function_t *pfn = NULL; separation_type sep_type; int code; + const gs_memory_t * mem = imemory; /* Verify that we have an array as our input parameter */ check_read_type(*op, t_array); @@ -89,7 +90,7 @@ zsetseparationspace(i_ctx_t *i_ctx_p) default: return_error(e_typecheck); case t_string: - code = name_from_string(&sname, &sname); + code = name_from_string(mem, &sname, &sname); if (code < 0) return code; /* falls through */ @@ -97,9 +98,9 @@ zsetseparationspace(i_ctx_t *i_ctx_p) break; } - if ((code = name_ref((const byte *)"All", 3, &name_all, 0)) < 0) + if ((code = name_ref(mem, (const byte *)"All", 3, &name_all, 0)) < 0) return code; - if ((code = name_ref((const byte *)"None", 4, &name_none, 0)) < 0) + if ((code = name_ref(mem, (const byte *)"None", 4, &name_none, 0)) < 0) return code; sep_type = ( name_eq(&sname, &name_all) ? SEP_ALL : name_eq(&sname, &name_none) ? SEP_NONE : SEP_OTHER); @@ -120,9 +121,9 @@ zsetseparationspace(i_ctx_t *i_ctx_p) if (code < 0) return code; pmap = cs.params.separation.map; - gs_cspace_init(&cs, &gs_color_space_type_Separation, NULL); + gs_cspace_init(&cs, &gs_color_space_type_Separation, mem, false); cs.params.separation.sep_type = sep_type; - cs.params.separation.sep_name = name_index(&sname); + cs.params.separation.sep_name = name_index(mem, &sname); cs.params.separation.get_colorname_string = gs_get_colorname_string; istate->colorspace.procs.special.separation.layer_name = pcsa[0]; istate->colorspace.procs.special.separation.tint_transform = pcsa[2]; diff --git a/gs/src/zdevice.c b/gs/src/zdevice.c index b3317adc8..fd06156e1 100644 --- a/gs/src/zdevice.c +++ b/gs/src/zdevice.c @@ -287,7 +287,7 @@ zmakewordimagedevice(i_ctx_t *i_ctx_p) colors = op1->value.bytes; colors_size = r_size(op1); } - if ((code = read_matrix(op - 4, &imat)) < 0) + if ((code = read_matrix(imemory, op - 4, &imat)) < 0) return code; /* Everything OK, create device */ code = gs_makewordimagedevice(&new_dev, &imat, diff --git a/gs/src/zdevice2.c b/gs/src/zdevice2.c index d5539a63f..691026975 100644 --- a/gs/src/zdevice2.c +++ b/gs/src/zdevice2.c @@ -254,7 +254,7 @@ restore_page_device(const gs_state * pgs_old, const gs_state * pgs_new) gx_device *dev_new; gx_device *dev_t1; gx_device *dev_t2; - bool samepagedevice = obj_eq(&gs_int_gstate(pgs_old)->pagedevice, + bool samepagedevice = obj_eq(dev_old->memory, &gs_int_gstate(pgs_old)->pagedevice, &gs_int_gstate(pgs_new)->pagedevice); if ((dev_t1 = (*dev_proc(dev_old, get_page_device)) (dev_old)) == 0) @@ -367,7 +367,7 @@ push_callout(i_ctx_t *i_ctx_p, const char *callout_name) int code; check_estack(1); - code = name_enter_string(callout_name, esp + 1); + code = name_enter_string(imemory, callout_name, esp + 1); if (code < 0) return code; ++esp; diff --git a/gs/src/zdict.c b/gs/src/zdict.c index 105384475..c4da2b479 100644 --- a/gs/src/zdict.c +++ b/gs/src/zdict.c @@ -104,7 +104,7 @@ zop_def(i_ctx_t *i_ctx_p) switch (r_type(op1)) { case t_name: { /* We can use the fast single-probe lookup here. */ - uint nidx = name_index(op1); + uint nidx = name_index(imemory, op1); uint htemp; if_dict_find_name_by_index_top(nidx, htemp, pvslot) { @@ -264,7 +264,7 @@ zcopy_dict(i_ctx_t *i_ctx_p) check_type(*op1, t_dictionary); check_dict_read(*op1); check_dict_write(*op); - if (!dict_auto_expand && + if (!imemory->gs_lib_ctx->dict_auto_expand && (dict_length(op) != 0 || dict_maxlength(op) < dict_length(op1)) ) return_error(e_rangecheck); @@ -346,7 +346,7 @@ zdictcopynew(i_ctx_t *i_ctx_p) check_type(*op, t_dictionary); check_dict_write(*op); /* This is only recognized in Level 2 mode. */ - if (!dict_auto_expand) + if (!imemory->gs_lib_ctx->dict_auto_expand) return_error(e_undefined); code = idict_copy_new(op1, op); if (code < 0) diff --git a/gs/src/zdps.c b/gs/src/zdps.c index a25b2e800..dd942cf5e 100644 --- a/gs/src/zdps.c +++ b/gs/src/zdps.c @@ -102,7 +102,7 @@ zimage2(i_ctx_t *i_ctx_p) ref *pDataSource; gs_image2_t_init(&image); - if ((code = dict_matrix_param(op, "ImageMatrix", + if ((code = dict_matrix_param(imemory, op, "ImageMatrix", &image.ImageMatrix)) < 0 || (code = dict_find_string(op, "DataSource", &pDataSource)) < 0 || (code = dict_float_param(op, "XOrigin", 0.0, @@ -205,7 +205,8 @@ zdefineusername(i_ctx_t *i_ctx_p) if (code < 0) return code; } - if (array_get(user_names_p, op[-1].value.intval, &uname) >= 0) { + if (array_get(imemory, user_names_p, + op[-1].value.intval, &uname) >= 0) { switch (r_type(&uname)) { case t_null: break; diff --git a/gs/src/zdps1.c b/gs/src/zdps1.c index ecf980404..610a7b270 100644 --- a/gs/src/zdps1.c +++ b/gs/src/zdps1.c @@ -314,7 +314,7 @@ zrectstroke(i_ctx_t *i_ctx_p) local_rects_t lr; int npop, code; - if (read_matrix(op, &mat) >= 0) { + if (read_matrix(imemory, op, &mat) >= 0) { /* Concatenate the matrix to the CTM just before stroking the path. */ npop = rect_get(&lr, op - 1, imemory); if (npop < 0) @@ -386,7 +386,7 @@ rect_get(local_rects_t * plr, os_ptr op, gs_memory_t *mem) int i; for (i = 0; i < 4; i++) { - code = num_array_get((const ref *)op, format, + code = num_array_get(mem, (const ref *)op, format, (n << 2) + i, &rnum); switch (code) { case t_integer: diff --git a/gs/src/zfapi.c b/gs/src/zfapi.c index 95c77131f..2a99c0c4d 100644 --- a/gs/src/zfapi.c +++ b/gs/src/zfapi.c @@ -129,6 +129,7 @@ private inline bool IsType1GlyphData(const gs_font_base *pbfont) typedef struct sfnts_reader_s sfnts_reader; struct sfnts_reader_s { ref *sfnts; + const gs_memory_t *memory; const byte *p; long index; uint offset; @@ -147,7 +148,7 @@ private void sfnts_next_elem(sfnts_reader *r) if (r->error) return; r->index++; - r->error |= (array_get(r->sfnts, r->index, &s) < 0); + r->error |= (array_get(r->memory, r->sfnts, r->index, &s) < 0); if (r->error) return; r->p = s.value.const_bytes; @@ -457,7 +458,7 @@ private ulong FAPI_FF_get_long(FAPI_font *ff, fapi_font_feature var_id, int inde for (k = 0; k < 2; k++) { if (dict_find_string(Private, name[k], &Subrs) > 0) for (i = r_size(Subrs) - 1; i >= 0; i--) { - array_get(Subrs, i, &v); + array_get(pfont->memory, Subrs, i, &v); size += r_size(&v) - (ff->need_decrypt ? 0 : lenIV); } } @@ -536,10 +537,11 @@ private ushort FAPI_FF_get_subr(FAPI_font *ff, int index, byte *buf, ushort buf_ */ n = (n1 < n2 ? n2 : n1); if (index < n && Subrs != NULL) { - if (array_get(Subrs, index, &subr) < 0 || r_type(&subr) != t_string) + if (array_get(ff->memory, Subrs, index, &subr) < 0 || r_type(&subr) != t_string) return 0; } else if (index >= n && GlobalSubrs != NULL) { - if (array_get(GlobalSubrs, index - n, &subr) < 0 || r_type(&subr) != t_string) + if (array_get(ff->memory, + GlobalSubrs, index - n, &subr) < 0 || r_type(&subr) != t_string) return 0; } else return 0; @@ -558,7 +560,8 @@ private bool sfnt_get_glyph_offset(ref *pdr, gs_font_type42 *pfont42, int index, return r.error; } -private int get_GlyphDirectory_data_ptr(ref *pdr, int char_code, const byte **ptr) +private int get_GlyphDirectory_data_ptr(const gs_memory_t *mem, + ref *pdr, int char_code, const byte **ptr) { ref *GlyphDirectory, glyph0, *glyph = &glyph0, glyph_index; if ((dict_find_string(pdr, "GlyphDirectory", &GlyphDirectory) > 0 && @@ -566,7 +569,7 @@ private int get_GlyphDirectory_data_ptr(ref *pdr, int char_code, const byte **pt ( make_int(&glyph_index, char_code), dict_find(GlyphDirectory, &glyph_index, &glyph) > 0))) || ((r_type(GlyphDirectory) == t_array && - array_get(GlyphDirectory, char_code, &glyph0) >= 0) && + array_get(mem, GlyphDirectory, char_code, &glyph0) >= 0) && r_type(glyph) == t_string)) { *ptr = glyph->value.const_bytes; return r_size(glyph); @@ -618,7 +621,8 @@ private ushort FAPI_FF_get_glyph(FAPI_font *ff, int char_code, byte *buf, ushort * with 'glyphshow' may render a character which has no * Encoding entry. */ - if (name_ref(ff->char_data, ff->char_data_len, &char_name, -1) < 0) + if (name_ref(ff->memory, ff->char_data, + ff->char_data_len, &char_name, -1) < 0) return -1; if (buf != NULL) { /* @@ -633,8 +637,8 @@ private ushort FAPI_FF_get_glyph(FAPI_font *ff, int char_code, byte *buf, ushort ref *StandardEncoding; if (dict_find_string(systemdict, "StandardEncoding", &StandardEncoding) <= 0 || - array_get(StandardEncoding, char_code, &char_name) < 0) - if (name_ref((const byte *)".notdef", 7, &char_name, -1) < 0) + array_get(ff->memory, StandardEncoding, char_code, &char_name) < 0) + if (name_ref(ff->memory, (const byte *)".notdef", 7, &char_name, -1) < 0) return -1; } if (dict_find_string(pdr, "CharStrings", &CharStrings) <= 0) @@ -645,7 +649,7 @@ private ushort FAPI_FF_get_glyph(FAPI_font *ff, int char_code, byte *buf, ushort } } else { /* type 42 */ const byte *data_ptr; - int l = get_GlyphDirectory_data_ptr(pdr, char_code, &data_ptr); + int l = get_GlyphDirectory_data_ptr(ff->memory, pdr, char_code, &data_ptr); if (l >= 0) { int MetricsCount = get_MetricsCount(ff), mc = MetricsCount << 1; @@ -676,6 +680,7 @@ private ushort FAPI_FF_get_glyph(FAPI_font *ff, int char_code, byte *buf, ushort private const FAPI_font ff_stub = { 0, /* server_font_data */ 0, /* need_decrypt */ + NULL, /* const gs_memory_t */ 0, /* font_file_path */ 0, /* subfont */ false, /* is_type1 */ @@ -782,6 +787,7 @@ private int FAPI_prepare_font(i_ctx_t *i_ctx_p, FAPI_server *I, ref *pdr, gs_fon subfont = SubfontId->value.intval; ff.font_file_path = font_file_path; ff.is_type1 = IsType1GlyphData(pbfont); + ff.memory = imemory; ff.client_ctx_p = i_ctx_p; ff.client_font_data = pbfont; ff.client_font_data2 = pdr; @@ -816,13 +822,14 @@ private int FAPI_prepare_font(i_ctx_t *i_ctx_p, FAPI_server *I, ref *pdr, gs_fon return_error(e_invalidfont); ff = ff_stub; ff.is_type1 = true; + ff.memory = imemory; ff.client_ctx_p = i_ctx_p; for (i = 0; i < n; i++) { gs_font_type1 *pbfont1 = FDArray[i]; int BBox_temp[4]; pbfont1->FontBBox = pbfont->FontBBox; /* Inherit FontBBox from the type 9 font. */ - if(array_get(rFDArray, i, &f) < 0 || r_type(&f) != t_dictionary) + if(array_get(imemory, rFDArray, i, &f) < 0 || r_type(&f) != t_dictionary) return_error(e_invalidfont); ff.client_font_data = pbfont1; pbfont1->FAPI = pbfont->FAPI; @@ -932,17 +939,19 @@ private int FAPI_refine_font(i_ctx_t *i_ctx_p, os_ptr op, gs_font_base *pbfont, return_error(e_invalidfont); ordering_length = min(r_size(Ordering), sizeof(buf) - 2 - decodingID_length); memcpy(buf, Ordering->value.const_bytes, ordering_length); - if ((code = name_ref(buf, ordering_length, &SubstNWP, 0)) < 0) + if ((code = name_ref(imemory, buf, ordering_length, &SubstNWP, 0)) < 0) return code; if ((code = dict_put_string(pdr, "SubstNWP", &SubstNWP, NULL)) < 0) return code; buf[ordering_length] = '.'; memcpy(buf + ordering_length + 1, decodingID, decodingID_length); buf[decodingID_length + 1 + ordering_length] = 0; /* Debug purpose only */ - if ((code = name_ref(buf, decodingID_length + 1 + ordering_length, &Decoding, 0)) < 0) + if ((code = name_ref(imemory, buf, + decodingID_length + 1 + ordering_length, &Decoding, 0)) < 0) return code; } else - if ((code = name_ref((const byte *)decodingID, strlen(decodingID), &Decoding, 0)) < 0) + if ((code = name_ref(imemory, (const byte *)decodingID, + strlen(decodingID), &Decoding, 0)) < 0) return code; if ((code = dict_put_string(pdr, "Decoding", &Decoding, NULL)) < 0) return code; @@ -996,7 +1005,7 @@ private int zFAPIrebuildfont(i_ctx_t *i_ctx_p) } else { if (dict_find_string(op - 1, "FAPI", &v) <= 0 || !r_has_type(v, t_name)) return_error(e_invalidfont); - obj_string_data(v, &pchars, &len); + obj_string_data(imemory, v, &pchars, &len); len = min(len, sizeof(FAPI_ID) - 1); strncpy(FAPI_ID, (const char *)pchars, len); FAPI_ID[len] = 0; @@ -1007,12 +1016,12 @@ private int zFAPIrebuildfont(i_ctx_t *i_ctx_p) if (dict_find_string(op - 1, "Path", &v) <= 0 || !r_has_type(v, t_string)) v = NULL; if (pfont->FontType == ft_CID_encrypted && v == NULL) { - if ((code = build_proc_name_refs(&build, ".FAPIBuildGlyph9", ".FAPIBuildGlyph9")) < 0) + if ((code = build_proc_name_refs(imemory, &build, ".FAPIBuildGlyph9", ".FAPIBuildGlyph9")) < 0) return code; } else - if ((code = build_proc_name_refs(&build, ".FAPIBuildChar", ".FAPIBuildGlyph")) < 0) + if ((code = build_proc_name_refs(imemory, &build, ".FAPIBuildChar", ".FAPIBuildGlyph")) < 0) return code; - if (name_index(&pdata->BuildChar) == name_index(&build.BuildChar)) { + if (name_index(imemory, &pdata->BuildChar) == name_index(imemory, &build.BuildChar)) { /* Already rebuilt - maybe a substituted font. */ } else { ref_assign_new(&pdata->BuildChar, &build.BuildChar); @@ -1029,11 +1038,11 @@ private int zFAPIrebuildfont(i_ctx_t *i_ctx_p) return code; } -private ulong array_find(ref *Encoding, ref *char_name) { +private ulong array_find(const gs_memory_t *mem, ref *Encoding, ref *char_name) { ulong n = r_size(Encoding), i; ref v; for (i = 0; i < n; i++) - if (array_get(Encoding, i, &v) < 0) + if (array_get(mem, Encoding, i, &v) < 0) break; else if(r_type(char_name) == r_type(&v) && char_name->value.const_pname == v.value.const_pname) return i; @@ -1295,8 +1304,8 @@ retry_oversampling: int_param(op, 0xFF, &client_char_code); if (dict_find_string(pdr, "Encoding", &Encoding) > 0 && (r_has_type(Encoding, t_array) || r_has_type(Encoding, t_shortarray))) { - if (array_get(Encoding, client_char_code, &char_name) < 0) - if ((code = name_ref((const byte *)".notdef", 7, &char_name, -1)) < 0) + if (array_get(imemory, Encoding, client_char_code, &char_name) < 0) + if ((code = name_ref(imemory, (const byte *)".notdef", 7, &char_name, -1)) < 0) return code; } else return_error(e_invalidfont); @@ -1314,7 +1323,7 @@ retry_oversampling: if (dict_find_string(pdr, "SubstNWP", &SubstNWP) <= 0 || !r_has_type(SubstNWP, t_array)) return_error(e_invalidfont); - code = cid_to_TT_charcode(Decoding, NULL, SubstNWP, + code = cid_to_TT_charcode(imemory, Decoding, NULL, SubstNWP, client_char_code, &c, &src_type, &dst_type); if (code < 0) return code; @@ -1333,7 +1342,7 @@ retry_oversampling: return_error(e_invalidfont); if (dict_find(CharStrings, &char_name, &glyph_index) < 0) { cr.char_code = 0; /* .notdef */ - if ((code = name_ref((const byte *)".notdef", 7, &char_name, -1)) < 0) + if ((code = name_ref(imemory, (const byte *)".notdef", 7, &char_name, -1)) < 0) return code; } else if (r_has_type(glyph_index, t_integer)) cr.char_code = glyph_index->value.intval; @@ -1359,13 +1368,13 @@ retry_oversampling: */ ref *Encoding; if (dict_find_string(osp - 1, "Encoding", &Encoding) > 0) - cr.char_code = (uint)array_find(Encoding, op); + cr.char_code = (uint)array_find(imemory, Encoding, op); else return_error(e_invalidfont); } } else { /* a non-embedded font, i.e. a disk font */ bool can_retrieve_char_by_name = false; - obj_string_data(&char_name, &cr.char_name, &cr.char_name_length); + obj_string_data(imemory, &char_name, &cr.char_name, &cr.char_name_length); if ((code = renderer_retcode(i_ctx_p, I, I->can_retrieve_char_by_name(I, &ff, &cr, &can_retrieve_char_by_name))) < 0) return code; if (!can_retrieve_char_by_name) { @@ -1381,7 +1390,7 @@ retry_oversampling: /* Provide glyph data for renderer : */ if (!ff.is_cid) { ref sname; - name_string_ref(&char_name, &sname); + name_string_ref(imemory, &char_name, &sname); ff.char_data = sname.value.const_bytes; ff.char_data_len = r_size(&sname); } else if (ff.is_type1) @@ -1395,7 +1404,7 @@ retry_oversampling: if (MetricsCount > 0) { const byte *data_ptr; - int l = get_GlyphDirectory_data_ptr(pdr, cr.char_code, &data_ptr); + int l = get_GlyphDirectory_data_ptr(imemory, pdr, cr.char_code, &data_ptr); if (MetricsCount == 2 && l >= 4) { if (!bVertical0) { @@ -1613,7 +1622,7 @@ private int FAPIBuildGlyph9aux(i_ctx_t *i_ctx_p) font_index = op[0].value.intval; if (dict_find_string(&font9, "FDArray", &rFDArray) <= 0 || r_type(rFDArray) != t_array) return_error(e_invalidfont); - if(array_get(rFDArray, font_index, &f) < 0 || r_type(&f) != t_dictionary) + if(array_get(imemory, rFDArray, font_index, &f) < 0 || r_type(&f) != t_dictionary) return_error(e_invalidfont); op[0] = op[-2]; op[-2] = op[-1]; /* Keep the charstring on ostack for the garbager. */ @@ -1702,7 +1711,7 @@ private int do_FAPIpassfont(i_ctx_t *i_ctx_p, char *font_file_path, bool *succes continue; } pbfont->FAPI = I; /* We found a good renderer, so go with it */ - if ((code = name_ref((const byte *)I->ig.d->subtype, strlen(I->ig.d->subtype), &FAPI_ID, false)) < 0) + if ((code = name_ref(imemory, (const byte *)I->ig.d->subtype, strlen(I->ig.d->subtype), &FAPI_ID, false)) < 0) return code; if ((code = dict_put_string(pdr, "FAPI", &FAPI_ID, NULL)) < 0) return code; /* Insert FAPI entry to font dictionary. */ diff --git a/gs/src/zfcid0.c b/gs/src/zfcid0.c index 32c631ba6..54a35d4b5 100644 --- a/gs/src/zfcid0.c +++ b/gs/src/zfcid0.c @@ -99,7 +99,7 @@ cid0_read_bytes(gs_font_cid0 *pfont, ulong base, uint count, byte *buf, uint size; for (;; skip -= size, ++index) { - int code = array_get(pgdata, index, &rstr); + int code = array_get(pfont->memory, pgdata, index, &rstr); if (code < 0) return code; @@ -123,7 +123,7 @@ cid0_read_bytes(gs_font_cid0 *pfont, ulong base, uint count, byte *buf, memcpy(data, rstr.value.bytes + skip, size); copied = size; while (copied < count) { - int code = array_get(pgdata, ++index, &rstr); + int code = array_get(pfont->memory, pgdata, ++index, &rstr); if (code < 0) goto err; @@ -181,7 +181,8 @@ z9_glyph_data(gs_font_base *pbfont, gs_glyph glyph, gs_glyph_data_t *pgd, int code; if (!r_has_type(&pfdata->u.cid0.GlyphDirectory, t_null)) { - code = font_gdir_get_outline(&pfdata->u.cid0.GlyphDirectory, + code = font_gdir_get_outline(pfont->memory, + &pfdata->u.cid0.GlyphDirectory, glyph_index, &gdata); if (code < 0) return code; @@ -259,7 +260,7 @@ z9_glyph_outline(gs_font *font, int WMode, gs_glyph glyph, const gs_matrix *pmat &fidx); if (code < 0) return code; - glyph_ref(glyph, &gref); + glyph_ref(font->memory, glyph, &gref); ocode = zcharstring_outline(pfcid->cidata.FDArray[fidx], WMode, &gref, &gdata, pmat, ppath); gs_glyph_data_free(&gdata, "z9_glyph_outline"); @@ -316,20 +317,20 @@ fd_array_element(i_ctx_t *i_ctx_p, gs_font_type1 **ppfont, ref *prfd) data1.interpret = gs_type1_interpret; data1.subroutineNumberBias = 0; data1.lenIV = DEFAULT_LENIV_1; - code = charstring_font_params(prfd, &refs, &data1); + code = charstring_font_params(imemory, prfd, &refs, &data1); if (code < 0) return code; - code = build_proc_name_refs(&build, + code = build_proc_name_refs(imemory, &build, "%Type1BuildChar", "%Type1BuildGlyph"); break; case 2: code = type2_font_params(prfd, &refs, &data1); if (code < 0) return code; - code = charstring_font_params(prfd, &refs, &data1); + code = charstring_font_params(imemory, prfd, &refs, &data1); if (code < 0) return code; - code = build_proc_name_refs(&build, + code = build_proc_name_refs(imemory, &build, "%Type2BuildChar", "%Type2BuildGlyph"); break; default: /* can't happen */ @@ -357,7 +358,7 @@ zbuildfont9(i_ctx_t *i_ctx_p) { os_ptr op = osp; build_proc_refs build; - int code = build_proc_name_refs(&build, NULL, "%Type9BuildGlyph"); + int code = build_proc_name_refs(imemory, &build, NULL, "%Type9BuildGlyph"); gs_font_cid_data common; ref GlyphDirectory, GlyphData, DataSource; ref *prfda, cfnstr, *CIDFontName; @@ -423,7 +424,7 @@ zbuildfont9(i_ctx_t *i_ctx_p) for (i = 0; i < FDArray_size; ++i) { ref rfd; - array_get(prfda, (long)i, &rfd); + array_get(imemory, prfda, (long)i, &rfd); code = fd_array_element(i_ctx_p, &FDArray[i], &rfd); if (code < 0) goto fail; @@ -444,7 +445,7 @@ zbuildfont9(i_ctx_t *i_ctx_p) pfcid->cidata.FDBytes = FDBytes; pfcid->cidata.glyph_data = z9_glyph_data; pfcid->cidata.proc_data = 0; /* for GC */ - get_font_name(&cfnstr, CIDFontName); + get_font_name(imemory, &cfnstr, CIDFontName); copy_font_name(&pfcid->font_name, &cfnstr); ref_assign(&pfont_data(pfont)->u.cid0.GlyphDirectory, &GlyphDirectory); ref_assign(&pfont_data(pfont)->u.cid0.GlyphData, &GlyphData); diff --git a/gs/src/zfcid1.c b/gs/src/zfcid1.c index e3e3b8936..38c3d300b 100644 --- a/gs/src/zfcid1.c +++ b/gs/src/zfcid1.c @@ -97,7 +97,7 @@ z11_CIDMap_proc(gs_font_cid2 *pfont, gs_glyph glyph) return_error(e_typecheck); return prgnum->value.intval; default: /* array type */ - code = string_array_access_proc(pcidmap, 1, cid * gdbytes, + code = string_array_access_proc(pfont->memory, pcidmap, 1, cid * gdbytes, gdbytes, &data); if (code < 0) @@ -282,7 +282,7 @@ zbuildfont11(i_ctx_t *i_ctx_p) if (code <= 0 || r_type(a) != t_array) return_error(e_invalidfont); for (j = 0; j < 2; j++) { - code = array_get(a, j, &v); + code = array_get(imemory, a, j, &v); if (code < 0 || r_type(&v) != t_integer) return_error(e_invalidfont); loca_glyph_pos[i][j] = v.value.intval; @@ -291,7 +291,7 @@ zbuildfont11(i_ctx_t *i_ctx_p) } else file = NULL; - code = font_string_array_param(op, "CIDMap", &rcidmap); + code = font_string_array_param(imemory, op, "CIDMap", &rcidmap); switch (code) { case 0: /* in PLRM3 */ gdb: @@ -330,7 +330,7 @@ zbuildfont11(i_ctx_t *i_ctx_p) pfont->procs.glyph_info = z11_glyph_info; pfont->procs.glyph_outline = z11_glyph_outline; pfont->data.get_glyph_index = z11_get_glyph_index; - get_font_name(&cfnstr, CIDFontName); + get_font_name(imemory, &cfnstr, CIDFontName); copy_font_name(&pfcid->font_name, &cfnstr); if (MetricsCount) { /* "Wrap" the glyph accessor procedures. */ @@ -403,7 +403,7 @@ zfillCIDMap(i_ctx_t *i_ctx_p) check_type(*SubstNWP, t_array); check_type(*GDBytes, t_integer); check_type(*CIDMap, t_array); - code = cid_fill_CIDMap(Decoding, TT_cmap, SubstNWP, GDBytes->value.intval, CIDMap); + code = cid_fill_CIDMap(imemory, Decoding, TT_cmap, SubstNWP, GDBytes->value.intval, CIDMap); pop(5); return code; } diff --git a/gs/src/zfcmap.c b/gs/src/zfcmap.c index 63484f157..622df4660 100644 --- a/gs/src/zfcmap.c +++ b/gs/src/zfcmap.c @@ -82,8 +82,8 @@ acquire_code_ranges(gs_cmap_adobe1_t *cmap, const ref *pref, gs_memory_t *mem) ref rfirst, rlast; int size; - array_get(pref, i * 2L, &rfirst); - array_get(pref, i * 2L + 1, &rlast); + array_get(mem, pref, i * 2L, &rfirst); + array_get(mem, pref, i * 2L + 1, &rlast); if (!r_has_type(&rfirst, t_string) || !r_has_type(&rlast, t_string) || (size = r_size(&rfirst)) == 0 || size > MAX_CMAP_CODE_SIZE || @@ -120,11 +120,11 @@ acquire_code_map(gx_code_map_t *pcmap, const ref *pref, gs_cmap_adobe1_t *root, for (i = 0; i < num_lookup * 5; i += 5, ++pclr) { ref rprefix, rmisc, rkeys, rvalues, rfxs; - array_get(pref, i, &rprefix); - array_get(pref, i + 1, &rmisc); - array_get(pref, i + 2, &rkeys); - array_get(pref, i + 3, &rvalues); - array_get(pref, i + 4, &rfxs); + array_get(mem, pref, i, &rprefix); + array_get(mem, pref, i + 1, &rmisc); + array_get(mem, pref, i + 2, &rkeys); + array_get(mem, pref, i + 3, &rvalues); + array_get(mem, pref, i + 4, &rfxs); if (!r_has_type(&rprefix, t_string) || !r_has_type(&rmisc, t_string) || @@ -188,10 +188,10 @@ acquire_code_map(gx_code_map_t *pcmap, const ref *pref, gs_cmap_adobe1_t *root, gs_glyph value; int i; - array_get(&rvalues, k, &rvalue); + array_get(mem, &rvalues, k, &rvalue); if (!r_has_type(&rvalue, t_name)) return_error(e_rangecheck); - value = name_index(&rvalue); + value = name_index(mem, &rvalue); /* * We need a special check here because some CPUs cannot * shift by the full size of an int or long. @@ -238,10 +238,10 @@ acquire_cid_system_info(ref *psia, const ref *op) * null, return 1. */ private int -get_cid_system_info(gs_cid_system_info_t *pcidsi, const ref *psia, uint index) +get_cid_system_info(const gs_memory_t *mem, gs_cid_system_info_t *pcidsi, const ref *psia, uint index) { ref rcidsi; - int code = array_get(psia, (long)index, &rcidsi); + int code = array_get(mem, psia, (long)index, &rcidsi); if (code < 0 || r_has_type(&rcidsi, t_null)) { cid_system_info_set_null(pcidsi); @@ -301,7 +301,7 @@ ztype0_get_cmap(const gs_cmap_t **ppcmap, const ref *pfdepvector, for (i = 0; i < num_fonts; ++i) { ref rfdep, rfsi; - array_get(pfdepvector, (long)i, &rfdep); + array_get(imem, pfdepvector, (long)i, &rfdep); code = acquire_cid_system_info(&rfsi, &rfdep); if (code < 0) return code; @@ -338,15 +338,16 @@ ztype0_get_cmap(const gs_cmap_t **ppcmap, const ref *pfdepvector, * For details, see lib/gs_cmap.ps and the Adobe documentation. */ private int -zfcmap_glyph_name(gs_glyph glyph, gs_const_string *pstr, void *proc_data) +zfcmap_glyph_name(const gs_memory_t *mem, + gs_glyph glyph, gs_const_string *pstr, void *proc_data) { ref nref, nsref; int code = 0; - /*code = */name_index_ref((uint)glyph, &nref); + /*code = */name_index_ref(mem, (uint)glyph, &nref); if (code < 0) return code; - name_string_ref(&nref, &nsref); + name_string_ref(mem, &nref, &nsref); pstr->data = nsref.value.const_bytes; pstr->size = r_size(&nsref); return 0; @@ -375,7 +376,7 @@ zbuildcmap(i_ctx_t *i_ctx_p) code = gs_note_error(e_typecheck); goto fail; } - name_string_ref(pcmapname, &rname); + name_string_ref(imemory, pcmapname, &rname); if (dict_find_string(op, ".CodeMapData", &pcodemapdata) <= 0 || !r_has_type(pcodemapdata, t_array) || r_size(pcodemapdata) != 3 || @@ -405,13 +406,13 @@ zbuildcmap(i_ctx_t *i_ctx_p) pcmap->UIDOffset = puidoffset->value.intval; /* long, not int */ } for (i = 0; i < r_size(&rcidsi); ++i) { - code = get_cid_system_info(pcmap->CIDSystemInfo + i, &rcidsi, i); + code = get_cid_system_info(imemory, pcmap->CIDSystemInfo + i, &rcidsi, i); if (code < 0) goto fail; } - array_get(pcodemapdata, 0L, &rcoderanges); - array_get(pcodemapdata, 1L, &rdefs); - array_get(pcodemapdata, 2L, &rnotdefs); + array_get(imemory, pcodemapdata, 0L, &rcoderanges); + array_get(imemory, pcodemapdata, 1L, &rdefs); + array_get(imemory, pcodemapdata, 2L, &rnotdefs); if ((code = acquire_code_ranges(pcmap, &rcoderanges, imemory)) < 0) goto fail; if ((code = acquire_code_map(&pcmap->def, &rdefs, pcmap, imemory)) < 0) diff --git a/gs/src/zfile.c b/gs/src/zfile.c index 6a1defd16..4d8f07026 100644 --- a/gs/src/zfile.c +++ b/gs/src/zfile.c @@ -170,7 +170,7 @@ check_file_permissions_reduced(i_ctx_t *i_ctx_p, const char *fname, int len, uint permlen; int cwd_len = 0; - if (array_get(permitlist, i, &permitstring) < 0 || + if (array_get(imemory, permitlist, i, &permitstring) < 0 || r_type(&permitstring) != t_string ) break; /* any problem, just fail */ @@ -302,7 +302,7 @@ file_is_tempfile(i_ctx_t *i_ctx_p, const ref *op) if (dict_find_string(systemdict, "SAFETY", &SAFETY) <= 0 || dict_find_string(SAFETY, "tempfiles", &tempfiles) <= 0) return false; - if (name_ref(op->value.bytes, r_size(op), &kname, -1) < 0 || + if (name_ref(imemory, op->value.bytes, r_size(op), &kname, -1) < 0 || dict_find(tempfiles, &kname, &SAFETY) <= 0) return false; return true; @@ -633,7 +633,7 @@ zlibfile(i_ctx_t *i_ctx_p) } else { ref fref; - code = lib_file_open(i_ctx_p, pname.fname, pname.len, cname, MAX_CNAME, + code = lib_file_open(i_ctx_p->lib_path, i_ctx_p, pname.fname, pname.len, cname, MAX_CNAME, &clen, &fref, imemory); if (code >= 0) { s = fptr(&fref); @@ -951,10 +951,15 @@ check_file_permissions_aux(i_ctx_t *i_ctx_p, char *fname, uint flen) /* The startup code calls this to open @-files. */ private int -lib_fopen_with_libpath(i_ctx_t *i_ctx_p, gx_io_device *iodev, - const char *fname, uint flen, char fmode[4], char *buffer, int blen, - FILE **file) -{ /* i_ctx_p is NULL running init files. */ +lib_fopen_with_libpath(gs_file_path_ptr lib_path, + const gs_memory_t *mem, + i_ctx_t *i_ctx_p, + gx_io_device *iodev, + const char *fname, uint flen, char fmode[4], char *buffer, int blen, + FILE **file) +{ /* i_ctx_p is NULL running init files. + * lib_path and mem are never NULL + */ bool starting_arg_file = false; bool search_with_no_combine = false; bool search_with_combine = false; @@ -989,7 +994,7 @@ lib_fopen_with_libpath(i_ctx_t *i_ctx_p, gx_io_device *iodev, skip:; } if (search_with_combine) { - const gs_file_path *pfpath = &gs_lib_path; + const gs_file_path *pfpath = lib_path; uint pi; for (pi = 0; pi < r_size(&pfpath->list); ++pi) { @@ -1018,7 +1023,7 @@ lib_fopen_with_libpath(i_ctx_t *i_ctx_p, gx_io_device *iodev, /* The startup code calls this to open @-files. */ FILE * -lib_fopen(const char *fname) +lib_fopen(const gs_file_path_ptr pfpath, const gs_memory_t *mem, const char *fname) { /* We need a buffer to hold the expanded file name. */ char buffer[gp_file_name_sizeof]; @@ -1029,7 +1034,7 @@ lib_fopen(const char *fname) FILE *file = NULL; strcat(fmode, gp_fmode_binary_suffix); - lib_fopen_with_libpath(NULL, &iodev_default_copy, fname, strlen(fname), + lib_fopen_with_libpath(pfpath, mem, NULL, &iodev_default_copy, fname, strlen(fname), fmode, buffer, sizeof(buffer), &file); return file; } @@ -1038,7 +1043,8 @@ lib_fopen(const char *fname) /* using the search paths. */ /* The startup code calls this to open the initialization file gs_init.ps. */ int -lib_file_open(i_ctx_t *i_ctx_p, const char *fname, uint len, byte * cname, uint max_clen, +lib_file_open(const gs_file_path_ptr pfpath, + i_ctx_t *i_ctx_p, const char *fname, uint len, byte * cname, uint max_clen, uint * pclen, ref * pfile, gs_memory_t *mem) { /* i_ctx_p is NULL running init files. */ stream *s; @@ -1056,7 +1062,8 @@ lib_file_open(i_ctx_t *i_ctx_p, const char *fname, uint len, byte * cname, uint if (fname == 0) return 0; buffer = (char *)s->cbuf; - code = lib_fopen_with_libpath(i_ctx_p, iodev, fname, len, fmode, buffer, s->bsize, &file); + code = lib_fopen_with_libpath(pfpath, mem, i_ctx_p, + iodev, fname, len, fmode, buffer, s->bsize, &file); if (code < 0) { s->cbuf = NULL; s->bsize = s->cbsize = 0; diff --git a/gs/src/zfileio.c b/gs/src/zfileio.c index cff3d4e64..152ca0efb 100644 --- a/gs/src/zfileio.c +++ b/gs/src/zfileio.c @@ -762,7 +762,7 @@ zwritecvp_at(i_ctx_t *i_ctx_p, os_ptr op, uint start, bool first) code = obj_cvp(op - 1, str, sizeof(str), &len, (int)op->value.intval, start, imemory); if (code == e_rangecheck) { - code = obj_string_data(op - 1, &data, &len); + code = obj_string_data(imemory, op - 1, &data, &len); if (len < start) return_error(e_rangecheck); data += start; diff --git a/gs/src/zfont.c b/gs/src/zfont.c index d21ce63db..635995b9c 100644 --- a/gs/src/zfont.c +++ b/gs/src/zfont.c @@ -42,22 +42,22 @@ gs_font_dir *ifont_dir = 0; /* needed for buildfont */ /* Mark a glyph as a PostScript name (if it isn't a CID). */ bool -zfont_mark_glyph_name(gs_glyph glyph, void *ignore_data) +zfont_mark_glyph_name(const gs_memory_t *mem, gs_glyph glyph, void *ignore_data) { return (glyph >= gs_min_cid_glyph || glyph == gs_no_glyph ? false : - name_mark_index((uint) glyph)); + name_mark_index(mem, (uint) glyph)); } /* Get a global glyph code. */ private int -zfont_global_glyph_code(gs_const_string *gstr, gs_glyph *pglyph) +zfont_global_glyph_code(const gs_memory_t *mem, gs_const_string *gstr, gs_glyph *pglyph) { ref v; - int code = name_ref(gstr->data, gstr->size, &v, 0); + int code = name_ref(mem, gstr->data, gstr->size, &v, 0); if (code < 0) return code; - *pglyph = (gs_glyph)name_index(&v); + *pglyph = (gs_glyph)name_index(mem, &v); return 0; } @@ -65,7 +65,7 @@ zfont_global_glyph_code(gs_const_string *gstr, gs_glyph *pglyph) private int zfont_init(i_ctx_t *i_ctx_p) { - ifont_dir = gs_font_dir_alloc2(imemory, &gs_memory_default); + ifont_dir = gs_font_dir_alloc2(imemory, imemory->non_gc_memory); ifont_dir->ccache.mark_glyph = zfont_mark_glyph_name; ifont_dir->global_glyph_code = zfont_global_glyph_code; return gs_register_struct_root(imemory, NULL, (void **)&ifont_dir, @@ -96,7 +96,7 @@ zmakefont(i_ctx_t *i_ctx_p) int code; gs_matrix mat; - if ((code = read_matrix(op, &mat)) < 0) + if ((code = read_matrix(imemory, op, &mat)) < 0) return code; return make_font(i_ctx_p, &mat); } @@ -265,7 +265,7 @@ font_param(const ref * pfdict, gs_font ** ppfont) return_error(e_invalidfont); pfont = r_ptr(pid, gs_font); pdata = pfont->client_data; - if (!obj_eq(&pdata->dict, pfdict)) + if (!obj_eq(pfont->memory, &pdata->dict, pfdict)) return_error(e_invalidfont); *ppfont = pfont; if (pfont == 0) @@ -331,7 +331,7 @@ make_font(i_ctx_t *i_ctx_p, const gs_matrix * pmat) * font_data of the new font was simply copied from the old one. */ if (pencoding != 0 && - !obj_eq(pencoding, &pfont_data(newfont)->Encoding) + !obj_eq(imemory, pencoding, &pfont_data(newfont)->Encoding) ) { if (newfont->FontType == ft_composite) return_error(e_rangecheck); @@ -408,7 +408,7 @@ zdefault_make_font(gs_font_dir * pdir, const gs_font * oldfont, ref *ppsm; if (!(dict_find_string(fp, "ScaleMatrix", &ppsm) > 0 && - read_matrix(ppsm, &prev_scale) >= 0 && + read_matrix(mem, ppsm, &prev_scale) >= 0 && gs_matrix_multiply(pmat, &prev_scale, &scale) >= 0) ) scale = *pmat; @@ -444,9 +444,9 @@ make_uint_array(register os_ptr op, const uint * intp, int count) /* Remove scaled font and character cache entries that would be */ /* invalidated by a restore. */ private bool -purge_if_name_removed(cached_char * cc, void *vsave) +purge_if_name_removed(const gs_memory_t *mem, cached_char * cc, void *vsave) { - return alloc_name_index_is_since_save(cc->code, vsave); + return alloc_name_index_is_since_save(mem, cc->code, vsave); } /* Remove entries from font and character caches. */ diff --git a/gs/src/zfont0.c b/gs/src/zfont0.c index bd64b33fc..5d79f10a1 100644 --- a/gs/src/zfont0.c +++ b/gs/src/zfont0.c @@ -91,7 +91,7 @@ zbuildfont0(i_ctx_t *i_ctx_p) ref fdep; gs_font *psub; - array_get(&fdepvector, i, &fdep); + array_get(imemory, &fdepvector, i, &fdep); if ((code = font_param(&fdep, &psub)) < 0) return code; /* @@ -165,7 +165,7 @@ zbuildfont0(i_ctx_t *i_ctx_p) { build_proc_refs build; - code = build_proc_name_refs(&build, + code = build_proc_name_refs(imemory, &build, "%Type0BuildChar", "%Type0BuildGlyph"); if (code < 0) return code; @@ -202,7 +202,7 @@ zbuildfont0(i_ctx_t *i_ctx_p) for (i = 0; i < data.encoding_size; i++) { ref enc; - array_get(&pdata->Encoding, i, &enc); + array_get(imemory, &pdata->Encoding, i, &enc); if (!r_has_type(&enc, t_integer)) { code = gs_note_error(e_typecheck); goto fail; @@ -225,7 +225,7 @@ zbuildfont0(i_ctx_t *i_ctx_p) ref fdep; ref *pfid; - array_get(&fdepvector, i, &fdep); + array_get(pfont->memory, &fdepvector, i, &fdep); /* The lookup can't fail, because of the pre-check above. */ dict_find_string(&fdep, "FID", &pfid); data.FDepVector[i] = r_ptr(pfid, gs_font); @@ -239,7 +239,7 @@ fail: if (r_has_type(&save_FID, t_null)) { ref rnfid; - name_enter_string("FID", &rnfid); + name_enter_string(pfont->memory, "FID", &rnfid); idict_undef(op, &rnfid); } else idict_put_string(op, "FID", &save_FID); diff --git a/gs/src/zfont1.c b/gs/src/zfont1.c index ba2e2c6b5..032b80bbf 100644 --- a/gs/src/zfont1.c +++ b/gs/src/zfont1.c @@ -62,7 +62,7 @@ z1_enumerate_glyph(gs_font * pfont, int *pindex, gs_glyph_space_t ignored, const gs_font_type1 *const pfont1 = (gs_font_type1 *)pfont; const ref *pcsdict = &pfont_data(pfont1)->CharStrings; - return zchar_enumerate_glyph(pcsdict, pindex, pglyph); + return zchar_enumerate_glyph(pfont->memory, pcsdict, pindex, pglyph); } /* ------ Public procedures ------ */ @@ -93,7 +93,8 @@ charstring_font_get_refs(const_os_ptr op, charstring_font_refs_t *pfr) /* Get the parameters of a CharString-based font or a FDArray entry. */ int -charstring_font_params(const_os_ptr op, charstring_font_refs_t *pfr, +charstring_font_params(const gs_memory_t *mem, + const_os_ptr op, charstring_font_refs_t *pfr, gs_type1_data *pdata1) { const ref *pprivate = pfr->Private; @@ -112,15 +113,15 @@ charstring_font_params(const_os_ptr op, charstring_font_refs_t *pfr, (code = dict_float_param(pprivate, "BlueShift", 7.0, &pdata1->BlueShift)) < 0 || (code = pdata1->BlueValues.count = - dict_float_array_param(pprivate, "BlueValues", max_BlueValues * 2, + dict_float_array_param(mem, pprivate, "BlueValues", max_BlueValues * 2, &pdata1->BlueValues.values[0], NULL)) < 0 || (code = dict_float_param(pprivate, "ExpansionFactor", 0.06, &pdata1->ExpansionFactor)) < 0 || (code = pdata1->FamilyBlues.count = - dict_float_array_param(pprivate, "FamilyBlues", max_FamilyBlues * 2, + dict_float_array_param(mem, pprivate, "FamilyBlues", max_FamilyBlues * 2, &pdata1->FamilyBlues.values[0], NULL)) < 0 || (code = pdata1->FamilyOtherBlues.count = - dict_float_array_param(pprivate, + dict_float_array_param(mem, pprivate, "FamilyOtherBlues", max_FamilyOtherBlues * 2, &pdata1->FamilyOtherBlues.values[0], NULL)) < 0 || (code = dict_bool_param(pprivate, "ForceBold", false, @@ -132,27 +133,27 @@ charstring_font_params(const_os_ptr op, charstring_font_refs_t *pfr, (code = dict_int_param(pprivate, "LanguageGroup", min_int, max_int, 0, &pdata1->LanguageGroup)) < 0 || (code = pdata1->OtherBlues.count = - dict_float_array_param(pprivate, "OtherBlues", max_OtherBlues * 2, + dict_float_array_param(mem, pprivate, "OtherBlues", max_OtherBlues * 2, &pdata1->OtherBlues.values[0], NULL)) < 0 || (code = dict_bool_param(pprivate, "RndStemUp", true, &pdata1->RndStemUp)) < 0 || (code = pdata1->StdHW.count = - dict_float_array_check_param(pprivate, "StdHW", 1, + dict_float_array_check_param(mem, pprivate, "StdHW", 1, &pdata1->StdHW.values[0], NULL, 0, e_rangecheck)) < 0 || (code = pdata1->StdVW.count = - dict_float_array_check_param(pprivate, "StdVW", 1, + dict_float_array_check_param(mem, pprivate, "StdVW", 1, &pdata1->StdVW.values[0], NULL, 0, e_rangecheck)) < 0 || (code = pdata1->StemSnapH.count = - dict_float_array_param(pprivate, "StemSnapH", max_StemSnap, + dict_float_array_param(mem, pprivate, "StemSnapH", max_StemSnap, &pdata1->StemSnapH.values[0], NULL)) < 0 || (code = pdata1->StemSnapV.count = - dict_float_array_param(pprivate, "StemSnapV", max_StemSnap, + dict_float_array_param(mem, pprivate, "StemSnapV", max_StemSnap, &pdata1->StemSnapV.values[0], NULL)) < 0 || /* The WeightVector is in the font dictionary, not Private. */ (code = pdata1->WeightVector.count = - dict_float_array_param(op, "WeightVector", max_WeightVector, + dict_float_array_param(mem, op, "WeightVector", max_WeightVector, pdata1->WeightVector.values, NULL)) < 0 ) return code; @@ -218,7 +219,7 @@ build_charstring_font(i_ctx_t *i_ctx_p, os_ptr op, build_proc_refs *pbuild, font_type ftype, charstring_font_refs_t *pfr, gs_type1_data *pdata1, build_font_options_t options) { - int code = charstring_font_params(op, pfr, pdata1); + int code = charstring_font_params(imemory, op, pfr, pdata1); gs_font_type1 *pfont; if (code < 0) @@ -259,7 +260,7 @@ zbuildfont1(i_ctx_t *i_ctx_p) { os_ptr op = osp; build_proc_refs build; - int code = build_proc_name_refs(&build, + int code = build_proc_name_refs(imemory, &build, "%Type1BuildChar", "%Type1BuildGlyph"); if (code < 0) @@ -302,9 +303,10 @@ same_font_dict(const font_data *pdata, const font_data *podata, bool present = dict_find_string(&pdata->dict, key, &pvalue) > 0; ref *povalue; bool opresent = dict_find_string(&podata->dict, key, &povalue) > 0; + dict *pdict = (&(podata->dict))->value.pdict; return (present == opresent && - (present <= 0 || obj_eq(pvalue, povalue))); + (present <= 0 || obj_eq(dict_mem(pdict), pvalue, povalue))); } private int z1_same_font(const gs_font *font, const gs_font *ofont, int mask) @@ -327,7 +329,7 @@ z1_same_font(const gs_font *font, const gs_font *ofont, int mask) if ((check & (FONT_SAME_OUTLINES | FONT_SAME_METRICS)) && !memcmp(&pofont1->data.procs, &z1_data_procs, sizeof(z1_data_procs)) && - obj_eq(&pdata->CharStrings, &podata->CharStrings) && + obj_eq(font->memory, &pdata->CharStrings, &podata->CharStrings) && /* * We use same_font_dict for convenience: we know that * both fonts do have Private dictionaries. @@ -347,7 +349,7 @@ z1_same_font(const gs_font *font, const gs_font *ofont, int mask) if ((check & FONT_SAME_ENCODING) && pofont1->procs.same_font == z1_same_font && - obj_eq(&pdata->Encoding, &podata->Encoding) + obj_eq(font->memory, &pdata->Encoding, &podata->Encoding) ) same |= FONT_SAME_ENCODING; diff --git a/gs/src/zfont2.c b/gs/src/zfont2.c index 5af86a8a1..f5612c076 100644 --- a/gs/src/zfont2.c +++ b/gs/src/zfont2.c @@ -27,6 +27,7 @@ #include "idparam.h" #include "ifont1.h" #include "ifont2.h" +#include "ialloc.h" /* Private utilities */ private uint @@ -92,7 +93,7 @@ zbuildfont2(i_ctx_t *i_ctx_p) os_ptr op = osp; charstring_font_refs_t refs; build_proc_refs build; - int code = build_proc_name_refs(&build, + int code = build_proc_name_refs(imemory, &build, "%Type2BuildChar", "%Type2BuildGlyph"); gs_type1_data data1; diff --git a/gs/src/zfont32.c b/gs/src/zfont32.c index d2c4f3cb9..1e42a4cb4 100644 --- a/gs/src/zfont32.c +++ b/gs/src/zfont32.c @@ -43,7 +43,7 @@ zbuildfont32(i_ctx_t *i_ctx_p) gs_font_base *pfont; check_type(*op, t_dictionary); - code = build_proc_name_refs(&build, NULL, "%Type32BuildGlyph"); + code = build_proc_name_refs(imemory, &build, NULL, "%Type32BuildGlyph"); if (code < 0) return code; code = build_gs_simple_font(i_ctx_p, op, &pfont, ft_CID_bitmap, diff --git a/gs/src/zfont42.c b/gs/src/zfont42.c index e62d1c64b..fb58bc6b7 100644 --- a/gs/src/zfont42.c +++ b/gs/src/zfont42.c @@ -55,7 +55,7 @@ build_gs_TrueType_font(i_ctx_t *i_ctx_p, os_ptr op, gs_font_type42 **ppfont, font_data *pdata; int code; - code = build_proc_name_refs(&build, bcstr, bgstr); + code = build_proc_name_refs(imemory, &build, bcstr, bgstr); if (code < 0) return code; check_type(*op, t_dictionary); @@ -63,7 +63,7 @@ build_gs_TrueType_font(i_ctx_t *i_ctx_p, os_ptr op, gs_font_type42 **ppfont, * Since build_gs_primitive_font may resize the dictionary and cause * pointers to become invalid, we save sfnts and GlyphDirectory. */ - if ((code = font_string_array_param(op, "sfnts", &sfnts)) < 0 || + if ((code = font_string_array_param(imemory, op, "sfnts", &sfnts)) < 0 || (code = font_GlyphDirectory_param(op, &GlyphDirectory)) < 0 ) return code; @@ -120,7 +120,7 @@ zbuildfont42(i_ctx_t *i_ctx_p) * value even if it is of the wrong type. */ int -font_string_array_param(os_ptr op, const char *kstr, ref *psa) +font_string_array_param(const gs_memory_t *mem, os_ptr op, const char *kstr, ref *psa) { ref *pvsa; ref rstr0; @@ -133,7 +133,7 @@ font_string_array_param(os_ptr op, const char *kstr, ref *psa) * We only check the first element of the array now, as a sanity test; * elements are checked as needed by string_array_access_proc. */ - if ((code = array_get(pvsa, 0L, &rstr0)) < 0) + if ((code = array_get(mem, pvsa, 0L, &rstr0)) < 0) return code; if (!r_has_type(&rstr0, t_string)) return_error(e_typecheck); @@ -166,7 +166,8 @@ font_GlyphDirectory_param(os_ptr op, ref *pGlyphDirectory) * >0 - number of accessible bytes (client must cycle). */ int -string_array_access_proc(const ref *psa, int modulus, ulong offset, +string_array_access_proc(const gs_memory_t *mem, + const ref *psa, int modulus, ulong offset, uint length, const byte **pdata) { ulong left = offset; @@ -176,7 +177,7 @@ string_array_access_proc(const ref *psa, int modulus, ulong offset, return 0; for (;; ++index) { ref rstr; - int code = array_get(psa, index, &rstr); + int code = array_get(mem, psa, index, &rstr); uint size; if (code < 0) @@ -216,7 +217,7 @@ glyph_to_index(const gs_font *font, gs_glyph glyph) if (glyph >= GS_MIN_GLYPH_INDEX) return glyph; - name_index_ref(glyph, &gref); + name_index_ref(font->memory, glyph, &gref); if (dict_find(&pfont_data(font)->CharStrings, &gref, &pcstr) > 0 && r_has_type(pcstr, t_integer) ) { @@ -240,7 +241,9 @@ z42_get_glyph_index(gs_font_type42 *pfont, gs_glyph glyph) * the glyph is missing or out of range. */ int -font_gdir_get_outline(const ref *pgdir, long glyph_index, +font_gdir_get_outline(const gs_memory_t *mem, + const ref *pgdir, + long glyph_index, gs_glyph_data_t *pgd) { ref iglyph; @@ -252,7 +255,7 @@ font_gdir_get_outline(const ref *pgdir, long glyph_index, make_int(&iglyph, glyph_index); code = dict_find(pgdir, &iglyph, &pgdef) - 1; /* 0 => not found */ } else { - code = array_get(pgdir, glyph_index, &gdef); + code = array_get(mem, pgdir, glyph_index, &gdef); pgdef = &gdef; } if (code < 0) { @@ -272,7 +275,7 @@ z42_gdir_get_outline(gs_font_type42 * pfont, uint glyph_index, const font_data *pfdata = pfont_data(pfont); const ref *pgdir = &pfdata->u.type42.GlyphDirectory; - return font_gdir_get_outline(pgdir, (long)glyph_index, pgd); + return font_gdir_get_outline(pfont->memory, pgdir, (long)glyph_index, pgd); } /* Enumerate glyphs from CharStrings or loca / glyf. */ @@ -285,7 +288,7 @@ z42_enumerate_glyph(gs_font *font, int *pindex, gs_glyph_space_t glyph_space, else { const ref *pcsdict = &pfont_data(font)->CharStrings; - return zchar_enumerate_glyph(pcsdict, pindex, pglyph); + return zchar_enumerate_glyph(font->memory, pcsdict, pindex, pglyph); } } @@ -303,7 +306,7 @@ z42_gdir_enumerate_glyph(gs_font *font, int *pindex, ref gdef; for (;; (*pindex)++) { - if (array_get(pgdict, (long)*pindex, &gdef) < 0) { + if (array_get(font->memory, pgdict, (long)*pindex, &gdef) < 0) { *pindex = 0; return 0; } @@ -316,7 +319,7 @@ z42_gdir_enumerate_glyph(gs_font *font, int *pindex, } else pgdict = &pfont_data(font)->CharStrings; /* A trick : use zchar_enumerate_glyph to enumerate GIDs : */ - code = zchar_enumerate_glyph(pgdict, pindex, pglyph); + code = zchar_enumerate_glyph(font->memory, pgdict, pindex, pglyph); if (*pindex != 0 && *pglyph >= gs_min_cid_glyph) *pglyph = *pglyph - gs_min_cid_glyph + GS_MIN_GLYPH_INDEX; return code; @@ -357,6 +360,6 @@ private int z42_string_proc(gs_font_type42 * pfont, ulong offset, uint length, const byte ** pdata) { - return string_array_access_proc(&pfont_data(pfont)->u.type42.sfnts, 2, + return string_array_access_proc(pfont->memory, &pfont_data(pfont)->u.type42.sfnts, 2, offset, length, pdata); } diff --git a/gs/src/zfontenum.c b/gs/src/zfontenum.c index 13a2162ce..fed804f2e 100644 --- a/gs/src/zfontenum.c +++ b/gs/src/zfontenum.c @@ -63,7 +63,7 @@ z_fontenum(i_ctx_t *i_ctx_p) return code; } - r = results = gs_malloc(1, sizeof(fontenum_t), "fontenum list"); + r = results = gs_malloc(imemory->non_gc_memory, 1, sizeof(fontenum_t), "fontenum list"); elements = 0; while((code = gp_enumerate_fonts_next(enum_state, &fontname, &path )) > 0) { if (fontname == NULL || path == NULL) { @@ -72,14 +72,14 @@ z_fontenum(i_ctx_t *i_ctx_p) } length = strlen(fontname) + 1; - r->fontname = gs_malloc(length, 1, "native font name"); + r->fontname = gs_malloc(imemory->non_gc_memory, length, 1, "native font name"); memcpy(r->fontname, fontname, length); length = strlen(path) + 1; - r->path = gs_malloc(length, 1, "native font path"); + r->path = gs_malloc(imemory->non_gc_memory, length, 1, "native font path"); memcpy(r->path, path, length); - r->next = gs_malloc(1, sizeof(fontenum_t), "fontenum list"); + r->next = gs_malloc(imemory->non_gc_memory, 1, sizeof(fontenum_t), "fontenum list"); r = r->next; elements += 1; } @@ -112,9 +112,12 @@ z_fontenum(i_ctx_t *i_ctx_p) results = r; r = r->next; - gs_free(results->fontname, strlen(results->fontname) + 1, 1, "native font name"); - gs_free(results->path, strlen(results->path) + 1, 1, "native font path"); - gs_free(results, 1, sizeof(fontenum_t), "fontenum list"); + gs_free(imemory->non_gc_memory, + results->fontname, strlen(results->fontname) + 1, 1, "native font name"); + gs_free(imemory->non_gc_memory, + results->path, strlen(results->path) + 1, 1, "native font path"); + gs_free(imemory->non_gc_memory, + results, 1, sizeof(fontenum_t), "fontenum list"); } push(2); diff --git a/gs/src/zfrsd.c b/gs/src/zfrsd.c index 5f2f4c800..b97885e05 100644 --- a/gs/src/zfrsd.c +++ b/gs/src/zfrsd.c @@ -78,16 +78,16 @@ zrsdparams(i_ctx_t *i_ctx_p) for (i = 0; i < r_size(pFilter); ++i) { ref f, fname, dp; - array_get(pFilter, (long)i, &f); + array_get(imemory, pFilter, (long)i, &f); if (!r_has_type(&f, t_name)) return_error(e_typecheck); - name_string_ref(&f, &fname); + name_string_ref(imemory, &f, &fname); if (r_size(&fname) < 6 || memcmp(fname.value.bytes + r_size(&fname) - 6, "Decode", 6) ) return_error(e_rangecheck); if (pDecodeParms) { - array_get(pDecodeParms, (long)i, &dp); + array_get(imemory, pDecodeParms, (long)i, &dp); if (!(r_has_type(&dp, t_dictionary) || r_has_type(&dp, t_null))) return_error(e_typecheck); } diff --git a/gs/src/zfunc.c b/gs/src/zfunc.c index 51934dc29..4c1b0a859 100644 --- a/gs/src/zfunc.c +++ b/gs/src/zfunc.c @@ -271,7 +271,8 @@ fn_build_float_array(const ref * op, const char *kstr, bool required, if (ptr == 0) return_error(e_VMerror); - code = dict_float_array_check_param(op, kstr, size, ptr, NULL, + code = dict_float_array_check_param(mem, op, kstr, size, + ptr, NULL, 0, e_rangecheck); if (code < 0 || (even && (code & 1) != 0)) { gs_free_object(mem, ptr, kstr); @@ -311,7 +312,8 @@ fn_build_float_array_forced(const ref * op, const char *kstr, bool required, if (ptr == 0) return_error(e_VMerror); if(r_is_array(par) ) - code = dict_float_array_check_param(op, kstr, size, ptr, NULL, + code = dict_float_array_check_param(mem, op, kstr, + size, ptr, NULL, 0, e_rangecheck); else { code = dict_float_param(op, kstr, 0., ptr); /* defailt cannot happen */ diff --git a/gs/src/zfunc3.c b/gs/src/zfunc3.c index 1979f0c4c..ef9b743c4 100644 --- a/gs/src/zfunc3.c +++ b/gs/src/zfunc3.c @@ -93,7 +93,7 @@ gs_build_function_3(i_ctx_t *i_ctx_p, const ref *op, const gs_function_params_t for (i = 0; i < params.k; ++i) { ref subfn; - array_get(pFunctions, (long)i, &subfn); + array_get(mem, pFunctions, (long)i, &subfn); code = fn_build_sub_function(i_ctx_p, &subfn, &ptr[i], depth, mem); if (code < 0) goto fail; diff --git a/gs/src/zfunc4.c b/gs/src/zfunc4.c index f1d4c8776..e903188e4 100644 --- a/gs/src/zfunc4.c +++ b/gs/src/zfunc4.c @@ -27,7 +27,7 @@ #include "ifunc.h" #include "iname.h" #include "dstack.h" - +#include "ialloc.h" /* * FunctionType 4 functions are not defined in the PostScript language. We * provide support for them because they are needed for PDF 1.3. In @@ -143,7 +143,7 @@ check_psc_function(i_ctx_t *i_ctx_p, const ref *pref, int depth, byte *ops, int ref * delp; int code; - array_get(pref, i, &elt); + array_get(imemory, pref, i, &elt); switch (r_btype(&elt)) { case t_integer: { int i = elt.value.intval; @@ -178,7 +178,7 @@ check_psc_function(i_ctx_t *i_ctx_p, const ref *pref, int depth, byte *ops, int case t_name: if (!r_has_attr(&elt, a_executable)) return_error(e_rangecheck); - name_string_ref(&elt, &elt); + name_string_ref(imemory, &elt, &elt); if (!bytes_compare(elt.value.bytes, r_size(&elt), (const byte *)"true", 4)) { *p = PtCr_true; @@ -216,7 +216,7 @@ check_psc_function(i_ctx_t *i_ctx_p, const ref *pref, int depth, byte *ops, int return_error(e_typecheck); if (depth == MAX_PSC_FUNCTION_NESTING) return_error(e_limitcheck); - if ((code = array_get(pref, ++i, &elt2)) < 0) + if ((code = array_get(imemory, pref, ++i, &elt2)) < 0) return code; *psize += 3; code = check_psc_function(i_ctx_p, &elt, depth + 1, ops, psize); @@ -233,7 +233,7 @@ check_psc_function(i_ctx_t *i_ctx_p, const ref *pref, int depth, byte *ops, int } } else if (!r_is_proc(&elt2)) return_error(e_rangecheck); - else if ((code == array_get(pref, ++i, &elt3)) < 0) + else if ((code == array_get(imemory, pref, ++i, &elt3)) < 0) return code; else if (R_IS_OPER(&elt3, zifelse)) { if (ops) { diff --git a/gs/src/zgeneric.c b/gs/src/zgeneric.c index 1a3737315..4b13f83cd 100644 --- a/gs/src/zgeneric.c +++ b/gs/src/zgeneric.c @@ -131,7 +131,7 @@ zlength(i_ctx_t *i_ctx_p) case t_name: { ref str; - name_string_ref(op, &str); + name_string_ref(imemory, op, &str); make_int(op, r_size(&str)); return 0; } @@ -172,7 +172,7 @@ zget(i_ctx_t *i_ctx_p) check_type(*op, t_integer); check_read(*op1); - code = array_get(op1, op->value.intval, op1); + code = array_get(imemory, op1, op->value.intval, op1); if (code < 0) { /* Might be a stackunderflow reported as typecheck. */ if (code == e_typecheck) return_op_typecheck(op1); @@ -516,7 +516,7 @@ packedarray_continue(i_ctx_t *i_ctx_p) r_dec_size(obj, 1); push(1); - packed_get(packed, op); + packed_get(imemory, packed, op); obj->value.packed = packed_next(packed); esp += 2; *esp = obj[1]; @@ -600,7 +600,7 @@ copy_interval(i_ctx_t *i_ctx_p /* for ref_assign_old */, os_ptr prto, ref elt; for (i = 0; i < fromsize; i++, pdest++) { - packed_get(packed, &elt); + packed_get(imemory, packed, &elt); ref_assign_old(prto, pdest, &elt, cname); packed = packed_next(packed); } diff --git a/gs/src/zgstate.c b/gs/src/zgstate.c index 6ac93c4b3..d621dacd0 100644 --- a/gs/src/zgstate.c +++ b/gs/src/zgstate.c @@ -311,7 +311,7 @@ zsetdash(i_ctx_t *i_ctx_p) for (i = 0, code = 0; i < n && code >= 0; ++i) { ref element; - array_get(op1, (long)i, &element); + array_get(mem, op1, (long)i, &element); code = float_param(&element, &pattern[i]); } if (code >= 0) diff --git a/gs/src/zht2.c b/gs/src/zht2.c index ed292ebe0..c1c4da058 100644 --- a/gs/src/zht2.c +++ b/gs/src/zht2.c @@ -45,14 +45,14 @@ private int dict_threshold2_params(const ref *, gs_threshold2_halftone *, * pointer and a string length. */ int -gs_get_colorname_string(gs_separation_name colorname_index, +gs_get_colorname_string(const gs_memory_t *mem, gs_separation_name colorname_index, unsigned char **ppstr, unsigned int *pname_size) { ref nref; - name_index_ref(colorname_index, &nref); - name_string_ref(&nref, &nref); - return obj_string_data(&nref, (const unsigned char**) ppstr, pname_size); + name_index_ref(mem, colorname_index, &nref); + name_string_ref(mem, &nref, &nref); + return obj_string_data(mem, &nref, (const unsigned char**) ppstr, pname_size); } /* Dummy spot function */ @@ -89,6 +89,8 @@ zsethalftone5(i_ctx_t *i_ctx_p) int halftonetype, type = 0; gs_state *pgs = igs; + mem = (gs_memory_t *) idmemory->spaces_indexed[r_space_index(op - 1)]; + check_type(*op, t_dictionary); check_dict_read(*op); check_type(op[-1], t_dictionary); @@ -121,8 +123,8 @@ zsethalftone5(i_ctx_t *i_ctx_p) continue; /* Get the name of the component verify that we will use it. */ - cname = name_index(&rvalue[0]); - code = gs_get_colorname_string(cname, &pname, &name_size); + cname = name_index(mem, &rvalue[0]); + code = gs_get_colorname_string(mem, cname, &pname, &name_size); if (code < 0) break; colorant_number = gs_cname_to_colorant_number(pgs, pname, name_size, @@ -147,7 +149,6 @@ zsethalftone5(i_ctx_t *i_ctx_p) } } - mem = (gs_memory_t *) idmemory->spaces_indexed[r_space_index(op - 1)]; check_estack(5); /* for sampling Type 1 screens */ refset_null(sprocs, count); refset_null(tprocs, count); @@ -179,8 +180,8 @@ zsethalftone5(i_ctx_t *i_ctx_p) continue; /* Get the name of the component */ - cname = name_index(&rvalue[0]); - code = gs_get_colorname_string(cname, &pname, &name_size); + cname = name_index(mem, &rvalue[0]); + code = gs_get_colorname_string(mem, cname, &pname, &name_size); if (code < 0) break; colorant_number = gs_cname_to_colorant_number(pgs, pname, name_size, @@ -245,8 +246,8 @@ zsethalftone5(i_ctx_t *i_ctx_p) continue; /* Get the name of the component and verify that we will use it. */ - cname = name_index(&rvalue[0]); - code = gs_get_colorname_string(cname, &pname, &name_size); + cname = name_index(mem, &rvalue[0]); + code = gs_get_colorname_string(mem, cname, &pname, &name_size); if (code < 0) break; colorant_number = gs_cname_to_colorant_number(pgs, pname, name_size, diff --git a/gs/src/zht2.h b/gs/src/zht2.h index 63a71c5a8..8a052d2ec 100644 --- a/gs/src/zht2.h +++ b/gs/src/zht2.h @@ -26,7 +26,9 @@ * This routine translates a gs_separation_name value into a character string * pointer and a string length. */ -int gs_get_colorname_string(gs_separation_name colorname_index, - unsigned char **ppstr, unsigned int *pname_size); +int gs_get_colorname_string(const gs_memory_t *mem, + gs_separation_name colorname_index, + unsigned char **ppstr, + unsigned int *pname_size); #endif /* zht2_INCLUDED */ diff --git a/gs/src/zicc.c b/gs/src/zicc.c index 7ecd657d9..03ebbd867 100644 --- a/gs/src/zicc.c +++ b/gs/src/zicc.c @@ -32,7 +32,7 @@ #include "idparam.h" #include "igstate.h" #include "icie.h" - +#include "ialloc.h" /* * <dict> .seticcspace - @@ -111,7 +111,8 @@ zseticcspace(i_ctx_t * i_ctx_p) * space, we use the range values only to restrict the set of input * values; they are not used for normalization. */ - code = dict_floats_param( op, + code = dict_floats_param( imemory, + op, "Range", 2 * ncomps, range_buff, diff --git a/gs/src/zimage.c b/gs/src/zimage.c index db9016a9a..a4baf0d3f 100644 --- a/gs/src/zimage.c +++ b/gs/src/zimage.c @@ -52,7 +52,8 @@ private int image_cleanup(i_ctx_t *); /* Extract and check the parameters for a gs_data_image_t. */ int -data_image_params(const ref *op, gs_data_image_t *pim, +data_image_params(const gs_memory_t *mem, + const ref *op, gs_data_image_t *pim, image_params *pip, bool require_DataSource, int num_components, int max_bits_per_component, bool has_alpha) @@ -67,14 +68,14 @@ data_image_params(const ref *op, gs_data_image_t *pim, -1, &pim->Width)) < 0 || (code = dict_int_param(op, "Height", 0, max_int_in_fixed / 2, -1, &pim->Height)) < 0 || - (code = dict_matrix_param(op, "ImageMatrix", + (code = dict_matrix_param(mem, op, "ImageMatrix", &pim->ImageMatrix)) < 0 || (code = dict_bool_param(op, "MultipleDataSources", false, &pip->MultipleDataSources)) < 0 || (code = dict_int_param(op, "BitsPerComponent", 1, max_bits_per_component, -1, &pim->BitsPerComponent)) < 0 || - (code = decode_size = dict_floats_param(op, "Decode", + (code = decode_size = dict_floats_param(mem, op, "Decode", num_components * 2, &pim->Decode[0], NULL)) < 0 || (code = dict_bool_param(op, "Interpolate", false, @@ -95,7 +96,7 @@ data_image_params(const ref *op, gs_data_image_t *pim, if (r_size(pds) != n) return_error(e_rangecheck); for (i = 0; i < n; ++i) - array_get(pds, i, &pip->DataSource[i]); + array_get(mem, pds, i, &pip->DataSource[i]); } else pip->DataSource[0] = *pds; return 0; @@ -114,7 +115,7 @@ pixel_image_params(i_ctx_t *i_ctx_p, const ref *op, gs_pixel_image_t *pim, if (num_components < 1) return_error(e_rangecheck); /* Pattern space not allowed */ pim->ColorSpace = gs_currentcolorspace(igs); - code = data_image_params(op, (gs_data_image_t *) pim, pip, true, + code = data_image_params(imemory, op, (gs_data_image_t *) pim, pip, true, num_components, max_bits_per_component, has_alpha); if (code < 0) @@ -187,7 +188,7 @@ zimagemask1(i_ctx_t *i_ctx_p) gs_image_t_init_mask_adjust(&image, false, gs_incachedevice(igs) != CACHE_DEVICE_NONE); - code = data_image_params(op, (gs_data_image_t *) & image, + code = data_image_params(imemory, op, (gs_data_image_t *) & image, &ip, true, 1, 1, false); if (code < 0) return code; diff --git a/gs/src/zimage3.c b/gs/src/zimage3.c index ce94ae02d..01ea16960 100644 --- a/gs/src/zimage3.c +++ b/gs/src/zimage3.c @@ -28,6 +28,7 @@ #include "idparam.h" #include "igstate.h" #include "iimage.h" +#include "ialloc.h" /* <dict> .image3 - */ private int @@ -56,7 +57,7 @@ zimage3(i_ctx_t *i_ctx_p) if ((code = pixel_image_params(i_ctx_p, pDataDict, (gs_pixel_image_t *)&image, &ip_data, 12, false)) < 0 || - (mcode = code = data_image_params(pMaskDict, &image.MaskDict, + (mcode = code = data_image_params(imemory, pMaskDict, &image.MaskDict, &ip_mask, false, 1, 12, false)) < 0 || (code = dict_int_param(pDataDict, "ImageType", 1, 1, 0, &ignored)) < 0 || (code = dict_int_param(pMaskDict, "ImageType", 1, 1, 0, &ignored)) < 0 diff --git a/gs/src/ziodevs.c b/gs/src/ziodevs.c index 05ac00955..72362dfff 100644 --- a/gs/src/ziodevs.c +++ b/gs/src/ziodevs.c @@ -47,21 +47,18 @@ const char iodev_dtype_stdio[] = "Special"; */ #define STDIN_BUF_SIZE 128 -/*#define ref_stdin ref_stdio[0] *//* in files.h */ -bool gs_stdin_is_interactive; /* exported for command line only */ + private iodev_proc_init(stdin_init); private iodev_proc_open_device(stdin_open); const gx_io_device gs_iodev_stdin = iodev_special("%stdin%", stdin_init, stdin_open); #define STDOUT_BUF_SIZE 128 -/*#define ref_stdout ref_stdio[1] *//* in files.h */ private iodev_proc_open_device(stdout_open); const gx_io_device gs_iodev_stdout = iodev_special("%stdout%", iodev_no_init, stdout_open); #define STDERR_BUF_SIZE 128 -/*#define ref_stderr ref_stdio[2] *//* in files.h */ private iodev_proc_open_device(stderr_open); const gx_io_device gs_iodev_stderr = iodev_special("%stderr%", iodev_no_init, stderr_open); @@ -82,7 +79,7 @@ private int private int stdin_init(gx_io_device * iodev, gs_memory_t * mem) { - gs_stdin_is_interactive = true; + mem->gs_lib_ctx->stdin_is_interactive = true; return 0; } @@ -99,7 +96,7 @@ s_stdin_read_process(stream_state * st, stream_cursor_read * ignore_pr, if (wcount <= 0) return 0; count = gp_stdin_read( (char*) pw->ptr + 1, wcount, - gs_stdin_is_interactive, file); + st->memory->gs_lib_ctx->stdin_is_interactive, file); pw->ptr += (count < 0) ? 0 : count; return ((count < 0) ? ERRC : (count == 0) ? EOFC : count); } diff --git a/gs/src/ziodevsc.c b/gs/src/ziodevsc.c index bce908dc8..f4df172c8 100644 --- a/gs/src/ziodevsc.c +++ b/gs/src/ziodevsc.c @@ -48,21 +48,17 @@ const char iodev_dtype_stdio[] = "Special"; */ #define STDIN_BUF_SIZE 128 -/*#define ref_stdin ref_stdio[0] *//* in files.h */ -bool gs_stdin_is_interactive; /* exported for command line only */ private iodev_proc_init(stdin_init); private iodev_proc_open_device(stdin_open); const gx_io_device gs_iodev_stdin = iodev_special("%stdin%", stdin_init, stdin_open); #define STDOUT_BUF_SIZE 128 -/*#define ref_stdout ref_stdio[1] *//* in files.h */ private iodev_proc_open_device(stdout_open); const gx_io_device gs_iodev_stdout = iodev_special("%stdout%", iodev_no_init, stdout_open); #define STDERR_BUF_SIZE 128 -/*#define ref_stderr ref_stdio[2] *//* in files.h */ private iodev_proc_open_device(stderr_open); const gx_io_device gs_iodev_stderr = iodev_special("%stderr%", iodev_no_init, stderr_open); @@ -90,7 +86,7 @@ stdio_close(stream *s) private int stdin_init(gx_io_device * iodev, gs_memory_t * mem) { - gs_stdin_is_interactive = true; + mem->gs_lib_ctx->stdin_is_interactive = true; return 0; } diff --git a/gs/src/zmatrix.c b/gs/src/zmatrix.c index dc4f6cede..27367e39d 100644 --- a/gs/src/zmatrix.c +++ b/gs/src/zmatrix.c @@ -91,7 +91,7 @@ zsetdefaultmatrix(i_ctx_t *i_ctx_p) else { gs_matrix mat; - code = read_matrix(op, &mat); + code = read_matrix(imemory, op, &mat); if (code < 0) return code; code = gs_setdefaultmatrix(igs, &mat); @@ -201,7 +201,7 @@ zconcat(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_matrix mat; - int code = read_matrix(op, &mat); + int code = read_matrix(imemory, op, &mat); if (code < 0) return code; @@ -220,8 +220,8 @@ zconcatmatrix(i_ctx_t *i_ctx_p) gs_matrix m1, m2, mp; int code; - if ((code = read_matrix(op - 2, &m1)) < 0 || - (code = read_matrix(op - 1, &m2)) < 0 || + if ((code = read_matrix(imemory, op - 2, &m1)) < 0 || + (code = read_matrix(imemory, op - 1, &m2)) < 0 || (code = gs_matrix_multiply(&m1, &m2, &mp)) < 0 || (code = write_matrix(op, &mp)) < 0 ) @@ -288,7 +288,7 @@ common_transform(i_ctx_t *i_ctx_p, gs_matrix mat; gs_matrix *pmat = &mat; - if ((code = read_matrix(op, pmat)) < 0 || + if ((code = read_matrix(imemory, op, pmat)) < 0 || (code = num_params(op - 1, 2, opxy)) < 0 || (code = (*matproc) (opxy[0], opxy[1], pmat, &pt)) < 0 ) { /* Might be a stack underflow. */ @@ -328,7 +328,7 @@ zinvertmatrix(i_ctx_t *i_ctx_p) gs_matrix m; int code; - if ((code = read_matrix(op - 1, &m)) < 0 || + if ((code = read_matrix(imemory, op - 1, &m)) < 0 || (code = gs_matrix_invert(&m, &m)) < 0 || (code = write_matrix(op, &m)) < 0 ) diff --git a/gs/src/zmedia2.c b/gs/src/zmedia2.c index 977bf4a1d..b466ad8c0 100644 --- a/gs/src/zmedia2.c +++ b/gs/src/zmedia2.c @@ -29,7 +29,8 @@ /* <pagedict> <attrdict> <policydict> <keys> .matchmedia <key> true */ /* <pagedict> <attrdict> <policydict> <keys> .matchmedia false */ /* <pagedict> null <policydict> <keys> .matchmedia null true */ -private int zmatch_page_size(const ref * pvreq, const ref * pvmed, +private int zmatch_page_size(const gs_memory_t *mem, + const ref * pvreq, const ref * pvmed, int policy, int orient, bool roll, float *best_mismatch, gs_matrix * pmat, gs_point * pmsize); @@ -137,7 +138,7 @@ zmatchmedia(i_ctx_t *i_ctx_p) ref *ppvalue; int policy; - array_get(pkeys, ki, &key); + array_get(imemory, pkeys, ki, &key); if (dict_find(&aelt.dict, &key, &pmvalue) <= 0) continue; if (dict_find(preq, &key, &prvalue) <= 0 || @@ -161,21 +162,21 @@ zmatchmedia(i_ctx_t *i_ctx_p) * below. */ if (r_has_type(&key, t_name) && - (name_string_ref(&key, &kstr), + (name_string_ref(imemory, &key, &kstr), r_size(&kstr) == 8 && !memcmp(kstr.value.bytes, "PageSize", 8)) ) { gs_matrix ignore_mat; gs_point ignore_msize; - if (zmatch_page_size(prvalue, pmvalue, + if (zmatch_page_size(imemory, prvalue, pmvalue, policy, orient, roll, &best_mismatch, &ignore_mat, &ignore_msize) <= 0) goto no; - } else if (!obj_eq(prvalue, pmvalue)) + } else if (!obj_eq(imemory, prvalue, pmvalue)) goto no; } /* We have a match. Save the match in case no better match is found */ @@ -200,8 +201,8 @@ zmatchmedia(i_ctx_t *i_ctx_p) ref pri; pi--; - array_get(ppriority, pi, &pri); - if (obj_eq(&aelt.key, &pri)) { /* Yes, higher priority. */ + array_get(imemory, ppriority, pi, &pri); + if (obj_eq(imemory, &aelt.key, &pri)) { /* Yes, higher priority. */ match.best_key = aelt.key; match.priority = pi; break; @@ -248,7 +249,8 @@ zmatchpagesize(i_ctx_t *i_ctx_p) } check_type(op[-1], t_boolean); roll = op[-1].value.boolval; - code = zmatch_page_size(op - 5, op - 4, (int)op[-3].value.intval, + code = zmatch_page_size(imemory, + op - 5, op - 4, (int)op[-3].value.intval, orient, roll, &ignore_mismatch, &mat, &media_size); switch (code) { @@ -279,7 +281,7 @@ match_page_size(const gs_point * request, float *best_mismatch, gs_matrix * pmat, gs_point * pmsize); private int -zmatch_page_size(const ref * pvreq, const ref * pvmed, +zmatch_page_size(const gs_memory_t *mem, const ref * pvreq, const ref * pvmed, int policy, int orient, bool roll, float *best_mismatch, gs_matrix * pmat, gs_point * pmsize) { @@ -289,10 +291,10 @@ zmatch_page_size(const ref * pvreq, const ref * pvmed, /* array_get checks array types and size. */ /* This allows normal or packed arrays to be used */ - if ((code = array_get(pvreq, 1, &rv[1])) < 0) + if ((code = array_get(mem, pvreq, 1, &rv[1])) < 0) return_error(code); nr = r_size(pvreq); - if ((code = array_get(pvmed, 1, &rv[3])) < 0) + if ((code = array_get(mem, pvmed, 1, &rv[3])) < 0) return_error(code); nm = r_size(pvmed); if (!((nm == 2 || nm == 4) && (nr == 2 || nr == nm))) @@ -302,9 +304,9 @@ zmatch_page_size(const ref * pvreq, const ref * pvmed, double v[6]; int code; - array_get(pvreq, 0, &rv[0]); + array_get(mem, pvreq, 0, &rv[0]); for (i = 0; i < 4; ++i) - array_get(pvmed, i % nm, &rv[i + 2]); + array_get(mem,pvmed, i % nm, &rv[i + 2]); if ((code = num_params(rv + 5, 6, v)) < 0) return code; { diff --git a/gs/src/zmisc.c b/gs/src/zmisc.c index edf7dc8aa..920298753 100644 --- a/gs/src/zmisc.c +++ b/gs/src/zmisc.c @@ -84,7 +84,7 @@ zbind(i_ctx_t *i_ctx_p) ref nref; ref *pvalue; - name_index_ref(packed_name_index(&elt), + name_index_ref(imemory, packed_name_index(&elt), &nref); if ((pvalue = dict_find_name(&nref)) != 0 && r_is_ex_oper(pvalue) @@ -279,7 +279,7 @@ zmakeoperator(i_ctx_t *i_ctx_p) if (count == r_size(&opt->table)) return_error(e_limitcheck); ref_assign_old(&opt->table, &tab[count], op, "makeoperator"); - opt->nx_table[count] = name_index(op - 1); + opt->nx_table[count] = name_index(imemory, op - 1); op_index_ref(opt->base_index + count, op - 1); opt->count = count + 1; pop(1); diff --git a/gs/src/zmisc2.c b/gs/src/zmisc2.c index 536bae8a6..a466c8a8c 100644 --- a/gs/src/zmisc2.c +++ b/gs/src/zmisc2.c @@ -125,7 +125,7 @@ set_language_level(i_ctx_t *i_ctx_p, int new_level) *pgdict = *pdict; } /* Set other flags for Level 2 operation. */ - dict_auto_expand = true; + imemory->gs_lib_ctx->dict_auto_expand = true; } code = swap_level_dict(i_ctx_p, "level2dict"); if (code < 0) @@ -153,11 +153,11 @@ set_language_level(i_ctx_t *i_ctx_p, int new_level) while ((index = dict_next(pgdict, index, &elt[0])) >= 0) if (r_has_type(&elt[0], t_name)) - name_invalidate_value_cache(&elt[0]); + name_invalidate_value_cache(imemory, &elt[0]); /* Overwrite globaldict in the dictionary stack. */ *pgdict = *systemdict; /* Set other flags for Level 1 operation. */ - dict_auto_expand = false; + imemory->gs_lib_ctx->dict_auto_expand = false; } code = swap_level_dict(i_ctx_p, "level2dict"); break; @@ -200,7 +200,7 @@ swap_level_dict(i_ctx_t *i_ctx_p, const char *dict_name) while ((index = dict_next(&rleveldict, index, &elt[0])) >= 0) if (r_has_type(&elt[1], t_dictionary) && dict_find(&elt[1], &elt[0], &psubdict) > 0 && - obj_eq(&elt[1], psubdict) + obj_eq(imemory, &elt[1], psubdict) ) { /* elt[1] is the 2nd-level sub-dictionary */ int isub = dict_first(&elt[1]); @@ -212,7 +212,7 @@ swap_level_dict(i_ctx_t *i_ctx_p, const char *dict_name) continue; rsubdict = *psubdict; while ((isub = dict_next(&elt[1], isub, &subelt[0])) >= 0) - if (!obj_eq(&subelt[0], &elt[0])) { + if (!obj_eq(imemory, &subelt[0], &elt[0])) { /* don't swap dict itself */ int code = swap_entry(i_ctx_p, subelt, &rsubdict, &elt[1]); diff --git a/gs/src/zmisc3.c b/gs/src/zmisc3.c index 1679f1406..6d889f43f 100644 --- a/gs/src/zmisc3.c +++ b/gs/src/zmisc3.c @@ -73,8 +73,8 @@ zeqproc(i_ctx_t *i_ctx_p) } /* Look at the next elements of the arrays. */ i = r_size(&top->proc1) - 1; - array_get(&top->proc1, i, &top[1].proc1); - array_get(&top->proc2, i, &top[1].proc2); + array_get(imemory, &top->proc1, i, &top[1].proc1); + array_get(imemory, &top->proc2, i, &top[1].proc2); r_dec_size(&top->proc1, 1); ++top; /* @@ -88,7 +88,7 @@ zeqproc(i_ctx_t *i_ctx_p) ) break; #endif - if (obj_eq(&top->proc1, &top->proc2)) { + if (obj_eq(imemory, &top->proc1, &top->proc2)) { /* Names don't match strings. */ if (r_type(&top->proc1) != r_type(&top->proc2) && (r_type(&top->proc1) == t_name || diff --git a/gs/src/zpacked.c b/gs/src/zpacked.c index 4410cd953..3d733c300 100644 --- a/gs/src/zpacked.c +++ b/gs/src/zpacked.c @@ -26,6 +26,7 @@ #include "ivmspace.h" #include "oper.h" #include "store.h" +#include "gxalloc.h" /* - currentpacking <bool> */ private int @@ -104,7 +105,7 @@ make_packed_array(ref * parr, ref_stack_t * pstack, uint size, pref = ref_stack_index(pstack, i - 1); switch (r_btype(pref)) { /* not r_type, opers are special */ case t_name: - if (name_index(pref) >= packed_name_max_index) + if (name_index(imem, pref) >= packed_name_max_index) break; /* can't pack */ idest++; continue; @@ -173,7 +174,7 @@ make_packed_array(ref * parr, ref_stack_t * pstack, uint size, switch (r_btype(pref)) { /* not r_type, opers are special */ case t_name: { - uint nidx = name_index(pref); + uint nidx = name_index(imem, pref); if (nidx >= packed_name_max_index) break; /* can't pack */ @@ -220,7 +221,7 @@ make_packed_array(ref * parr, ref_stack_t * pstack, uint size, while (--i >= 0) { --psrc; --pmove; - packed_get(psrc, pmove); + packed_get(imem, psrc, pmove); } } pshort = pdest += packed_per_ref; diff --git a/gs/src/zpcolor.c b/gs/src/zpcolor.c index a42dad2c2..04c6f9e5b 100644 --- a/gs/src/zpcolor.c +++ b/gs/src/zpcolor.c @@ -95,11 +95,11 @@ zbuildpattern1(i_ctx_t *i_ctx_p) check_type(*op1, t_dictionary); check_dict_read(*op1); gs_pattern1_init(&template); - if ((code = read_matrix(op, &mat)) < 0 || + if ((code = read_matrix(imemory, op, &mat)) < 0 || (code = dict_uid_param(op1, &template.uid, 1, imemory, i_ctx_p)) != 1 || (code = dict_int_param(op1, "PaintType", 1, 2, 0, &template.PaintType)) < 0 || (code = dict_int_param(op1, "TilingType", 1, 3, 0, &template.TilingType)) < 0 || - (code = dict_floats_param(op1, "BBox", 4, BBox, NULL)) < 0 || + (code = dict_floats_param(imemory, op1, "BBox", 4, BBox, NULL)) < 0 || (code = dict_float_param(op1, "XStep", 0.0, &template.XStep)) != 0 || (code = dict_float_param(op1, "YStep", 0.0, &template.YStep)) != 0 || (code = dict_find_string(op1, "PaintProc", &pPaintProc)) <= 0 @@ -157,7 +157,7 @@ zsetpatternspace(i_ctx_t *i_ctx_p) } cs.params.pattern.has_base_space = true; } - gs_cspace_init(&cs, &gs_color_space_type_Pattern, NULL); + gs_cspace_init(&cs, &gs_color_space_type_Pattern, imemory, false); code = gs_setcolorspace(igs, &cs); if (code < 0) { ref_stack_pop_to(&e_stack, edepth); diff --git a/gs/src/zrelbit.c b/gs/src/zrelbit.c index 9976bb77f..922c90565 100644 --- a/gs/src/zrelbit.c +++ b/gs/src/zrelbit.c @@ -49,7 +49,7 @@ zeq(i_ctx_t *i_ctx_p) os_ptr op = osp; EQ_CHECK_READ(op - 1, check_op(2)); EQ_CHECK_READ(op, DO_NOTHING); - make_bool(op - 1, (obj_eq(op - 1, op) ? 1 : 0)); + make_bool(op - 1, (obj_eq(imemory, op - 1, op) ? 1 : 0)); pop(1); return 0; } @@ -279,7 +279,7 @@ zidenteq(i_ctx_t *i_ctx_p) EQ_CHECK_READ(op - 1, check_op(2)); EQ_CHECK_READ(op, DO_NOTHING); - make_bool(op - 1, (obj_ident_eq(op - 1, op) ? 1 : 0)); + make_bool(op - 1, (obj_ident_eq(imemory, op - 1, op) ? 1 : 0)); pop(1); return 0; diff --git a/gs/src/zshade.c b/gs/src/zshade.c index d2c097e69..1f4d7a50c 100644 --- a/gs/src/zshade.c +++ b/gs/src/zshade.c @@ -100,7 +100,7 @@ zbuildshadingpattern(i_ctx_t *i_ctx_p) check_type(*op2, t_dictionary); check_dict_read(*op2); gs_pattern2_init(&template); - if ((code = read_matrix(op - 1, &mat)) < 0 || + if ((code = read_matrix(imemory, op - 1, &mat)) < 0 || (code = dict_uid_param(op2, &template.uid, 1, imemory, i_ctx_p)) != 1 || (code = shading_param(op, &template.Shading)) < 0 || (code = int_pattern_alloc(&pdata, op2, imemory)) < 0 @@ -187,7 +187,7 @@ build_shading(i_ctx_t *i_ctx_p, build_shading_proc_t proc) } pcc->pattern = 0; params.Background = pcc; - code = dict_floats_param(op, "Background", + code = dict_floats_param(imemory, op, "Background", gs_color_space_num_components(pcs), pcc->paint.values, NULL); if (code < 0) @@ -196,7 +196,8 @@ build_shading(i_ctx_t *i_ctx_p, build_shading_proc_t proc) } if (dict_find_string(op, "BBox", &pvalue) <= 0) params.have_BBox = false; - else if ((code = dict_floats_param(op, "BBox", 4, box, NULL)) == 4) { + else if ((code = dict_floats_param(imemory, op, "BBox", + 4, box, NULL)) == 4) { params.BBox.p.x = box[0]; params.BBox.p.y = box[1]; params.BBox.q.x = box[2]; @@ -248,7 +249,7 @@ build_shading_function(i_ctx_t *i_ctx_p, const ref * op, gs_function_t ** ppfn, for (i = 0; i < size; ++i) { ref rsubfn; - array_get(pFunction, (long)i, &rsubfn); + array_get(imemory, pFunction, (long)i, &rsubfn); code = fn_build_function(i_ctx_p, &rsubfn, &Functions[i], mem); if (code < 0) break; @@ -301,10 +302,11 @@ build_shading_1(i_ctx_t *i_ctx_p, const ref * op, const gs_shading_params_t * pc *(gs_shading_params_t *)¶ms = *pcommon; gs_make_identity(¶ms.Matrix); params.Function = 0; - if ((code = dict_floats_param(op, "Domain", 4, params.Domain, + if ((code = dict_floats_param(imemory, op, "Domain", + 4, params.Domain, default_Domain)) < 0 || (dict_find_string(op, "Matrix", &pmatrix) > 0 && - (code = read_matrix(pmatrix, ¶ms.Matrix)) < 0) || + (code = read_matrix(imemory, pmatrix, ¶ms.Matrix)) < 0) || (code = build_shading_function(i_ctx_p, op, ¶ms.Function, 2, mem)) < 0 || (code = check_indexed_vs_function(params.ColorSpace, params.Function)) < 0 || (code = gs_shading_Fb_init(ppsh, ¶ms, mem)) < 0 @@ -327,13 +329,14 @@ build_directional_shading(i_ctx_t *i_ctx_p, const ref * op, float *Coords, int n float Domain[2], gs_function_t ** pFunction, bool Extend[2], gs_memory_t *mem) { - int code = dict_floats_param(op, "Coords", num_Coords, Coords, NULL); + int code = dict_floats_param(imemory, op, "Coords", + num_Coords, Coords, NULL); static const float default_Domain[2] = {0, 1}; ref *pExtend; *pFunction = 0; if (code < 0 || - (code = dict_floats_param(op, "Domain", 2, Domain, + (code = dict_floats_param(imemory, op, "Domain", 2, Domain, default_Domain)) < 0 || (code = build_shading_function(i_ctx_p, op, pFunction, 1, mem)) < 0 ) @@ -349,8 +352,10 @@ build_directional_shading(i_ctx_t *i_ctx_p, const ref * op, float *Coords, int n return_error(e_typecheck); else if (r_size(pExtend) != 2) return_error(e_rangecheck); - else if ((array_get(pExtend, 0L, &E0), !r_has_type(&E0, t_boolean)) || - (array_get(pExtend, 1L, &E1), !r_has_type(&E1, t_boolean)) + else if ((array_get(imemory, pExtend, 0L, &E0), + !r_has_type(&E0, t_boolean)) || + (array_get(imemory, pExtend, 1L, &E1), + !r_has_type(&E1, t_boolean)) ) return_error(e_typecheck); Extend[0] = E0.value.boolval, Extend[1] = E1.value.boolval; @@ -432,7 +437,7 @@ build_mesh_shading(i_ctx_t *i_ctx_p, const ref * op, "build_mesh_shading"); if (data == 0) return_error(e_VMerror); - code = process_float_array(pDataSource, size, data); + code = process_float_array(mem, pDataSource, size, data); if (code < 0) { gs_free_object(mem, data, "build_mesh_shading"); return code; @@ -480,7 +485,7 @@ build_mesh_shading(i_ctx_t *i_ctx_p, const ref * op, if (*pDecode == 0) code = gs_note_error(e_VMerror); else { - code = dict_floats_param(op, "Decode", num_decode, *pDecode, NULL); + code = dict_floats_param(mem, op, "Decode", num_decode, *pDecode, NULL); if (code < 0) { gs_free_object(mem, *pDecode, "build_mesh_shading"); *pDecode = 0; diff --git a/gs/src/zstring.c b/gs/src/zstring.c index 378f675d5..ab6a66c61 100644 --- a/gs/src/zstring.c +++ b/gs/src/zstring.c @@ -71,7 +71,7 @@ znamestring(i_ctx_t *i_ctx_p) os_ptr op = osp; check_type(*op, t_name); - name_string_ref(op, op); + name_string_ref(imemory, op, op); return 0; } @@ -183,7 +183,7 @@ zstringmatch(i_ctx_t *i_ctx_p) check_read(*op1); goto cmp; case t_name: - name_string_ref(op1, op1); /* can't fail */ + name_string_ref(imemory, op1, op1); /* can't fail */ cmp: result = string_match(op1->value.const_bytes, r_size(op1), op->value.const_bytes, r_size(op), diff --git a/gs/src/ztoken.c b/gs/src/ztoken.c index 2af587a69..c0ff6f6fa 100644 --- a/gs/src/ztoken.c +++ b/gs/src/ztoken.c @@ -282,7 +282,7 @@ ztoken_handle_comment(i_ctx_t *i_ctx_p, const ref *fop, scanner_state *sstate, return code; } check_estack(4); - code = name_enter_string(proc_name, esp + 4); + code = name_enter_string(imemory, proc_name, esp + 4); if (code < 0) return code; if (save) { diff --git a/gs/src/ztrans.c b/gs/src/ztrans.c index 25c332977..435ba4dd1 100644 --- a/gs/src/ztrans.c +++ b/gs/src/ztrans.c @@ -64,12 +64,13 @@ current_float_value(i_ctx_t *i_ctx_p, } private int -enum_param(const ref *pnref, const char *const names[]) +enum_param(const gs_memory_t *mem, const ref *pnref, + const char *const names[]) { const char *const *p; ref nsref; - name_string_ref(pnref, &nsref); + name_string_ref(mem, pnref, &nsref); for (p = names; *p; ++p) if (r_size(&nsref) == strlen(*p) && !memcmp(*p, nsref.value.const_bytes, r_size(&nsref)) @@ -92,7 +93,7 @@ zsetblendmode(i_ctx_t *i_ctx_p) int code; check_type(*op, t_name); - if ((code = enum_param(op, blend_mode_names)) < 0 || + if ((code = enum_param(imemory, op, blend_mode_names)) < 0 || (code = gs_setblendmode(igs, code)) < 0 ) return code; @@ -107,7 +108,7 @@ zcurrentblendmode(i_ctx_t *i_ctx_p) os_ptr op = osp; const char *mode_name = blend_mode_names[gs_currentblendmode(igs)]; ref nref; - int code = name_enter_string(mode_name, &nref); + int code = name_enter_string(imemory, mode_name, &nref); if (code < 0) return code; @@ -261,10 +262,10 @@ zbegintransparencymask(i_ctx_t *i_ctx_p) check_dict_read(*dop); if (dict_find_string(dop, "Subtype", &pparam) <= 0) return_error(e_rangecheck); - if ((code = enum_param(pparam, subtype_names)) < 0) + if ((code = enum_param(imemory, pparam, subtype_names)) < 0) return code; gs_trans_mask_params_init(¶ms, code); - if ((code = dict_floats_param(dop, "Background", 1, + if ((code = dict_floats_param(imemory, dop, "Background", 1, params.Background, NULL)) < 0 ) return code; @@ -323,7 +324,8 @@ zinittransparencymask(i_ctx_t *i_ctx_p) /* ------ Soft-mask images ------ */ /* <dict> .image3x - */ -private int mask_dict_param(os_ptr, image_params *, const char *, int, +private int mask_dict_param(const gs_memory_t *mem, os_ptr, + image_params *, const char *, int, gs_image3x_mask_t *); private int zimage3x(i_ctx_t *i_ctx_p) @@ -352,9 +354,11 @@ zimage3x(i_ctx_t *i_ctx_p) * We have to process the masks in the reverse order, because they * insert their DataSource before the one(s) for the DataDict. */ - if ((code = mask_dict_param(op, &ip_data, "ShapeMaskDict", num_components, + if ((code = mask_dict_param(imemory, op, &ip_data, + "ShapeMaskDict", num_components, &image.Shape)) < 0 || - (code = mask_dict_param(op, &ip_data, "OpacityMaskDict", num_components, + (code = mask_dict_param(imemory, op, &ip_data, + "OpacityMaskDict", num_components, &image.Opacity)) < 0 ) return code; @@ -365,7 +369,8 @@ zimage3x(i_ctx_t *i_ctx_p) /* Get one soft-mask dictionary parameter. */ private int -mask_dict_param(os_ptr op, image_params *pip_data, const char *dict_name, +mask_dict_param(const gs_memory_t *mem, os_ptr op, +image_params *pip_data, const char *dict_name, int num_components, gs_image3x_mask_t *pixm) { ref *pMaskDict; @@ -375,12 +380,13 @@ mask_dict_param(os_ptr op, image_params *pip_data, const char *dict_name, if (dict_find_string(op, dict_name, &pMaskDict) <= 0) return 1; - if ((mcode = code = data_image_params(pMaskDict, &pixm->MaskDict, + if ((mcode = code = data_image_params(mem, pMaskDict, &pixm->MaskDict, &ip_mask, false, 1, 12, false)) < 0 || (code = dict_int_param(pMaskDict, "ImageType", 1, 1, 0, &ignored)) < 0 || (code = dict_int_param(pMaskDict, "InterleaveType", 1, 3, -1, &pixm->InterleaveType)) < 0 || - (code = dict_floats_param(op, "Matte", num_components, pixm->Matte, NULL)) < 0 + (code = dict_floats_param(mem, op, "Matte", num_components, + pixm->Matte, NULL)) < 0 ) return code; pixm->has_Matte = code > 0; diff --git a/gs/src/ztype.c b/gs/src/ztype.c index 897659fc4..0a26fe97a 100644 --- a/gs/src/ztype.c +++ b/gs/src/ztype.c @@ -40,7 +40,7 @@ /* Forward references */ private int access_check(i_ctx_t *, int, bool); -private int convert_to_string(os_ptr, os_ptr); +private int convert_to_string(const gs_memory_t *mem, os_ptr, os_ptr); /* * Max and min integer values expressed as reals. @@ -69,7 +69,7 @@ ztype(i_ctx_t *i_ctx_p) { os_ptr op = osp; ref tnref; - int code = array_get(op, (long)r_btype(op - 1), &tnref); + int code = array_get(imemory, op, (long)r_btype(op - 1), &tnref); if (code < 0) return code; @@ -80,7 +80,7 @@ ztype(i_ctx_t *i_ctx_p) const char *sname = gs_struct_type_name_string(gs_object_type(imemory, op[-1].value.pstruct)); - int code = name_ref((const byte *)sname, strlen(sname), + int code = name_ref(imemory, (const byte *)sname, strlen(sname), (ref *) (op - 1), 0); if (code < 0) @@ -109,7 +109,7 @@ ztypenames(i_ctx_t *i_ctx_p) if (i >= countof(tnames) || tnames[i] == 0) make_null(rtnp); else { - int code = name_enter_string(tnames[i], rtnp); + int code = name_enter_string(imemory, tnames[i], rtnp); if (code < 0) return code; @@ -284,7 +284,7 @@ zcvn(i_ctx_t *i_ctx_p) os_ptr op = osp; check_read_type(*op, t_string); - return name_from_string(op, op); + return name_from_string(imemory, op, op); } /* <num> cvr <real> */ @@ -343,7 +343,7 @@ zcvrs(i_ctx_t *i_ctx_p) case t_integer: case t_real: { - int code = convert_to_string(op - 2, op); + int code = convert_to_string(imemory, op - 2, op); if (code < 0) return code; @@ -400,7 +400,7 @@ zcvs(i_ctx_t *i_ctx_p) check_op(2); check_write_type(*op, t_string); - code = convert_to_string(op - 1, op); + code = convert_to_string(imemory, op - 1, op); if (code >= 0) pop(1); return code; @@ -483,11 +483,11 @@ access_check(i_ctx_t *i_ctx_p, /* the source. This is a separate procedure so that */ /* cvrs can use it when the radix is 10. */ private int -convert_to_string(os_ptr op1, os_ptr op) +convert_to_string(const gs_memory_t *mem, os_ptr op1, os_ptr op) { uint len; const byte *pstr = 0; - int code = obj_cvs(op1, op->value.bytes, r_size(op), &len, &pstr); + int code = obj_cvs(mem, op1, op->value.bytes, r_size(op), &len, &pstr); if (code < 0) { /* diff --git a/gs/src/zupath.c b/gs/src/zupath.c index 43ace507f..ae8ff80f7 100644 --- a/gs/src/zupath.c +++ b/gs/src/zupath.c @@ -447,7 +447,7 @@ make_upath(i_ctx_t *i_ctx_p, ref *rupath, gs_state *pgs, gx_path *ppath, /* Construct the path. */ next = rupath->value.refs; if (with_ucache) { - if ((code = name_enter_string("ucache", next)) < 0) + if ((code = name_enter_string(pgs->memory, "ucache", next)) < 0) return code; r_set_attrs(next, a_executable | l_new); ++next; @@ -469,7 +469,7 @@ make_upath(i_ctx_t *i_ctx_p, ref *rupath, gs_state *pgs, gx_path *ppath, make_real_new(next + 2, bbox.q.x); make_real_new(next + 3, bbox.q.y); next += 4; - if ((code = name_enter_string("setbbox", next)) < 0) + if ((code = name_enter_string(pgs->memory, "setbbox", next)) < 0) return code; r_set_attrs(next, a_executable | l_new); ++next; @@ -512,7 +512,7 @@ make_upath(i_ctx_t *i_ctx_p, ref *rupath, gs_state *pgs, gx_path *ppath, default: return_error(e_unregistered); } - if ((code = name_enter_string(opstr, next)) < 0) + if ((code = name_enter_string(pgs->memory, opstr, next)) < 0) return code; r_set_attrs(next, a_executable); ++next; @@ -535,7 +535,7 @@ upath_append_aux(os_ptr oppath, i_ctx_t *i_ctx_p) return_error(e_typecheck); if ( r_size(oppath) == 2 && - array_get(oppath, 1, &opcodes) >= 0 && + array_get(imemory, oppath, 1, &opcodes) >= 0 && r_has_type(&opcodes, t_string) ) { /* 1st element is operands, 2nd is operators */ ref operands; @@ -544,7 +544,7 @@ upath_append_aux(os_ptr oppath, i_ctx_t *i_ctx_p) const byte *opp; uint ocount, i = 0; - array_get(oppath, 0, &operands); + array_get(imemory, oppath, 0, &operands); code = num_array_format(&operands); if (code < 0) return code; @@ -565,7 +565,7 @@ upath_append_aux(os_ptr oppath, i_ctx_t *i_ctx_p) while (opargs--) { push(1); - code = num_array_get(&operands, format, i++, op); + code = num_array_get(imemory, &operands, format, i++, op); switch (code) { case t_integer: r_set_type_attrs(op, t_integer, 0); @@ -598,7 +598,7 @@ upath_append_aux(os_ptr oppath, i_ctx_t *i_ctx_p) ref *defp; os_ptr op = osp; - array_get(arp, index, &rup); + array_get(imemory, arp, index, &rup); switch (r_type(&rup)) { case t_integer: case t_real: @@ -659,7 +659,7 @@ upath_stroke(i_ctx_t *i_ctx_p, gs_matrix *pmat) int code, npop; gs_matrix mat; - if ((code = read_matrix(op, &mat)) >= 0) { + if ((code = read_matrix(imemory, op, &mat)) >= 0) { if ((code = upath_append(op - 1, i_ctx_p)) >= 0) { if (pmat) *pmat = mat; diff --git a/gs/src/zusparam.c b/gs/src/zusparam.c index 08b9ee79c..6a3df3283 100644 --- a/gs/src/zusparam.c +++ b/gs/src/zusparam.c @@ -102,7 +102,7 @@ zcheckpassword(i_ctx_t *i_ctx_p) array_param_list list; gs_param_list *const plist = (gs_param_list *)&list; int result = 0; - int code = name_ref((const byte *)"Password", 8, ¶ms[0], 0); + int code = name_ref(imemory, (const byte *)"Password", 8, ¶ms[0], 0); password pass; if (code < 0) @@ -699,7 +699,7 @@ currentparam1(i_ctx_t *i_ctx_p, const param_set * pset) check_type(*op, t_name); check_ostack(2); - name_string_ref((const ref *)op, &sref); + name_string_ref(imemory, (const ref *)op, &sref); code = current_param_list(i_ctx_p, pset, &sref); if (code < 0) return code; diff --git a/gs/src/zvmem.c b/gs/src/zvmem.c index 76799ae3d..851a3caac 100644 --- a/gs/src/zvmem.c +++ b/gs/src/zvmem.c @@ -28,7 +28,6 @@ #include "stream.h" /* for files.h */ #include "files.h" /* for e-stack processing */ #include "store.h" -#include "gsmalloc.h" /* for gs_memory_default */ #include "gsmatrix.h" /* for gsstate.h */ #include "gsstate.h" @@ -232,7 +231,8 @@ restore_check_stack(const ref_stack_t * pstack, const alloc_save_t * asave, break; case t_name: /* Names are special because of how they are allocated. */ - if (alloc_name_is_since_save(stkp, asave)) + if (alloc_name_is_since_save((const gs_memory_t *)pstack->memory, + stkp, asave)) return_error(e_invalidrestore); continue; case t_string: @@ -336,7 +336,7 @@ zvmstatus(i_ctx_t *i_ctx_p) mstat.allocated += sstat.allocated; mstat.used += sstat.used; } - gs_memory_status(&gs_memory_default, &dstat); + gs_memory_status(imemory->non_gc_memory, &dstat); push(3); make_int(op - 2, imemory_save_level(iimemory_local)); make_int(op - 1, mstat.used); |