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