Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/psi/iparam.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2022 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.,  1305 Grant Avenue - Suite 200, Novato,
13
   CA 94945, U.S.A., +1(415)492-9861, for further information.
14
*/
15
16
17
/* Interpreter implementations of parameter dictionaries */
18
#include "memory_.h"
19
#include "string_.h"
20
#include "ghost.h"
21
#include "ierrors.h"
22
#include "oper.h"   /* for check_type */
23
#include "opcheck.h"
24
#include "ialloc.h"
25
#include "idict.h"
26
#include "imemory.h"    /* for iutil.h */
27
#include "iname.h"
28
#include "istack.h"
29
#include "iparam.h"
30
#include "iutil.h"    /* for num_params */
31
#include "ivmspace.h"
32
#include "store.h"
33
#include "gsstruct.h"           /* for st_bytes */
34
35
/* ================ Utilities ================ */
36
37
/* Convert a key to a ref. */
38
static int
39
ref_param_key(const iparam_list * plist, gs_param_name pkey, ref * pkref)
40
524M
{
41
524M
    if (plist->int_keys) {
42
0
        long key;
43
44
0
        if (sscanf(pkey, "%ld", &key) != 1)
45
0
            return_error(gs_error_rangecheck);
46
0
        make_int(pkref, key);
47
0
        return 0;
48
0
    } else
49
524M
        return name_ref(plist->memory, (const byte *)pkey, strlen(pkey), pkref, 0);
50
524M
}
51
52
/* Fill in a gs_param_key_t from a name or int ref. */
53
static int
54
ref_to_key(const ref * pref, gs_param_key_t * key, iparam_list *plist)
55
1.61M
{
56
1.61M
    if (r_has_type(pref, t_name)) {
57
1.61M
        ref nref;
58
59
1.61M
        name_string_ref(plist->memory, pref, &nref);
60
1.61M
        key->data = nref.value.const_bytes;
61
1.61M
        key->size = r_size(&nref);
62
1.61M
        key->persistent = false; /* names may be freed */
63
1.61M
    } else if (r_has_type(pref, t_integer)) {
64
0
        char istr[sizeof(long) * 8 / 3 + 2];
65
0
        int len;
66
0
        byte *buf;
67
68
0
        gs_snprintf(istr, sizeof(istr), "%"PRIpsint, pref->value.intval);
69
0
        len = strlen(istr);
70
        /* GC will take care of freeing this: */
71
0
        buf = gs_alloc_string(plist->memory, len, "ref_to_key");
72
0
        if (!buf)
73
0
            return_error(gs_error_VMerror);
74
0
        key->data = buf;
75
0
        key->size = len;
76
0
        key->persistent = true;
77
0
    } else
78
0
        return_error(gs_error_typecheck);
79
1.61M
    return 0;
80
1.61M
}
81
82
/* ================ Writing parameters to refs ================ */
83
84
/* Forward references */
85
static int array_new_indexed_plist_write(dict_param_list *plist,
86
                                          ref *parray, const ref *pwanted,
87
                                          gs_ref_memory_t *imem);
88
89
/* ---------------- Generic writing procedures ---------------- */
90
91
static param_proc_begin_xmit_collection(ref_param_begin_write_collection);
92
static param_proc_end_xmit_collection(ref_param_end_write_collection);
93
static param_proc_xmit_typed(ref_param_write_typed);
94
static param_proc_next_key(ref_param_get_next_key);
95
static param_proc_requested(ref_param_requested);
96
static const gs_param_list_procs ref_write_procs =
97
{
98
    ref_param_write_typed,
99
    ref_param_begin_write_collection,
100
    ref_param_end_write_collection,
101
    ref_param_get_next_key,
102
    NULL,     /* request */
103
    ref_param_requested
104
};
105
static int ref_array_param_requested(const iparam_list *, gs_param_name,
106
                                      ref *, uint, client_name_t);
107
static int ref_param_write(iparam_list *, gs_param_name, const ref *);
108
static int ref_param_write_string_value(ref *, const gs_param_string *,
109
                                         gs_ref_memory_t *);
110
static int ref_param_write_name_value(const gs_memory_t *mem, ref *, const gs_param_string *);
111
static int
112
ref_param_make_int(ref *pe, const void *pvalue, uint i, gs_ref_memory_t *imem)
113
8.63M
{
114
8.63M
    make_tav(pe, t_integer, imemory_new_mask(imem), intval,
115
8.63M
             ((const gs_param_int_array *)pvalue)->data[i]);
116
8.63M
    return 0;
117
8.63M
}
118
static int
119
ref_param_make_float(ref *pe, const void *pvalue, uint i, gs_ref_memory_t *imem)
120
6.39M
{
121
6.39M
    make_tav(pe, t_real, imemory_new_mask(imem), realval,
122
6.39M
             ((const gs_param_float_array *)pvalue)->data[i]);
123
6.39M
    return 0;
124
6.39M
}
125
static int
126
ref_param_make_string(ref *pe, const void *pvalue, uint i, gs_ref_memory_t *imem)
127
0
{
128
0
    return ref_param_write_string_value(pe,
129
0
                         &((const gs_param_string_array *)pvalue)->data[i],
130
0
                                        imem);
131
0
}
132
static int
133
ref_param_make_name(ref * pe, const void *pvalue, uint i, gs_ref_memory_t *imem)
134
973k
{
135
973k
    return ref_param_write_name_value((const gs_memory_t *)imem, pe,
136
973k
                         &((const gs_param_string_array *)pvalue)->data[i]);
137
973k
}
138
static int
139
ref_param_write_typed_array(gs_param_list * plist, gs_param_name pkey,
140
                            void *pvalue, uint count,
141
                            int (*make)(ref *, const void *, uint,
142
                                        gs_ref_memory_t *))
143
17.7M
{
144
17.7M
    iparam_list *const iplist = (iparam_list *) plist;
145
17.7M
    ref value;
146
17.7M
    uint i;
147
17.7M
    ref *pe;
148
17.7M
    int code;
149
150
17.7M
    if ((code = ref_array_param_requested(iplist, pkey, &value, count,
151
17.7M
                                       "ref_param_write_typed_array")) <= 0)
152
12.1M
        return code;
153
21.5M
    for (i = 0, pe = value.value.refs; i < count; ++i, ++pe)
154
16.0M
        if ((code = (*make) (pe, pvalue, i, iplist->ref_memory)) < 0)
155
0
            return code;
156
5.54M
    return ref_param_write(iplist, pkey, &value);
157
5.54M
}
158
static int
159
ref_param_begin_write_collection(gs_param_list * plist, gs_param_name pkey,
160
                                 gs_param_dict * pvalue,
161
                                 gs_param_collection_type_t coll_type)
162
1.29M
{
163
1.29M
    iparam_list *const iplist = (iparam_list *) plist;
164
1.29M
    gs_ref_memory_t *imem = iplist->ref_memory;
165
1.29M
    dict_param_list *dlist = (dict_param_list *)
166
1.29M
        gs_alloc_bytes(plist->memory, size_of(dict_param_list),
167
1.29M
                       "ref_param_begin_write_collection");
168
1.29M
    int code;
169
170
1.29M
    if (dlist == 0)
171
0
        return_error(gs_error_VMerror);
172
1.29M
    if (coll_type != gs_param_collection_array) {
173
1.29M
        ref dref;
174
175
1.29M
        code = dict_alloc(imem, pvalue->size, &dref);
176
1.29M
        if (code >= 0) {
177
1.29M
            code = dict_param_list_write(dlist, &dref, NULL, imem);
178
1.29M
            dlist->int_keys = coll_type == gs_param_collection_dict_int_keys;
179
1.29M
        }
180
1.29M
    } else {
181
0
        ref aref;
182
183
0
        code = gs_alloc_ref_array(imem, &aref, a_all, pvalue->size,
184
0
                                  "ref_param_begin_write_collection");
185
0
        if (code >= 0)
186
0
            code = array_new_indexed_plist_write(dlist, &aref, NULL, imem);
187
0
    }
188
1.29M
    if (code < 0)
189
0
        gs_free_object(plist->memory, dlist, "ref_param_begin_write_collection");
190
1.29M
    else
191
1.29M
        pvalue->list = (gs_param_list *) dlist;
192
1.29M
    return code;
193
1.29M
}
194
static int
195
ref_param_end_write_collection(gs_param_list * plist, gs_param_name pkey,
196
                               gs_param_dict * pvalue)
197
1.29M
{
198
1.29M
    iparam_list *const iplist = (iparam_list *) plist;
199
1.29M
    int code = ref_param_write(iplist, pkey,
200
1.29M
                               &((dict_param_list *) pvalue->list)->dict);
201
202
1.29M
    gs_free_object(plist->memory, pvalue->list, "ref_param_end_write_collection");
203
1.29M
    pvalue->list = 0;
204
1.29M
    return code;
205
1.29M
}
206
static int
207
ref_param_write_typed(gs_param_list * plist, gs_param_name pkey,
208
                      gs_param_typed_value * pvalue)
209
289M
{
210
289M
    iparam_list *const iplist = (iparam_list *) plist;
211
289M
    ref value;
212
289M
    int code = 0;
213
214
289M
    switch (pvalue->type) {
215
5.90M
        case gs_param_type_null:
216
5.90M
            make_null(&value);
217
5.90M
            break;
218
72.8M
        case gs_param_type_bool:
219
72.8M
            make_bool(&value, pvalue->value.b);
220
72.8M
            break;
221
86.5M
        case gs_param_type_int:
222
86.5M
            make_int(&value, pvalue->value.i);
223
86.5M
            break;
224
10.3M
        case gs_param_type_long:
225
            /* FIXME: Rangecheck? */
226
10.3M
            make_int(&value, pvalue->value.l);
227
10.3M
            break;
228
8.93M
        case gs_param_type_size_t:
229
            /* FIXME: Rangecheck? */
230
8.93M
            make_int(&value, pvalue->value.z);
231
8.93M
            break;
232
1.58M
        case gs_param_type_i64:
233
            /* FIXME: Rangecheck? */
234
1.58M
            make_int(&value, pvalue->value.i64);
235
1.58M
            break;
236
20.6M
        case gs_param_type_float:
237
20.6M
            make_real(&value, pvalue->value.f);
238
20.6M
            break;
239
55.2M
        case gs_param_type_string:
240
55.2M
            if (!ref_param_requested(plist, pkey))
241
44.7M
                return 0;
242
10.4M
            code = ref_param_write_string_value(&value, &pvalue->value.s,
243
10.4M
                                                iplist->ref_memory);
244
10.4M
            break;
245
9.58M
        case gs_param_type_name:
246
9.58M
            if (!ref_param_requested(plist, pkey))
247
6.91M
                return 0;
248
2.67M
            code = ref_param_write_name_value(iplist->memory, &value, &pvalue->value.n);
249
2.67M
            break;
250
3.67M
        case gs_param_type_int_array:
251
3.67M
            return ref_param_write_typed_array(plist, pkey, &pvalue->value.ia,
252
3.67M
                                               pvalue->value.ia.size,
253
3.67M
                                               ref_param_make_int);
254
10.5M
        case gs_param_type_float_array:
255
10.5M
            return ref_param_write_typed_array(plist, pkey, &pvalue->value.fa,
256
10.5M
                                               pvalue->value.fa.size,
257
10.5M
                                               ref_param_make_float);
258
258k
        case gs_param_type_string_array:
259
258k
            return ref_param_write_typed_array(plist, pkey, &pvalue->value.sa,
260
258k
                                               pvalue->value.sa.size,
261
258k
                                               ref_param_make_string);
262
3.28M
        case gs_param_type_name_array:
263
3.28M
            return ref_param_write_typed_array(plist, pkey, &pvalue->value.na,
264
3.28M
                                               pvalue->value.na.size,
265
3.28M
                                               ref_param_make_name);
266
0
        case gs_param_type_dict:
267
0
        case gs_param_type_dict_int_keys:
268
0
        case gs_param_type_array:
269
0
            return ref_param_begin_write_collection(plist, pkey,
270
0
                                                    &pvalue->value.d,
271
0
              (gs_param_collection_type_t)(pvalue->type - gs_param_type_dict));
272
0
        default:
273
0
            return_error(gs_error_typecheck);
274
289M
    }
275
219M
    if (code < 0)
276
0
        return code;
277
219M
    return ref_param_write(iplist, pkey, &value);
278
219M
}
279
280
/* Check whether a given parameter was requested. */
281
static int
282
ref_param_requested(const gs_param_list * plist, gs_param_name pkey)
283
312M
{
284
312M
    const iparam_list *const ciplist = (const iparam_list *)plist;
285
312M
    ref kref;
286
312M
    ref *ignore_value;
287
288
312M
    if (!r_has_type(&ciplist->u.w.wanted, t_dictionary))
289
66.5M
        return -1;
290
245M
    if (ref_param_key(ciplist, pkey, &kref) < 0)
291
0
        return -1;   /* catch it later */
292
245M
    return (dict_find(&ciplist->u.w.wanted, &kref, &ignore_value) > 0);
293
245M
}
294
295
/* Check whether an array parameter is wanted, and allocate it if so. */
296
/* Return <0 on error, 0 if not wanted, 1 if wanted. */
297
static int
298
ref_array_param_requested(const iparam_list *iplist, gs_param_name pkey,
299
                          ref *pvalue, uint size, client_name_t cname)
300
17.7M
{
301
17.7M
    int code;
302
303
17.7M
    if (!ref_param_requested((const gs_param_list *)iplist, pkey))
304
12.1M
        return 0;
305
5.54M
    code = gs_alloc_ref_array(iplist->ref_memory, pvalue, a_all, size, cname);
306
5.54M
    return (code < 0 ? code : 1);
307
17.7M
}
308
309
/* ---------------- Internal routines ---------------- */
310
311
/* Prepare to write a string value. */
312
static int
313
ref_param_write_string_value(ref * pref, const gs_param_string * pvalue,
314
                             gs_ref_memory_t *imem)
315
10.4M
{
316
10.4M
    const byte *pdata = pvalue->data;
317
10.4M
    uint n = pvalue->size;
318
319
10.4M
    if (pvalue->persistent)
320
10.4M
        make_const_string(pref, a_readonly | avm_foreign, n, pdata);
321
4.88M
    else {
322
4.88M
        byte *pstr = gs_alloc_string((gs_memory_t *)imem, n,
323
4.88M
                                     "ref_param_write_string");
324
325
4.88M
        if (pstr == 0)
326
0
            return_error(gs_error_VMerror);
327
4.88M
        memcpy(pstr, pdata, n);
328
4.88M
        make_string(pref, a_readonly | imemory_space(imem), n, pstr);
329
4.88M
    }
330
10.4M
    return 0;
331
10.4M
}
332
333
/* Prepare to write a name value. */
334
static int
335
ref_param_write_name_value(const gs_memory_t *mem, ref * pref, const gs_param_string * pvalue)
336
3.64M
{
337
3.64M
    return name_ref(mem, pvalue->data, pvalue->size, pref,
338
3.64M
                    (pvalue->persistent ? 0 : 1));
339
3.64M
}
340
341
/* Generic routine for writing a ref parameter. */
342
static int
343
ref_param_write(iparam_list * plist, gs_param_name pkey, const ref * pvalue)
344
226M
{
345
226M
    ref kref;
346
226M
    int code;
347
348
226M
    if (!ref_param_requested((gs_param_list *) plist, pkey))
349
159M
        return 0;
350
67.1M
    code = ref_param_key(plist, pkey, &kref);
351
67.1M
    if (code < 0)
352
0
        return code;
353
67.1M
    return (*plist->u.w.write) (plist, &kref, pvalue);
354
67.1M
}
355
356
/* ---------------- Implementations ---------------- */
357
358
/* Initialize for writing parameters. */
359
static void
360
ref_param_write_init(iparam_list * plist, const ref * pwanted,
361
                     gs_ref_memory_t *imem)
362
8.07M
{
363
8.07M
    gs_param_list_init((gs_param_list *)plist, &ref_write_procs,
364
8.07M
                       (gs_memory_t *)imem);
365
8.07M
    plist->ref_memory = imem;
366
8.07M
    if (pwanted == 0)
367
8.07M
        make_null(&plist->u.w.wanted);
368
5.28M
    else
369
5.28M
        plist->u.w.wanted = *pwanted;
370
8.07M
    plist->results = 0;
371
8.07M
    plist->int_keys = false;
372
8.07M
}
373
374
/* Implementation for getting parameters to a stack. */
375
static int
376
stack_param_write(iparam_list * plist, const ref * pkey, const ref * pvalue)
377
63.6M
{
378
63.6M
    stack_param_list *const splist = (stack_param_list *) plist;
379
63.6M
    ref_stack_t *pstack = splist->pstack;
380
63.6M
    s_ptr p = pstack->p;
381
382
63.6M
    if (pstack->top - p < 2) {
383
116
        int code = ref_stack_push(pstack, 2);
384
385
116
        if (code < 0)
386
0
            return code;
387
116
        *ref_stack_index(pstack, 1) = *pkey;
388
116
        p = pstack->p;
389
63.6M
    } else {
390
63.6M
        pstack->p = p += 2;
391
63.6M
        p[-1] = *pkey;
392
63.6M
    }
393
63.6M
    *p = *pvalue;
394
63.6M
    splist->count++;
395
63.6M
    return 0;
396
63.6M
}
397
398
/* Implementation for enumerating parameters on a stack */
399
static int      /* ret 0 ok, 1 if EOF, or -ve err */
400
stack_param_enumerate(iparam_list * plist, gs_param_enumerator_t * penum,
401
                      gs_param_key_t * key, ref_type * type)
402
0
{
403
0
    int code;
404
0
    stack_param_list *const splist = (stack_param_list *) plist;
405
0
    int index = penum->intval;
406
0
    ref *stack_element;
407
408
0
    do {
409
0
        if (index >= splist->count*2)
410
0
            return 1;
411
0
        stack_element =
412
0
            ref_stack_index(splist->pstack, index + 1 + splist->skip);
413
0
        if (!stack_element)
414
0
            return 1;
415
0
        index += 2;
416
0
    } while (!r_has_type(stack_element, t_name));
417
0
    *type = r_type(stack_element);
418
0
    code = ref_to_key(stack_element, key, plist);
419
0
    penum->intval = index;
420
0
    return code;
421
0
}
422
423
int
424
stack_param_list_write(stack_param_list * plist, ref_stack_t * pstack,
425
                       const ref * pwanted, gs_ref_memory_t *imem)
426
6.70M
{
427
6.70M
    plist->u.w.write = stack_param_write;
428
6.70M
    ref_param_write_init((iparam_list *) plist, pwanted, imem);
429
6.70M
    plist->enumerate = stack_param_enumerate;
430
6.70M
    plist->pstack = pstack;
431
6.70M
    plist->skip = 0;
432
6.70M
    plist->count = 0;
433
6.70M
    return 0;
434
6.70M
}
435
436
/* Implementation for getting parameters to a dictionary. */
437
static int
438
dict_param_write(iparam_list * plist, const ref * pkey, const ref * pvalue)
439
3.53M
{
440
3.53M
    int code =
441
3.53M
        dict_put(&((dict_param_list *) plist)->dict, pkey, pvalue, NULL);
442
443
3.53M
    return min(code, 0);
444
3.53M
}
445
446
/* Implementation for enumerating parameters in a dictionary */
447
static int      /* ret 0 ok, 1 if EOF, or -ve err */
448
dict_param_enumerate(iparam_list * plist, gs_param_enumerator_t * penum,
449
                     gs_param_key_t * key, ref_type * type)
450
2.08M
{
451
2.08M
    ref elt[2];
452
2.08M
    int code;
453
2.08M
    dict_param_list *const pdlist = (dict_param_list *) plist;
454
2.08M
    int index =
455
2.08M
    (penum->intval != 0 ? penum->intval : dict_first(&pdlist->dict));
456
457
2.08M
    index = dict_next(&pdlist->dict, index, elt);
458
2.08M
    if (index < 0)
459
471k
        return 1;
460
1.61M
    *type = r_type(&elt[0]);
461
1.61M
    code = ref_to_key(&elt[0], key, plist);
462
1.61M
    penum->intval = index;
463
1.61M
    return code;
464
2.08M
}
465
466
int
467
dict_param_list_write(dict_param_list *plist, ref *pdict, const ref *pwanted,
468
                      gs_ref_memory_t *imem)
469
1.36M
{
470
1.36M
    check_dict_write(*pdict);
471
1.36M
    plist->u.w.write = dict_param_write;
472
1.36M
    plist->enumerate = dict_param_enumerate;
473
1.36M
    ref_param_write_init((iparam_list *) plist, pwanted, imem);
474
1.36M
    plist->dict = *pdict;
475
1.36M
    return 0;
476
1.36M
}
477
478
/* Implementation for getting parameters to an indexed array. */
479
/* Note that this is now internal, since it only handles "new" arrays. */
480
static int
481
array_new_indexed_param_write(iparam_list * iplist, const ref * pkey,
482
                          const ref * pvalue)
483
0
{
484
0
    const ref *const arr = &((dict_param_list *)iplist)->dict;
485
0
    ref *eltp;
486
487
0
    if (!r_has_type(pkey, t_integer))
488
0
        return_error(gs_error_typecheck);
489
0
    check_int_ltu(*pkey, r_size(arr));
490
0
    store_check_dest(arr, pvalue);
491
0
    eltp = arr->value.refs + pkey->value.intval;
492
    /* ref_assign_new(eltp, pvalue); */
493
0
    ref_assign(eltp, pvalue);
494
0
    r_set_attrs(eltp, imemory_new_mask(iplist->ref_memory));
495
0
    return 0;
496
0
}
497
static int
498
array_new_indexed_plist_write(dict_param_list * plist, ref * parray,
499
                              const ref * pwanted, gs_ref_memory_t *imem)
500
0
{
501
0
    check_array(*parray);
502
0
    check_write(*parray);
503
0
    plist->u.w.write = array_new_indexed_param_write;
504
0
    ref_param_write_init((iparam_list *) plist, pwanted, imem);
505
0
    plist->dict = *parray;
506
0
    plist->int_keys = true;
507
0
    return 0;
508
0
}
509
510
/* ================ Reading refs to parameters ================ */
511
512
/* ---------------- Generic reading procedures ---------------- */
513
514
static param_proc_begin_xmit_collection(ref_param_begin_read_collection);
515
static param_proc_end_xmit_collection(ref_param_end_read_collection);
516
static param_proc_xmit_typed(ref_param_read_typed);
517
518
/*static param_proc_next_key(ref_param_get_next_key); already dec'ld above */
519
static param_proc_get_policy(ref_param_read_get_policy);
520
static param_proc_signal_error(ref_param_read_signal_error);
521
static param_proc_commit(ref_param_read_commit);
522
static const gs_param_list_procs ref_read_procs =
523
{
524
    ref_param_read_typed,
525
    ref_param_begin_read_collection,
526
    ref_param_end_read_collection,
527
    ref_param_get_next_key,
528
    NULL,     /* request */
529
    NULL,     /* requested */
530
    ref_param_read_get_policy,
531
    ref_param_read_signal_error,
532
    ref_param_read_commit,
533
    NULL
534
};
535
static int ref_param_read(iparam_list *, gs_param_name,
536
                           iparam_loc *, int);
537
static int ref_param_read_string_value(gs_memory_t *mem,
538
                                        const iparam_loc *,
539
                                        gs_param_string *);
540
static int ref_param_read_array(iparam_list *, gs_param_name,
541
                                 iparam_loc *);
542
543
#define iparam_note_error(loc, code)\
544
0
  gs_note_error(*(loc).presult = code)
545
#define iparam_check_type(loc, typ)\
546
0
  if ( !r_has_type((loc).pvalue, typ) )\
547
0
    return iparam_note_error(loc, gs_error_typecheck)
548
#define iparam_check_read(loc)\
549
10.2M
  if ( !r_has_attr((loc).pvalue, a_read) )\
550
10.2M
    return iparam_note_error(loc, gs_error_invalidaccess)
551
552
static int
553
ref_param_read_int_array(gs_param_list * plist, gs_param_name pkey,
554
                         gs_param_int_array * pvalue)
555
2.47M
{
556
2.47M
    iparam_list *const iplist = (iparam_list *) plist;
557
2.47M
    iparam_loc loc;
558
2.47M
    int code = ref_param_read_array(iplist, pkey, &loc);
559
2.47M
    int *piv;
560
2.47M
    uint size;
561
2.47M
    long i;
562
563
2.47M
    if (code != 0)
564
0
        return code;
565
2.47M
    size = r_size(loc.pvalue);
566
2.47M
    piv = (int *)gs_alloc_byte_array(plist->memory, size, sizeof(int),
567
2.47M
                                     "ref_param_read_int_array");
568
569
2.47M
    if (piv == 0)
570
0
        return_error(gs_error_VMerror);
571
12.4M
    for (i = 0; i < size; i++) {
572
10.0M
        ref elt;
573
574
10.0M
        array_get(plist->memory, loc.pvalue, i, &elt);
575
10.0M
        if (!r_has_type(&elt, t_integer)) {
576
0
            code = gs_note_error(gs_error_typecheck);
577
0
            break;
578
0
        }
579
10.0M
        piv[i] = (int)elt.value.intval;
580
10.0M
    }
581
2.47M
    if (code < 0) {
582
0
        gs_free_object(plist->memory, piv, "ref_param_read_int_array");
583
0
        return (*loc.presult = code);
584
0
    }
585
2.47M
    pvalue->data = piv;
586
2.47M
    pvalue->size = size;
587
2.47M
    pvalue->persistent = true;
588
2.47M
    return 0;
589
2.47M
}
590
static int
591
ref_param_read_float_array(gs_param_list * plist, gs_param_name pkey,
592
                           gs_param_float_array * pvalue)
593
794k
{
594
794k
    iparam_list *const iplist = (iparam_list *) plist;
595
794k
    iparam_loc loc;
596
794k
    ref aref, elt;
597
794k
    int code = ref_param_read_array(iplist, pkey, &loc);
598
794k
    float *pfv;
599
794k
    uint size;
600
794k
    long i;
601
602
794k
    if (code != 0)
603
0
        return code;
604
794k
    size = r_size(loc.pvalue);
605
794k
    pfv = (float *)gs_alloc_byte_array(plist->memory, size, sizeof(float),
606
794k
                                       "ref_param_read_float_array");
607
608
794k
    if (pfv == 0)
609
0
        return_error(gs_error_VMerror);
610
794k
    aref = *loc.pvalue;
611
794k
    loc.pvalue = &elt;
612
2.45M
    for (i = 0; code >= 0 && i < size; i++) {
613
1.66M
        array_get(plist->memory, &aref, i, &elt);
614
1.66M
        code = float_param(&elt, pfv + i);
615
1.66M
    }
616
794k
    if (code < 0) {
617
0
        gs_free_object(plist->memory, pfv, "ref_read_float_array_param");
618
0
        return (*loc.presult = code);
619
0
    }
620
794k
    pvalue->data = pfv;
621
794k
    pvalue->size = size;
622
794k
    pvalue->persistent = true;
623
794k
    return 0;
624
794k
}
625
static int
626
ref_param_read_string_array(gs_param_list * plist, gs_param_name pkey,
627
                            gs_param_string_array * pvalue)
628
115k
{
629
115k
    iparam_list *const iplist = (iparam_list *) plist;
630
115k
    iparam_loc loc;
631
115k
    ref aref;
632
115k
    int code = ref_param_read_array(iplist, pkey, &loc);
633
115k
    gs_param_string *psv;
634
115k
    uint size;
635
115k
    long i;
636
637
115k
    if (code != 0)
638
0
        return code;
639
115k
    size = r_size(loc.pvalue);
640
115k
    psv = (gs_param_string *)
641
115k
        gs_alloc_byte_array(plist->memory, size, sizeof(gs_param_string),
642
115k
                            "ref_param_read_string_array");
643
115k
    if (psv == 0)
644
0
        return_error(gs_error_VMerror);
645
115k
    aref = *loc.pvalue;
646
115k
    if (r_has_type(&aref, t_array)) {
647
1.47M
        for (i = 0; code >= 0 && i < size; i++) {
648
1.35M
            loc.pvalue = aref.value.refs + i;
649
1.35M
            code = ref_param_read_string_value(plist->memory, &loc, psv + i);
650
1.35M
        }
651
115k
    } else {
652
0
        ref elt;
653
654
0
        loc.pvalue = &elt;
655
0
        for (i = 0; code >= 0 && i < size; i++) {
656
0
            array_get(plist->memory, &aref, i, &elt);
657
0
            code = ref_param_read_string_value(plist->memory, &loc, psv + i);
658
0
        }
659
0
    }
660
115k
    if (code < 0) {
661
0
        gs_free_object(plist->memory, psv, "ref_param_read_string_array");
662
0
        return (*loc.presult = code);
663
0
    }
664
115k
    pvalue->data = psv;
665
115k
    pvalue->size = size;
666
115k
    pvalue->persistent = true;
667
115k
    return 0;
668
115k
}
669
static int
670
ref_param_begin_read_collection(gs_param_list * plist, gs_param_name pkey,
671
                                gs_param_dict * pvalue,
672
                                gs_param_collection_type_t coll_type)
673
2.88M
{
674
2.88M
    iparam_list *const iplist = (iparam_list *) plist;
675
2.88M
    iparam_loc loc;
676
2.88M
    bool int_keys = coll_type != 0;
677
2.88M
    int code = ref_param_read(iplist, pkey, &loc, -1);
678
2.88M
    dict_param_list *dlist;
679
680
2.88M
    if (code != 0)
681
2.41M
        return code;
682
471k
    dlist = (dict_param_list *)
683
471k
        gs_alloc_bytes(plist->memory, size_of(dict_param_list),
684
471k
                       "ref_param_begin_read_collection");
685
471k
    if (dlist == 0)
686
0
        return_error(gs_error_VMerror);
687
471k
    if (r_has_type(loc.pvalue, t_dictionary)) {
688
471k
        code = dict_param_list_read(dlist, loc.pvalue, NULL, false,
689
471k
                                    iplist->ref_memory);
690
471k
        dlist->int_keys = int_keys;
691
471k
        if (code >= 0)
692
471k
            pvalue->size = dict_length(loc.pvalue);
693
471k
    } else if (int_keys && r_is_array(loc.pvalue)) {
694
0
        code = array_indexed_param_list_read(dlist, loc.pvalue, NULL, false,
695
0
                                             iplist->ref_memory);
696
0
        if (code >= 0)
697
0
            pvalue->size = r_size(loc.pvalue);
698
0
    } else
699
0
        code = gs_note_error(gs_error_typecheck);
700
471k
    if (code < 0) {
701
0
        gs_free_object(plist->memory, dlist, "ref_param_begin_write_collection");
702
0
        return iparam_note_error(loc, code);
703
0
    }
704
471k
    pvalue->list = (gs_param_list *) dlist;
705
471k
    return 0;
706
471k
}
707
static int
708
ref_param_end_read_collection(gs_param_list * plist, gs_param_name pkey,
709
                              gs_param_dict * pvalue)
710
471k
{
711
471k
    iparam_list_release((dict_param_list *) pvalue->list);
712
471k
    gs_free_object(plist->memory, pvalue->list,
713
471k
                   "ref_param_end_read_collection");
714
471k
    return 0;
715
471k
}
716
static int
717
ref_param_read_typed(gs_param_list * plist, gs_param_name pkey,
718
                     gs_param_typed_value * pvalue)
719
205M
{
720
205M
    iparam_list *const iplist = (iparam_list *) plist;
721
205M
    iparam_loc loc;
722
205M
    ref elt;
723
205M
    int code = ref_param_read(iplist, pkey, &loc, -1);
724
725
205M
    if (code != 0)
726
182M
        return code;
727
22.8M
    switch (r_type(loc.pvalue)) {
728
3.52M
        case t_array:
729
3.52M
        case t_mixedarray:
730
3.52M
        case t_shortarray:
731
3.52M
            iparam_check_read(loc);
732
3.52M
            if (r_size(loc.pvalue) <= 0) {
733
                /* 0-length array; can't get type info */
734
145k
                pvalue->type = gs_param_type_array;
735
145k
                pvalue->value.d.list = 0;
736
145k
                pvalue->value.d.size = 0;
737
145k
                return 0;
738
145k
            }
739
            /*
740
             * We have to guess at the array type.  First we guess based
741
             * on the type of the first element of the array.  If that
742
             * fails, we try again with more general types.
743
             */
744
3.38M
            array_get(plist->memory, loc.pvalue, 0, &elt);
745
3.38M
            switch (r_type(&elt)) {
746
2.47M
                case t_integer:
747
2.47M
                    pvalue->type = gs_param_type_int_array;
748
2.47M
                    code = ref_param_read_int_array(plist, pkey,
749
2.47M
                                                    &pvalue->value.ia);
750
2.47M
                    if (code != gs_error_typecheck)
751
2.47M
                        return code;
752
                    /* This might be a float array.  Fall through. */
753
0
                    *loc.presult = 0;  /* reset error */
754
794k
                case t_real:
755
794k
                    pvalue->type = gs_param_type_float_array;
756
794k
                    return ref_param_read_float_array(plist, pkey,
757
794k
                                                      &pvalue->value.fa);
758
0
                case t_string:
759
0
                    pvalue->type = gs_param_type_string_array;
760
0
                    return ref_param_read_string_array(plist, pkey,
761
0
                                                       &pvalue->value.sa);
762
115k
                case t_name:
763
115k
                    pvalue->type = gs_param_type_name_array;
764
115k
                    return ref_param_read_string_array(plist, pkey,
765
115k
                                                       &pvalue->value.na);
766
0
                default:
767
0
                    break;
768
3.38M
            }
769
0
            return gs_note_error(gs_error_typecheck);
770
5.41M
        case t_boolean:
771
5.41M
            pvalue->type = gs_param_type_bool;
772
5.41M
            pvalue->value.b = loc.pvalue->value.boolval;
773
5.41M
            return 0;
774
0
        case t_dictionary:
775
0
            code = ref_param_begin_read_collection(plist, pkey,
776
0
                            &pvalue->value.d, gs_param_collection_dict_any);
777
0
            if (code < 0)
778
0
                return code;
779
0
            pvalue->type = gs_param_type_dict;
780
781
            /* fixup new dict's type & int_keys field if contents have int keys */
782
0
            {
783
0
                gs_param_enumerator_t enumr;
784
0
                gs_param_key_t key;
785
0
                ref_type keytype;
786
0
                dict_param_list *dlist = (dict_param_list *) pvalue->value.d.list;
787
788
0
                param_init_enumerator(&enumr);
789
0
                if (!(*(dlist->enumerate))
790
0
                    ((iparam_list *) dlist, &enumr, &key, &keytype)
791
0
                    && keytype == t_integer) {
792
0
                    dlist->int_keys = 1;
793
0
                    pvalue->type = gs_param_type_dict_int_keys;
794
0
                }
795
0
            }
796
0
            return 0;
797
8.17M
        case t_integer:
798
8.17M
            pvalue->type = gs_param_type_i64;
799
8.17M
            pvalue->value.i64 = loc.pvalue->value.intval;
800
8.17M
            return 0;
801
1.04M
        case t_name:
802
1.04M
            pvalue->type = gs_param_type_name;
803
1.04M
            return ref_param_read_string_value(plist->memory, &loc, &pvalue->value.n);
804
113k
        case t_null:
805
113k
            pvalue->type = gs_param_type_null;
806
113k
            return 0;
807
1.24M
        case t_real:
808
1.24M
            pvalue->value.f = loc.pvalue->value.realval;
809
1.24M
            pvalue->type = gs_param_type_float;
810
1.24M
            return 0;
811
3.32M
        case t_string:
812
3.32M
        case t_astruct:
813
3.32M
            pvalue->type = gs_param_type_string;
814
3.32M
            return ref_param_read_string_value(plist->memory, &loc, &pvalue->value.s);
815
0
        default:
816
0
            break;
817
22.8M
    }
818
0
    return gs_note_error(gs_error_typecheck);
819
22.8M
}
820
821
static int
822
ref_param_read_get_policy(gs_param_list * plist, gs_param_name pkey)
823
152
{
824
152
    iparam_list *const iplist = (iparam_list *) plist;
825
152
    ref *pvalue;
826
827
152
    if (!(r_has_type(&iplist->u.r.policies, t_dictionary) &&
828
152
          dict_find_string(&iplist->u.r.policies, pkey, &pvalue) > 0 &&
829
152
          r_has_type(pvalue, t_integer))
830
152
        )
831
152
        return gs_param_policy_ignore;
832
0
    return (int)pvalue->value.intval;
833
152
}
834
static int
835
ref_param_read_signal_error(gs_param_list * plist, gs_param_name pkey, int code)
836
152
{
837
152
    iparam_list *const iplist = (iparam_list *) plist;
838
152
    iparam_loc loc = {0};
839
840
152
    ref_param_read(iplist, pkey, &loc, -1);
841
152
    if (loc.presult)
842
76
        *loc.presult = code;
843
152
    switch (ref_param_read_get_policy(plist, pkey)) {
844
152
        case gs_param_policy_ignore:
845
152
            return 0;
846
0
        case gs_param_policy_consult_user:
847
0
            return_error(gs_error_configurationerror);
848
0
        default:
849
0
            return code;
850
152
    }
851
152
}
852
static int
853
ref_param_read_commit(gs_param_list * plist)
854
813k
{
855
813k
    iparam_list *const iplist = (iparam_list *) plist;
856
813k
    int i;
857
813k
    int ecode = 0;
858
859
813k
    if (!iplist->u.r.require_all)
860
230k
        return 0;
861
    /* Check to make sure that all parameters were actually read. */
862
5.75M
    for (i = 0; i < iplist->count; ++i)
863
5.17M
        if (iplist->results[i] == 0)
864
582k
            iplist->results[i] = ecode = gs_note_error(gs_error_undefined);
865
582k
    return ecode;
866
813k
}
867
static int
868
ref_param_get_next_key(gs_param_list * plist, gs_param_enumerator_t * penum,
869
                       gs_param_key_t * key)
870
2.08M
{
871
2.08M
    ref_type keytype;   /* result not needed here */
872
2.08M
    iparam_list *const pilist = (iparam_list *) plist;
873
874
2.08M
    return (*pilist->enumerate) (pilist, penum, key, &keytype);
875
2.08M
}
876
877
/* ---------------- Internal routines ---------------- */
878
879
/* Read a string value. */
880
static int
881
ref_param_read_string_value(gs_memory_t *mem, const iparam_loc * ploc, gs_param_string * pvalue)
882
5.72M
{
883
5.72M
    const ref *pref = ploc->pvalue;
884
885
5.72M
    switch (r_type(pref)) {
886
2.37M
        case t_name: {
887
2.37M
            ref nref;
888
889
2.37M
            name_string_ref(mem, pref, &nref);
890
2.37M
            pvalue->data = nref.value.const_bytes;
891
2.37M
            pvalue->size = r_size(&nref);
892
2.37M
            pvalue->persistent = true;
893
2.37M
        }
894
2.37M
            break;
895
3.34M
        case t_string:
896
3.34M
            iparam_check_read(*ploc);
897
3.34M
            pvalue->data = pref->value.const_bytes;
898
3.34M
            pvalue->size = r_size(pref);
899
3.34M
            pvalue->persistent = false;
900
3.34M
            break;
901
0
        case t_astruct:
902
            /* Note: technically, instead of the "mem" argument, we
903
               should be using the plists's ref_memory. However, in a
904
               simple call to .putdeviceparams, they are identical. */
905
0
            iparam_check_read(*ploc);
906
0
            if (gs_object_type(mem, pref->value.pstruct) != &st_bytes)
907
0
                return iparam_note_error(*ploc, gs_error_typecheck);
908
0
            pvalue->data = r_ptr(pref, byte);
909
0
            pvalue->size = gs_object_size(mem, pref->value.pstruct);
910
0
            pvalue->persistent = false;
911
0
            break;
912
0
        default:
913
0
            return iparam_note_error(*ploc, gs_error_typecheck);
914
5.72M
    }
915
5.72M
    return 0;
916
5.72M
}
917
918
/* Read an array (or packed array) parameter. */
919
static int
920
ref_param_read_array(iparam_list * plist, gs_param_name pkey, iparam_loc * ploc)
921
3.38M
{
922
3.38M
    int code = ref_param_read(plist, pkey, ploc, -1);
923
924
3.38M
    if (code != 0)
925
0
        return code;
926
3.38M
    if (!r_is_array(ploc->pvalue))
927
0
        return iparam_note_error(*ploc, gs_error_typecheck);
928
3.38M
    iparam_check_read(*ploc);
929
3.38M
    return 0;
930
3.38M
}
931
932
/* Generic routine for reading a ref parameter. */
933
static int
934
ref_param_read(iparam_list * plist, gs_param_name pkey, iparam_loc * ploc,
935
               int type)
936
211M
{
937
211M
    iparam_list *const iplist = (iparam_list *) plist;
938
211M
    ref kref;
939
211M
    int code = ref_param_key(plist, pkey, &kref);
940
941
211M
    if (code < 0)
942
0
        return code;
943
211M
    code = (*plist->u.r.read) (iplist, &kref, ploc);
944
211M
    if (code != 0)
945
184M
        return code;
946
26.6M
    if (type >= 0)
947
0
        iparam_check_type(*ploc, type);
948
26.6M
    return 0;
949
26.6M
}
950
951
/* ---------------- Implementations ---------------- */
952
953
/* Implementation for putting parameters from an empty collection. */
954
static int
955
empty_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc)
956
0
{
957
0
    return 1;
958
0
}
959
960
/* Initialize for reading parameters. */
961
static int
962
ref_param_read_init(iparam_list * plist, uint count, const ref * ppolicies,
963
                    bool require_all, gs_ref_memory_t *imem)
964
3.88M
{
965
3.88M
    gs_param_list_init((gs_param_list *)plist, &ref_read_procs,
966
3.88M
                       (gs_memory_t *)imem);
967
3.88M
    plist->ref_memory = imem;
968
3.88M
    if (ppolicies == 0)
969
3.88M
        make_null(&plist->u.r.policies);
970
837k
    else
971
837k
        plist->u.r.policies = *ppolicies;
972
3.88M
    plist->u.r.require_all = require_all;
973
3.88M
    plist->count = count;
974
3.88M
    plist->results = (int *)
975
3.88M
        gs_alloc_byte_array(plist->memory, count, sizeof(int),
976
3.88M
                            "ref_param_read_init");
977
978
3.88M
    if (plist->results == 0)
979
0
        return_error(gs_error_VMerror);
980
3.88M
    memset(plist->results, 0, count * sizeof(int));
981
982
3.88M
    plist->int_keys = false;
983
3.88M
    return 0;
984
3.88M
}
985
986
/* Implementation for putting parameters from an indexed array. */
987
static int
988
array_indexed_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc)
989
0
{
990
0
    ref *const arr = &((dict_param_list *) plist)->dict;
991
992
0
    check_type(*pkey, t_integer);
993
0
    if (pkey->value.intval < 0 || pkey->value.intval >= r_size(arr))
994
0
        return 1;
995
0
    ploc->pvalue = arr->value.refs + pkey->value.intval;
996
0
    ploc->presult = &plist->results[pkey->value.intval];
997
0
    *ploc->presult = 1;
998
0
    return 0;
999
0
}
1000
int
1001
array_indexed_param_list_read(dict_param_list * plist, const ref * parray,
1002
                              const ref * ppolicies, bool require_all,
1003
                              gs_ref_memory_t *ref_memory)
1004
0
{
1005
0
    iparam_list *const iplist = (iparam_list *) plist;
1006
0
    int code;
1007
1008
0
    check_read_type(*parray, t_array);
1009
0
    plist->u.r.read = array_indexed_param_read;
1010
0
    plist->dict = *parray;
1011
0
    code = ref_param_read_init(iplist, r_size(parray), ppolicies,
1012
0
                               require_all, ref_memory);
1013
0
    plist->int_keys = true;
1014
0
    return code;
1015
0
}
1016
1017
/* Implementation for putting parameters from an array. */
1018
static int
1019
array_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc)
1020
0
{
1021
0
    ref *bot = ((array_param_list *) plist)->bot;
1022
0
    ref *ptr = bot;
1023
0
    ref *top = ((array_param_list *) plist)->top;
1024
1025
0
    for (; ptr < top; ptr += 2) {
1026
0
        if (r_has_type(ptr, t_name) && name_eq(ptr, pkey)) {
1027
0
            ploc->pvalue = ptr + 1;
1028
0
            ploc->presult = &plist->results[ptr - bot];
1029
0
            *ploc->presult = 1;
1030
0
            return 0;
1031
0
        }
1032
0
    }
1033
0
    return 1;
1034
0
}
1035
1036
/* Implementation for enumerating parameters in an array */
1037
static int      /* ret 0 ok, 1 if EOF, or -ve err */
1038
array_param_enumerate(iparam_list * plist, gs_param_enumerator_t * penum,
1039
                      gs_param_key_t * key, ref_type * type)
1040
0
{
1041
0
    int index = penum->intval;
1042
0
    ref *bot = ((array_param_list *) plist)->bot;
1043
0
    ref *ptr = bot + index;
1044
0
    ref *top = ((array_param_list *) plist)->top;
1045
1046
0
    for (; ptr < top; ptr += 2) {
1047
0
        index += 2;
1048
1049
0
        if (r_has_type(ptr, t_name)) {
1050
0
            int code = ref_to_key(ptr, key, plist);
1051
1052
0
            *type = r_type(ptr);
1053
0
            penum->intval = index;
1054
0
            return code;
1055
0
        }
1056
0
    }
1057
0
    return 1;
1058
0
}
1059
1060
int
1061
array_param_list_read(array_param_list * plist, ref * bot, uint count,
1062
                      const ref * ppolicies, bool require_all,
1063
                      gs_ref_memory_t *imem)
1064
0
{
1065
0
    iparam_list *const iplist = (iparam_list *) plist;
1066
1067
0
    if (count & 1)
1068
0
        return_error(gs_error_rangecheck);
1069
0
    plist->u.r.read = array_param_read;
1070
0
    plist->enumerate = array_param_enumerate;
1071
0
    plist->bot = bot;
1072
0
    plist->top = bot + count;
1073
0
    return ref_param_read_init(iplist, count, ppolicies, require_all, imem);
1074
0
}
1075
1076
/* Implementation for putting parameters from a stack. */
1077
static int
1078
stack_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc)
1079
136M
{
1080
136M
    stack_param_list *const splist = (stack_param_list *) plist;
1081
136M
    ref_stack_t *pstack = splist->pstack;
1082
1083
    /* This implementation is slow, but it probably doesn't matter. */
1084
136M
    uint index = splist->skip + 1;
1085
136M
    uint count = splist->count;
1086
1087
1.93G
    for (; count; count--, index += 2) {
1088
1.81G
        const ref *p = ref_stack_index(pstack, index);
1089
1090
1.81G
        if (r_has_type(p, t_name) && name_eq(p, pkey)) {
1091
12.9M
            ploc->pvalue = ref_stack_index(pstack, index - 1);
1092
12.9M
            ploc->presult = &plist->results[count - 1];
1093
12.9M
            *ploc->presult = 1;
1094
12.9M
            return 0;
1095
12.9M
        }
1096
1.81G
    }
1097
123M
    return 1;
1098
136M
}
1099
int
1100
stack_param_list_read(stack_param_list * plist, ref_stack_t * pstack,
1101
                      uint skip, const ref * ppolicies, bool require_all,
1102
                      gs_ref_memory_t *imem)
1103
837k
{
1104
837k
    iparam_list *const iplist = (iparam_list *) plist;
1105
837k
    uint count = ref_stack_counttomark(pstack);
1106
1107
837k
    if (count == 0)
1108
0
        return_error(gs_error_unmatchedmark);
1109
837k
    count -= skip + 1;
1110
837k
    if (count & 1)
1111
0
        return_error(gs_error_rangecheck);
1112
837k
    plist->u.r.read = stack_param_read;
1113
837k
    plist->enumerate = stack_param_enumerate;
1114
837k
    plist->pstack = pstack;
1115
837k
    plist->skip = skip;
1116
837k
    return ref_param_read_init(iplist, count >> 1, ppolicies, require_all, imem);
1117
837k
}
1118
1119
/* Implementation for putting parameters from a dictionary. */
1120
static int
1121
dict_param_read(iparam_list * plist, const ref * pkey, iparam_loc * ploc)
1122
75.0M
{
1123
75.0M
    ref const *spdict = &((dict_param_list *) plist)->dict;
1124
75.0M
    int code = dict_find(spdict, pkey, &ploc->pvalue);
1125
1126
75.0M
    if (code != 1)
1127
61.2M
        return 1;
1128
13.7M
    ploc->presult =
1129
13.7M
        &plist->results[dict_value_index(spdict, ploc->pvalue)];
1130
13.7M
    *ploc->presult = 1;
1131
13.7M
    return 0;
1132
75.0M
}
1133
int
1134
dict_param_list_read(dict_param_list * plist, const ref * pdict,
1135
                     const ref * ppolicies, bool require_all,
1136
                     gs_ref_memory_t *imem)
1137
3.04M
{
1138
3.04M
    iparam_list *const iplist = (iparam_list *) plist;
1139
3.04M
    uint count;
1140
1141
3.04M
    if (pdict == 0) {
1142
0
        plist->u.r.read = empty_param_read;
1143
0
        count = 0;
1144
3.04M
    } else {
1145
3.04M
        check_dict_read(*pdict);
1146
3.04M
        plist->u.r.read = dict_param_read;
1147
3.04M
        plist->dict = *pdict;
1148
3.04M
        count = dict_max_index(pdict) + 1;
1149
3.04M
    }
1150
3.04M
    plist->enumerate = dict_param_enumerate;
1151
3.04M
    return ref_param_read_init(iplist, count, ppolicies, require_all, imem);
1152
3.04M
}