Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/psi/zgeneric.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 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
911M
{
50
911M
    os_ptr op = osp;
51
911M
    int type;
52
911M
    check_op(1);
53
911M
    type = r_type(op);
54
911M
    if (type == t_integer)
55
859M
        return zcopy_integer(i_ctx_p);
56
52.3M
    check_op(2);
57
52.3M
    switch (type) {
58
21.6M
        case t_array:
59
50.1M
        case t_string:
60
50.1M
            return zcopy_interval(i_ctx_p);
61
2.27M
        case t_dictionary:
62
2.27M
            return zcopy_dict(i_ctx_p);
63
11
        default:
64
11
            return_op_typecheck(op);
65
52.3M
    }
66
52.3M
}
67
68
/* <obj1> ... <objn> <int> copy <obj1> ... <objn> <obj1> ... <objn> */
69
static int
70
zcopy_integer(i_ctx_t *i_ctx_p)
71
859M
{
72
859M
    os_ptr op = osp;
73
859M
    os_ptr op1 = op - 1;
74
859M
    int count, i;
75
859M
    int code;
76
77
859M
    if ((uint) op->value.intval > (uint)(op - osbot)) {
78
        /* There might be enough elements in other blocks. */
79
43
        check_type(*op, t_integer);
80
43
        if (op->value.intval >= (int)ref_stack_count(&o_stack))
81
10
            return_error(gs_error_stackunderflow);
82
33
        if (op->value.intval < 0)
83
33
            return_error(gs_error_rangecheck);
84
33
        check_int_ltu(*op, ref_stack_count(&o_stack));
85
0
        count = op->value.intval;
86
859M
    } else if (op1 + (count = op->value.intval) <= ostop) {
87
        /* Fast case. */
88
859M
        memcpy((char *)op, (char *)(op - count), count * sizeof(ref));
89
859M
        push(count - 1);
90
859M
        return 0;
91
859M
    }
92
    /* Do it the slow, general way. */
93
32
    code = ref_stack_push(&o_stack, count - 1);
94
32
    if (code < 0)
95
0
        return code;
96
152
    for (i = 0; i < count; i++) {
97
120
        ref *o = ref_stack_index(&o_stack, i);
98
120
        ref *o1 = ref_stack_index(&o_stack, i + count);
99
100
120
        if (o == NULL || o1 == NULL)
101
0
            return_error(gs_error_stackunderflow);
102
120
        *o = *o1;
103
120
    }
104
32
    return 0;
105
32
}
106
107
/* <array1> <array2> copy <subarray2> */
108
/* <string1> <string2> copy <substring2> */
109
static int
110
zcopy_interval(i_ctx_t *i_ctx_p)
111
50.1M
{
112
50.1M
    os_ptr op = osp;
113
50.1M
    os_ptr op1 = op - 1;
114
50.1M
    int code = copy_interval(i_ctx_p, op, 0, op1, "copy");
115
116
50.1M
    if (code < 0)
117
3
        return code;
118
50.1M
    r_set_size(op, r_size(op1));
119
50.1M
    *op1 = *op;
120
50.1M
    pop(1);
121
50.1M
    return 0;
122
50.1M
}
123
124
/* <array|dict|name|packedarray|string> length <int> */
125
static int
126
zlength(i_ctx_t *i_ctx_p)
127
508M
{
128
508M
    os_ptr op = osp;
129
130
508M
    check_op(1);
131
508M
    switch (r_type(op)) {
132
52.7M
        case t_array:
133
379M
        case t_string:
134
381M
        case t_mixedarray:
135
383M
        case t_shortarray:
136
383M
            check_read(*op);
137
383M
            make_int(op, r_size(op));
138
383M
            return 0;
139
122M
        case t_dictionary:
140
122M
            check_dict_read(*op);
141
122M
            make_int(op, dict_length(op));
142
122M
            return 0;
143
2.18M
        case t_name: {
144
2.18M
            ref str;
145
146
2.18M
            name_string_ref(imemory, op, &str);
147
2.18M
            make_int(op, r_size(&str));
148
2.18M
            return 0;
149
122M
        }
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
18
        default:
157
18
            return_op_typecheck(op);
158
508M
    }
159
508M
}
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.88G
{
166
1.88G
    int code;
167
1.88G
    os_ptr op = osp;
168
1.88G
    os_ptr op1 = op - 1;
169
1.88G
    ref *pvalue;
170
171
1.88G
    check_op(2);
172
173
1.88G
    switch (r_type(op1)) {
174
389M
        case t_dictionary:
175
389M
            check_dict_read(*op1);
176
389M
            if (dict_find(op1, op, &pvalue) <= 0)
177
28
                return_error(gs_error_undefined);
178
389M
            op[-1] = *pvalue;
179
389M
            break;
180
442M
        case t_string:
181
442M
            check_read(*op1);
182
442M
            check_int_ltu(*op, r_size(op1));
183
442M
            make_int(op1, op1->value.bytes[(uint) op->value.intval]);
184
442M
            break;
185
961M
        case t_array:
186
1.00G
        case t_mixedarray:
187
1.04G
        case t_shortarray:
188
1.04G
            check_type(*op, t_integer);
189
1.04G
            check_read(*op1);
190
1.04G
            code = array_get(imemory, op1, op->value.intval, op1);
191
1.04G
            if (code < 0)
192
1
                return code;
193
1.04G
            break;
194
1.04G
        case t__invalid:
195
0
            return_error(gs_error_stackunderflow);
196
24
        default:
197
24
            return_error(gs_error_typecheck);
198
1.88G
    }
199
1.88G
    pop(1);
200
1.88G
    return 0;
201
1.88G
}
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.21G
{
209
1.21G
    os_ptr op = osp;
210
1.21G
    os_ptr op1 = op - 1;
211
1.21G
    os_ptr op2 = op1 - 1;
212
1.21G
    byte *sdata;
213
1.21G
    uint ssize;
214
215
1.21G
    check_op(3);
216
1.21G
    switch (r_type(op2)) {
217
951M
        case t_dictionary:
218
951M
            check_dict_write(*op2);
219
951M
            {
220
951M
                int code = idict_put(op2, op1, op);
221
222
951M
                if (code < 0)
223
0
                    return code; /* error */
224
951M
            }
225
951M
            break;
226
951M
        case t_array:
227
78.8M
            check_write(*op2);
228
78.8M
            check_int_ltu(*op1, r_size(op2));
229
78.8M
            store_check_dest(op2, op);
230
78.8M
            {
231
78.8M
                ref *eltp = op2->value.refs + (uint) op1->value.intval;
232
233
78.8M
                ref_assign_old(op2, eltp, op, "put");
234
78.8M
            }
235
78.8M
            break;
236
0
        case t_mixedarray:  /* packed arrays are read-only */
237
0
        case t_shortarray:
238
0
            return_error(gs_error_invalidaccess);
239
187M
        case t_string:
240
187M
            sdata = op2->value.bytes;
241
187M
            ssize = r_size(op2);
242
187M
str:      check_write(*op2);
243
187M
            check_int_ltu(*op1, ssize);
244
187M
            check_int_leu(*op, 0xff);
245
187M
            sdata[(uint)op1->value.intval] = (byte)op->value.intval;
246
187M
            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
15
        default:
254
15
            return_op_typecheck(op2);
255
1.21G
    }
256
1.21G
    pop(3);
257
1.21G
    return 0;
258
1.21G
}
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
75.9M
{
273
75.9M
    os_ptr op = osp;
274
75.9M
    os_ptr op1 = op - 1;
275
75.9M
    os_ptr op2 = op - 2;
276
75.9M
    int code;
277
278
75.9M
    check_op(3);
279
280
75.9M
    switch (r_type(op2)) {
281
162k
    case t_array:
282
162k
        check_int_ltu(*op1, r_size(op2));
283
162k
        if (r_space(op2) > r_space(op)) {
284
0
            if (imemory_save_level(iimemory))
285
0
                return_error(gs_error_invalidaccess);
286
0
        }
287
162k
        {
288
162k
            ref *eltp = op2->value.refs + (uint) op1->value.intval;
289
290
162k
            ref_assign_old(op2, eltp, op, "put");
291
162k
        }
292
162k
        break;
293
75.8M
    case t_dictionary:
294
75.8M
        if (op2->value.pdict == systemdict->value.pdict ||
295
75.8M
            !imemory_save_level(iimemory)
296
75.8M
            ) {
297
72.9M
            uint space = r_space(op2);
298
299
72.9M
            r_set_space(op2, avm_local);
300
72.9M
            code = idict_put(op2, op1, op);
301
72.9M
            r_set_space(op2, space);
302
72.9M
        } else
303
2.87M
            code = idict_put(op2, op1, op);
304
75.8M
        if (code < 0)
305
5
            return code;
306
75.8M
        break;
307
75.8M
    default:
308
0
        return_error(gs_error_typecheck);
309
75.9M
    }
310
75.9M
    pop(3);
311
75.9M
    return 0;
312
75.9M
}
313
314
/* <seq:array|packedarray|string> <index> <count> getinterval <subseq> */
315
static int
316
zgetinterval(i_ctx_t *i_ctx_p)
317
69.9M
{
318
69.9M
    os_ptr op = osp;
319
69.9M
    os_ptr op1 = op - 1;
320
69.9M
    os_ptr op2 = op1 - 1;
321
69.9M
    uint index;
322
69.9M
    uint count;
323
324
69.9M
    check_op(3);
325
326
69.9M
    switch (r_type(op2)) {
327
6
        default:
328
6
            return_op_typecheck(op2);
329
4.08M
        case t_array:
330
44.8M
        case t_string:
331
69.9M
        case t_mixedarray:
332
69.9M
        case t_shortarray:;
333
69.9M
    }
334
69.9M
    check_read(*op2);
335
69.9M
    check_int_leu(*op1, r_size(op2));
336
69.9M
    index = op1->value.intval;
337
69.9M
    check_int_leu(*op, r_size(op2) - index);
338
69.9M
    count = op->value.intval;
339
69.9M
    switch (r_type(op2)) {
340
4.08M
        case t_array:
341
4.08M
            op2->value.refs += index;
342
4.08M
            break;
343
40.7M
        case t_string:
344
40.7M
            op2->value.bytes += index;
345
40.7M
            break;
346
25.0M
        case t_mixedarray: {
347
25.0M
            const ref_packed *packed = op2->value.packed;
348
349
198M
            for (; index--;)
350
173M
                packed = packed_next(packed);
351
25.0M
            op2->value.packed = packed;
352
25.0M
            break;
353
0
        }
354
0
        case t_shortarray:
355
0
            op2->value.packed += index;
356
0
            break;
357
69.9M
    }
358
69.9M
    r_set_size(op2, count);
359
69.9M
    pop(2);
360
69.9M
    return 0;
361
69.9M
}
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
22.3M
{
369
22.3M
    os_ptr op = osp;
370
22.3M
    os_ptr opindex = op - 1;
371
22.3M
    os_ptr opto = opindex - 1;
372
22.3M
    int code;
373
374
22.3M
    check_op(3);
375
376
22.3M
    switch (r_type(opto)) {
377
7
        default:
378
7
            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
3.11M
        case t_array:
388
22.3M
        case t_string:
389
22.3M
            check_write(*opto);
390
22.3M
            check_int_leu(*opindex, r_size(opto));
391
22.3M
            code = copy_interval(i_ctx_p, opto, (uint)(opindex->value.intval),
392
22.3M
                                 op, "putinterval");
393
22.3M
            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
22.3M
    }
412
22.3M
    if (code >= 0)
413
22.3M
        pop(3);
414
22.3M
    return code;
415
22.3M
}
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
69.1M
{
428
69.1M
    os_ptr op = osp;
429
69.1M
    os_ptr obj = op - 1;
430
69.1M
    es_ptr ep;
431
69.1M
    es_ptr cproc;
432
433
69.1M
    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
69.1M
    ep = esp;
438
69.1M
    cproc = ep + 4;
439
69.1M
    check_proc(*op);
440
69.1M
    switch (r_type(obj)) {
441
13
        default:
442
13
            return_op_typecheck(obj);
443
22.9M
        case t_array:
444
22.9M
            check_read(*obj);
445
22.9M
            make_op_estack(cproc, array_continue);
446
22.9M
            break;
447
36.4M
        case t_dictionary:
448
36.4M
            check_dict_read(*obj);
449
36.4M
            make_int(cproc, dict_first(obj));
450
36.4M
            ++cproc;
451
36.4M
            make_op_estack(cproc, dict_continue);
452
36.4M
            break;
453
162k
        case t_string:
454
162k
            check_read(*obj);
455
162k
            make_op_estack(cproc, string_continue);
456
162k
            break;
457
7.34M
        case t_mixedarray:
458
9.61M
        case t_shortarray:
459
9.61M
            check_read(*obj);
460
9.61M
            make_op_estack(cproc, packedarray_continue);
461
9.61M
            break;
462
69.1M
    }
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
69.1M
    make_mark_estack(ep + 1, es_for, forall_cleanup);
472
69.1M
    ep[2] = *obj;
473
69.1M
    ep[3] = *op;
474
69.1M
    esp = cproc - 1;
475
69.1M
    ref_stack_pop(&o_stack, 2);
476
69.1M
    return (*real_opproc(cproc))(i_ctx_p);
477
69.1M
}
478
/* Continuation operator for arrays */
479
static int
480
array_continue(i_ctx_t *i_ctx_p)
481
244M
{
482
244M
    os_ptr op = osp;
483
244M
    es_ptr obj = esp - 1;
484
485
244M
    if (r_size(obj)) {   /* continue */
486
221M
        push(1);
487
221M
        r_dec_size(obj, 1);
488
221M
        *op = *obj->value.refs;
489
221M
        obj->value.refs++;
490
221M
        esp += 2;
491
221M
        *esp = obj[1];
492
221M
        return o_push_estack;
493
221M
    } else {     /* done */
494
22.7M
        esp -= 3;    /* pop mark, object, proc */
495
22.7M
        return o_pop_estack;
496
22.7M
    }
497
244M
}
498
/* Continuation operator for dictionaries */
499
static int
500
dict_continue(i_ctx_t *i_ctx_p)
501
1.58G
{
502
1.58G
    os_ptr op = osp;
503
1.58G
    es_ptr obj = esp - 2;
504
1.58G
    int index = esp->value.intval;
505
506
1.58G
    if (r_type(obj) != t_dictionary)
507
0
        return_error(gs_error_typecheck);
508
509
1.58G
    push(2);     /* make room for key and value */
510
1.58G
    if ((index = dict_next(obj, index, op - 1)) >= 0) { /* continue */
511
1.54G
        esp->value.intval = index;
512
1.54G
        esp += 2;
513
1.54G
        *esp = obj[1];
514
1.54G
        return o_push_estack;
515
1.54G
    } else {     /* done */
516
35.9M
        pop(2);      /* undo push */
517
35.9M
        esp -= 4;    /* pop mark, object, proc, index */
518
35.9M
        return o_pop_estack;
519
35.9M
    }
520
1.58G
}
521
/* Continuation operator for strings */
522
static int
523
string_continue(i_ctx_t *i_ctx_p)
524
162k
{
525
162k
    os_ptr op = osp;
526
162k
    es_ptr obj = esp - 1;
527
528
162k
    if (r_size(obj)) {   /* continue */
529
120
        push(1);    /* check for result space on stack BEFORE changing string size */
530
120
        r_dec_size(obj, 1); /* Bug 701550 :-O */
531
120
        make_int(op, *obj->value.bytes);
532
120
        obj->value.bytes++;
533
120
        esp += 2;
534
120
        *esp = obj[1];
535
120
        return o_push_estack;
536
162k
    } else {     /* done */
537
162k
        esp -= 3;    /* pop mark, object, proc */
538
162k
        return o_pop_estack;
539
162k
    }
540
162k
}
541
/* Continuation operator for packed arrays */
542
static int
543
packedarray_continue(i_ctx_t *i_ctx_p)
544
49.3M
{
545
49.3M
    os_ptr op = osp;
546
49.3M
    es_ptr obj = esp - 1;
547
548
49.3M
    if (r_size(obj)) {   /* continue */
549
39.7M
        const ref_packed *packed = obj->value.packed;
550
551
39.7M
        r_dec_size(obj, 1);
552
39.7M
        push(1);
553
39.7M
        packed_get(imemory, packed, op);
554
39.7M
        obj->value.packed = packed_next(packed);
555
39.7M
        esp += 2;
556
39.7M
        *esp = obj[1];
557
39.7M
        return o_push_estack;
558
39.7M
    } else {     /* done */
559
9.61M
        esp -= 3;    /* pop mark, object, proc */
560
9.61M
        return o_pop_estack;
561
9.61M
    }
562
49.3M
}
563
/* Vacuous cleanup procedure */
564
static int
565
forall_cleanup(i_ctx_t *i_ctx_p)
566
663k
{
567
663k
    return 0;
568
663k
}
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
72.4M
{
601
72.4M
    int fromtype = r_type(prfrom);
602
72.4M
    uint fromsize = r_size(prfrom);
603
604
72.4M
    if (!(fromtype == r_type(prto) ||
605
72.4M
          ((fromtype == t_shortarray || fromtype == t_mixedarray) &&
606
162k
           r_type(prto) == t_array))
607
72.4M
        )
608
72.4M
        return_op_typecheck(prfrom);
609
72.4M
    check_read(*prfrom);
610
72.4M
    check_write(*prto);
611
72.4M
    if (fromsize > r_size(prto) - index)
612
0
        return_error(gs_error_rangecheck);
613
72.4M
    switch (fromtype) {
614
24.5M
        case t_array:
615
24.5M
            {     /* We have to worry about aliasing, */
616
                /* but refcpy_to_old takes care of it for us. */
617
24.5M
                return refcpy_to_old(prto, index, prfrom->value.refs,
618
24.5M
                                     fromsize, idmemory, cname);
619
0
            }
620
47.7M
        case t_string:
621
47.7M
            { /* memmove takes care of aliasing. */
622
47.7M
                memmove(prto->value.bytes + index, prfrom->value.bytes,
623
47.7M
                        fromsize);
624
47.7M
            }
625
47.7M
            break;
626
162k
        case t_mixedarray:
627
162k
        case t_shortarray:
628
162k
            { /* 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
162k
                uint i;
632
162k
                const ref_packed *packed = prfrom->value.packed;
633
162k
                ref *pdest = prto->value.refs + index;
634
162k
                ref elt;
635
636
41.7M
                for (i = 0; i < fromsize; i++, pdest++) {
637
41.5M
                    packed_get(imemory, packed, &elt);
638
41.5M
                    ref_assign_old(prto, pdest, &elt, cname);
639
41.5M
                    packed = packed_next(packed);
640
41.5M
                }
641
162k
            }
642
162k
            break;
643
72.4M
    }
644
47.8M
    return 0;
645
72.4M
}