Coverage Report

Created: 2026-04-09 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/psi/zgeneric.c
Line
Count
Source
1
/* Copyright (C) 2001-2026 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* Array/string/dictionary generic operators for PostScript */
18
#include "memory_.h"
19
#include "ghost.h"
20
#include "gsstruct.h"   /* for st_bytes */
21
#include "oper.h"
22
#include "dstack.h"   /* for systemdict */
23
#include "estack.h"   /* for forall */
24
#include "iddict.h"
25
#include "iname.h"
26
#include "ipacked.h"
27
#include "ivmspace.h"
28
#include "store.h"
29
30
/* This file implements copy, get, put, getinterval, putinterval, */
31
/* length, and forall, which apply generically to */
32
/* arrays, strings, and dictionaries.  (Copy also has a special */
33
/* meaning for copying the top N elements of the stack.) */
34
35
/* See the comment in opdef.h for an invariant which allows */
36
/* more efficient implementation of forall. */
37
38
/* Forward references */
39
static int zcopy_integer(i_ctx_t *);
40
static int zcopy_interval(i_ctx_t *);
41
static int copy_interval(i_ctx_t *, os_ptr, uint, os_ptr, client_name_t);
42
43
/* <various1> <various2> copy <various> */
44
/* <obj1> ... <objn> <int> copy <obj1> ... <objn> <obj1> ... <objn> */
45
/* Note that this implements copy for arrays and strings, */
46
/* but not for dictionaries (see zcopy_dict in zdict.c). */
47
int
48
zcopy(i_ctx_t *i_ctx_p)
49
836M
{
50
836M
    os_ptr op = osp;
51
836M
    int type;
52
836M
    check_op(1);
53
836M
    type = r_type(op);
54
836M
    if (type == t_integer)
55
791M
        return zcopy_integer(i_ctx_p);
56
45.3M
    check_op(2);
57
45.3M
    switch (type) {
58
20.1M
        case t_array:
59
43.2M
        case t_string:
60
43.2M
            return zcopy_interval(i_ctx_p);
61
2.11M
        case t_dictionary:
62
2.11M
            return zcopy_dict(i_ctx_p);
63
11
        default:
64
11
            return_op_typecheck(op);
65
45.3M
    }
66
45.3M
}
67
68
/* <obj1> ... <objn> <int> copy <obj1> ... <objn> <obj1> ... <objn> */
69
static int
70
zcopy_integer(i_ctx_t *i_ctx_p)
71
791M
{
72
791M
    os_ptr op = osp;
73
791M
    os_ptr op1 = op - 1;
74
791M
    int count, i;
75
791M
    int code;
76
77
791M
    if ((uint) op->value.intval > (uint)(op - osbot)) {
78
        /* There might be enough elements in other blocks. */
79
37
        check_type(*op, t_integer);
80
37
        if (op->value.intval >= (int)ref_stack_count(&o_stack))
81
10
            return_error(gs_error_stackunderflow);
82
27
        if (op->value.intval < 0)
83
27
            return_error(gs_error_rangecheck);
84
27
        check_int_ltu(*op, ref_stack_count(&o_stack));
85
0
        count = op->value.intval;
86
791M
    } else if (op1 + (count = op->value.intval) <= ostop) {
87
        /* Fast case. */
88
791M
        memcpy((char *)op, (char *)(op - count), count * sizeof(ref));
89
791M
        push(count - 1);
90
791M
        return 0;
91
791M
    }
92
    /* Do it the slow, general way. */
93
36
    code = ref_stack_push(&o_stack, count - 1);
94
36
    if (code < 0)
95
0
        return code;
96
174
    for (i = 0; i < count; i++) {
97
138
        ref *o = ref_stack_index(&o_stack, i);
98
138
        ref *o1 = ref_stack_index(&o_stack, i + count);
99
100
138
        if (o == NULL || o1 == NULL)
101
0
            return_error(gs_error_stackunderflow);
102
138
        *o = *o1;
103
138
    }
104
36
    return 0;
105
36
}
106
107
/* <array1> <array2> copy <subarray2> */
108
/* <string1> <string2> copy <substring2> */
109
static int
110
zcopy_interval(i_ctx_t *i_ctx_p)
111
43.2M
{
112
43.2M
    os_ptr op = osp;
113
43.2M
    os_ptr op1 = op - 1;
114
43.2M
    int code = copy_interval(i_ctx_p, op, 0, op1, "copy");
115
116
43.2M
    if (code < 0)
117
3
        return code;
118
43.2M
    r_set_size(op, r_size(op1));
119
43.2M
    *op1 = *op;
120
43.2M
    pop(1);
121
43.2M
    return 0;
122
43.2M
}
123
124
/* <array|dict|name|packedarray|string> length <int> */
125
static int
126
zlength(i_ctx_t *i_ctx_p)
127
456M
{
128
456M
    os_ptr op = osp;
129
130
456M
    check_op(1);
131
456M
    switch (r_type(op)) {
132
48.1M
        case t_array:
133
339M
        case t_string:
134
340M
        case t_mixedarray:
135
343M
        case t_shortarray:
136
343M
            check_read(*op);
137
343M
            make_int(op, r_size(op));
138
343M
            return 0;
139
112M
        case t_dictionary:
140
112M
            check_dict_read(*op);
141
112M
            make_int(op, dict_length(op));
142
112M
            return 0;
143
1.81M
        case t_name: {
144
1.81M
            ref str;
145
146
1.81M
            name_string_ref(imemory, op, &str);
147
1.81M
            make_int(op, r_size(&str));
148
1.81M
            return 0;
149
112M
        }
150
2
        case t_astruct:
151
2
            if (gs_object_type(imemory, op->value.pstruct) != &st_bytes)
152
2
                return_error(gs_error_typecheck);
153
0
            check_read(*op);
154
0
            make_int(op, gs_object_size(imemory, op->value.pstruct));
155
0
            return 0;
156
13
        default:
157
13
            return_op_typecheck(op);
158
456M
    }
159
456M
}
160
161
/* <array|packedarray|string> <index> get <obj> */
162
/* <dict> <key> get <obj> */
163
static int
164
zget(i_ctx_t *i_ctx_p)
165
1.71G
{
166
1.71G
    int code;
167
1.71G
    os_ptr op = osp;
168
1.71G
    os_ptr op1 = op - 1;
169
1.71G
    ref *pvalue;
170
171
1.71G
    check_op(2);
172
173
1.71G
    switch (r_type(op1)) {
174
350M
        case t_dictionary:
175
350M
            check_dict_read(*op1);
176
350M
            if (dict_find(op1, op, &pvalue) <= 0)
177
22
                return_error(gs_error_undefined);
178
350M
            op[-1] = *pvalue;
179
350M
            break;
180
394M
        case t_string:
181
394M
            check_read(*op1);
182
394M
            check_int_ltu(*op, r_size(op1));
183
394M
            make_int(op1, op1->value.bytes[(uint) op->value.intval]);
184
394M
            break;
185
889M
        case t_array:
186
930M
        case t_mixedarray:
187
969M
        case t_shortarray:
188
969M
            check_type(*op, t_integer);
189
969M
            check_read(*op1);
190
969M
            code = array_get(imemory, op1, op->value.intval, op1);
191
969M
            if (code < 0)
192
3
                return code;
193
969M
            break;
194
969M
        case t__invalid:
195
0
            return_error(gs_error_stackunderflow);
196
19
        default:
197
19
            return_error(gs_error_typecheck);
198
1.71G
    }
199
1.71G
    pop(1);
200
1.71G
    return 0;
201
1.71G
}
202
203
/* <array> <index> <obj> put - */
204
/* <dict> <key> <value> put - */
205
/* <string> <index> <int> put - */
206
static int
207
zput(i_ctx_t *i_ctx_p)
208
1.07G
{
209
1.07G
    os_ptr op = osp;
210
1.07G
    os_ptr op1 = op - 1;
211
1.07G
    os_ptr op2 = op1 - 1;
212
1.07G
    byte *sdata;
213
1.07G
    uint ssize;
214
215
1.07G
    check_op(3);
216
1.07G
    switch (r_type(op2)) {
217
833M
        case t_dictionary:
218
833M
            check_dict_write(*op2);
219
833M
            {
220
833M
                int code = idict_put(op2, op1, op);
221
222
833M
                if (code < 0)
223
0
                    return code; /* error */
224
833M
            }
225
833M
            break;
226
833M
        case t_array:
227
73.2M
            check_write(*op2);
228
73.2M
            check_int_ltu(*op1, r_size(op2));
229
73.2M
            store_check_dest(op2, op);
230
73.2M
            {
231
73.2M
                ref *eltp = op2->value.refs + (uint) op1->value.intval;
232
233
73.2M
                ref_assign_old(op2, eltp, op, "put");
234
73.2M
            }
235
73.2M
            break;
236
0
        case t_mixedarray:  /* packed arrays are read-only */
237
0
        case t_shortarray:
238
0
            return_error(gs_error_invalidaccess);
239
168M
        case t_string:
240
168M
            sdata = op2->value.bytes;
241
168M
            ssize = r_size(op2);
242
168M
str:      check_write(*op2);
243
168M
            check_int_ltu(*op1, ssize);
244
168M
            check_int_leu(*op, 0xff);
245
168M
            sdata[(uint)op1->value.intval] = (byte)op->value.intval;
246
168M
            break;
247
0
        case t_astruct:
248
0
            if (gs_object_type(imemory, op2->value.pstruct) != &st_bytes)
249
0
                return_error(gs_error_typecheck);
250
0
            sdata = r_ptr(op2, byte);
251
0
            ssize = gs_object_size(imemory, op2->value.pstruct);
252
0
            goto str;
253
14
        default:
254
14
            return_op_typecheck(op2);
255
1.07G
    }
256
1.07G
    pop(3);
257
1.07G
    return 0;
258
1.07G
}
259
260
/* <array> <index> <obj> .forceput - */
261
/* <dict> <key> <value> .forceput - */
262
/*
263
 * This forces a "put" even if the object is not writable, and (if the
264
 * object is systemdict or the save level is 0) even if the value is in
265
 * local VM.  It is meant to be used only for replacing the value of
266
 * FontDirectory in systemdict when switching between local and global VM,
267
 * and a few similar applications.  After initialization, this operator
268
 * should no longer be accessible by name.
269
 */
270
static int
271
zforceput(i_ctx_t *i_ctx_p)
272
69.3M
{
273
69.3M
    os_ptr op = osp;
274
69.3M
    os_ptr op1 = op - 1;
275
69.3M
    os_ptr op2 = op - 2;
276
69.3M
    int code;
277
278
69.3M
    check_op(3);
279
280
69.3M
    switch (r_type(op2)) {
281
151k
    case t_array:
282
151k
        check_int_ltu(*op1, r_size(op2));
283
151k
        if (r_space(op2) > r_space(op)) {
284
0
            if (imemory_save_level(iimemory))
285
0
                return_error(gs_error_invalidaccess);
286
0
        }
287
151k
        {
288
151k
            ref *eltp = op2->value.refs + (uint) op1->value.intval;
289
290
151k
            ref_assign_old(op2, eltp, op, "put");
291
151k
        }
292
151k
        break;
293
69.2M
    case t_dictionary:
294
69.2M
        if (op2->value.pdict == systemdict->value.pdict ||
295
13.6M
            !imemory_save_level(iimemory)
296
69.2M
            ) {
297
66.9M
            uint space = r_space(op2);
298
299
66.9M
            r_set_space(op2, avm_local);
300
66.9M
            code = idict_put(op2, op1, op);
301
66.9M
            r_set_space(op2, space);
302
66.9M
        } else
303
2.29M
            code = idict_put(op2, op1, op);
304
69.2M
        if (code < 0)
305
6
            return code;
306
69.2M
        break;
307
69.2M
    default:
308
0
        return_error(gs_error_typecheck);
309
69.3M
    }
310
69.3M
    pop(3);
311
69.3M
    return 0;
312
69.3M
}
313
314
/* <seq:array|packedarray|string> <index> <count> getinterval <subseq> */
315
static int
316
zgetinterval(i_ctx_t *i_ctx_p)
317
61.4M
{
318
61.4M
    os_ptr op = osp;
319
61.4M
    os_ptr op1 = op - 1;
320
61.4M
    os_ptr op2 = op1 - 1;
321
61.4M
    uint index;
322
61.4M
    uint count;
323
324
61.4M
    check_op(3);
325
326
61.4M
    switch (r_type(op2)) {
327
3
        default:
328
3
            return_op_typecheck(op2);
329
3.69M
        case t_array:
330
38.1M
        case t_string:
331
61.4M
        case t_mixedarray:
332
61.4M
        case t_shortarray:;
333
61.4M
    }
334
61.4M
    check_read(*op2);
335
61.4M
    check_int_leu(*op1, r_size(op2));
336
61.4M
    index = op1->value.intval;
337
61.4M
    check_int_leu(*op, r_size(op2) - index);
338
61.4M
    count = op->value.intval;
339
61.4M
    switch (r_type(op2)) {
340
3.69M
        case t_array:
341
3.69M
            op2->value.refs += index;
342
3.69M
            break;
343
34.4M
        case t_string:
344
34.4M
            op2->value.bytes += index;
345
34.4M
            break;
346
23.2M
        case t_mixedarray: {
347
23.2M
            const ref_packed *packed = op2->value.packed;
348
349
184M
            for (; index--;)
350
161M
                packed = packed_next(packed);
351
23.2M
            op2->value.packed = packed;
352
23.2M
            break;
353
0
        }
354
0
        case t_shortarray:
355
0
            op2->value.packed += index;
356
0
            break;
357
61.4M
    }
358
61.4M
    r_set_size(op2, count);
359
61.4M
    pop(2);
360
61.4M
    return 0;
361
61.4M
}
362
363
/* <array1> <index> <array2|packedarray2> putinterval - */
364
/* <string1> <index> <string2> putinterval - */
365
/* <bytestring1> <index> <string2> putinterval - */
366
static int
367
zputinterval(i_ctx_t *i_ctx_p)
368
18.9M
{
369
18.9M
    os_ptr op = osp;
370
18.9M
    os_ptr opindex = op - 1;
371
18.9M
    os_ptr opto = opindex - 1;
372
18.9M
    int code;
373
374
18.9M
    check_op(3);
375
376
18.9M
    switch (r_type(opto)) {
377
8
        default:
378
8
            return_error(gs_error_typecheck);
379
0
        case t__invalid:
380
0
            if (r_type(op) != t_array && r_type(op) != t_string && r_type(op) != t__invalid)
381
0
                return_error(gs_error_typecheck); /* to match Distiller */
382
0
            else
383
0
                return_error(gs_error_stackunderflow);
384
0
        case t_mixedarray:
385
0
        case t_shortarray:
386
0
            return_error(gs_error_invalidaccess);
387
2.49M
        case t_array:
388
18.9M
        case t_string:
389
18.9M
            check_write(*opto);
390
18.9M
            check_int_leu(*opindex, r_size(opto));
391
18.9M
            code = copy_interval(i_ctx_p, opto, (uint)(opindex->value.intval),
392
18.9M
                                 op, "putinterval");
393
18.9M
            break;
394
0
        case t_astruct: {
395
0
            uint dsize, ssize, index;
396
397
0
            check_write(*opto);
398
0
            if (gs_object_type(imemory, opto->value.pstruct) != &st_bytes)
399
0
                return_error(gs_error_typecheck);
400
0
            dsize = gs_object_size(imemory, opto->value.pstruct);
401
0
            check_int_leu(*opindex, dsize);
402
0
            index = (uint)opindex->value.intval;
403
0
            check_read_type(*op, t_string);
404
0
            ssize = r_size(op);
405
0
            if (ssize > dsize - index)
406
0
                return_error(gs_error_rangecheck);
407
0
            memcpy(r_ptr(opto, byte) + index, op->value.const_bytes, ssize);
408
0
            code = 0;
409
0
            break;
410
0
        }
411
18.9M
    }
412
18.9M
    if (code >= 0)
413
18.9M
        pop(3);
414
18.9M
    return code;
415
18.9M
}
416
417
/* <array|packedarray|string> <<element> proc> forall - */
418
/* <dict> <<key> <value> proc> forall - */
419
static int
420
    array_continue(i_ctx_t *),
421
    dict_continue(i_ctx_t *),
422
    string_continue(i_ctx_t *),
423
    packedarray_continue(i_ctx_t *);
424
static int forall_cleanup(i_ctx_t *);
425
static int
426
zforall(i_ctx_t *i_ctx_p)
427
60.8M
{
428
60.8M
    os_ptr op = osp;
429
60.8M
    os_ptr obj = op - 1;
430
60.8M
    es_ptr ep;
431
60.8M
    es_ptr cproc;
432
433
60.8M
    check_estack(6);
434
    /* check_estack() could cause the exec stack to be copied to a new block
435
     * so don't caulculate ep and things based on ep until *after* the check
436
     */
437
60.8M
    ep = esp;
438
60.8M
    cproc = ep + 4;
439
60.8M
    check_proc(*op);
440
60.8M
    switch (r_type(obj)) {
441
15
        default:
442
15
            return_op_typecheck(obj);
443
19.1M
        case t_array:
444
19.1M
            check_read(*obj);
445
19.1M
            make_op_estack(cproc, array_continue);
446
19.1M
            break;
447
32.5M
        case t_dictionary:
448
32.5M
            check_dict_read(*obj);
449
32.5M
            make_int(cproc, dict_first(obj));
450
32.5M
            ++cproc;
451
32.5M
            make_op_estack(cproc, dict_continue);
452
32.5M
            break;
453
151k
        case t_string:
454
151k
            check_read(*obj);
455
151k
            make_op_estack(cproc, string_continue);
456
151k
            break;
457
6.84M
        case t_mixedarray:
458
8.95M
        case t_shortarray:
459
8.95M
            check_read(*obj);
460
8.95M
            make_op_estack(cproc, packedarray_continue);
461
8.95M
            break;
462
60.8M
    }
463
    /*
464
     * Push:
465
     *   - a mark;
466
     *   - the composite object;
467
     *   - the procedure;
468
     *   - the iteration index (only for dictionaries, done above);
469
     * and invoke the continuation operator.
470
     */
471
60.8M
    make_mark_estack(ep + 1, es_for, forall_cleanup);
472
60.8M
    ep[2] = *obj;
473
60.8M
    ep[3] = *op;
474
60.8M
    esp = cproc - 1;
475
60.8M
    ref_stack_pop(&o_stack, 2);
476
60.8M
    return (*real_opproc(cproc))(i_ctx_p);
477
60.8M
}
478
/* Continuation operator for arrays */
479
static int
480
array_continue(i_ctx_t *i_ctx_p)
481
191M
{
482
191M
    os_ptr op = osp;
483
191M
    es_ptr obj = esp - 1;
484
485
191M
    if (r_size(obj)) {   /* continue */
486
172M
        push(1);
487
172M
        r_dec_size(obj, 1);
488
172M
        *op = *obj->value.refs;
489
172M
        obj->value.refs++;
490
172M
        esp += 2;
491
172M
        *esp = obj[1];
492
172M
        return o_push_estack;
493
172M
    } else {     /* done */
494
19.0M
        esp -= 3;    /* pop mark, object, proc */
495
19.0M
        return o_pop_estack;
496
19.0M
    }
497
191M
}
498
/* Continuation operator for dictionaries */
499
static int
500
dict_continue(i_ctx_t *i_ctx_p)
501
1.38G
{
502
1.38G
    os_ptr op = osp;
503
1.38G
    es_ptr obj = esp - 2;
504
1.38G
    int index = esp->value.intval;
505
506
1.38G
    if (r_type(obj) != t_dictionary)
507
0
        return_error(gs_error_typecheck);
508
509
1.38G
    push(2);     /* make room for key and value */
510
1.38G
    if ((index = dict_next(obj, index, op - 1)) >= 0) { /* continue */
511
1.35G
        esp->value.intval = index;
512
1.35G
        esp += 2;
513
1.35G
        *esp = obj[1];
514
1.35G
        return o_push_estack;
515
1.35G
    } else {     /* done */
516
32.0M
        pop(2);      /* undo push */
517
32.0M
        esp -= 4;    /* pop mark, object, proc, index */
518
32.0M
        return o_pop_estack;
519
32.0M
    }
520
1.38G
}
521
/* Continuation operator for strings */
522
static int
523
string_continue(i_ctx_t *i_ctx_p)
524
151k
{
525
151k
    os_ptr op = osp;
526
151k
    es_ptr obj = esp - 1;
527
528
151k
    if (r_size(obj)) {   /* continue */
529
180
        push(1);    /* check for result space on stack BEFORE changing string size */
530
180
        r_dec_size(obj, 1); /* Bug 701550 :-O */
531
180
        make_int(op, *obj->value.bytes);
532
180
        obj->value.bytes++;
533
180
        esp += 2;
534
180
        *esp = obj[1];
535
180
        return o_push_estack;
536
151k
    } else {     /* done */
537
151k
        esp -= 3;    /* pop mark, object, proc */
538
151k
        return o_pop_estack;
539
151k
    }
540
151k
}
541
/* Continuation operator for packed arrays */
542
static int
543
packedarray_continue(i_ctx_t *i_ctx_p)
544
45.9M
{
545
45.9M
    os_ptr op = osp;
546
45.9M
    es_ptr obj = esp - 1;
547
548
45.9M
    if (r_size(obj)) {   /* continue */
549
36.9M
        const ref_packed *packed = obj->value.packed;
550
551
36.9M
        push(1);
552
36.9M
        r_dec_size(obj, 1);
553
36.9M
        packed_get(imemory, packed, op);
554
36.9M
        obj->value.packed = packed_next(packed);
555
36.9M
        esp += 2;
556
36.9M
        *esp = obj[1];
557
36.9M
        return o_push_estack;
558
36.9M
    } else {     /* done */
559
8.95M
        esp -= 3;    /* pop mark, object, proc */
560
8.95M
        return o_pop_estack;
561
8.95M
    }
562
45.9M
}
563
/* Vacuous cleanup procedure */
564
static int
565
forall_cleanup(i_ctx_t *i_ctx_p)
566
616k
{
567
616k
    return 0;
568
616k
}
569
570
/* ------ Initialization procedure ------ */
571
572
const op_def zgeneric_op_defs[] =
573
{
574
    {"1copy", zcopy},
575
    {"2forall", zforall},
576
    {"3.forceput", zforceput},
577
    {"2get", zget},
578
    {"3getinterval", zgetinterval},
579
    {"1length", zlength},
580
    {"3put", zput},
581
    {"3putinterval", zputinterval},
582
                /* Internal operators */
583
    {"0%array_continue", array_continue},
584
    {"0%dict_continue", dict_continue},
585
    {"0%packedarray_continue", packedarray_continue},
586
    {"0%string_continue", string_continue},
587
    op_def_end(0)
588
};
589
590
/* ------ Shared routines ------ */
591
592
/* Copy an interval from one operand to another. */
593
/* This is used by both putinterval and string/array copy. */
594
/* The destination is known to be an array or string, */
595
/* and the starting index is known to be less than or equal to */
596
/* its length; nothing else has been checked. */
597
static int
598
copy_interval(i_ctx_t *i_ctx_p /* for ref_assign_old */, os_ptr prto,
599
              uint index, os_ptr prfrom, client_name_t cname)
600
62.2M
{
601
62.2M
    int fromtype = r_type(prfrom);
602
62.2M
    uint fromsize = r_size(prfrom);
603
604
62.2M
    if (!(fromtype == r_type(prto) ||
605
151k
          ((fromtype == t_shortarray || fromtype == t_mixedarray) &&
606
151k
           r_type(prto) == t_array))
607
62.2M
        )
608
62.2M
        return_op_typecheck(prfrom);
609
62.2M
    check_read(*prfrom);
610
62.2M
    check_write(*prto);
611
62.2M
    if (fromsize > r_size(prto) - index)
612
0
        return_error(gs_error_rangecheck);
613
62.2M
    switch (fromtype) {
614
22.4M
        case t_array:
615
22.4M
            {     /* We have to worry about aliasing, */
616
                /* but refcpy_to_old takes care of it for us. */
617
22.4M
                return refcpy_to_old(prto, index, prfrom->value.refs,
618
22.4M
                                     fromsize, idmemory, cname);
619
0
            }
620
39.5M
        case t_string:
621
39.5M
            { /* memmove takes care of aliasing. */
622
39.5M
                memmove(prto->value.bytes + index, prfrom->value.bytes,
623
39.5M
                        fromsize);
624
39.5M
            }
625
39.5M
            break;
626
151k
        case t_mixedarray:
627
151k
        case t_shortarray:
628
151k
            { /* We don't have to worry about aliasing, because */
629
                /* packed arrays are read-only and hence the destination */
630
                /* can't be a packed array. */
631
151k
                uint i;
632
151k
                const ref_packed *packed = prfrom->value.packed;
633
151k
                ref *pdest = prto->value.refs + index;
634
151k
                ref elt;
635
636
38.8M
                for (i = 0; i < fromsize; i++, pdest++) {
637
38.7M
                    packed_get(imemory, packed, &elt);
638
38.7M
                    ref_assign_old(prto, pdest, &elt, cname);
639
38.7M
                    packed = packed_next(packed);
640
38.7M
                }
641
151k
            }
642
151k
            break;
643
62.2M
    }
644
39.7M
    return 0;
645
62.2M
}