Coverage Report

Created: 2025-06-10 07:06

/src/ghostpdl/base/jmemcust.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
#if !defined(SHARE_JPEG) || SHARE_JPEG==0
17
18
#include "jinclude.h"
19
#include "jpeglib.h"
20
#include "jerror.h"
21
#include "jmemcust.h"
22
23
GLOBAL(void *)
24
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
25
2.45k
{
26
2.45k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
27
28
2.45k
  return (void *) (cmem->j_mem_get_small)(cinfo, sizeofobject);
29
2.45k
}
30
31
GLOBAL(void)
32
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
33
2.45k
{
34
2.45k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
35
36
2.45k
  (cmem->j_mem_free_small)(cinfo, object, sizeofobject);
37
2.45k
}
38
39
/*
40
 * "Large" objects are treated the same as "small" ones.
41
 * NB: although we include FAR keywords in the routine declarations,
42
 * this file won't actually work in 80x86 small/medium model; at least,
43
 * you probably won't be able to process useful-size images in only 64KB.
44
 */
45
46
GLOBAL(void FAR *)
47
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
48
2.43k
{
49
2.43k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
50
51
2.43k
  return (void *) (cmem->j_mem_get_large)(cinfo, sizeofobject);
52
2.43k
}
53
54
GLOBAL(void)
55
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
56
2.43k
{
57
2.43k
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
58
59
2.43k
  (cmem->j_mem_free_large)(cinfo, object, sizeofobject);
60
2.43k
}
61
62
/*
63
 * This routine computes the total memory space available for allocation.
64
 * Here we always say, "we got all you want bud!"
65
 */
66
67
GLOBAL(long)
68
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
69
                    long max_bytes_needed, long already_allocated)
70
14
{
71
14
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
72
14
  long ret = max_bytes_needed;
73
74
14
  if (cmem->j_mem_avail)
75
0
    ret = (cmem->j_mem_avail)(cinfo);
76
77
14
  return ret;
78
14
}
79
80
/*
81
 * Backing store (temporary file) management.
82
 * Since jpeg_mem_available always promised the moon,
83
 * this should never be called and we can just error out.
84
 */
85
86
GLOBAL(void)
87
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
88
                         long total_bytes_needed)
89
0
{
90
0
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
91
92
0
  if (cmem->j_mem_open_backing_store) {
93
0
    (cmem->j_mem_open_backing_store)(cinfo, info, total_bytes_needed);
94
0
  }
95
0
  else
96
0
    ERREXIT(cinfo, JERR_NO_BACKING_STORE);
97
0
}
98
99
/*
100
 * These routines take care of any system-dependent initialization and
101
 * cleanup required.  Here, there isn't any.
102
 */
103
104
GLOBAL(long)
105
jpeg_mem_init (j_common_ptr cinfo)
106
678
{
107
678
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
108
678
  long ret = 0;
109
110
678
  if (cmem->j_mem_init)
111
678
    ret = (cmem->j_mem_init)(cinfo);
112
113
678
  return ret;
114
678
}
115
116
GLOBAL(void)
117
jpeg_mem_term (j_common_ptr cinfo)
118
678
{
119
678
  jpeg_cust_mem_data *cmem = GET_CUST_MEM_DATA(cinfo);
120
121
678
  if (cmem->j_mem_term)
122
678
    (cmem->j_mem_term)(cinfo);
123
678
}
124
125
GLOBAL(jpeg_cust_mem_data *)
126
jpeg_cust_mem_init(jpeg_cust_mem_data *custm, void *priv,
127
    j_custmem_init_ptr               init,
128
    j_custmem_term_ptr               term,
129
    j_custmem_avail_ptr              avail,
130
    j_custmem_get_small_ptr          get_small,
131
    j_custmem_free_small_ptr         free_small,
132
    j_cust_mem_get_large_ptr         get_large,
133
    j_custmem_free_large_ptr         free_large,
134
    j_custmem_open_backing_store_ptr open_backing_store)
135
678
{
136
678
  jpeg_cust_mem_data *lcustm = NULL;
137
138
  /* We need at least the following for a viable memory manager */
139
678
  if (get_small && free_small && get_large && free_large)
140
678
  {
141
678
    lcustm = custm;
142
143
678
    lcustm->priv = priv;
144
678
    lcustm->j_mem_init = init;
145
678
    lcustm->j_mem_term = term;
146
678
    lcustm->j_mem_avail = avail;
147
678
    lcustm->j_mem_get_small = get_small;
148
678
    lcustm->j_mem_free_small = free_small;
149
678
    lcustm->j_mem_get_large = get_large;
150
678
    lcustm->j_mem_free_large = free_large;
151
678
    lcustm->j_mem_open_backing_store = open_backing_store;
152
678
  }
153
678
  return lcustm;
154
678
}
155
156
GLOBAL(jpeg_cust_mem_data *)
157
jpeg_cust_mem_set_private(jpeg_cust_mem_data *custm, void *priv)
158
1.35k
{
159
1.35k
  if (custm)
160
1.35k
  {
161
1.35k
    custm->priv = priv;
162
1.35k
  }
163
1.35k
  return custm;
164
1.35k
}
165
166
#endif /* !defined(SHARE_JPEG) || SHARE_JPEG==0 */