Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/psi/zbseq.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
/* Level 2 binary object sequence operators */
18
#include "memory_.h"
19
#include "ghost.h"
20
#include "gxalloc.h"    /* for names_array in allocator */
21
#include "oper.h"
22
#include "ialloc.h"
23
#include "istruct.h"
24
#include "btoken.h"
25
#include "store.h"
26
27
/*
28
 * Define the structure that holds the t_*array ref for the system or
29
 * user name table.
30
 */
31
typedef struct names_array_ref_s {
32
    ref names;
33
} names_array_ref_t;
34
gs_private_st_ref_struct(st_names_array_ref, names_array_ref_t,
35
                         "names_array_ref_t");
36
37
/* Create a system or user name table (in the stable memory of mem). */
38
int
39
create_names_array(ref **ppnames, gs_memory_t *mem, client_name_t cname)
40
162k
{
41
162k
    ref *pnames = (ref *)
42
162k
        gs_alloc_struct(gs_memory_stable(mem), names_array_ref_t,
43
162k
                        &st_names_array_ref, cname);
44
45
162k
    if (pnames == 0)
46
0
        return_error(gs_error_VMerror);
47
162k
    make_empty_array(pnames, a_readonly);
48
162k
    *ppnames = pnames;
49
162k
    return 0;
50
162k
}
51
52
/* Initialize the binary token machinery. */
53
static int
54
zbseq_init(i_ctx_t *i_ctx_p)
55
162k
{
56
    /* Initialize a fake system name table. */
57
    /* PostScript code will install the real system name table. */
58
162k
    ref *psystem_names = 0;
59
162k
    int code = create_names_array(&psystem_names, imemory_global,
60
162k
                                  "zbseq_init(system_names)");
61
62
162k
    if (code < 0)
63
0
        return code;
64
162k
    system_names_p = psystem_names;
65
162k
    return 0;
66
162k
}
67
68
/* <names> .installsystemnames - */
69
static int
70
zinstallsystemnames(i_ctx_t *i_ctx_p)
71
162k
{
72
162k
    os_ptr op = osp;
73
74
162k
    check_op(1);
75
162k
    if (r_space(op) != avm_global || imemory_save_level(iimemory_global) != 0)
76
0
        return_error(gs_error_invalidaccess);
77
162k
    check_read_type(*op, t_shortarray);
78
162k
    ref_assign_old(NULL, system_names_p, op, ".installsystemnames");
79
162k
    pop(1);
80
162k
    return 0;
81
162k
}
82
83
/* - currentobjectformat <int> */
84
static int
85
zcurrentobjectformat(i_ctx_t *i_ctx_p)
86
148
{
87
148
    os_ptr op = osp;
88
89
148
    push(1);
90
148
    *op = ref_binary_object_format;
91
148
    return 0;
92
148
}
93
94
/* <int> setobjectformat - */
95
static int
96
zsetobjectformat(i_ctx_t *i_ctx_p)
97
162k
{
98
162k
    os_ptr op = osp;
99
162k
    ref cont;
100
101
162k
    check_op(1);
102
162k
    check_type(*op, t_integer);
103
162k
    if (op->value.intval < 0 || op->value.intval > 4)
104
2
        return_error(gs_error_rangecheck);
105
162k
    make_struct(&cont, avm_local, ref_binary_object_format_container);
106
162k
    ref_assign_old(&cont, &ref_binary_object_format, op, "setobjectformat");
107
162k
    pop(1);
108
162k
    return 0;
109
162k
}
110
111
/* <ref_offset> <char_offset> <obj> <string8> .bosobject */
112
/*   <ref_offset'> <char_offset'> <string8> */
113
/*
114
 * This converts a single object to its binary object sequence
115
 * representation, doing the dirty work of printobject and writeobject.
116
 * (The main control is in PostScript code, so that we don't have to worry
117
 * about interrupts or callouts in the middle of writing the various data
118
 * items.)  See encode_binary_token for more details.
119
 */
120
121
static int
122
zbosobject(i_ctx_t *i_ctx_p)
123
38
{
124
38
    os_ptr op = osp;
125
38
    int code;
126
127
38
    check_op(4);
128
38
    check_type(op[-3], t_integer);
129
38
    check_type(op[-2], t_integer);
130
38
    check_write_type(*op, t_string);
131
38
    if (r_size(op) < 8)
132
0
        return_error(gs_error_rangecheck);
133
38
    code = encode_binary_token(i_ctx_p, op - 1, &op[-3].value.intval,
134
38
                               &op[-2].value.intval, op->value.bytes);
135
38
    if (code < 0)
136
0
        return code;
137
38
    op[-1] = *op;
138
38
    r_set_size(op - 1, 8);
139
38
    pop(1);
140
38
    return 0;
141
38
}
142
143
/* ------ Initialization procedure ------ */
144
145
const op_def zbseq_l2_op_defs[] =
146
{
147
    op_def_begin_level2(),
148
    {"1.installsystemnames", zinstallsystemnames},
149
    {"0currentobjectformat", zcurrentobjectformat},
150
    {"1setobjectformat", zsetobjectformat},
151
    {"4.bosobject", zbosobject},
152
    op_def_end(zbseq_init)
153
};