74
74
if ((uint) op->value.intval > (uint)(op - osbot)) {
75
/* There might be enough elements in other blocks. */
76
check_type(*op, t_integer);
77
if (op->value.intval >= (int)ref_stack_count(&o_stack))
75
/* There might be enough elements in other blocks. */
76
check_type(*op, t_integer);
77
if (op->value.intval >= (int)ref_stack_count(&o_stack))
78
78
return_error(e_stackunderflow);
79
if (op->value.intval < 0)
79
if (op->value.intval < 0)
80
80
return_error(e_rangecheck);
81
81
check_int_ltu(*op, ref_stack_count(&o_stack));
82
count = op->value.intval;
82
count = op->value.intval;
83
83
} else if (op1 + (count = op->value.intval) <= ostop) {
85
memcpy((char *)op, (char *)(op - count), count * sizeof(ref));
85
memcpy((char *)op, (char *)(op - count), count * sizeof(ref));
89
89
/* Do it the slow, general way. */
90
90
code = ref_stack_push(&o_stack, count - 1);
93
93
for (i = 0; i < count; i++)
94
*ref_stack_index(&o_stack, i) =
95
*ref_stack_index(&o_stack, i + count);
94
*ref_stack_index(&o_stack, i) =
95
*ref_stack_index(&o_stack, i + count);
121
121
switch (r_type(op)) {
127
make_int(op, r_size(op));
130
check_dict_read(*op);
131
make_int(op, dict_length(op));
127
make_int(op, r_size(op));
130
check_dict_read(*op);
131
make_int(op, dict_length(op));
136
name_string_ref(imemory, op, &str);
137
make_int(op, r_size(&str));
141
if (gs_object_type(imemory, op->value.pstruct) != &st_bytes)
142
return_error(e_typecheck);
144
make_int(op, gs_object_size(imemory, op->value.pstruct));
147
return_op_typecheck(op);
136
name_string_ref(imemory, op, &str);
137
make_int(op, r_size(&str));
141
if (gs_object_type(imemory, op->value.pstruct) != &st_bytes)
142
return_error(e_typecheck);
144
make_int(op, gs_object_size(imemory, op->value.pstruct));
147
return_op_typecheck(op);
161
161
switch (r_type(op1)) {
163
check_dict_read(*op1);
164
if (dict_find(op1, op, &pvalue) <= 0)
165
return_error(e_undefined);
170
check_int_ltu(*op, r_size(op1));
171
make_int(op1, op1->value.bytes[(uint) op->value.intval]);
176
check_type(*op, t_integer);
178
code = array_get(imemory, op1, op->value.intval, op1);
163
check_dict_read(*op1);
164
if (dict_find(op1, op, &pvalue) <= 0)
165
return_error(e_undefined);
170
check_int_ltu(*op, r_size(op1));
171
make_int(op1, op1->value.bytes[(uint) op->value.intval]);
176
check_type(*op, t_integer);
178
code = array_get(imemory, op1, op->value.intval, op1);
183
183
return_error(e_stackunderflow);
185
return_error(e_typecheck);
185
return_error(e_typecheck);
203
203
switch (r_type(op2)) {
205
if (i_ctx_p->in_superexec == 0)
206
check_dict_write(*op2);
208
int code = idict_put(op2, op1, op);
211
return code; /* error */
216
check_int_ltu(*op1, r_size(op2));
217
store_check_dest(op2, op);
219
ref *eltp = op2->value.refs + (uint) op1->value.intval;
221
ref_assign_old(op2, eltp, op, "put");
224
case t_mixedarray: /* packed arrays are read-only */
226
return_error(e_invalidaccess);
228
sdata = op2->value.bytes;
205
if (i_ctx_p->in_superexec == 0)
206
check_dict_write(*op2);
208
int code = idict_put(op2, op1, op);
211
return code; /* error */
216
check_int_ltu(*op1, r_size(op2));
217
store_check_dest(op2, op);
219
ref *eltp = op2->value.refs + (uint) op1->value.intval;
221
ref_assign_old(op2, eltp, op, "put");
224
case t_mixedarray: /* packed arrays are read-only */
226
return_error(e_invalidaccess);
228
sdata = op2->value.bytes;
230
230
str: check_write(*op2);
231
check_int_ltu(*op1, ssize);
232
check_int_leu(*op, 0xff);
233
sdata[(uint)op1->value.intval] = (byte)op->value.intval;
236
if (gs_object_type(imemory, op2->value.pstruct) != &st_bytes)
237
return_error(e_typecheck);
238
sdata = r_ptr(op2, byte);
239
ssize = gs_object_size(imemory, op2->value.pstruct);
242
return_op_typecheck(op2);
231
check_int_ltu(*op1, ssize);
232
check_int_leu(*op, 0xff);
233
sdata[(uint)op1->value.intval] = (byte)op->value.intval;
236
if (gs_object_type(imemory, op2->value.pstruct) != &st_bytes)
237
return_error(e_typecheck);
238
sdata = r_ptr(op2, byte);
239
ssize = gs_object_size(imemory, op2->value.pstruct);
242
return_op_typecheck(op2);
266
266
switch (r_type(op2)) {
268
check_int_ltu(*op1, r_size(op2));
269
if (r_space(op2) > r_space(op)) {
270
if (imemory_save_level(iimemory))
271
return_error(e_invalidaccess);
274
ref *eltp = op2->value.refs + (uint) op1->value.intval;
268
check_int_ltu(*op1, r_size(op2));
269
if (r_space(op2) > r_space(op)) {
270
if (imemory_save_level(iimemory))
271
return_error(e_invalidaccess);
274
ref *eltp = op2->value.refs + (uint) op1->value.intval;
276
ref_assign_old(op2, eltp, op, "put");
276
ref_assign_old(op2, eltp, op, "put");
279
279
case t_dictionary:
280
if (op2->value.pdict == systemdict->value.pdict ||
281
!imemory_save_level(iimemory)
283
uint space = r_space(op2);
280
if (op2->value.pdict == systemdict->value.pdict ||
281
!imemory_save_level(iimemory)
283
uint space = r_space(op2);
285
r_set_space(op2, avm_local);
286
code = idict_put(op2, op1, op);
287
r_set_space(op2, space);
289
code = idict_put(op2, op1, op);
285
r_set_space(op2, avm_local);
286
code = idict_put(op2, op1, op);
287
r_set_space(op2, space);
289
code = idict_put(op2, op1, op);
294
return_error(e_typecheck);
294
return_error(e_typecheck);
321
321
check_int_leu(*op, r_size(op2) - index);
322
322
count = op->value.intval;
323
323
switch (r_type(op2)) {
325
op2->value.refs += index;
328
op2->value.bytes += index;
331
const ref_packed *packed = op2->value.packed;
325
op2->value.refs += index;
328
op2->value.bytes += index;
331
const ref_packed *packed = op2->value.packed;
334
packed = packed_next(packed);
335
op2->value.packed = packed;
339
op2->value.packed += index;
334
packed = packed_next(packed);
335
op2->value.packed = packed;
339
op2->value.packed += index;
342
342
r_set_size(op2, count);
358
358
switch (r_type(opto)) {
360
360
return_error(e_typecheck);
362
362
if (r_type(op) != t_array && r_type(op) != t_string && r_type(op) != t__invalid)
363
363
return_error(e_typecheck); /* to match Distiller */
365
365
return_error(e_stackunderflow);
368
return_error(e_invalidaccess);
372
check_int_leu(*opindex, r_size(opto));
373
code = copy_interval(i_ctx_p, opto, (uint)(opindex->value.intval),
377
uint dsize, ssize, index;
368
return_error(e_invalidaccess);
372
check_int_leu(*opindex, r_size(opto));
373
code = copy_interval(i_ctx_p, opto, (uint)(opindex->value.intval),
377
uint dsize, ssize, index;
380
if (gs_object_type(imemory, opto->value.pstruct) != &st_bytes)
381
return_error(e_typecheck);
382
dsize = gs_object_size(imemory, opto->value.pstruct);
383
check_int_leu(*opindex, dsize);
384
index = (uint)opindex->value.intval;
385
check_read_type(*op, t_string);
387
if (ssize > dsize - index)
388
return_error(e_rangecheck);
389
memcpy(r_ptr(opto, byte) + index, op->value.const_bytes, ssize);
380
if (gs_object_type(imemory, opto->value.pstruct) != &st_bytes)
381
return_error(e_typecheck);
382
dsize = gs_object_size(imemory, opto->value.pstruct);
383
check_int_leu(*opindex, dsize);
384
index = (uint)opindex->value.intval;
385
check_read_type(*op, t_string);
387
if (ssize > dsize - index)
388
return_error(e_rangecheck);
389
memcpy(r_ptr(opto, byte) + index, op->value.const_bytes, ssize);
417
417
switch (r_type(obj)) {
419
return_op_typecheck(obj);
422
make_op_estack(cproc, array_continue);
425
check_dict_read(*obj);
426
make_int(cproc, dict_first(obj));
428
make_op_estack(cproc, dict_continue);
432
make_op_estack(cproc, string_continue);
437
make_op_estack(cproc, packedarray_continue);
419
return_op_typecheck(obj);
422
make_op_estack(cproc, array_continue);
425
check_dict_read(*obj);
426
make_int(cproc, dict_first(obj));
428
make_op_estack(cproc, dict_continue);
432
make_op_estack(cproc, string_continue);
437
make_op_estack(cproc, packedarray_continue);
483
483
push(2); /* make room for key and value */
484
484
if ((index = dict_next(obj, index, op - 1)) >= 0) { /* continue */
485
esp->value.intval = index;
488
return o_push_estack;
485
esp->value.intval = index;
488
return o_push_estack;
489
489
} else { /* done */
490
pop(2); /* undo push */
491
esp -= 4; /* pop mark, object, proc, index */
490
pop(2); /* undo push */
491
esp -= 4; /* pop mark, object, proc, index */
495
495
/* Continuation operator for strings */
520
520
es_ptr obj = esp - 1;
522
522
if (r_size(obj)) { /* continue */
523
const ref_packed *packed = obj->value.packed;
523
const ref_packed *packed = obj->value.packed;
527
packed_get(imemory, packed, op);
528
obj->value.packed = packed_next(packed);
531
return o_push_estack;
527
packed_get(imemory, packed, op);
528
obj->value.packed = packed_next(packed);
531
return o_push_estack;
532
532
} else { /* done */
533
esp -= 3; /* pop mark, object, proc */
533
esp -= 3; /* pop mark, object, proc */
537
537
/* Vacuous cleanup procedure */
570
570
/* its length; nothing else has been checked. */
572
572
copy_interval(i_ctx_t *i_ctx_p /* for ref_assign_old */, os_ptr prto,
573
uint index, os_ptr prfrom, client_name_t cname)
573
uint index, os_ptr prfrom, client_name_t cname)
575
575
int fromtype = r_type(prfrom);
576
576
uint fromsize = r_size(prfrom);
578
578
if (!(fromtype == r_type(prto) ||
579
((fromtype == t_shortarray || fromtype == t_mixedarray) &&
580
r_type(prto) == t_array))
582
return_op_typecheck(prfrom);
579
((fromtype == t_shortarray || fromtype == t_mixedarray) &&
580
r_type(prto) == t_array))
582
return_op_typecheck(prfrom);
583
583
check_read(*prfrom);
584
584
check_write(*prto);
585
585
if (fromsize > r_size(prto) - index)
586
return_error(e_rangecheck);
586
return_error(e_rangecheck);
587
587
switch (fromtype) {
589
{ /* We have to worry about aliasing, */
590
/* but refcpy_to_old takes care of it for us. */
591
return refcpy_to_old(prto, index, prfrom->value.refs,
592
fromsize, idmemory, cname);
595
{ /* memmove takes care of aliasing. */
596
memmove(prto->value.bytes + index, prfrom->value.bytes,
602
{ /* We don't have to worry about aliasing, because */
603
/* packed arrays are read-only and hence the destination */
604
/* can't be a packed array. */
606
const ref_packed *packed = prfrom->value.packed;
607
ref *pdest = prto->value.refs + index;
589
{ /* We have to worry about aliasing, */
590
/* but refcpy_to_old takes care of it for us. */
591
return refcpy_to_old(prto, index, prfrom->value.refs,
592
fromsize, idmemory, cname);
595
{ /* memmove takes care of aliasing. */
596
memmove(prto->value.bytes + index, prfrom->value.bytes,
602
{ /* We don't have to worry about aliasing, because */
603
/* packed arrays are read-only and hence the destination */
604
/* can't be a packed array. */
606
const ref_packed *packed = prfrom->value.packed;
607
ref *pdest = prto->value.refs + index;
610
for (i = 0; i < fromsize; i++, pdest++) {
611
packed_get(imemory, packed, &elt);
612
ref_assign_old(prto, pdest, &elt, cname);
613
packed = packed_next(packed);
610
for (i = 0; i < fromsize; i++, pdest++) {
611
packed_get(imemory, packed, &elt);
612
ref_assign_old(prto, pdest, &elt, cname);
613
packed = packed_next(packed);