Exemple #1
0
/* If the font name isn't a name or a string, return an empty string. */
void
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(mem, op, pfname);
            break;
        default:
            /* This is weird, but legal.... */
            make_empty_string(pfname, a_readonly);
    }
}
Exemple #2
0
static gs_char
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) {
        uint cid = glyph - gs_min_cid_glyph;

        if (dict_find_string(map, "CIDCount", &v) > 0) {
            /* This is a CIDDEcoding resource. */
            make_int(&n, cid / 256);
            if (dict_find(map, &n, &v) > 0) {
                ref vv;

                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. */
        }
        /* This is GlyphNames2Unicode dictionary. */
        make_int(&n, cid);
    } else
        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);
            gs_char c = 0;

            for (i = 0; i < l; i++)
                c = (c << 8) | v->value.const_bytes[i];
            return c;
        }
        if (r_type(v) == t_integer)
            return v->value.intval;
    }
    return GS_NO_CHAR; /* Absent in the map. */
}
Exemple #3
0
/* <string> cvr <real> */
int
zcvr(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;

    switch (r_type(op)) {
	case t_integer:
	    make_real(op, (float)op->value.intval);
	case t_real:
	    return 0;
	default:
	    return_op_typecheck(op);
	case t_string:
	    {
		ref str, token;
		int code;

		ref_assign(&str, op);
		code = scan_string_token(i_ctx_p, &str, &token);
		if (code > 0)	/* anything other than a plain token */
		    code = gs_note_error(e_syntaxerror);
		if (code < 0)
		    return code;
		switch (r_type(&token)) {
		    case t_integer:
			make_real(op, (float)token.value.intval);
			return 0;
		    case t_real:
			*op = token;
			return 0;
		    default:
			return_error(e_typecheck);
		}
	    }
    }
}
Exemple #4
0
static int
zforall(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr obj = op - 1;
    es_ptr ep = esp;
    es_ptr cproc = ep + 4;

    check_estack(6);
    check_proc(*op);
    switch (r_type(obj)) {
	default:
	    return_op_typecheck(obj);
	case t_array:
	    check_read(*obj);
	    make_op_estack(cproc, array_continue);
	    break;
	case t_dictionary:
	    check_dict_read(*obj);
	    make_int(cproc, dict_first(obj));
	    ++cproc;
	    make_op_estack(cproc, dict_continue);
	    break;
	case t_string:
	    check_read(*obj);
	    make_op_estack(cproc, string_continue);
	    break;
	case t_mixedarray:
	case t_shortarray:
	    check_read(*obj);
	    make_op_estack(cproc, packedarray_continue);
	    break;
    }
    /*
     * Push:
     *   - a mark;
     *   - the composite object;
     *   - the procedure;
     *   - the iteration index (only for dictionaries, done above);
     * and invoke the continuation operator.
     */
    make_mark_estack(ep + 1, es_for, forall_cleanup);
    ep[2] = *obj;
    ep[3] = *op;
    esp = cproc - 1;
    pop(2);
    return (*real_opproc(cproc))(i_ctx_p);
}
Exemple #5
0
/* BitsPerSample. */
static int
dict_threshold2_params(const ref * pdict, gs_threshold2_halftone * ptp,
		       ref * ptproc, gs_memory_t *mem)
{
    ref *tstring;
    int code =
	dict_threshold_common_params(pdict,
				     (gs_threshold_halftone_common *)ptp,
				     &tstring, ptproc);
    int bps;
    uint size;
    int cw2, ch2;

    if (code < 0 ||
	(code = cw2 = dict_int_param(pdict, "Width2", 0, 0x7fff, 0,
				     &ptp->width2)) < 0 ||
	(code = ch2 = dict_int_param(pdict, "Height2", 0, 0x7fff, 0,
				     &ptp->height2)) < 0 ||
	(code = dict_int_param(pdict, "BitsPerSample", 8, 16, -1, &bps)) < 0
	)
	return code;
    if ((bps != 8 && bps != 16) || cw2 != ch2 ||
	(!cw2 && (ptp->width2 == 0 || ptp->height2 == 0))
	)
	return_error(e_rangecheck);
    ptp->bytes_per_sample = bps / 8;
    switch (r_type(tstring)) {
    case t_string:
	size = r_size(tstring);
	gs_bytestring_from_string(&ptp->thresholds, tstring->value.const_bytes,
				  size);
	break;
    case t_astruct:
	if (gs_object_type(mem, tstring->value.pstruct) != &st_bytes)
	    return_error(e_typecheck);
	size = gs_object_size(mem, tstring->value.pstruct);
	gs_bytestring_from_bytes(&ptp->thresholds, r_ptr(tstring, byte),
				 0, size);
	break;
    default:
	return_error(e_typecheck);
    }
    check_read(*tstring);
    if (size != (ptp->width * ptp->height + ptp->width2 * ptp->height2) *
	ptp->bytes_per_sample)
	return_error(e_rangecheck);
    return 0;
}
void test_sra()
{
	printf("===test SRA===\n");
	struct cpu_struct cpu;
	memset(&cpu, 0, sizeof(cpu));
	cpu.current_ins.rt = 1;
	cpu.current_ins.rd = 2;
	cpu.current_ins.shamt = 3;
	cpu.current_ins.funct = 0x03;
	cpu.reg[1] = 0x80000000;
	r_type(&cpu);
	printf("%s\n", word_to_binary(cpu.reg[1], 0, 31));
	printf("%s\n", word_to_binary(cpu.reg[2], 0, 31));
	assert(cpu.reg[2] == 0xf0000000);
	printf("pass\n\n");
}
Exemple #7
0
/* <num1> truncate <num2> */
int
ztruncate(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;

    switch (r_type(op)) {
	default:
	    return_op_typecheck(op);
	case t_real:
	    op->value.realval =
		(op->value.realval < 0.0 ?
		 ceil(op->value.realval) :
		 floor(op->value.realval));
	case t_integer:;
    }
    return 0;
}
Exemple #8
0
/* If an error is returned, the return value is not updated. */
int
real_param(const ref * op, double *pparam)
{
    switch (r_type(op)) {
	case t_integer:
	    *pparam = op->value.intval;
	    break;
	case t_real:
	    *pparam = op->value.realval;
	    break;
        case t__invalid:
	    return_error(e_stackunderflow);
	default:
	    return_error(e_typecheck);
    }
    return 0;
}
/* <int> not <int> */
int
znot(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;

    switch (r_type(op)) {
	case t_boolean:
	    op->value.boolval = !op->value.boolval;
	    break;
	case t_integer:
	    op->value.intval = ~op->value.intval;
	    break;
	default:
	    return_op_typecheck(op);
    }
    return 0;
}
Exemple #10
0
/*
 * If the new save level is zero, fix up the contents of a stack
 * by clearing the l_new bit in all the entries (since we can't tolerate
 * values with l_new set if the save level is zero).
 * Also, in any case, fix up the e-stack by replacing empty executable
 * strings and closed executable files that are newer than the save
 * with canonical ones that aren't.
 *
 * Note that this procedure is only called if restore_check_stack succeeded.
 */
static void
restore_fix_stack(ref_stack_t * pstack, const alloc_save_t * asave,
                  bool is_estack)
{
    ref_stack_enum_t rsenum;

    ref_stack_enum_begin(&rsenum, pstack);
    do {
        ref *stkp = rsenum.ptr;
        uint size = rsenum.size;

        for (; size; stkp++, size--) {
            r_clear_attrs(stkp, l_new);		/* always do it, no harm */
            if (is_estack) {
                ref ofile;

                ref_assign(&ofile, stkp);
                switch (r_type(stkp)) {
                case t_string:
                    if (r_size(stkp) == 0 &&
                            alloc_is_since_save(stkp->value.bytes,
                                                asave)
                       ) {
                        make_empty_const_string(stkp,
                                                avm_foreign);
                        break;
                    }
                    continue;
                case t_file:
                    if (alloc_is_since_save(stkp->value.pfile,
                                            asave)
                       ) {
                        make_invalid_file(stkp);
                        break;
                    }
                    continue;
                default:
                    continue;
                }
                r_copy_attrs(stkp, a_all | a_executable,
                             &ofile);
            }
        }
    } while (ref_stack_enum_next(&rsenum));
}
Exemple #11
0
/* Implementation for enumerating parameters in a dictionary */
static int			/* ret 0 ok, 1 if EOF, or -ve err */
dict_param_enumerate(iparam_list * plist, gs_param_enumerator_t * penum,
		     gs_param_key_t * key, ref_type * type)
{
    ref elt[2];
    int code;
    dict_param_list *const pdlist = (dict_param_list *) plist;
    int index =
    (penum->intval != 0 ? penum->intval : dict_first(&pdlist->dict));

    index = dict_next(&pdlist->dict, index, elt);
    if (index < 0)
	return 1;
    *type = r_type(&elt[1]);
    code = ref_to_key(&elt[0], key, plist);
    penum->intval = index;
    return code;
}
Exemple #12
0
/* float_params doesn't bother to keep track of the mask. */
int
float_params(const ref * op, int count, float *pval)
{
    for (pval += count; --count >= 0; --op)
	switch (r_type(op)) {
	    case t_real:
		*--pval = op->value.realval;
		break;
	    case t_integer:
		*--pval = (float)op->value.intval;
		break;
	    case t__invalid:
		return_error(e_stackunderflow);
	    default:
		return_error(e_typecheck);
	}
    return 0;
}
Exemple #13
0
/* <num1> abs <num2> */
int
zabs(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;

    switch (r_type(op)) {
	default:
	    return_op_typecheck(op);
	case t_real:
	    if (op->value.realval >= 0)
		return 0;
	    break;
	case t_integer:
	    if (op->value.intval >= 0)
		return 0;
	    break;
    }
    return zneg(i_ctx_p);
}
Exemple #14
0
/* <num1> neg <num2> */
int
zneg(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;

    switch (r_type(op)) {
	default:
	    return_op_typecheck(op);
	case t_real:
	    op->value.realval = -op->value.realval;
	    break;
	case t_integer:
	    if (op->value.intval == MIN_INTVAL)
		make_real(op, -(float)MIN_INTVAL);
	    else
		op->value.intval = -op->value.intval;
    }
    return 0;
}
Exemple #15
0
/* but not for dictionaries (see zcopy_dict in zdict.c). */
int
zcopy(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    int type = r_type(op);

    if (type == t_integer)
	return zcopy_integer(i_ctx_p);
    check_op(2);
    switch (type) {
	case t_array:
	case t_string:
	    return zcopy_interval(i_ctx_p);
	case t_dictionary:
	    return zcopy_dict(i_ctx_p);
	default:
	    return_op_typecheck(op);
    }
}
Exemple #16
0
/* Encode a character. */
gs_glyph
zfont_encode_char(gs_font *pfont, gs_char chr, gs_glyph_space_t gspace)
{
    font_data *pdata = pfont_data(pfont);
    const ref *pencoding = &pdata->Encoding;
    ulong index = chr;	/* work around VAX widening bug */
    ref 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(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.
               They need a glyph name but the font doesn't provide one
               due to an instandard BuildChar.
               Such fonts don't conform to PLRM section 5.3.7,
               but we've got real examples that we want to handle (Bug 686982).
               Construct a name here.
               Low level devices don't pass here, because regular PS interpretation
               doesn't need such names.
            */
            char buf[20];
            int code;

            if (gspace == GLYPH_SPACE_NOGEN)
                return gs_no_glyph;
            sprintf(buf, "j%ld", chr); /* 'j' is arbutrary. */
            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 */
            } else
                cname = tname;
        }
    }
    return (gs_glyph)name_index(pfont->memory, &cname);
}
Exemple #17
0
/* a missing value will return e_undefined rather than 1. */
int
dict_int_null_param(const ref * pdict, const char *kstr, int minval,
                    int maxval, int defaultval, int *pvalue)
{
    ref *pdval;
    int code, ival;

    if (pdict == 0 || dict_find_string(pdict, kstr, &pdval) <= 0) {
        ival = defaultval;
        code = 1;
    } else {
        switch (r_type(pdval)) {
            case t_integer:
                ival = pdval->value.intval;
                break;
            case t_real:
                /* Allow an integral real, because Fontographer */
                /* (which violates the Adobe specs in other ways */
                /* as well) sometimes generates output that */
                /* needs this. */
                if (pdval->value.realval < minval || pdval->value.realval > maxval)
                    return_error(e_rangecheck);
                ival = (long)pdval->value.realval;
                if (ival != pdval->value.realval)
                    return_error(e_rangecheck);
                break;
            case t_null:
                return 2;
            default:
                return_error(e_typecheck);
        }
        code = 0;
    }
    if (ival < minval || ival > maxval) {
        if (code == 1)
            return_error(e_undefined);
        else
            return_error(e_rangecheck);
    }
    *pvalue = (int)ival;
    return code;
}
Exemple #18
0
/* or if the object did not have the access already when modify=1. */
static int
access_check(i_ctx_t *i_ctx_p,
	     int access,	/* mask for attrs */
	     bool modify)	/* if true, reduce access */
{
    os_ptr op = osp;
    ref *aop;

    switch (r_type(op)) {
	case t_dictionary:
	    aop = dict_access_ref(op);
	    if (modify) {
		if (!r_has_attrs(aop, access))
		    return_error(e_invalidaccess);
		ref_save(op, aop, "access_check(modify)");
		r_clear_attrs(aop, a_all);
		r_set_attrs(aop, access);
		dict_set_top();
		return 0;
	    }
	    break;
	case t_array:
	case t_file:
	case t_string:
	case t_mixedarray:
	case t_shortarray:
	case t_astruct:
	case t_device:;
	    if (modify) {
		if (!r_has_attrs(op, access))
		    return_error(e_invalidaccess);
		r_clear_attrs(op, a_all);
		r_set_attrs(op, access);
		return 0;
	    }
	    aop = op;
	    break;
	default:
	    return_op_typecheck(op);
    }
    return (r_has_attrs(aop, access) ? 1 : 0);
}
/* <int1> <int2> xor <int> */
int
zxor(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;

    switch (r_type(op)) {
	case t_boolean:
	    check_type(op[-1], t_boolean);
	    op[-1].value.boolval ^= op->value.boolval;
	    break;
	case t_integer:
	    check_type(op[-1], t_integer);
	    op[-1].value.intval ^= op->value.intval;
	    break;
	default:
	    return_op_typecheck(op);
    }
    pop(1);
    return 0;
}
Exemple #20
0
/* Implementation for enumerating parameters on a stack */
static int			/* ret 0 ok, 1 if EOF, or -ve err */
stack_param_enumerate(iparam_list * plist, gs_param_enumerator_t * penum,
		      gs_param_key_t * key, ref_type * type)
{
    int code;
    stack_param_list *const splist = (stack_param_list *) plist;
    int index = penum->intval;
    ref *stack_element;

    do {
	stack_element =
	    ref_stack_index(splist->pstack, index + 1 + splist->skip);
	if (!stack_element)
	    return 1;
    } while (index += 2, !r_has_type(stack_element, t_name));
    *type = r_type(stack_element);
    code = ref_to_key(stack_element, key, plist);
    penum->intval = index;
    return code;
}
Exemple #21
0
/* Return 0 if found, 1 if defaulted, <0 if wrong type. */
int
dict_float_param(const ref * pdict, const char *kstr,
                 floatp defaultval, float *pvalue)
{
    ref *pdval;

    if (pdict == 0 || dict_find_string(pdict, kstr, &pdval) <= 0) {
        *pvalue = defaultval;
        return 1;
    }
    switch (r_type(pdval)) {
        case t_integer:
            *pvalue = (float)pdval->value.intval;
            return 0;
        case t_real:
            *pvalue = pdval->value.realval;
            return 0;
    }
    return_error(e_typecheck);
}
Exemple #22
0
/*
 * This forces a "put" even if the object is not writable, and (if the
 * object is systemdict or the save level is 0) even if the value is in
 * local VM.  It is meant to be used only for replacing the value of
 * FontDirectory in systemdict when switching between local and global VM,
 * and a few similar applications.  After initialization, this operator
 * should no longer be accessible by name.
 */
static int
zforceput(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr op1 = op - 1;
    os_ptr op2 = op - 2;
    int code;

    switch (r_type(op2)) {
    case t_array:
	check_int_ltu(*op1, r_size(op2));
	if (r_space(op2) > r_space(op)) {
	    if (imemory_save_level(iimemory))
		return_error(e_invalidaccess);
	}
	{
	    ref *eltp = op2->value.refs + (uint) op1->value.intval;

	    ref_assign_old(op2, eltp, op, "put");
	}
	break;
    case t_dictionary:
	if (op2->value.pdict == systemdict->value.pdict ||
	    !imemory_save_level(iimemory)
	    ) {
	    uint space = r_space(op2);

	    r_set_space(op2, avm_local);
	    code = idict_put(op2, op1, op);
	    r_set_space(op2, space);
	} else
	    code = idict_put(op2, op1, op);
	if (code < 0)
	    return code;
	break;
    default:
	return_error(e_typecheck);
    }
    pop(3);
    return 0;
}
Exemple #23
0
/* See idparam.h for specification. */
int
dict_int_array_check_param(const gs_memory_t *mem, const ref * pdict,
   const char *kstr, uint len, int *ivec, int under_error, int over_error)
{
    ref pa, *pdval;
    uint size;
    int i, code;

    if (pdict == 0 || dict_find_string(pdict, kstr, &pdval) <= 0)
        return 0;
    if (!r_is_array(pdval))
        return_error(e_typecheck);
    size = r_size(pdval);
    if (size > len)
        return_error(over_error);
    for (i = 0; i < size; i++) {
        code = array_get(mem, pdval, i, &pa);
        if (code < 0)
            return code;
        /* See dict_int_param above for why we allow reals here. */
        switch (r_type(&pa)) {
            case t_integer:
                if (pa.value.intval != (int)pa.value.intval)
                    return_error(e_rangecheck);
                ivec[i] = (int)pa.value.intval;
                break;
            case t_real:
                if (pa.value.realval < min_int ||
                    pa.value.realval > max_int ||
                    pa.value.realval != (int)pa.value.realval
                    )
                    return_error(e_rangecheck);
                ivec[i] = (int)pa.value.realval;
                break;
            default:
                return_error(e_typecheck);
        }
    }
    return (size == len || under_error >= 0 ? size :
            gs_note_error(under_error));
}
Exemple #24
0
/* Clear the relocation for a ref object. */
static void
refs_clear_reloc(obj_header_t *hdr, uint size)
{
    ref_packed *rp = (ref_packed *) (hdr + 1);
    ref_packed *end = (ref_packed *) ((byte *) rp + size);

    while (rp < end) {
	if (r_is_packed(rp))
	    rp++;
	else {
	    /* Full-size ref.  Store the relocation here if possible. */
	    ref *const pref = (ref *)rp;

	    if (!ref_type_uses_size_or_null(r_type(pref))) {
		if_debug1('8', "  [8]clearing reloc at 0x%lx\n", (ulong) rp);
		r_set_size(pref, 0);
	    }
	    rp += packed_per_ref;
	}
    }
}
Exemple #25
0
/*
 * 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 gs_memory_t *mem, const ref *op, const byte **pchars, uint *plen)
{
    switch (r_type(op)) {
    case t_name: {
	ref nref;

	name_string_ref(mem, op, &nref);
	*pchars = nref.value.bytes;
	*plen = r_size(&nref);
	return 0;
    }
    case t_string:
	check_read(*op);
	*pchars = op->value.bytes;
	*plen = r_size(op);
	return 0;
    default:
	return_error(e_typecheck);
    }
}
Exemple #26
0
void test_add()
{
	printf("===test ADD===\n");
	struct cpu_struct cpu;
	memset(&cpu, 0, sizeof(cpu));
	cpu.current_ins.rs = 1;
	cpu.current_ins.rt = 2;
	cpu.current_ins.rd = 3;
	cpu.current_ins.funct = 0x20;
	int i;
	for (i = 0; i < 100; i++) {
		int a = rand();
		int b = rand();
		cpu.reg[1] = a;
		cpu.reg[2] = b;
		r_type(&cpu);
		printf("%d + %d: %d\n", a, b, cpu.reg[3]);
		assert(cpu.reg[3] == a+b);
	}
	printf("pass\n\n");
}
Exemple #27
0
/* Implementation for enumerating parameters in an array */
static int			/* ret 0 ok, 1 if EOF, or -ve err */
array_param_enumerate(iparam_list * plist, gs_param_enumerator_t * penum,
		      gs_param_key_t * key, ref_type * type)
{
    int index = penum->intval;
    ref *bot = ((array_param_list *) plist)->bot;
    ref *ptr = bot + index;
    ref *top = ((array_param_list *) plist)->top;

    for (; ptr < top; ptr += 2) {
	index += 2;

	if (r_has_type(ptr, t_name)) {
	    int code = ref_to_key(ptr, key, plist);

	    *type = r_type(ptr);
	    penum->intval = index;
	    return code;
	}
    }
    return 1;
}
Exemple #28
0
/* <dict> <key> get <obj> */
static int
zget(i_ctx_t *i_ctx_p)
{
    int code;
    os_ptr op = osp;
    os_ptr op1 = op - 1;
    ref *pvalue;

    switch (r_type(op1)) {
	case t_dictionary:
	    check_dict_read(*op1);
	    if (dict_find(op1, op, &pvalue) <= 0)
		return_error(e_undefined);
	    op[-1] = *pvalue;
	    break;
	case t_string:
	    check_read(*op1);
	    check_int_ltu(*op, r_size(op1));
	    make_int(op1, op1->value.bytes[(uint) op->value.intval]);
	    break;
	case t_array:
	case t_mixedarray:
	case t_shortarray:
	    check_type(*op, t_integer);
	    check_read(*op1);
	    code = array_get(imemory, op1, op->value.intval, op1);
	    if (code < 0) 
	        return code;
	    break;
        case t__invalid:
            return_error(e_stackunderflow);
        default:
            return_error(e_typecheck); 
    }
    pop(1);
    return 0;
}
Exemple #29
0
/* Read a string value. */
static int
ref_param_read_string_value(gs_memory_t *mem, const iparam_loc * ploc, gs_param_string * pvalue)
{
    const ref *pref = ploc->pvalue;

    switch (r_type(pref)) {
	case t_name: {
	    ref nref;

	    name_string_ref(mem, pref, &nref);
	    pvalue->data = nref.value.const_bytes;
	    pvalue->size = r_size(&nref);
	    pvalue->persistent = true;
	}
	    break;
	case t_string:
	    iparam_check_read(*ploc);
	    pvalue->data = pref->value.const_bytes;
	    pvalue->size = r_size(pref);
	    pvalue->persistent = false;
	    break;
	case t_astruct:
	    /* Note: technically, instead of the "mem" argument, we
	       should be using the plists's ref_memory. However, in a
	       simple call to .putdeviceparams, they are identical. */
	    iparam_check_read(*ploc);
	    if (gs_object_type(mem, pref->value.pstruct) != &st_bytes) 
		return iparam_note_error(*ploc, e_typecheck);
	    pvalue->data = r_ptr(pref, byte);
	    pvalue->size = gs_object_size(mem, pref->value.pstruct);
	    pvalue->persistent = false;
	    break;
	default:
	    return iparam_note_error(*ploc, e_typecheck);
    }
    return 0;
}
Exemple #30
0
/* or an error if the format is invalid. */
int
num_array_get(const ref *op, int format, uint index, ref *np)
{	if ( format == num_array )
	  {	int code = array_get(op, (long)index, np);
		if ( code < 0 )
		  return t_null;
		switch ( r_type(np) )
		  {
		  case t_integer:
			return t_integer;
		  case t_real:
			return t_real;
		  default:
			return_error(e_rangecheck);
		  }
	  }
	else
	  {	uint nbytes = encoded_number_bytes(format);
		if ( index >= (r_size(op) - 4) / nbytes )
		  return t_null;
		return sdecode_number(op->value.bytes + 4 + index * nbytes,
				      format, np);
	  }
}