Coverage Report

Created: 2025-06-10 06:58

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