Esempio n. 1
0
static int
zcurrentfile(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    ref *fp;

    push(1);
    /* Check the cache first */
    if (esfile != 0) {
#ifdef DEBUG
        /* Check that esfile is valid. */
        ref *efp = zget_current_file(i_ctx_p);

        if (esfile != efp) {
            lprintf2("currentfile: esfile=0x%lx, efp=0x%lx\n",
                     (ulong) esfile, (ulong) efp);
            ref_assign(op, efp);
        } else
#endif
            ref_assign(op, esfile);
    } else if ((fp = zget_current_file(i_ctx_p)) == 0) {	/* Return an invalid file object. */
        /* This doesn't make a lot of sense to me, */
        /* but it's what the PostScript manual specifies. */
        make_invalid_file(i_ctx_p, op);
    } else {
        ref_assign(op, fp);
        esfile_set_cache(fp);
    }
    /* Make the returned value literal. */
    r_clear_attrs(op, a_executable);
    return 0;
}
Esempio n. 2
0
static byte *
gs_heap_resize_string(gs_memory_t * mem, byte * data, uint old_num, uint new_num,
		      client_name_t cname)
{
    if (gs_heap_object_type(mem, data) != &st_bytes)
	lprintf2("%s: resizing non-string 0x%lx!\n",
		 client_name_string(cname), (ulong) data);
    return gs_heap_resize_object(mem, data, new_num, cname);
}
Esempio n. 3
0
/* Run the initialization procedures of the individual operator files. */
int
zop_init(i_ctx_t *i_ctx_p)
{
    const op_def *const *tptr;
    int code;

    /* Because of a bug in Sun's SC1.0 compiler, */
    /* we have to spell out the typedef for op_def_ptr here: */
    const op_def *def;

    for (tptr = op_defs_all; *tptr != 0; tptr++) {
	for (def = *tptr; def->oname != 0; def++)
	    DO_NOTHING;
	if (def->proc != 0) {
	    code = def->proc(i_ctx_p);
	    if (code < 0) {
		lprintf2("op_init proc 0x%lx returned error %d!\n",
			 (ulong)def->proc, code);
		return code;
	    }
	}
    }

    /* Initialize the predefined names other than operators. */
    /* Do this here in case op_init changed any of them. */
    {
	ref vcr, vpr, vpf, vre, vrd;

	make_const_string(&vcr, a_readonly | avm_foreign,
			  strlen(gs_copyright), (const byte *)gs_copyright);
	make_const_string(&vpr, a_readonly | avm_foreign,
			  strlen(gs_product), (const byte *)gs_product);
	make_const_string(&vpf, a_readonly | avm_foreign,
			  strlen(gs_productfamily),
			  (const byte *)gs_productfamily);
	make_int(&vre, gs_revision);
	make_int(&vrd, gs_revisiondate);
	if ((code = initial_enter_name("copyright", &vcr)) < 0 ||
	    (code = initial_enter_name("product", &vpr)) < 0 ||
	    (code = initial_enter_name("productfamily", &vpf)) < 0 ||
	    (code = initial_enter_name("revision", &vre)) < 0 ||
	    (code = initial_enter_name("revisiondate", &vrd)) < 0)
	    return code;
    }

    return 0;
}
Esempio n. 4
0
int
gx_image_data(gx_image_enum_common_t * info, const byte ** plane_data,
	      int data_x, uint raster, int height)
{
    int num_planes = info->num_planes;
    gx_image_plane_t planes[GS_IMAGE_MAX_COMPONENTS];
    int i;

#ifdef DEBUG
    if (num_planes > GS_IMAGE_MAX_COMPONENTS) {
	lprintf2("num_planes=%d > GS_IMAGE_MAX_COMPONENTS=%d!\n",
		 num_planes, GS_IMAGE_MAX_COMPONENTS);
	return_error(gs_error_Fatal);
    }
#endif
    for (i = 0; i < num_planes; ++i) {
	planes[i].data = plane_data[i];
	planes[i].data_x = data_x;
	planes[i].raster = raster;
    }
    return gx_image_plane_data(info, planes, height);
}
Esempio n. 5
0
static void
gs_heap_free_object(gs_memory_t * mem, void *ptr, client_name_t cname)
{
    gs_malloc_memory_t *mmem = (gs_malloc_memory_t *) mem;
    gs_malloc_block_t *bp;
    gs_memory_type_ptr_t pstype;
    struct_proc_finalize((*finalize));

    if_debug3('a', "[a-]gs_free(%s) 0x%lx(%u)\n",
	      client_name_string(cname), (ulong) ptr,
	      (ptr == 0 ? 0 : ((gs_malloc_block_t *) ptr)[-1].size));
    if (ptr == 0)
	return;
    pstype = ((gs_malloc_block_t *) ptr)[-1].type;
    finalize = pstype->finalize;
    if (finalize != 0) {
	if_debug3('u', "[u]finalizing %s 0x%lx (%s)\n",
		  struct_type_name_string(pstype),
		  (ulong) ptr, client_name_string(cname));
	(*finalize) (ptr);
    }
    if (mmem->monitor)
	gx_monitor_enter(mmem->monitor);	/* Exclusive access */
    bp = mmem->allocated; /* If 'finalize' releases a memory,
			     this function could be called recursively and
			     change mmem->allocated. */
    if (ptr == bp + 1) {
	mmem->allocated = bp->next;
	mmem->used -= bp->size + sizeof(gs_malloc_block_t);

	if (mmem->allocated)
	    mmem->allocated->prev = 0;
	if (mmem->monitor)
	    gx_monitor_leave(mmem->monitor);	/* Done with exclusive access */
	gs_alloc_fill(bp, gs_alloc_fill_free,
		      bp->size + sizeof(gs_malloc_block_t));
	free(bp);
    } else {
	gs_malloc_block_t *np;

	/*
	 * bp == 0 at this point is an error, but we'd rather have an
	 * error message than an invalid access.
	 */
	if (bp) {
	    for (; (np = bp->next) != 0; bp = np) {
		if (ptr == np + 1) {
		    bp->next = np->next;
		    if (np->next)
			np->next->prev = bp;
		    mmem->used -= np->size + sizeof(gs_malloc_block_t);
		    if (mmem->monitor)
			gx_monitor_leave(mmem->monitor);	/* Done with exclusive access */
		    gs_alloc_fill(np, gs_alloc_fill_free,
				  np->size + sizeof(gs_malloc_block_t));
		    free(np);
		    return;
		}
	    }
	}
	if (mmem->monitor)
	    gx_monitor_leave(mmem->monitor);	/* Done with exclusive access */
	lprintf2("%s: free 0x%lx not found!\n",
		 client_name_string(cname), (ulong) ptr);
	free((char *)((gs_malloc_block_t *) ptr - 1));
    }
}