1
1
/*
2
- * Copyright (c) Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates .
3
3
* All rights reserved.
4
4
*
5
5
* This source code is licensed under both the BSD-style license (found in the
8
8
* You may select, at your option, one of the above-listed licenses.
9
9
*/
10
10
11
- #ifndef DICTBUILDER_H_001
12
- #define DICTBUILDER_H_001
13
-
14
11
#if defined (__cplusplus)
15
12
extern " C" {
16
13
#endif
17
14
15
+ #ifndef ZSTD_ZDICT_H
16
+ #define ZSTD_ZDICT_H
18
17
19
18
/* ====== Dependencies ======*/
20
19
#include < stddef.h> /* size_t */
21
20
22
21
23
22
/* ===== ZDICTLIB_API : control library symbols visibility ===== */
24
- #ifndef ZDICTLIB_VISIBILITY
25
- # if defined(__GNUC__) && (__GNUC__ >= 4)
26
- # define ZDICTLIB_VISIBILITY __attribute__ ((visibility (" default" )))
23
+ #ifndef ZDICTLIB_VISIBLE
24
+ /* Backwards compatibility with old macro name */
25
+ # ifdef ZDICTLIB_VISIBILITY
26
+ # define ZDICTLIB_VISIBLE ZDICTLIB_VISIBILITY
27
+ # elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
28
+ # define ZDICTLIB_VISIBLE __attribute__ ((visibility (" default" )))
29
+ # else
30
+ # define ZDICTLIB_VISIBLE
31
+ # endif
32
+ #endif
33
+
34
+ #ifndef ZDICTLIB_HIDDEN
35
+ # if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
36
+ # define ZDICTLIB_HIDDEN __attribute__ ((visibility (" hidden" )))
27
37
# else
28
- # define ZDICTLIB_VISIBILITY
38
+ # define ZDICTLIB_HIDDEN
29
39
# endif
30
40
#endif
41
+
31
42
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
32
- # define ZDICTLIB_API __declspec (dllexport) ZDICTLIB_VISIBILITY
43
+ # define ZDICTLIB_API __declspec (dllexport) ZDICTLIB_VISIBLE
33
44
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
34
- # define ZDICTLIB_API __declspec (dllimport) ZDICTLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
45
+ # define ZDICTLIB_API __declspec (dllimport) ZDICTLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
35
46
#else
36
- # define ZDICTLIB_API ZDICTLIB_VISIBILITY
47
+ # define ZDICTLIB_API ZDICTLIB_VISIBLE
37
48
#endif
38
49
39
50
/* ******************************************************************************
@@ -110,8 +121,8 @@ extern "C" {
110
121
* The zstd CLI defaults to a 110KB dictionary. You likely don't need a
111
122
* dictionary larger than that. But, most use cases can get away with a
112
123
* smaller dictionary. The advanced dictionary builders can automatically
113
- * shrink the dictionary for you, and select a the smallest size that
114
- * doesn't hurt compression ratio too much. See the `shrinkDict` parameter.
124
+ * shrink the dictionary for you, and select the smallest size that doesn't
125
+ * hurt compression ratio too much. See the `shrinkDict` parameter.
115
126
* A smaller dictionary can save memory, and potentially speed up
116
127
* compression.
117
128
*
@@ -201,9 +212,9 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCap
201
212
const size_t * samplesSizes, unsigned nbSamples);
202
213
203
214
typedef struct {
204
- int compressionLevel; /* < optimize for a specific zstd compression level; 0 means default */
205
- unsigned notificationLevel; /* < Write log to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */
206
- unsigned dictID; /* < force dictID value; 0 means auto mode (32-bits random value)
215
+ int compressionLevel; /* * < optimize for a specific zstd compression level; 0 means default */
216
+ unsigned notificationLevel; /* * < Write log to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */
217
+ unsigned dictID; /* * < force dictID value; 0 means auto mode (32-bits random value)
207
218
* NOTE: The zstd format reserves some dictionary IDs for future use.
208
219
* You may use them in private settings, but be warned that they
209
220
* may be used by zstd in a public dictionary registry in the future.
@@ -260,9 +271,21 @@ ZDICTLIB_API size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictS
260
271
ZDICTLIB_API unsigned ZDICT_isError (size_t errorCode);
261
272
ZDICTLIB_API const char * ZDICT_getErrorName (size_t errorCode);
262
273
274
+ #endif /* ZSTD_ZDICT_H */
263
275
276
+ #if defined(ZDICT_STATIC_LINKING_ONLY) && !defined(ZSTD_ZDICT_H_STATIC)
277
+ #define ZSTD_ZDICT_H_STATIC
264
278
265
- #ifdef ZDICT_STATIC_LINKING_ONLY
279
+ /* This can be overridden externally to hide static symbols. */
280
+ #ifndef ZDICTLIB_STATIC_API
281
+ # if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
282
+ # define ZDICTLIB_STATIC_API __declspec (dllexport) ZDICTLIB_VISIBLE
283
+ # elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
284
+ # define ZDICTLIB_STATIC_API __declspec (dllimport) ZDICTLIB_VISIBLE
285
+ # else
286
+ # define ZDICTLIB_STATIC_API ZDICTLIB_VISIBLE
287
+ # endif
288
+ #endif
266
289
267
290
/* ====================================================================================
268
291
* The definitions in this section are considered experimental.
@@ -318,7 +341,7 @@ typedef struct {
318
341
* In general, it's recommended to provide a few thousands samples, though this can vary a lot.
319
342
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
320
343
*/
321
- ZDICTLIB_API size_t ZDICT_trainFromBuffer_cover (
344
+ ZDICTLIB_STATIC_API size_t ZDICT_trainFromBuffer_cover (
322
345
void *dictBuffer, size_t dictBufferCapacity,
323
346
const void *samplesBuffer, const size_t *samplesSizes, unsigned nbSamples,
324
347
ZDICT_cover_params_t parameters);
@@ -340,7 +363,7 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_cover(
340
363
* See ZDICT_trainFromBuffer() for details on failure modes.
341
364
* Note: ZDICT_optimizeTrainFromBuffer_cover() requires about 8 bytes of memory for each input byte and additionally another 5 bytes of memory for each byte of memory for each thread.
342
365
*/
343
- ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover (
366
+ ZDICTLIB_STATIC_API size_t ZDICT_optimizeTrainFromBuffer_cover (
344
367
void * dictBuffer, size_t dictBufferCapacity,
345
368
const void * samplesBuffer, const size_t * samplesSizes, unsigned nbSamples,
346
369
ZDICT_cover_params_t* parameters);
@@ -361,7 +384,7 @@ ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
361
384
* In general, it's recommended to provide a few thousands samples, though this can vary a lot.
362
385
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
363
386
*/
364
- ZDICTLIB_API size_t ZDICT_trainFromBuffer_fastCover (void *dictBuffer,
387
+ ZDICTLIB_STATIC_API size_t ZDICT_trainFromBuffer_fastCover (void *dictBuffer,
365
388
size_t dictBufferCapacity, const void *samplesBuffer,
366
389
const size_t *samplesSizes, unsigned nbSamples,
367
390
ZDICT_fastCover_params_t parameters);
@@ -384,7 +407,7 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_fastCover(void *dictBuffer,
384
407
* See ZDICT_trainFromBuffer() for details on failure modes.
385
408
* Note: ZDICT_optimizeTrainFromBuffer_fastCover() requires about 6 * 2^f bytes of memory for each thread.
386
409
*/
387
- ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_fastCover (void * dictBuffer,
410
+ ZDICTLIB_STATIC_API size_t ZDICT_optimizeTrainFromBuffer_fastCover (void * dictBuffer,
388
411
size_t dictBufferCapacity, const void * samplesBuffer,
389
412
const size_t * samplesSizes, unsigned nbSamples,
390
413
ZDICT_fastCover_params_t* parameters);
@@ -409,7 +432,7 @@ typedef struct {
409
432
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
410
433
* Note: ZDICT_trainFromBuffer_legacy() will send notifications into stderr if instructed to, using notificationLevel>0.
411
434
*/
412
- ZDICTLIB_API size_t ZDICT_trainFromBuffer_legacy (
435
+ ZDICTLIB_STATIC_API size_t ZDICT_trainFromBuffer_legacy (
413
436
void * dictBuffer, size_t dictBufferCapacity,
414
437
const void * samplesBuffer, const size_t * samplesSizes, unsigned nbSamples,
415
438
ZDICT_legacy_params_t parameters);
@@ -421,32 +444,31 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_legacy(
421
444
or _CRT_SECURE_NO_WARNINGS in Visual.
422
445
Otherwise, it's also possible to manually define ZDICT_DISABLE_DEPRECATE_WARNINGS */
423
446
#ifdef ZDICT_DISABLE_DEPRECATE_WARNINGS
424
- # define ZDICT_DEPRECATED (message ) ZDICTLIB_API /* disable deprecation warnings */
447
+ # define ZDICT_DEPRECATED (message ) /* disable deprecation warnings */
425
448
#else
426
449
# define ZDICT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
427
450
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
428
- # define ZDICT_DEPRECATED (message ) [[deprecated(message)]] ZDICTLIB_API
451
+ # define ZDICT_DEPRECATED (message ) [[deprecated(message)]]
429
452
# elif defined(__clang__) || (ZDICT_GCC_VERSION >= 405)
430
- # define ZDICT_DEPRECATED (message ) ZDICTLIB_API __attribute__ ((deprecated(message)))
453
+ # define ZDICT_DEPRECATED (message ) __attribute__((deprecated(message)))
431
454
# elif (ZDICT_GCC_VERSION >= 301)
432
- # define ZDICT_DEPRECATED (message ) ZDICTLIB_API __attribute__ ((deprecated))
455
+ # define ZDICT_DEPRECATED (message ) __attribute__((deprecated))
433
456
# elif defined(_MSC_VER)
434
- # define ZDICT_DEPRECATED (message ) ZDICTLIB_API __declspec (deprecated(message))
457
+ # define ZDICT_DEPRECATED (message ) __declspec(deprecated(message))
435
458
# else
436
459
# pragma message("WARNING: You need to implement ZDICT_DEPRECATED for this compiler")
437
- # define ZDICT_DEPRECATED (message ) ZDICTLIB_API
460
+ # define ZDICT_DEPRECATED (message )
438
461
# endif
439
462
#endif /* ZDICT_DISABLE_DEPRECATE_WARNINGS */
440
463
441
464
ZDICT_DEPRECATED (" use ZDICT_finalizeDictionary() instead" )
465
+ ZDICTLIB_STATIC_API
442
466
size_t ZDICT_addEntropyTablesFromBuffer(void * dictBuffer, size_t dictContentSize, size_t dictBufferCapacity,
443
467
const void * samplesBuffer, const size_t * samplesSizes, unsigned nbSamples);
444
468
445
469
446
- #endif /* ZDICT_STATIC_LINKING_ONLY */
470
+ #endif /* ZSTD_ZDICT_H_STATIC */
447
471
448
472
#if defined (__cplusplus)
449
473
}
450
474
#endif
451
-
452
- #endif /* DICTBUILDER_H_001 */
0 commit comments