Debian Codegraph @

lib/compressor.c

raw symbols SCIP
1 /*
2 Copyright (C) 2009-2018 Brazil
3 Copyright (C) 2020-2025 Sutou Kouhei <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "grn_compressor.h"cxx . . $ `<file>/lib/grn_compressor.h`/
21
22 #include "grn.h"cxx . . $ `<file>/lib/grn.h`/
23 #include "grn_ctx.h"cxx . . $ `<file>/lib/grn_ctx.h`/
24
25 #ifdef GRN_WITH_ZLIBcxx . . $ `build/config.h:121:9`!
26 # include <zlib.h>
27 #endif
28
29 #ifdef GRN_WITH_LZ4cxx . . $ `build/config.h:106:9`!
30 # include <lz4.h>
31 #endif
32
33 #ifdef GRN_WITH_ZSTDcxx . . $ `build/config.h:122:9`!
34 # include <zstd.h>cxx . . $ `<file>/build/_deps/openzl-src/deps/zstd/lib/zstd.h`/
35 #endif
36
37 #ifdef GRN_WITH_BLOSC
38 # include <blosc2.h>
39 # include <blosc2/filters-registry.h>
40
41 # define GRN_BLOSC_META_HEADER "header"
42 # define GRN_BLOSC_META_FOOTER "footer"
43 #endif
44
45 #ifdef GRN_WITH_OPENZLcxx . . $ `build/config.h:112:9`!
46 # include <openzl/openzl.h>cxx . . $ `<file>/build/_deps/openzl-src/include/openzl/openzl.h`/
47 #endif
48
49 /*
50 * Compressed value uses the following format:
51 *
52 * +-------------------+------+
53 * | uint64_t metadata | data |
54 * +-------------------+------+
55 *
56 * Metadata:
57 * * Upper 32bit is flags
58 * * Lower 32bit is data length in byte of the original data
59 *
60 * Available flags:
61 *
62 * * COMPRESSED_VALUE_META_FLAG_RAW: Data is raw data (not compressed
63 * original data). If raw data is small (< COMPRESS_THRESHOLD_BYTE),
64 * compression is meaningless. So raw data is stored as-is.
65 *
66 * If COMPRESSED_VALUE_META_FLAG_RAW isn't used, data is compressed
67 * data.
68 */
69
70 #define COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(data_len) (sizeof(uint64_t) + (data_len))
71 #define COMPRESSED_VALUE_GET_METADATAcxx . . $ `lib/compressor.c:71:9`!(value) (*((uint64_t *)(value)))
72 #define COMPRESSED_VALUE_SET_METADATAcxx . . $ `lib/compressor.c:72:9`!(value, metadata) \
73 *((uint64_t *)(value)) = (metadata)
74 #define COMPRESSED_VALUE_GET_DATAcxx . . $ `lib/compressor.c:74:9`!(value) ((void *)(((uint64_t *)(value)) + 1))
75 #define COMPRESSED_VALUE_GET_DATA_LENcxx . . $ `lib/compressor.c:75:9`!(value_len) (value_len - sizeof(uint64_t))
76
77 #define COMPRESSED_VALUE_METADATA_PACKcxx . . $ `lib/compressor.c:77:9`!(original_len, flags) \
78 ((original_len) | (flags))
79 #define COMPRESSED_VALUE_METADATA_FLAGcxx . . $ `lib/compressor.c:79:9`!(metadata) \
80 ((metadata) & 0xf000000000000000)
81 #define COMPRESSED_VALUE_METADATA_FLAG_RAWcxx . . $ `lib/compressor.c:81:9`! 0x1000000000000000
82 #define COMPRESSED_VALUE_METADATA_ORIGINAL_LENcxx . . $ `lib/compressor.c:82:9`!(metadata) \
83 ((metadata) & 0x0fffffffffffffff)
84
85 #define COMPRESS_THRESHOLD_BYTEcxx . . $ `lib/compressor.c:85:9`! 256
86
87 /*
88 * Create a compressed value format data for small data. It has
89 * the COMPRESSED_VALUE_META_FLAG_RAW flag.
90 */
91 static inline grn_rccxx . . $ grn_rc#
92 grn_compressor_packcxx . . $ grn_compressor_pack(38ea3b41608d581c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_compress_datacxx . . $ grn_compress_data# *data)
93 {
94 uint64_tcxx . . $ uint64_t# input_len = data->header_lencxx . . $ grn_compress_data#header_len. + data->body_lencxx . . $ grn_compress_data#body_len. + data->footer_lencxx . . $ grn_compress_data#footer_len.;
95 data->packed_value_lencxx . . $ grn_compress_data#packed_value_len. = COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(input_len);
96 uint64_tcxx . . $ uint64_t# packed_value_metadata =
97 COMPRESSED_VALUE_METADATA_PACKcxx . . $ `lib/compressor.c:77:9`!(input_len,
98 COMPRESSED_VALUE_METADATA_FLAG_RAWcxx . . $ `lib/compressor.c:81:9`!);
99
100 COMPRESSED_VALUE_SET_METADATAcxx . . $ `lib/compressor.c:72:9`!(data->packed_value, packed_value_metadata);
101 char *packed_value_data = COMPRESSED_VALUE_GET_DATAcxx . . $ `lib/compressor.c:74:9`!(data->packed_value);
102 size_t offset = 0;
103 if (data->header_lencxx . . $ grn_compress_data#header_len. > 0) {
104 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(packed_value_data + offset, data->header, data->header_len);
105 offset += data->header_lencxx . . $ grn_compress_data#header_len.;
106 }
107 if (data->body_lencxx . . $ grn_compress_data#body_len. > 0) {
108 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(packed_value_data + offset, data->body, data->body_len);
109 offset += data->body_lencxx . . $ grn_compress_data#body_len.;
110 }
111 if (data->footer_lencxx . . $ grn_compress_data#footer_len. > 0) {
112 grn_memcpycxx . . $ `include/groonga/portability.h:32:13`!(packed_value_data + offset, data->footer, data->footer_len);
113 offset += data->footer_lencxx . . $ grn_compress_data#footer_len.;
114 }
115
116 return ctx->rccxx . . $ _grn_ctx#rc.;
117 }
118
119 /*
120 * Parse a compressed value format data. If it has the
121 * COMPRESSED_VALUE_METADATA_FLAG_RAW flag, data is stored in
122 * data->unpacked_value and data->unpacked_value_len. Otherwise, data
123 * is stored in data->compressed_value and data->compressed_value_len.
124 */
125 static inline grn_rccxx . . $ grn_rc#
126 grn_compressor_unpackcxx . . $ grn_compressor_unpack(a8f2aa4281176350).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_decompress_datacxx . . $ grn_decompress_data# *data)
127 {
128 uint64_tcxx . . $ uint64_t# compressed_value_metadata =
129 COMPRESSED_VALUE_GET_METADATAcxx . . $ `lib/compressor.c:71:9`!(data->raw_value);
130 data->compressed_valuecxx . . $ grn_decompress_data#compressed_value. = COMPRESSED_VALUE_GET_DATAcxx . . $ `lib/compressor.c:74:9`!(data->raw_value);
131 data->compressed_value_lencxx . . $ grn_decompress_data#compressed_value_len. =
132 COMPRESSED_VALUE_GET_DATA_LENcxx . . $ `lib/compressor.c:75:9`!(data->raw_value_len);
133
134 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. =
135 (uint32_tcxx . . $ uint32_t#)COMPRESSED_VALUE_METADATA_ORIGINAL_LENcxx . . $ `lib/compressor.c:82:9`!(compressed_value_metadata);
136 if (COMPRESSED_VALUE_METADATA_FLAGcxx . . $ `lib/compressor.c:79:9`!(compressed_value_metadata) &
137 COMPRESSED_VALUE_METADATA_FLAG_RAWcxx . . $ `lib/compressor.c:81:9`!) {
138 data->unpacked_valuecxx . . $ grn_decompress_data#unpacked_value. = data->compressed_valuecxx . . $ grn_decompress_data#compressed_value.;
139 data->compressed_valuecxx . . $ grn_decompress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
140 data->unpacked_value_lencxx . . $ grn_decompress_data#unpacked_value_len. = data->compressed_value_lencxx . . $ grn_decompress_data#compressed_value_len.;
141 data->compressed_value_lencxx . . $ grn_decompress_data#compressed_value_len. = 0;
142 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
143 }
144
145 return ctx->rccxx . . $ _grn_ctx#rc.;
146 }
147
148 #ifdef GRN_WITH_ZLIBcxx . . $ `build/config.h:121:9`!
149 static inline const char *
150 grn_zrc_to_stringcxx . . $ grn_zrc_to_string(f7ae7e56280f18ae).(int zrc)
151 {
152 switch (zrc) {
153 case Z_OKcxx . . $ `<external>/8929586433573063152/zlib.h:181:9`!:
154 return "OK";
155 case Z_STREAM_ENDcxx . . $ `<external>/8929586433573063152/zlib.h:182:9`!:
156 return "Stream is end";
157 case Z_NEED_DICTcxx . . $ `<external>/8929586433573063152/zlib.h:183:9`!:
158 return "Need dictionary";
159 case Z_ERRNOcxx . . $ `<external>/8929586433573063152/zlib.h:184:9`!:
160 return "See errno";
161 case Z_STREAM_ERRORcxx . . $ `<external>/8929586433573063152/zlib.h:185:9`!:
162 return "Stream error";
163 case Z_DATA_ERRORcxx . . $ `<external>/8929586433573063152/zlib.h:186:9`!:
164 return "Data error";
165 case Z_MEM_ERRORcxx . . $ `<external>/8929586433573063152/zlib.h:187:9`!:
166 return "Memory error";
167 case Z_BUF_ERRORcxx . . $ `<external>/8929586433573063152/zlib.h:188:9`!:
168 return "Buffer error";
169 case Z_VERSION_ERRORcxx . . $ `<external>/8929586433573063152/zlib.h:189:9`!:
170 return "Version error";
171 default:
172 return "Unknown";
173 }
174 }
175
176 static inline grn_rccxx . . $ grn_rc#
177 grn_compressor_compress_zlibcxx . . $ grn_compressor_compress_zlib(38ea3b41608d581c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_compress_datacxx . . $ grn_compress_data# *data)
178 {
179 const char *tag = "[compressor][compress][zlib] failed to compress:";
180
181 z_streamcxx . . $ z_stream# zstream = {0};
182 zstream.zalloccxx . . $ z_stream_s#zalloc. = Z_NULLcxx . . $ `<external>/8929586433573063152/zlib.h:216:9`!;
183 zstream.zfreecxx . . $ z_stream_s#zfree. = Z_NULLcxx . . $ `<external>/8929586433573063152/zlib.h:216:9`!;
184 int zwindow_bits = 15;
185 int zmem_level = 8;
186 int zrc = deflateInit2cxx . . $ `<external>/8929586433573063152/zlib.h:1936:11`!(&zstream,
187 Z_DEFAULT_COMPRESSIONcxx . . $ `<external>/8929586433573063152/zlib.h:197:9`!,
188 Z_DEFLATEDcxx . . $ `<external>/8929586433573063152/zlib.h:213:9`!,
189 zwindow_bits,
190 zmem_level,
191 Z_DEFAULT_STRATEGYcxx . . $ `<external>/8929586433573063152/zlib.h:204:9`!);
192 if (zrc != Z_OKcxx . . $ `<external>/8929586433573063152/zlib.h:181:9`!) {
193 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s initialize: %s", tag, grn_zrc_to_string(zrc));
194 return ctx->rccxx . . $ _grn_ctx#rc.;
195 }
196
197 uint64_tcxx . . $ uint64_t# input_len = data->header_lencxx . . $ grn_compress_data#header_len. + data->body_lencxx . . $ grn_compress_data#body_len. + data->footer_lencxx . . $ grn_compress_data#footer_len.;
198 zstream.avail_outcxx . . $ z_stream_s#avail_out. = deflateBoundcxx . . $ deflateBound(996e82aa022e553f).(&zstream, input_len);
199 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(zstream.avail_out));
200 if (!data->compressed_valuecxx . . $ grn_compress_data#compressed_value.) {
201 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
202 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
203 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s allocate buffer: %s", tag, message);
204 deflateEndcxx . . $ deflateEnd(486a74ec0f38e374).(&zstream);
205 return ctx->rccxx . . $ _grn_ctx#rc.;
206 }
207 COMPRESSED_VALUE_SET_METADATAcxx . . $ `lib/compressor.c:72:9`!(data->compressed_value,
208 COMPRESSED_VALUE_METADATA_PACKcxx . . $ `lib/compressor.c:77:9`!(input_len, 0));
209 zstream.next_outcxx . . $ z_stream_s#next_out. = COMPRESSED_VALUE_GET_DATAcxx . . $ `lib/compressor.c:74:9`!(data->compressed_value);
210
211 if (data->header_lencxx . . $ grn_compress_data#header_len. == 0 && data->footer_lencxx . . $ grn_compress_data#footer_len. == 0) {
212 zstream.next_incxx . . $ z_stream_s#next_in. = data->bodycxx . . $ grn_compress_data#body.;
213 zstream.avail_incxx . . $ z_stream_s#avail_in. = data->body_lencxx . . $ grn_compress_data#body_len.;
214 zrc = deflatecxx . . $ deflate(bbdd8fdeb65a331e).(&zstream, Z_FINISHcxx . . $ `<external>/8929586433573063152/zlib.h:176:9`!);
215 if (zrc != Z_STREAM_ENDcxx . . $ `<external>/8929586433573063152/zlib.h:182:9`!) {
216 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s finish: %s", tag, grn_zrc_to_string(zrc));
217 deflateEndcxx . . $ deflateEnd(486a74ec0f38e374).(&zstream);
218 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
219 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
220 return ctx->rccxx . . $ _grn_ctx#rc.;
221 }
222 } else {
223 if (data->header_lencxx . . $ grn_compress_data#header_len. > 0) {
224 zstream.next_incxx . . $ z_stream_s#next_in. = data->headercxx . . $ grn_compress_data#header.;
225 zstream.avail_incxx . . $ z_stream_s#avail_in. = data->header_lencxx . . $ grn_compress_data#header_len.;
226 /* TODO: Z_NO_FLUSH here may not be safe. All zstream.next_in
227 * may not be processed. */
228 zrc = deflatecxx . . $ deflate(bbdd8fdeb65a331e).(&zstream, Z_NO_FLUSHcxx . . $ `<external>/8929586433573063152/zlib.h:172:9`!);
229 if (zrc != Z_OKcxx . . $ `<external>/8929586433573063152/zlib.h:181:9`!) {
230 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s header: %s", tag, grn_zrc_to_string(zrc));
231 deflateEndcxx . . $ deflateEnd(486a74ec0f38e374).(&zstream);
232 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
233 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
234 return ctx->rccxx . . $ _grn_ctx#rc.;
235 }
236 }
237
238 if (data->body_lencxx . . $ grn_compress_data#body_len. > 0) {
239 zstream.next_incxx . . $ z_stream_s#next_in. = data->bodycxx . . $ grn_compress_data#body.;
240 zstream.avail_incxx . . $ z_stream_s#avail_in. = data->body_lencxx . . $ grn_compress_data#body_len.;
241 /* TODO: Z_NO_FLUSH here may not be safe. All zstream.next_in
242 * may not be processed. */
243 zrc = deflatecxx . . $ deflate(bbdd8fdeb65a331e).(&zstream, Z_NO_FLUSHcxx . . $ `<external>/8929586433573063152/zlib.h:172:9`!);
244 if (zrc != Z_OKcxx . . $ `<external>/8929586433573063152/zlib.h:181:9`!) {
245 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s body: %s", tag, grn_zrc_to_string(zrc));
246 deflateEndcxx . . $ deflateEnd(486a74ec0f38e374).(&zstream);
247 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
248 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
249 return ctx->rccxx . . $ _grn_ctx#rc.;
250 }
251 }
252
253 if (data->footer_lencxx . . $ grn_compress_data#footer_len. > 0) {
254 zstream.next_incxx . . $ z_stream_s#next_in. = data->footercxx . . $ grn_compress_data#footer.;
255 zstream.avail_incxx . . $ z_stream_s#avail_in. = data->footer_lencxx . . $ grn_compress_data#footer_len.;
256 /* TODO: Z_NO_FLUSH here may not be safe. All zstream.next_in
257 * may not be processed. */
258 zrc = deflatecxx . . $ deflate(bbdd8fdeb65a331e).(&zstream, Z_NO_FLUSHcxx . . $ `<external>/8929586433573063152/zlib.h:172:9`!);
259 if (zrc != Z_OKcxx . . $ `<external>/8929586433573063152/zlib.h:181:9`!) {
260 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s footer: %s", tag, grn_zrc_to_string(zrc));
261 deflateEndcxx . . $ deflateEnd(486a74ec0f38e374).(&zstream);
262 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
263 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
264 return ctx->rccxx . . $ _grn_ctx#rc.;
265 }
266 }
267
268 zrc = deflatecxx . . $ deflate(bbdd8fdeb65a331e).(&zstream, Z_FINISHcxx . . $ `<external>/8929586433573063152/zlib.h:176:9`!);
269 if (zrc != Z_STREAM_ENDcxx . . $ `<external>/8929586433573063152/zlib.h:182:9`!) {
270 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s finish: %s", tag, grn_zrc_to_string(zrc));
271 deflateEndcxx . . $ deflateEnd(486a74ec0f38e374).(&zstream);
272 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
273 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
274 return ctx->rccxx . . $ _grn_ctx#rc.;
275 }
276 }
277 data->compressed_value_lencxx . . $ grn_compress_data#compressed_value_len. = COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(zstream.total_out);
278
279 zrc = deflateEndcxx . . $ deflateEnd(486a74ec0f38e374).(&zstream);
280 if (zrc != Z_OKcxx . . $ `<external>/8929586433573063152/zlib.h:181:9`!) {
281 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s end: %s", tag, grn_zrc_to_string(zrc));
282 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
283 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
284 data->compressed_value_lencxx . . $ grn_compress_data#compressed_value_len. = 0;
285 return ctx->rccxx . . $ _grn_ctx#rc.;
286 }
287
288 return ctx->rccxx . . $ _grn_ctx#rc.;
289 }
290
291 static inline grn_rccxx . . $ grn_rc#
292 grn_compressor_decompress_zlibcxx . . $ grn_compressor_decompress_zlib(a8f2aa4281176350).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_decompress_datacxx . . $ grn_decompress_data# *data)
293 {
294 const char *tag = "[compressor][decompress][zlib] failed to decompress:";
295
296 z_streamcxx . . $ z_stream# zstream = {0};
297 zstream.next_incxx . . $ z_stream_s#next_in. = (Bytefcxx . . $ Bytef# *)(data->compressed_valuecxx . . $ grn_decompress_data#compressed_value.);
298 zstream.avail_incxx . . $ z_stream_s#avail_in. = data->compressed_value_lencxx . . $ grn_decompress_data#compressed_value_len.;
299 zstream.zalloccxx . . $ z_stream_s#zalloc. = Z_NULLcxx . . $ `<external>/8929586433573063152/zlib.h:216:9`!;
300 zstream.zfreecxx . . $ z_stream_s#zfree. = Z_NULLcxx . . $ `<external>/8929586433573063152/zlib.h:216:9`!;
301 int zrc = inflateInit2cxx . . $ `<external>/8929586433573063152/zlib.h:1939:11`!(&zstream, 15 /* windowBits */);
302 if (zrc != Z_OKcxx . . $ `<external>/8929586433573063152/zlib.h:181:9`!) {
303 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s initialize: %s", tag, grn_zrc_to_string(zrc));
304 return ctx->rccxx . . $ _grn_ctx#rc.;
305 }
306 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(data->decompressed_value_len);
307 if (!data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value.) {
308 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
309 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
310 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s allocate buffer: %s", tag, message);
311 inflateEndcxx . . $ inflateEnd(486a74ec0f38e374).(&zstream);
312 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
313 return ctx->rccxx . . $ _grn_ctx#rc.;
314 }
315 zstream.next_outcxx . . $ z_stream_s#next_out. = (Bytefcxx . . $ Bytef# *)(data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value.);
316 zstream.avail_outcxx . . $ z_stream_s#avail_out. = data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len.;
317 zrc = inflatecxx . . $ inflate(bbdd8fdeb65a331e).(&zstream, Z_FINISHcxx . . $ `<external>/8929586433573063152/zlib.h:176:9`!);
318 if (zrc != Z_STREAM_ENDcxx . . $ `<external>/8929586433573063152/zlib.h:182:9`!) {
319 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s finish: %s", tag, grn_zrc_to_string(zrc));
320 inflateEndcxx . . $ inflateEnd(486a74ec0f38e374).(&zstream);
321 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->decompressed_value);
322 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
323 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
324 return ctx->rccxx . . $ _grn_ctx#rc.;
325 }
326 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = zstream.total_outcxx . . $ z_stream_s#total_out.;
327 zrc = inflateEndcxx . . $ inflateEnd(486a74ec0f38e374).(&zstream);
328 if (zrc != Z_OKcxx . . $ `<external>/8929586433573063152/zlib.h:181:9`!) {
329 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZLIB_ERROR, "%s end: %s", tag, grn_zrc_to_string(zrc));
330 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->decompressed_value);
331 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
332 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
333 return ctx->rccxx . . $ _grn_ctx#rc.;
334 }
335 return ctx->rccxx . . $ _grn_ctx#rc.;
336 }
337 #endif /* GRN_WITH_ZLIB */
338
339 #ifdef GRN_WITH_LZ4cxx . . $ `build/config.h:106:9`!
340 static inline grn_rccxx . . $ grn_rc#
341 grn_compressor_compress_lz4cxx . . $ grn_compressor_compress_lz4(38ea3b41608d581c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_compress_datacxx . . $ grn_compress_data# *data)
342 {
343 const char *tag = "[compressor][compress][lz4] failed to compress:";
344
345 size_t input_len = data->header_lencxx . . $ grn_compress_data#header_len. + data->body_lencxx . . $ grn_compress_data#body_len. + data->footer_lencxx . . $ grn_compress_data#footer_len.;
346 if (input_len > (size_t)LZ4_MAX_INPUT_SIZEcxx . . $ `<external>/13995811473035019148/lz4.h:214:9`!) {
347 data->packed_valuecxx . . $ grn_compress_data#packed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(input_len));
348 if (!data->packed_valuecxx . . $ grn_compress_data#packed_value.) {
349 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
350 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
351 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_LZ4_ERROR, "%s allocate packed buffer: %s", tag, message);
352 return ctx->rccxx . . $ _grn_ctx#rc.;
353 }
354 grn_rccxx . . $ grn_rc# rc = grn_compressor_packcxx . . $ grn_compressor_pack(38ea3b41608d581c).(ctx, data);
355 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
356 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->packed_value);
357 data->packed_valuecxx . . $ grn_compress_data#packed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
358 data->packed_value_lencxx . . $ grn_compress_data#packed_value_len. = 0;
359 }
360 return rc;
361 }
362
363 int lz4_value_len_max = LZ4_compressBoundcxx . . $ LZ4_compressBound(7864480464b09eea).((int)input_len);
364 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(lz4_value_len_max));
365 if (!data->compressed_valuecxx . . $ grn_compress_data#compressed_value.) {
366 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
367 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
368 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_LZ4_ERROR, "%s allocate compressed buffer: %s", tag, message);
369 return ctx->rccxx . . $ _grn_ctx#rc.;
370 }
371 COMPRESSED_VALUE_SET_METADATAcxx . . $ `lib/compressor.c:72:9`!(data->compressed_value,
372 COMPRESSED_VALUE_METADATA_PACKcxx . . $ `lib/compressor.c:77:9`!(input_len, 0));
373
374 char *lz4_value = COMPRESSED_VALUE_GET_DATAcxx . . $ `lib/compressor.c:74:9`!(data->compressed_value);
375 grn_objcxx . . $ grn_obj# value;
376 if (data->header_lencxx . . $ grn_compress_data#header_len. == 0 && data->footer_lencxx . . $ grn_compress_data#footer_len. == 0) {
377 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&value, GRN_OBJ_DO_SHALLOW_COPYcxx . . $ `include/groonga/groonga.h:2732:9`!);
378 GRN_TEXT_SETcxx . . $ `include/groonga/groonga.h:2761:9`!(ctx, &value, data->body, data->body_len);
379 } else {
380 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&value, 0);
381 if (data->header_lencxx . . $ grn_compress_data#header_len. > 0) {
382 GRN_TEXT_PUTcxx . . $ `include/groonga/groonga.h:2773:9`!(ctx, &value, data->header, data->header_len);
383 }
384 if (data->body_lencxx . . $ grn_compress_data#body_len. > 0) {
385 GRN_TEXT_PUTcxx . . $ `include/groonga/groonga.h:2773:9`!(ctx, &value, data->body, data->body_len);
386 }
387 if (data->footer_lencxx . . $ grn_compress_data#footer_len. > 0) {
388 GRN_TEXT_PUTcxx . . $ `include/groonga/groonga.h:2773:9`!(ctx, &value, data->footer, data->footer_len);
389 }
390 }
391 int lz4_value_len_real = LZ4_compress_defaultcxx . . $ LZ4_compress_default(c1398f734f7e736).(GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&value),
392 lz4_value,
393 GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&value),
394 lz4_value_len_max);
395 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &value);
396 if (lz4_value_len_real <= 0) {
397 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_LZ4_ERROR, "%s compress", tag);
398 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
399 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
400 return ctx->rccxx . . $ _grn_ctx#rc.;
401 }
402 data->compressed_value_lencxx . . $ grn_compress_data#compressed_value_len. = COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(lz4_value_len_real);
403
404 return ctx->rccxx . . $ _grn_ctx#rc.;
405 }
406
407 static inline grn_rccxx . . $ grn_rc#
408 grn_compressor_decompress_lz4cxx . . $ grn_compressor_decompress_lz4(a8f2aa4281176350).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_decompress_datacxx . . $ grn_decompress_data# *data)
409 {
410 const char *tag = "[compressor][decompress][lz4] failed to decompress:";
411
412 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(data->decompressed_value_len);
413 if (!data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value.) {
414 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
415 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
416 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_LZ4_ERROR, "%s allocate buffer: %s", tag, message);
417 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
418 return ctx->rccxx . . $ _grn_ctx#rc.;
419 }
420 if (LZ4_decompress_safecxx . . $ LZ4_decompress_safe(c1398f734f7e736).((const char *)(data->compressed_valuecxx . . $ grn_decompress_data#compressed_value.),
421 (char *)(data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value.),
422 data->compressed_value_lencxx . . $ grn_decompress_data#compressed_value_len.,
423 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len.) < 0) {
424 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_LZ4_ERROR, "%s decompress", tag);
425 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->decompressed_value);
426 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
427 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
428 return ctx->rccxx . . $ _grn_ctx#rc.;
429 }
430
431 return ctx->rccxx . . $ _grn_ctx#rc.;
432 }
433 #endif /* GRN_WITH_LZ4 */
434
435 #ifdef GRN_WITH_ZSTDcxx . . $ `build/config.h:122:9`!
436 static inline grn_rccxx . . $ grn_rc#
437 grn_compressor_compress_zstdcxx . . $ grn_compressor_compress_zstd(38ea3b41608d581c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_compress_datacxx . . $ grn_compress_data# *data)
438 {
439 const char *tag = "[compressor][compress][zstd] failed to compress:";
440
441 const int zstd_compression_level = ZSTD_CLEVEL_DEFAULTcxx . . $ `build/_deps/openzl-src/deps/zstd/lib/zstd.h:134:11`!;
442
443 ZSTD_CCtxcxx . . $ ZSTD_CCtx# *zstd_cctx = ZSTD_createCCtxcxx . . $ ZSTD_createCCtx(2ca7968cdc96fd62).();
444 if (!zstd_cctx) {
445 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZSTD_ERROR, "%s allocate compress context", tag);
446 return ctx->rccxx . . $ _grn_ctx#rc.;
447 }
448
449 size_t input_len = data->header_lencxx . . $ grn_compress_data#header_len. + data->body_lencxx . . $ grn_compress_data#body_len. + data->footer_lencxx . . $ grn_compress_data#footer_len.;
450 size_t zstd_value_len_max = ZSTD_compressBoundcxx . . $ ZSTD_compressBound(ecdaa1632f49f591).(input_len);
451 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(zstd_value_len_max));
452 if (!data->compressed_valuecxx . . $ grn_compress_data#compressed_value.) {
453 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
454 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
455 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZSTD_ERROR, "%s allocate compress buffer: %s", tag, message);
456 ZSTD_freeCCtxcxx . . $ ZSTD_freeCCtx(d5ed167abb0918e).(zstd_cctx);
457 return ctx->rccxx . . $ _grn_ctx#rc.;
458 }
459 void *zstd_value = COMPRESSED_VALUE_GET_DATAcxx . . $ `lib/compressor.c:74:9`!(data->compressed_value);
460 COMPRESSED_VALUE_SET_METADATAcxx . . $ `lib/compressor.c:72:9`!(data->compressed_value,
461 COMPRESSED_VALUE_METADATA_PACKcxx . . $ `lib/compressor.c:77:9`!(input_len, 0));
462
463 if (data->header_lencxx . . $ grn_compress_data#header_len. == 0 && data->footer_lencxx . . $ grn_compress_data#footer_len. == 0) {
464 size_t zstd_value_len_real = ZSTD_compressCCtxcxx . . $ ZSTD_compressCCtx(fd8aec8663284346).(zstd_cctx,
465 zstd_value,
466 zstd_value_len_max,
467 data->bodycxx . . $ grn_compress_data#body.,
468 data->body_lencxx . . $ grn_compress_data#body_len.,
469 zstd_compression_level);
470 if (ZSTD_isErrorcxx . . $ ZSTD_isError(ea88b852781e8a38).(zstd_value_len_real)) {
471 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZSTD_ERROR,
472 "%s compress: %s",
473 tag,
474 ZSTD_getErrorName(zstd_value_len_real));
475 ZSTD_freeCCtxcxx . . $ ZSTD_freeCCtx(d5ed167abb0918e).(zstd_cctx);
476 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
477 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
478 return ctx->rccxx . . $ _grn_ctx#rc.;
479 }
480 data->compressed_value_lencxx . . $ grn_compress_data#compressed_value_len. = COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(zstd_value_len_real);
481 } else {
482 ZSTD_outBuffercxx . . $ ZSTD_outBuffer# zstd_output = {0};
483 zstd_output.dstcxx . . $ ZSTD_outBuffer_s#dst. = zstd_value;
484 zstd_output.sizecxx . . $ ZSTD_outBuffer_s#size. = zstd_value_len_max;
485
486 if (data->header_lencxx . . $ grn_compress_data#header_len. > 0) {
487 ZSTD_inBuffercxx . . $ ZSTD_inBuffer# zstd_input = {0};
488 zstd_input.srccxx . . $ ZSTD_inBuffer_s#src. = data->headercxx . . $ grn_compress_data#header.;
489 zstd_input.sizecxx . . $ ZSTD_inBuffer_s#size. = data->header_lencxx . . $ grn_compress_data#header_len.;
490 zstd_input.poscxx . . $ ZSTD_inBuffer_s#pos. = 0;
491 size_t zstd_result = ZSTD_compressStream2cxx . . $ ZSTD_compressStream2(99fa29fb50e9e7f6).(zstd_cctx,
492 &zstd_output,
493 &zstd_input,
494 ZSTD_e_flushcxx . . $ ZSTD_e_flush.);
495 if (ZSTD_isErrorcxx . . $ ZSTD_isError(ea88b852781e8a38).(zstd_result)) {
496 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZSTD_ERROR,
497 "%s compress header: %s",
498 tag,
499 ZSTD_getErrorName(zstd_result));
500 ZSTD_freeCCtxcxx . . $ ZSTD_freeCCtx(d5ed167abb0918e).(zstd_cctx);
501 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
502 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
503 return ctx->rccxx . . $ _grn_ctx#rc.;
504 }
505 }
506
507 if (data->body_lencxx . . $ grn_compress_data#body_len. > 0) {
508 ZSTD_inBuffercxx . . $ ZSTD_inBuffer# zstd_input = {0};
509 zstd_input.srccxx . . $ ZSTD_inBuffer_s#src. = data->bodycxx . . $ grn_compress_data#body.;
510 zstd_input.sizecxx . . $ ZSTD_inBuffer_s#size. = data->body_lencxx . . $ grn_compress_data#body_len.;
511 zstd_input.poscxx . . $ ZSTD_inBuffer_s#pos. = 0;
512 size_t zstd_result = ZSTD_compressStream2cxx . . $ ZSTD_compressStream2(99fa29fb50e9e7f6).(zstd_cctx,
513 &zstd_output,
514 &zstd_input,
515 ZSTD_e_flushcxx . . $ ZSTD_e_flush.);
516 if (ZSTD_isErrorcxx . . $ ZSTD_isError(ea88b852781e8a38).(zstd_result)) {
517 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZSTD_ERROR,
518 "%s compress body: %s",
519 tag,
520 ZSTD_getErrorName(zstd_result));
521 ZSTD_freeCCtxcxx . . $ ZSTD_freeCCtx(d5ed167abb0918e).(zstd_cctx);
522 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
523 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
524 return ctx->rccxx . . $ _grn_ctx#rc.;
525 }
526 }
527
528 if (data->footer_lencxx . . $ grn_compress_data#footer_len. > 0) {
529 ZSTD_inBuffercxx . . $ ZSTD_inBuffer# zstd_input = {0};
530 zstd_input.srccxx . . $ ZSTD_inBuffer_s#src. = data->footercxx . . $ grn_compress_data#footer.;
531 zstd_input.sizecxx . . $ ZSTD_inBuffer_s#size. = data->footer_lencxx . . $ grn_compress_data#footer_len.;
532 zstd_input.poscxx . . $ ZSTD_inBuffer_s#pos. = 0;
533 size_t zstd_result = ZSTD_compressStream2cxx . . $ ZSTD_compressStream2(99fa29fb50e9e7f6).(zstd_cctx,
534 &zstd_output,
535 &zstd_input,
536 ZSTD_e_flushcxx . . $ ZSTD_e_flush.);
537 if (ZSTD_isErrorcxx . . $ ZSTD_isError(ea88b852781e8a38).(zstd_result)) {
538 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZSTD_ERROR,
539 "%s compress footer: %s",
540 tag,
541 ZSTD_getErrorName(zstd_result));
542 ZSTD_freeCCtxcxx . . $ ZSTD_freeCCtx(d5ed167abb0918e).(zstd_cctx);
543 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
544 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
545 return ctx->rccxx . . $ _grn_ctx#rc.;
546 }
547 }
548
549 {
550 ZSTD_inBuffercxx . . $ ZSTD_inBuffer# zstd_input = {0};
551 size_t zstd_result =
552 ZSTD_compressStream2cxx . . $ ZSTD_compressStream2(99fa29fb50e9e7f6).(zstd_cctx, &zstd_output, &zstd_input, ZSTD_e_endcxx . . $ ZSTD_e_end.);
553 if (ZSTD_isErrorcxx . . $ ZSTD_isError(ea88b852781e8a38).(zstd_result)) {
554 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZSTD_ERROR, "%s end: %s", tag, ZSTD_getErrorName(zstd_result));
555 ZSTD_freeCCtxcxx . . $ ZSTD_freeCCtx(d5ed167abb0918e).(zstd_cctx);
556 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
557 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
558 return ctx->rccxx . . $ _grn_ctx#rc.;
559 }
560 }
561 data->compressed_value_lencxx . . $ grn_compress_data#compressed_value_len. = COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(zstd_output.pos);
562 }
563 ZSTD_freeCCtxcxx . . $ ZSTD_freeCCtx(d5ed167abb0918e).(zstd_cctx);
564
565 return ctx->rccxx . . $ _grn_ctx#rc.;
566 }
567
568 static inline grn_rccxx . . $ grn_rc#
569 grn_compressor_decompress_zstdcxx . . $ grn_compressor_decompress_zstd(a8f2aa4281176350).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_decompress_datacxx . . $ grn_decompress_data# *data)
570 {
571 const char *tag = "[compressor][decompress][zstd] failed to decompress:";
572
573 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(data->decompressed_value_len);
574 if (!data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value.) {
575 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
576 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
577 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZSTD_ERROR, "%s allocate buffer: %s", tag, message);
578 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
579 return ctx->rccxx . . $ _grn_ctx#rc.;
580 }
581
582 size_t written_len = ZSTD_decompresscxx . . $ ZSTD_decompress(1c632c8c599a8c0a).((char *)(data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value.),
583 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len.,
584 data->compressed_valuecxx . . $ grn_decompress_data#compressed_value.,
585 data->compressed_value_lencxx . . $ grn_decompress_data#compressed_value_len.);
586 if (ZSTD_isErrorcxx . . $ ZSTD_isError(ea88b852781e8a38).(written_len)) {
587 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_ZSTD_ERROR,
588 "%s decompress: %s",
589 tag,
590 ZSTD_getErrorName(written_len));
591 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->decompressed_value);
592 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
593 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
594 return ctx->rccxx . . $ _grn_ctx#rc.;
595 }
596
597 return ctx->rccxx . . $ _grn_ctx#rc.;
598 }
599 #endif /* GRN_WITH_ZSTD */
600
601 #ifdef GRN_WITH_BLOSC
602 static inline blosc2_schunk *
603 grn_compressor_compress_blosc_create_schunk(grn_ctx *ctx,
604 grn_compress_data *data,
605 blosc2_cparams *cparams,
606 blosc2_storage *storage)
607 {
608 *cparams = BLOSC2_CPARAMS_DEFAULTS;
609 switch (data->body_column_flags & GRN_OBJ_COMPRESS_MASK) {
610 # ifdef GRN_WITH_ZLIB
611 case GRN_OBJ_COMPRESS_ZLIB:
612 cparams->compcode = BLOSC_ZLIB;
613 break;
614 # endif
615 # ifdef GRN_WITH_LZ4
616 case GRN_OBJ_COMPRESS_LZ4:
617 cparams->compcode = BLOSC_LZ4;
618 break;
619 # endif
620 # ifdef GRN_WITH_ZSTD
621 case GRN_OBJ_COMPRESS_ZSTD:
622 cparams->compcode = BLOSC_ZSTD;
623 break;
624 # endif
625 default:
626 break;
627 }
628 if (grn_type_id_is_text_family(ctx, data->body_range)) {
629 cparams->typesize = sizeof(char);
630 } else {
631 cparams->typesize = grn_type_id_size(ctx, data->body_range);
632 if (data->body_column_flags & GRN_OBJ_WITH_WEIGHT) {
633 if (data->body_column_flags & GRN_OBJ_WEIGHT_BFLOAT16) {
634 # ifdef GRN_HAVE_BFLOAT16
635 cparams->typesize += sizeof(grn_bfloat16);
636 # else
637 cparams->typesize += sizeof(float);
638 # endif
639 } else if (data->body_column_flags & GRN_OBJ_WEIGHT_FLOAT32) {
640 cparams->typesize += sizeof(float);
641 } else {
642 cparams->typesize += sizeof(double);
643 }
644 }
645 }
646 size_t current_filter_id = BLOSC2_MAX_FILTERS - 1;
647 cparams->filters[current_filter_id] = BLOSC_NOFILTER;
648 if (data->body_n_elements > 1) {
649 if (data->body_column_flags & GRN_OBJ_COMPRESS_FILTER_BYTE_DELTA) {
650 cparams->filters[current_filter_id] = BLOSC_FILTER_BYTEDELTA;
651 cparams->filters_meta[current_filter_id] = cparams->typesize;
652 current_filter_id--;
653 }
654 if (cparams->typesize > (int32_t)sizeof(char)) {
655 if (data->body_column_flags & GRN_OBJ_COMPRESS_FILTER_SHUFFLE) {
656 cparams->filters[current_filter_id] = BLOSC_SHUFFLE;
657 current_filter_id--;
658 }
659 }
660 if (data->body_range == GRN_DB_FLOAT ||
661 data->body_range == GRN_DB_FLOAT32) {
662 if (data->body_column_flags &
663 GRN_OBJ_COMPRESS_FILTER_TRUNCATE_PRECISION_2BYTES) {
664 cparams->filters[current_filter_id] = BLOSC_TRUNC_PREC;
665 cparams->filters_meta[current_filter_id] = -16;
666 current_filter_id--;
667 } else if (data->body_column_flags &
668 GRN_OBJ_COMPRESS_FILTER_TRUNCATE_PRECISION_1BYTE) {
669 cparams->filters[current_filter_id] = BLOSC_TRUNC_PREC;
670 cparams->filters_meta[current_filter_id] = -8;
671 current_filter_id--;
672 }
673 }
674 }
675
676 *storage = BLOSC2_STORAGE_DEFAULTS;
677 storage->contiguous = true;
678 storage->cparams = cparams;
679
680 return blosc2_schunk_new(storage);
681 }
682
683 static inline grn_rc
684 grn_compressor_compress_blosc(grn_ctx *ctx, grn_compress_data *data)
685 {
686 const char *tag = "[compressor][compress][blosc] failed to compress:";
687
688 blosc2_cparams cparams;
689 blosc2_storage storage;
690 blosc2_schunk *schunk =
691 grn_compressor_compress_blosc_create_schunk(ctx, data, &cparams, &storage);
692
693 if (data->header_len > 0) {
694 int meta_index = blosc2_meta_add(schunk,
695 GRN_BLOSC_META_HEADER,
696 data->header,
697 data->header_len);
698 if (meta_index < 0) {
699 ERR(GRN_BLOSC_ERROR, "%s set header: %s", tag, print_error(meta_index));
700 blosc2_schunk_free(schunk);
701 return ctx->rc;
702 }
703 }
704
705 if (data->footer_len > 0) {
706 int meta_index = blosc2_meta_add(schunk,
707 GRN_BLOSC_META_FOOTER,
708 data->footer,
709 data->footer_len);
710 if (meta_index < 0) {
711 ERR(GRN_BLOSC_ERROR, "%s set footer: %s", tag, print_error(meta_index));
712 blosc2_schunk_free(schunk);
713 return ctx->rc;
714 }
715 }
716
717 if (data->body_len > 0) {
718 int64_t n_chunks =
719 blosc2_schunk_append_buffer(schunk, data->body, data->body_len);
720 if (n_chunks < 0) {
721 ERR(GRN_BLOSC_ERROR, "%s compress body: %s", tag, print_error(n_chunks));
722 blosc2_schunk_free(schunk);
723 return ctx->rc;
724 }
725 }
726
727 uint8_t *blosc_value = NULL;
728 bool blosc_value_need_free = false;
729 int64_t blosc_value_len =
730 blosc2_schunk_to_buffer(schunk, &blosc_value, &blosc_value_need_free);
731 if (blosc_value_len < 0) {
732 ERR(GRN_BLOSC_ERROR,
733 "%s serialize compressed value: %s",
734 tag,
735 print_error(blosc_value_len));
736 blosc2_schunk_free(schunk);
737 return ctx->rc;
738 }
739
740 data->compressed_value_len = COMPRESSED_VALUE_LEN(blosc_value_len);
741 data->compressed_value = GRN_MALLOC(data->compressed_value_len);
742 if (!data->compressed_value) {
743 ERR(GRN_BLOSC_ERROR, "%s allocate packed value buffer", tag);
744 if (blosc_value_need_free) {
745 free(blosc_value);
746 }
747 blosc2_schunk_free(schunk);
748 data->compressed_value_len = 0;
749 return ctx->rc;
750 }
751 size_t input_len = data->header_len + data->body_len + data->footer_len;
752 COMPRESSED_VALUE_SET_METADATA(data->compressed_value,
753 COMPRESSED_VALUE_METADATA_PACK(input_len, 0));
754 grn_memcpy(COMPRESSED_VALUE_GET_DATA(data->compressed_value),
755 blosc_value,
756 blosc_value_len);
757 if (blosc_value_need_free) {
758 free(blosc_value);
759 }
760 blosc2_schunk_free(schunk);
761
762 return ctx->rc;
763 }
764
765 static inline bool
766 grn_compressor_decompress_blosc_copy_meta(grn_ctx *ctx,
767 blosc2_schunk *schunk,
768 uint8_t **destination,
769 int32_t *destination_len,
770 const char *name,
771 const char *tag)
772 {
773 int i = 0;
774 for (i = 0; i < schunk->nmetalayers; i++) {
775 blosc2_metalayer *metalayer = schunk->metalayers[i];
776 if (strcmp(metalayer->name, name) == 0) {
777 if (metalayer->content_len > *destination_len) {
778 ERR(GRN_BLOSC_ERROR,
779 "%s %s is too large: %d > %d",
780 tag,
781 name,
782 metalayer->content_len,
783 *destination_len);
784 return false;
785 }
786 memcpy(*destination, metalayer->content, metalayer->content_len);
787 *destination += metalayer->content_len;
788 *destination_len -= metalayer->content_len;
789 break;
790 }
791 }
792 return true;
793 }
794
795 static grn_rc
796 grn_compressor_decompress_blosc(grn_ctx *ctx, grn_decompress_data *data)
797 {
798 const char *tag = "[compressor][decompress][blosc] failed to decompress:";
799
800 data->decompressed_value = GRN_MALLOC(data->decompressed_value_len);
801 if (!data->decompressed_value) {
802 char message[GRN_CTX_MSGSIZE];
803 grn_strcpy(message, GRN_CTX_MSGSIZE, ctx->errbuf);
804 ERR(GRN_BLOSC_ERROR, "%s allocate buffer: %s", tag, message);
805 data->decompressed_value_len = 0;
806 return ctx->rc;
807 }
808
809 blosc2_schunk *schunk = blosc2_schunk_from_buffer(data->compressed_value,
810 data->compressed_value_len,
811 false);
812 if (!schunk) {
813 ERR(GRN_BLOSC_ERROR, "%s failed to load super chunk", tag);
814 GRN_FREE(data->decompressed_value);
815 data->decompressed_value = NULL;
816 data->decompressed_value_len = 0;
817 return ctx->rc;
818 }
819 uint8_t *destination = data->decompressed_value;
820 int32_t destination_len = data->decompressed_value_len;
821 if (!grn_compressor_decompress_blosc_copy_meta(ctx,
822 schunk,
823 &destination,
824 &destination_len,
825 GRN_BLOSC_META_HEADER,
826 tag)) {
827 blosc2_schunk_free(schunk);
828 GRN_FREE(data->decompressed_value);
829 data->decompressed_value = NULL;
830 data->decompressed_value_len = 0;
831 return ctx->rc;
832 }
833 {
834 int64_t i;
835 for (i = 0; i < schunk->nchunks; i++) {
836 int decompressed_len =
837 blosc2_schunk_decompress_chunk(schunk, i, destination, destination_len);
838 if (decompressed_len <= 0) {
839 ERR(GRN_BLOSC_ERROR,
840 "%s failed to decode a chunk: %" GRN_FMT_INT64D ": %s",
841 tag,
842 i,
843 print_error(decompressed_len));
844 blosc2_schunk_free(schunk);
845 GRN_FREE(data->decompressed_value);
846 data->decompressed_value = NULL;
847 data->decompressed_value_len = 0;
848 return ctx->rc;
849 }
850 destination += decompressed_len;
851 destination_len -= decompressed_len;
852 }
853 }
854 if (!grn_compressor_decompress_blosc_copy_meta(ctx,
855 schunk,
856 &destination,
857 &destination_len,
858 GRN_BLOSC_META_FOOTER,
859 tag)) {
860 blosc2_schunk_free(schunk);
861 GRN_FREE(data->decompressed_value);
862 data->decompressed_value = NULL;
863 data->decompressed_value_len = 0;
864 return ctx->rc;
865 }
866 blosc2_schunk_free(schunk);
867 if (destination_len != 0) {
868 ERR(GRN_BLOSC_ERROR,
869 "%s decompressed size isn't match: expected:%u actual:%d",
870 tag,
871 data->decompressed_value_len,
872 destination_len);
873 GRN_FREE(data->decompressed_value);
874 data->decompressed_value = NULL;
875 data->decompressed_value_len = 0;
876 return ctx->rc;
877 }
878
879 return ctx->rc;
880 }
881 #endif
882
883 #ifdef GRN_WITH_OPENZLcxx . . $ `build/config.h:112:9`!
884 static inline ZL_GraphIDcxx . . $ ZL_GraphID#
885 openzl_build_float32_graph_idcxx . . $ openzl_build_float32_graph_id(afa92ea4df984893).(ZL_Compressorcxx . . $ ZL_Compressor# *zl_compressor)
886 {
887 /*
888 ZL_NODE_FLOAT32_DECONSTRUCT outputs:
889 * fixed-size-fields stream containing sign and fraction bits
890 * serial stream containing exponent bits
891 See also:
892 https://github.com/facebook/openzl/blob/v0.1.0/include/openzl/codecs/zl_float_deconstruct.h#L12-L18
893 */
894 const ZL_GraphIDcxx . . $ ZL_GraphID# successor_graphs[] = {ZL_GRAPH_STOREcxx . . $ `build/_deps/openzl-src/include/openzl/codecs/zl_store.h:13:9`!, ZL_GRAPH_FSEcxx . . $ `build/_deps/openzl-src/include/openzl/codecs/zl_entropy.h:14:9`!};
895 /*
896 n_successor_graphs must be equal to the number of
897 ZL_NODE_FLOAT32_DECONSTRUCT output items defined in the API documentation
898 for ZL_Compressor_buildStaticGraph().
899
900 See also:
901 https://openzl.org/api/c/compressor/#ZL_Compressor_buildStaticGraph
902 */
903 const size_t n_successor_graphs =
904 sizeof(successor_graphs) / sizeof(ZL_GraphIDcxx . . $ ZL_GraphID#);
905 ZL_RESULT_OFcxx . . $ `build/_deps/openzl-src/include/openzl/zl_errors.h:105:9`!(ZL_GraphID)
906 result = ZL_Compressor_buildStaticGraphcxx . . $ ZL_Compressor_buildStaticGraph(44c60cb36b2c2a9).(zl_compressor,
907 ZL_NODE_FLOAT32_DECONSTRUCTcxx . . $ `build/_deps/openzl-src/include/openzl/codecs/zl_float_deconstruct.h:19:9`!,
908 successor_graphs,
909 n_successor_graphs,
910 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
911 if (ZL_RES_isErrorcxx . . $ `build/_deps/openzl-src/include/openzl/zl_errors.h:180:9`!(result)) {
912 return ZL_GRAPH_ILLEGALcxx . . $ `build/_deps/openzl-src/include/openzl/codecs/zl_illegal.h:21:9`!;
913 }
914 return ZL_RES_valuecxx . . $ `build/_deps/openzl-src/include/openzl/zl_errors.h:183:9`!(result);
915 }
916
917 static inline boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
918 openzl_is_plain_vector_columncxx . . $ openzl_is_plain_vector_column(885f7550af75c4ff).(grn_compress_datacxx . . $ grn_compress_data# *data)
919 {
920 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_vector_column = ((data->body_column_flagscxx . . $ grn_compress_data#body_column_flags. &
921 GRN_OBJ_COLUMN_TYPE_MASKcxx . . $ `include/groonga/groonga.h:726:9`!) == GRN_OBJ_COLUMN_VECTORcxx . . $ `include/groonga/groonga.h:736:9`!);
922 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_with_weight = ((data->body_column_flagscxx . . $ grn_compress_data#body_column_flags. & GRN_OBJ_WITH_WEIGHTcxx . . $ `include/groonga/groonga.h:785:9`!) != 0);
923 return is_vector_column && !is_with_weight;
924 }
925
926 static inline ZL_GraphIDcxx . . $ ZL_GraphID#
927 openzl_build_graph_idcxx . . $ openzl_build_graph_id(dc7d387e6d53c08f).(ZL_Compressorcxx . . $ ZL_Compressor# *zl_compressor, grn_compress_datacxx . . $ grn_compress_data# *data)
928 {
929 if (openzl_is_plain_vector_columncxx . . $ openzl_is_plain_vector_column(885f7550af75c4ff).(data)) {
930 switch (data->body_rangecxx . . $ grn_compress_data#body_range.) {
931 case GRN_DB_FLOAT32cxx . . $ GRN_DB_FLOAT32.:
932 return openzl_build_float32_graph_idcxx . . $ openzl_build_float32_graph_id(afa92ea4df984893).(zl_compressor);
933 default:
934 break;
935 }
936 }
937 return ZL_GRAPH_ZSTDcxx . . $ `build/_deps/openzl-src/include/openzl/codecs/zl_zstd.h:13:9`!;
938 }
939
940 static inline void
941 openzl_compresscxx . . $ openzl_compress(3dd74f69216be495).(grn_ctxcxx . . $ grn_ctx# *ctx,
942 const char *tag,
943 grn_compress_datacxx . . $ grn_compress_data# *data,
944 ZL_CCtxcxx . . $ ZL_CCtx# *zl_cctx,
945 ZL_Compressorcxx . . $ ZL_Compressor# *zl_compressor,
946 void *zl_value,
947 const size_t zl_value_len_max,
948 const ZL_TypedRefcxx . . $ ZL_TypedRef# *inputs[],
949 size_t n_inputs)
950 {
951 ZL_Reportcxx . . $ ZL_Report# zl_report = ZL_CCtx_refCompressorcxx . . $ ZL_CCtx_refCompressor(638aadf51a7dbd5c).(zl_cctx, zl_compressor);
952 if (ZL_isErrorcxx . . $ ZL_isError(40a0489e3e267bf1).(zl_report)) {
953 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR,
954 "%s failed to reference compressor: %s",
955 tag,
956 ZL_ErrorCode_toString(ZL_errorCode(zl_report)));
957 return;
958 }
959 zl_report = ZL_CCtx_compressMultiTypedRefcxx . . $ ZL_CCtx_compressMultiTypedRef(700f49dbdb24ae83).(zl_cctx,
960 zl_value,
961 zl_value_len_max,
962 inputs,
963 n_inputs);
964 if (ZL_isErrorcxx . . $ ZL_isError(40a0489e3e267bf1).(zl_report)) {
965 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR,
966 "%s failed to compress data: %s",
967 tag,
968 ZL_ErrorCode_toString(ZL_errorCode(zl_report)));
969 return;
970 }
971 size_t zl_compressed_size = ZL_validResultcxx . . $ ZL_validResult(6b3b70f7ce111804).(zl_report);
972 data->compressed_value_lencxx . . $ grn_compress_data#compressed_value_len. = COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(zl_compressed_size);
973 }
974
975 static inline ZL_TypedRefcxx . . $ ZL_TypedRef# *
976 openzl_create_type_refcxx . . $ openzl_create_type_ref(5750f5fbf66961b2).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *tag, grn_compress_datacxx . . $ grn_compress_data# *data)
977 {
978 ZL_TypedRefcxx . . $ ZL_TypedRef# *typed_ref = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
979 if (openzl_is_plain_vector_columncxx . . $ openzl_is_plain_vector_column(885f7550af75c4ff).(data)) {
980 switch (data->body_rangecxx . . $ grn_compress_data#body_range.) {
981 case GRN_DB_FLOAT32cxx . . $ GRN_DB_FLOAT32.:
982 typed_ref = ZL_TypedRef_createNumericcxx . . $ ZL_TypedRef_createNumeric(e0c55f5f24aaf964).(data->bodycxx . . $ grn_compress_data#body.,
983 data->body_element_sizecxx . . $ grn_compress_data#body_element_size.,
984 data->body_n_elementscxx . . $ grn_compress_data#body_n_elements.);
985 break;
986 default:
987 typed_ref = ZL_TypedRef_createSerialcxx . . $ ZL_TypedRef_createSerial(85705b7f40ebcd3f).(data->bodycxx . . $ grn_compress_data#body., data->body_lencxx . . $ grn_compress_data#body_len.);
988 break;
989 }
990 } else {
991 typed_ref = ZL_TypedRef_createSerialcxx . . $ ZL_TypedRef_createSerial(85705b7f40ebcd3f).(data->bodycxx . . $ grn_compress_data#body., data->body_lencxx . . $ grn_compress_data#body_len.);
992 }
993
994 if (!typed_ref) {
995 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR,
996 "%s failed to create OpenZL input type reference",
997 tag);
998 }
999 return typed_ref;
1000 }
1001
1002 static inline void
1003 openzl_compress_only_bodycxx . . $ openzl_compress_only_body(23932e162fd713c1).(grn_ctxcxx . . $ grn_ctx# *ctx,
1004 const char *tag,
1005 grn_compress_datacxx . . $ grn_compress_data# *data,
1006 ZL_CCtxcxx . . $ ZL_CCtx# *zl_cctx,
1007 ZL_Compressorcxx . . $ ZL_Compressor# *zl_compressor,
1008 void *zl_value,
1009 const size_t zl_value_len_max)
1010 {
1011 ZL_GraphIDcxx . . $ ZL_GraphID# zl_graph_id = openzl_build_graph_idcxx . . $ openzl_build_graph_id(dc7d387e6d53c08f).(zl_compressor, data);
1012 if (!ZL_GraphID_isValidcxx . . $ ZL_GraphID_isValid(e9bc34d387029b46).(zl_graph_id)) {
1013 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR,
1014 "%s Invalid API parameter passing for input data type: %s(%u)",
1015 tag,
1016 grn_type_id_to_string_builtin(ctx, data->body_range),
1017 data->body_range);
1018 return;
1019 }
1020
1021 ZL_TypedRefcxx . . $ ZL_TypedRef# *typed_ref = openzl_create_type_refcxx . . $ openzl_create_type_ref(5750f5fbf66961b2).(ctx, tag, data);
1022 if (!typed_ref) {
1023 return;
1024 }
1025
1026 ZL_Reportcxx . . $ ZL_Report# zl_report =
1027 ZL_Compressor_selectStartingGraphIDcxx . . $ ZL_Compressor_selectStartingGraphID(f0bc7c290a1d7287).(zl_compressor, zl_graph_id);
1028 if (ZL_isErrorcxx . . $ ZL_isError(40a0489e3e267bf1).(zl_report)) {
1029 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR,
1030 "%s failed to select starting graph ID: %s",
1031 tag,
1032 ZL_ErrorCode_toString(ZL_errorCode(zl_report)));
1033 ZL_TypedRef_freecxx . . $ ZL_TypedRef_free(85bde9c6140722bc).(typed_ref);
1034 return;
1035 }
1036 /*
1037 * "ZL_CCtx_compressMultiTypedRef()" requires a value of type "const
1038 * ZL_TypedRef *[]" as its fourth argument.
1039 * Ref: https://openzl.org/api/c/compress/#ZL_CCtx_compressMultiTypedRef
1040 * Therefore, we prepare a "const ZL_TypedRef *[]" value here and pass it to
1041 * "openzl_compress()".
1042 * "ZL_CCtx_compressMultiTypedRef()" is called inside "openzl_compress()".
1043 *
1044 * Since the OpenZL tests uses the same approach, we are following it here as
1045 * well.
1046 * (Ref:
1047 * https://github.com/facebook/openzl/blob/dev/tests/round_trip/test_n_to_n.cpp#L89-L109)
1048 */
1049 const ZL_TypedRefcxx . . $ ZL_TypedRef# *inputs[] = {typed_ref};
1050 openzl_compresscxx . . $ openzl_compress(3dd74f69216be495).(ctx,
1051 tag,
1052 data,
1053 zl_cctx,
1054 zl_compressor,
1055 zl_value,
1056 zl_value_len_max,
1057 inputs,
1058 1);
1059 ZL_TypedRef_freecxx . . $ ZL_TypedRef_free(85bde9c6140722bc).(typed_ref);
1060 }
1061
1062 static inline grn_rccxx . . $ grn_rc#
1063 grn_compressor_compress_openzlcxx . . $ grn_compressor_compress_openzl(38ea3b41608d581c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_compress_datacxx . . $ grn_compress_data# *data)
1064 {
1065 const char *tag = "[compressor][compress][openzl]";
1066 ZL_CCtxcxx . . $ ZL_CCtx# *zl_cctx = ZL_CCtx_createcxx . . $ ZL_CCtx_create(7f4efe692f188aaf).();
1067 if (!zl_cctx) {
1068 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR, "%s failed to allocate compress context", tag);
1069 return ctx->rccxx . . $ _grn_ctx#rc.;
1070 }
1071
1072 ZL_Compressorcxx . . $ ZL_Compressor# *zl_compressor = ZL_Compressor_createcxx . . $ ZL_Compressor_create(faafa94823bfeb28).();
1073 if (!zl_compressor) {
1074 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR, "%s failed to allocate compressor", tag);
1075 ZL_CCtx_freecxx . . $ ZL_CCtx_free(f9d44ccfbcf19add).(zl_cctx);
1076 return ctx->rccxx . . $ _grn_ctx#rc.;
1077 }
1078
1079 const size_t input_len = data->header_lencxx . . $ grn_compress_data#header_len. + data->body_lencxx . . $ grn_compress_data#body_len. + data->footer_lencxx . . $ grn_compress_data#footer_len.;
1080 const size_t zl_value_len_max = ZL_compressBoundcxx . . $ ZL_compressBound(ecdaa1632f49f591).(input_len);
1081 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(zl_value_len_max));
1082 if (!data->compressed_valuecxx . . $ grn_compress_data#compressed_value.) {
1083 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
1084 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
1085 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR,
1086 "%s failed to allocate compress buffer: %s",
1087 tag,
1088 message);
1089 ZL_Compressor_freecxx . . $ ZL_Compressor_free(2324d8dd7fde8c1b).(zl_compressor);
1090 ZL_CCtx_freecxx . . $ ZL_CCtx_free(f9d44ccfbcf19add).(zl_cctx);
1091 return ctx->rccxx . . $ _grn_ctx#rc.;
1092 }
1093
1094 void *zl_value = COMPRESSED_VALUE_GET_DATAcxx . . $ `lib/compressor.c:74:9`!(data->compressed_value);
1095 COMPRESSED_VALUE_SET_METADATAcxx . . $ `lib/compressor.c:72:9`!(data->compressed_value,
1096 COMPRESSED_VALUE_METADATA_PACKcxx . . $ `lib/compressor.c:77:9`!(input_len, 0));
1097
1098 ZL_Reportcxx . . $ ZL_Report# zl_report = ZL_Compressor_setParametercxx . . $ ZL_Compressor_setParameter(7a701fcfd62695e4).(zl_compressor,
1099 ZL_CParam_formatVersioncxx . . $ ZL_CParam_formatVersion.,
1100 ZL_MAX_FORMAT_VERSIONcxx . . $ `build/_deps/openzl-src/include/openzl/zl_version.h:63:9`!);
1101 if (ZL_isErrorcxx . . $ ZL_isError(40a0489e3e267bf1).(zl_report)) {
1102 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR,
1103 "%s failed to set compressor parameter: %s",
1104 tag,
1105 ZL_ErrorCode_toString(ZL_errorCode(zl_report)));
1106 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
1107 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1108 data->compressed_value_lencxx . . $ grn_compress_data#compressed_value_len. = 0;
1109 ZL_Compressor_freecxx . . $ ZL_Compressor_free(2324d8dd7fde8c1b).(zl_compressor);
1110 ZL_CCtx_freecxx . . $ ZL_CCtx_free(f9d44ccfbcf19add).(zl_cctx);
1111 return ctx->rccxx . . $ _grn_ctx#rc.;
1112 }
1113
1114 if (data->header_lencxx . . $ grn_compress_data#header_len. == 0 && data->footer_lencxx . . $ grn_compress_data#footer_len. == 0) {
1115 openzl_compress_only_bodycxx . . $ openzl_compress_only_body(23932e162fd713c1).(ctx,
1116 tag,
1117 data,
1118 zl_cctx,
1119 zl_compressor,
1120 zl_value,
1121 zl_value_len_max);
1122 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
1123 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
1124 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1125 data->compressed_value_lencxx . . $ grn_compress_data#compressed_value_len. = 0;
1126 }
1127 ZL_Compressor_freecxx . . $ ZL_Compressor_free(2324d8dd7fde8c1b).(zl_compressor);
1128 ZL_CCtx_freecxx . . $ ZL_CCtx_free(f9d44ccfbcf19add).(zl_cctx);
1129 } else {
1130 /*
1131 * We don't implement compression of header, body, and footer yet.
1132 * So, if a header or footer exists, we don't compress data currently.
1133 */
1134 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_FUNCTION_NOT_IMPLEMENTED,
1135 "%s compress of vector columns is not implemented yet",
1136 tag);
1137 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->compressed_value);
1138 data->compressed_valuecxx . . $ grn_compress_data#compressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1139 data->compressed_value_lencxx . . $ grn_compress_data#compressed_value_len. = 0;
1140 ZL_Compressor_freecxx . . $ ZL_Compressor_free(2324d8dd7fde8c1b).(zl_compressor);
1141 ZL_CCtx_freecxx . . $ ZL_CCtx_free(f9d44ccfbcf19add).(zl_cctx);
1142 }
1143 return ctx->rccxx . . $ _grn_ctx#rc.;
1144 }
1145
1146 static inline grn_rccxx . . $ grn_rc#
1147 grn_compressor_decompress_openzlcxx . . $ grn_compressor_decompress_openzl(a8f2aa4281176350).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_decompress_datacxx . . $ grn_decompress_data# *data)
1148 {
1149 const char *tag = "[compressor][decompress][openzl]";
1150 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(data->decompressed_value_len);
1151 if (!data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value.) {
1152 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
1153 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
1154 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR, "%s failed to allocate buffer: %s", tag, message);
1155 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
1156 return ctx->rccxx . . $ _grn_ctx#rc.;
1157 }
1158
1159 ZL_TypedBuffercxx . . $ ZL_TypedBuffer# *outputs[1] = {ZL_TypedBuffer_createcxx . . $ ZL_TypedBuffer_create(5f9348df517a4152).()};
1160 if (!outputs[0]) {
1161 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR, "%s failed to allocate output buffer", tag);
1162 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->decompressed_value);
1163 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1164 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
1165 return ctx->rccxx . . $ _grn_ctx#rc.;
1166 }
1167
1168 ZL_DCtxcxx . . $ ZL_DCtx# *zl_dctx = ZL_DCtx_createcxx . . $ ZL_DCtx_create(5fd94a6b675cf898).();
1169 if (!zl_dctx) {
1170 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR, "%s failed to allocate decompress context", tag);
1171 ZL_TypedBuffer_freecxx . . $ ZL_TypedBuffer_free(8067f0be1cac9540).(outputs[0]);
1172 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->decompressed_value);
1173 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1174 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
1175 return ctx->rccxx . . $ _grn_ctx#rc.;
1176 }
1177 ZL_Reportcxx . . $ ZL_Report# zl_decompress =
1178 ZL_DCtx_decompressMultiTBuffercxx . . $ ZL_DCtx_decompressMultiTBuffer(906caf77ea4042fa).(zl_dctx,
1179 outputs,
1180 1,
1181 data->compressed_valuecxx . . $ grn_decompress_data#compressed_value.,
1182 data->compressed_value_lencxx . . $ grn_decompress_data#compressed_value_len.);
1183 if (ZL_isErrorcxx . . $ ZL_isError(40a0489e3e267bf1).(zl_decompress)) {
1184 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR,
1185 "%s failed to decompress: %s",
1186 tag,
1187 ZL_ErrorCode_toString(ZL_errorCode(zl_decompress)));
1188 ZL_DCtx_freecxx . . $ ZL_DCtx_free(cfdad7c0e3a405d6).(zl_dctx);
1189 ZL_TypedBuffer_freecxx . . $ ZL_TypedBuffer_free(8067f0be1cac9540).(outputs[0]);
1190 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->decompressed_value);
1191 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1192 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
1193 return ctx->rccxx . . $ _grn_ctx#rc.;
1194 }
1195
1196 size_t decompressed_size = ZL_TypedBuffer_byteSizecxx . . $ ZL_TypedBuffer_byteSize(f675a89e0b6397c).(outputs[0]);
1197 if (data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. != (uint32_tcxx . . $ uint32_t#)decompressed_size) {
1198 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_OPENZL_ERROR,
1199 "%s unexpected decompressed size: expected %" GRN_FMT_INT32Ucxx . . $ `lib/grn.h:368:11`! " bytes"
1200 " but got %" GRN_FMT_SIZEcxx . . $ `lib/grn.h:408:11`! " bytes",
1201 tag,
1202 data->decompressed_value_len,
1203 decompressed_size);
1204 ZL_DCtx_freecxx . . $ ZL_DCtx_free(cfdad7c0e3a405d6).(zl_dctx);
1205 ZL_TypedBuffer_freecxx . . $ ZL_TypedBuffer_free(8067f0be1cac9540).(outputs[0]);
1206 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->decompressed_value);
1207 data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1208 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len. = 0;
1209 return ctx->rccxx . . $ _grn_ctx#rc.;
1210 }
1211
1212 memcpycxx . . $ memcpy(cc817cb175f282d).(data->decompressed_valuecxx . . $ grn_decompress_data#decompressed_value.,
1213 ZL_TypedBuffer_rPtrcxx . . $ ZL_TypedBuffer_rPtr(bec554309983a2de).(outputs[0]),
1214 data->decompressed_value_lencxx . . $ grn_decompress_data#decompressed_value_len.);
1215
1216 ZL_DCtx_freecxx . . $ ZL_DCtx_free(cfdad7c0e3a405d6).(zl_dctx);
1217 ZL_TypedBuffer_freecxx . . $ ZL_TypedBuffer_free(8067f0be1cac9540).(outputs[0]);
1218 return ctx->rccxx . . $ _grn_ctx#rc.;
1219 }
1220 #endif /* GRN_WITH_OPENZL */
1221
1222 grn_rccxx . . $ grn_rc#
1223 grn_compressor_compresscxx . . $ grn_compressor_compress(38ea3b41608d581c).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_compress_datacxx . . $ grn_compress_data# *data)
1224 {
1225 size_t input_len = data->header_lencxx . . $ grn_compress_data#header_len. + data->body_lencxx . . $ grn_compress_data#body_len. + data->footer_lencxx . . $ grn_compress_data#footer_len.;
1226 if (input_len < COMPRESS_THRESHOLD_BYTEcxx . . $ `lib/compressor.c:85:9`!) {
1227 data->packed_valuecxx . . $ grn_compress_data#packed_value. = GRN_MALLOCcxx . . $ `lib/grn_alloc.h:41:9`!(COMPRESSED_VALUE_LENcxx . . $ `lib/compressor.c:70:9`!(input_len));
1228 if (!data->packed_valuecxx . . $ grn_compress_data#packed_value.) {
1229 char message[GRN_CTX_MSGSIZEcxx . . $ `include/groonga/groonga.h:334:9`!];
1230 grn_strcpycxx . . $ `include/groonga/portability.h:101:11`!(message, GRN_CTX_MSGSIZE, ctx->errbuf);
1231 grn_rccxx . . $ grn_rc# rc;
1232 switch (data->typecxx . . $ grn_compress_data#type.) {
1233 case GRN_COMPRESSION_TYPE_ZLIBcxx . . $ GRN_COMPRESSION_TYPE_ZLIB.:
1234 rc = GRN_ZLIB_ERRORcxx . . $ GRN_ZLIB_ERROR.;
1235 break;
1236 case GRN_COMPRESSION_TYPE_LZ4cxx . . $ GRN_COMPRESSION_TYPE_LZ4.:
1237 rc = GRN_LZ4_ERRORcxx . . $ GRN_LZ4_ERROR.;
1238 break;
1239 case GRN_COMPRESSION_TYPE_ZSTDcxx . . $ GRN_COMPRESSION_TYPE_ZSTD.:
1240 rc = GRN_ZSTD_ERRORcxx . . $ GRN_ZSTD_ERROR.;
1241 break;
1242 case GRN_COMPRESSION_TYPE_BLOSCcxx . . $ GRN_COMPRESSION_TYPE_BLOSC.:
1243 rc = GRN_BLOSC_ERRORcxx . . $ GRN_BLOSC_ERROR.;
1244 break;
1245 case GRN_COMPRESSION_TYPE_OPENZLcxx . . $ GRN_COMPRESSION_TYPE_OPENZL.:
1246 rc = GRN_OPENZL_ERRORcxx . . $ GRN_OPENZL_ERROR.;
1247 break;
1248 default:
1249 rc = ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS. ? GRN_UNKNOWN_ERRORcxx . . $ GRN_UNKNOWN_ERROR. : ctx->rccxx . . $ _grn_ctx#rc.;
1250 break;
1251 }
1252 ERRcxx . . $ `lib/grn_error.h:156:9`!(rc,
1253 "[compressor][compress] failed to allocate packed buffer: %s",
1254 message);
1255 return ctx->rccxx . . $ _grn_ctx#rc.;
1256 }
1257
1258 grn_rccxx . . $ grn_rc# rc = grn_compressor_packcxx . . $ grn_compressor_pack(38ea3b41608d581c).(ctx, data);
1259 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
1260 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(data->packed_value);
1261 data->packed_valuecxx . . $ grn_compress_data#packed_value. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
1262 data->packed_value_lencxx . . $ grn_compress_data#packed_value_len. = 0;
1263 }
1264 return rc;
1265 }
1266
1267 switch (data->typecxx . . $ grn_compress_data#type.) {
1268 #ifdef GRN_WITH_ZLIBcxx . . $ `build/config.h:121:9`!
1269 case GRN_COMPRESSION_TYPE_ZLIBcxx . . $ GRN_COMPRESSION_TYPE_ZLIB.:
1270 return grn_compressor_compress_zlibcxx . . $ grn_compressor_compress_zlib(38ea3b41608d581c).(ctx, data);
1271 #endif /* GRN_WITH_ZLIB */
1272 #ifdef GRN_WITH_LZ4cxx . . $ `build/config.h:106:9`!
1273 case GRN_COMPRESSION_TYPE_LZ4cxx . . $ GRN_COMPRESSION_TYPE_LZ4.:
1274 return grn_compressor_compress_lz4cxx . . $ grn_compressor_compress_lz4(38ea3b41608d581c).(ctx, data);
1275 #endif /* GRN_WITH_LZ4 */
1276 #ifdef GRN_WITH_ZSTDcxx . . $ `build/config.h:122:9`!
1277 case GRN_COMPRESSION_TYPE_ZSTDcxx . . $ GRN_COMPRESSION_TYPE_ZSTD.:
1278 return grn_compressor_compress_zstdcxx . . $ grn_compressor_compress_zstd(38ea3b41608d581c).(ctx, data);
1279 #endif /* GRN_WITH_ZSTD */
1280 #ifdef GRN_WITH_BLOSC
1281 case GRN_COMPRESSION_TYPE_BLOSC:
1282 return grn_compressor_compress_blosc(ctx, data);
1283 #endif
1284 #ifdef GRN_WITH_OPENZLcxx . . $ `build/config.h:112:9`!
1285 case GRN_COMPRESSION_TYPE_OPENZLcxx . . $ GRN_COMPRESSION_TYPE_OPENZL.:
1286 return grn_compressor_compress_openzlcxx . . $ grn_compressor_compress_openzl(38ea3b41608d581c).(ctx, data);
1287 #endif /* GRN_WITH_OPENZL */
1288 default:
1289 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_FUNCTION_NOT_IMPLEMENTED,
1290 "[compressor][compress] unsupported type: %d",
1291 data->type);
1292 return ctx->rccxx . . $ _grn_ctx#rc.;
1293 }
1294 }
1295
1296 grn_rccxx . . $ grn_rc#
1297 grn_compressor_decompresscxx . . $ grn_compressor_decompress(a8f2aa4281176350).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_decompress_datacxx . . $ grn_decompress_data# *data)
1298 {
1299 grn_rccxx . . $ grn_rc# rc = grn_compressor_unpackcxx . . $ grn_compressor_unpack(a8f2aa4281176350).(ctx, data);
1300 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
1301 return rc;
1302 }
1303 if (data->unpacked_valuecxx . . $ grn_decompress_data#unpacked_value.) {
1304 return ctx->rccxx . . $ _grn_ctx#rc.;
1305 }
1306
1307 switch (data->typecxx . . $ grn_decompress_data#type.) {
1308 #ifdef GRN_WITH_ZLIBcxx . . $ `build/config.h:121:9`!
1309 case GRN_COMPRESSION_TYPE_ZLIBcxx . . $ GRN_COMPRESSION_TYPE_ZLIB.:
1310 return grn_compressor_decompress_zlibcxx . . $ grn_compressor_decompress_zlib(a8f2aa4281176350).(ctx, data);
1311 #endif /* GRN_WITH_ZLIB */
1312 #ifdef GRN_WITH_LZ4cxx . . $ `build/config.h:106:9`!
1313 case GRN_COMPRESSION_TYPE_LZ4cxx . . $ GRN_COMPRESSION_TYPE_LZ4.:
1314 return grn_compressor_decompress_lz4cxx . . $ grn_compressor_decompress_lz4(a8f2aa4281176350).(ctx, data);
1315 #endif /* GRN_WITH_LZ4 */
1316 #ifdef GRN_WITH_ZSTDcxx . . $ `build/config.h:122:9`!
1317 case GRN_COMPRESSION_TYPE_ZSTDcxx . . $ GRN_COMPRESSION_TYPE_ZSTD.:
1318 return grn_compressor_decompress_zstdcxx . . $ grn_compressor_decompress_zstd(a8f2aa4281176350).(ctx, data);
1319 #endif /* GRN_WITH_ZSTD */
1320 #ifdef GRN_WITH_BLOSC
1321 case GRN_COMPRESSION_TYPE_BLOSC:
1322 return grn_compressor_decompress_blosc(ctx, data);
1323 #endif
1324 #ifdef GRN_WITH_OPENZLcxx . . $ `build/config.h:112:9`!
1325 case GRN_COMPRESSION_TYPE_OPENZLcxx . . $ GRN_COMPRESSION_TYPE_OPENZL.:
1326 return grn_compressor_decompress_openzlcxx . . $ grn_compressor_decompress_openzl(a8f2aa4281176350).(ctx, data);
1327 #endif /* GRN_WITH_OPENZL */
1328 default:
1329 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_FUNCTION_NOT_IMPLEMENTED,
1330 "[compressor][decompress] unsupported type: %d",
1331 data->type);
1332 return ctx->rccxx . . $ _grn_ctx#rc.;
1333 }
1334 }