Coverage Report

Created: 2025-06-10 06:49

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