Ejemplo n.º 1
0
/*
 * Convert an operator index to an operator or oparray ref.
 * This is only used for debugging and for 'get' from packed arrays,
 * so it doesn't have to be very fast.
 */
void
op_index_ref(uint index, ref * pref)
{
    const op_array_table *opt;

    if (op_index_is_operator(index)) {
	make_oper(pref, index, op_index_proc(index));
	return;
    }
    opt = op_index_op_array_table(index);
    make_tasv(pref, t_oparray, opt->attrs, index,
	      const_refs, (opt->table.value.const_refs
			   + index - opt->base_index));
}
Ejemplo n.º 2
0
/* string */
int
zstring(register os_ptr op)
{	byte *sbody;
	uint size;
	check_type(*op, t_integer);
	if ( op->value.intval < 0 || (ulong)(op->value.intval) > max_uint )
		return e_rangecheck;
	size = op->value.intval;
	sbody = (byte *)alloc(size, 1, "string");
	if ( sbody == 0 ) return e_VMerror;
	make_tasv(op, t_string, a_all, size, bytes, sbody);
	memset(sbody, 0, size);
	return 0;
}
Ejemplo n.º 3
0
/* the VM space where the dictionary is allocated. */
static int
dict_create_contents(uint size, const ref * pdref, bool pack)
{
    dict *pdict = pdref->value.pdict;
    gs_ref_memory_t *mem = dict_memory(pdict);
    uint new_mask = imemory_new_mask(mem);
    uint asize = dict_round_size((size == 0 ? 1 : size));
    int code;
    register uint i;

    if (asize == 0 || asize > max_array_size - 1)	/* too large */
        return_error(gs_error_limitcheck);
    asize++;			/* allow room for wraparound entry */
    code = gs_alloc_ref_array(mem, &pdict->values, a_all, asize,
                              "dict_create_contents(values)");
    if (code < 0)
        return code;
    r_set_attrs(&pdict->values, new_mask);
    refset_null_new(pdict->values.value.refs, asize, new_mask);
    if (pack) {
        uint ksize = (asize + packed_per_ref - 1) / packed_per_ref;
        ref arr;
        ref_packed *pkp;
        ref_packed *pzp;

        code = gs_alloc_ref_array(mem, &arr, a_all, ksize,
                                  "dict_create_contents(packed keys)");
        if (code < 0)
            return code;
        pkp = (ref_packed *) arr.value.refs;
        make_tasv(&pdict->keys, t_shortarray,
                  r_space(&arr) | a_all | new_mask,
                  asize, packed, pkp);
        for (pzp = pkp, i = 0; i < asize || i % packed_per_ref; pzp++, i++)
            *pzp = packed_key_empty;
        *pkp = packed_key_deleted;	/* wraparound entry */
    } else {			/* not packed */
        int code = dict_create_unpacked_keys(asize, pdref);

        if (code < 0)
            return code;
    }
    make_tav(&pdict->count, t_integer, new_mask, intval, 0);
    make_tav(&pdict->maxlength, t_integer, new_mask, intval, size);
    return 0;
}