Coverage Report

Created: 2025-06-10 07:27

/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
159k
{
41
159k
    ref *pnames = (ref *)
42
159k
        gs_alloc_struct(gs_memory_stable(mem), names_array_ref_t,
43
159k
                        &st_names_array_ref, cname);
44
45
159k
    if (pnames == 0)
46
0
        return_error(gs_error_VMerror);
47
159k
    make_empty_array(pnames, a_readonly);
48
159k
    *ppnames = pnames;
49
159k
    return 0;
50
159k
}
51
52
/* Initialize the binary token machinery. */
53
static int
54
zbseq_init(i_ctx_t *i_ctx_p)
55
159k
{
56
    /* Initialize a fake system name table. */
57
    /* PostScript code will install the real system name table. */
58
159k
    ref *psystem_names = 0;
59
159k
    int code = create_names_array(&psystem_names, imemory_global,
60
159k
                                  "zbseq_init(system_names)");
61
62
159k
    if (code < 0)
63
0
        return code;
64
159k
    system_names_p = psystem_names;
65
159k
    return 0;
66
159k
}
67
68
/* <names> .installsystemnames - */
69
static int
70
zinstallsystemnames(i_ctx_t *i_ctx_p)
71
159k
{
72
159k
    os_ptr op = osp;
73
74
159k
    check_op(1);
75
159k
    if (r_space(op) != avm_global || imemory_save_level(iimemory_global) != 0)
76
0
        return_error(gs_error_invalidaccess);
77
159k
    check_read_type(*op, t_shortarray);
78
159k
    ref_assign_old(NULL, system_names_p, op, ".installsystemnames");
79
159k
    pop(1);
80
159k
    return 0;
81
159k
}
82
83
/* - currentobjectformat <int> */
84
static int
85
zcurrentobjectformat(i_ctx_t *i_ctx_p)
86
145
{
87
145
    os_ptr op = osp;
88
89
145
    push(1);
90
145
    *op = ref_binary_object_format;
91
145
    return 0;
92
145
}
93
94
/* <int> setobjectformat - */
95
static int
96
zsetobjectformat(i_ctx_t *i_ctx_p)
97
159k
{
98
159k
    os_ptr op = osp;
99
159k
    ref cont;
100
101
159k
    check_op(1);
102
159k
    check_type(*op, t_integer);
103
159k
    if (op->value.intval < 0 || op->value.intval > 4)
104
1
        return_error(gs_error_rangecheck);
105
159k
    make_struct(&cont, avm_local, ref_binary_object_format_container);
106
159k
    ref_assign_old(&cont, &ref_binary_object_format, op, "setobjectformat");
107
159k
    pop(1);
108
159k
    return 0;
109
159k
}
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
37
{
124
37
    os_ptr op = osp;
125
37
    int code;
126
127
37
    check_op(4);
128
37
    check_type(op[-3], t_integer);
129
37
    check_type(op[-2], t_integer);
130
37
    check_write_type(*op, t_string);
131
37
    if (r_size(op) < 8)
132
0
        return_error(gs_error_rangecheck);
133
37
    code = encode_binary_token(i_ctx_p, op - 1, &op[-3].value.intval,
134
37
                               &op[-2].value.intval, op->value.bytes);
135
37
    if (code < 0)
136
0
        return code;
137
37
    op[-1] = *op;
138
37
    r_set_size(op - 1, 8);
139
37
    pop(1);
140
37
    return 0;
141
37
}
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
};