multi_compress 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -3
  3. data/GET_STARTED.md +3 -3
  4. data/README.md +75 -66
  5. data/THIRD_PARTY_NOTICES.md +24 -0
  6. data/ext/multi_compress/brotli_dec_static_init.c +3 -0
  7. data/ext/multi_compress/brotli_enc_static_init.c +3 -0
  8. data/ext/multi_compress/extconf.rb +22 -1
  9. data/ext/multi_compress/multi_compress.c +152 -72
  10. data/ext/multi_compress/vendor/.vendored +2 -2
  11. data/ext/multi_compress/vendor/brotli/LICENSE +19 -0
  12. data/ext/multi_compress/vendor/brotli/c/common/constants.c +7 -7
  13. data/ext/multi_compress/vendor/brotli/c/common/constants.h +2 -5
  14. data/ext/multi_compress/vendor/brotli/c/common/context.c +2 -2
  15. data/ext/multi_compress/vendor/brotli/c/common/context.h +1 -2
  16. data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +4 -5856
  17. data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +1 -2
  18. data/ext/multi_compress/vendor/brotli/c/common/dictionary_inc.h +5847 -0
  19. data/ext/multi_compress/vendor/brotli/c/common/platform.c +0 -4
  20. data/ext/multi_compress/vendor/brotli/c/common/platform.h +182 -43
  21. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +3 -7
  22. data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
  23. data/ext/multi_compress/vendor/brotli/c/common/static_init.h +56 -0
  24. data/ext/multi_compress/vendor/brotli/c/common/transform.c +6 -4
  25. data/ext/multi_compress/vendor/brotli/c/common/transform.h +1 -2
  26. data/ext/multi_compress/vendor/brotli/c/common/version.h +3 -3
  27. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +2 -3
  28. data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +0 -4
  29. data/ext/multi_compress/vendor/brotli/c/dec/decode.c +128 -39
  30. data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +2 -5
  31. data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +0 -2
  32. data/ext/multi_compress/vendor/brotli/c/dec/prefix.c +67 -0
  33. data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +18 -708
  34. data/ext/multi_compress/vendor/brotli/c/dec/prefix_inc.h +707 -0
  35. data/ext/multi_compress/vendor/brotli/c/dec/state.c +18 -15
  36. data/ext/multi_compress/vendor/brotli/c/dec/state.h +2 -6
  37. data/ext/multi_compress/vendor/brotli/c/dec/static_init.c +53 -0
  38. data/ext/multi_compress/vendor/brotli/c/dec/static_init.h +30 -0
  39. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +32 -8
  40. data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +1 -5
  41. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +15 -15
  42. data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +1 -5
  43. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +28 -4
  44. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +8 -40
  45. data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
  46. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +9 -12
  47. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +0 -3
  48. data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
  49. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
  50. data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
  51. data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +0 -2
  52. data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +0 -2
  53. data/ext/multi_compress/vendor/brotli/c/enc/command.c +1 -1
  54. data/ext/multi_compress/vendor/brotli/c/enc/command.h +8 -10
  55. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +3 -5
  56. data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +1 -4
  57. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +3 -13
  58. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +0 -2
  59. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
  60. data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
  61. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
  62. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +23 -3
  63. data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
  64. data/ext/multi_compress/vendor/brotli/c/enc/encode.c +77 -52
  65. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +9 -7
  66. data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +2 -4
  67. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +3 -6
  68. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +2 -4
  69. data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
  70. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +1 -1
  71. data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +2 -3
  72. data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +0 -2
  73. data/ext/multi_compress/vendor/brotli/c/enc/hash.h +38 -31
  74. data/ext/multi_compress/vendor/brotli/c/enc/hash_base.h +38 -0
  75. data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
  76. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
  77. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
  78. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
  79. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
  80. data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
  81. data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +1 -0
  82. data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +0 -4
  83. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +4 -6
  84. data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +0 -2
  85. data/ext/multi_compress/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
  86. data/ext/multi_compress/vendor/brotli/c/enc/memory.c +0 -5
  87. data/ext/multi_compress/vendor/brotli/c/enc/memory.h +0 -4
  88. data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +7 -9
  89. data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +3 -3
  90. data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +4 -4
  91. data/ext/multi_compress/vendor/brotli/c/enc/params.h +0 -1
  92. data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +0 -2
  93. data/ext/multi_compress/vendor/brotli/c/enc/quality.h +17 -10
  94. data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +1 -4
  95. data/ext/multi_compress/vendor/brotli/c/enc/state.h +2 -2
  96. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +5 -11
  97. data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +1 -3
  98. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.c +224 -0
  99. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
  100. data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
  101. data/ext/multi_compress/vendor/brotli/c/enc/static_init.c +59 -0
  102. data/ext/multi_compress/vendor/brotli/c/enc/static_init.h +30 -0
  103. data/ext/multi_compress/vendor/brotli/c/enc/static_init_lazy.cc +26 -0
  104. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +1 -1
  105. data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +0 -2
  106. data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +0 -2
  107. data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -1
  108. data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +5 -1
  109. data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +4 -7
  110. data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +2 -2
  111. data/ext/multi_compress/vendor/lz4/LICENSE +12 -0
  112. data/ext/multi_compress/vendor/zstd/COPYING +339 -0
  113. data/ext/multi_compress/vendor/zstd/LICENSE +30 -0
  114. data/ext/multi_compress/vendor/zstd/lib/Makefile +67 -35
  115. data/ext/multi_compress/vendor/zstd/lib/README.md +33 -2
  116. data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
  117. data/ext/multi_compress/vendor/zstd/lib/common/bits.h +205 -0
  118. data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +84 -108
  119. data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +170 -41
  120. data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +37 -1
  121. data/ext/multi_compress/vendor/zstd/lib/common/debug.c +7 -1
  122. data/ext/multi_compress/vendor/zstd/lib/common/debug.h +21 -21
  123. data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +12 -40
  124. data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +10 -2
  125. data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +46 -47
  126. data/ext/multi_compress/vendor/zstd/lib/common/fse.h +8 -100
  127. data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +28 -116
  128. data/ext/multi_compress/vendor/zstd/lib/common/huf.h +79 -166
  129. data/ext/multi_compress/vendor/zstd/lib/common/mem.h +46 -66
  130. data/ext/multi_compress/vendor/zstd/lib/common/pool.c +27 -11
  131. data/ext/multi_compress/vendor/zstd/lib/common/pool.h +8 -11
  132. data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +45 -11
  133. data/ext/multi_compress/vendor/zstd/lib/common/threading.c +74 -14
  134. data/ext/multi_compress/vendor/zstd/lib/common/threading.h +5 -18
  135. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +5 -11
  136. data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +2411 -1003
  137. data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +1 -36
  138. data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +13 -1
  139. data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +13 -182
  140. data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +6 -13
  141. data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +1 -1
  142. data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +15 -131
  143. data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +11 -1
  144. data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +8 -1
  145. data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +283 -189
  146. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +2419 -903
  147. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +423 -245
  148. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +116 -40
  149. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +16 -8
  150. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +10 -10
  151. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +8 -7
  152. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +254 -139
  153. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  154. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +184 -95
  155. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +163 -81
  156. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +18 -14
  157. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +507 -197
  158. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +7 -14
  159. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +579 -484
  160. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +133 -65
  161. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +61 -40
  162. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +7 -15
  163. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +1 -1
  164. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +352 -218
  165. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +37 -21
  166. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
  167. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
  168. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +239 -175
  169. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +5 -16
  170. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +543 -488
  171. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +78 -61
  172. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +4 -4
  173. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +1 -1
  174. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +295 -115
  175. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +430 -293
  176. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +7 -2
  177. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +11 -7
  178. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +1 -1
  179. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +1 -1
  180. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +1 -1
  181. data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +3 -1
  182. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +95 -46
  183. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +3 -9
  184. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -10
  185. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +4 -4
  186. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +25 -97
  187. data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +1 -1
  188. data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +1 -1
  189. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +38 -1
  190. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +19 -50
  191. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +1 -1
  192. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +27 -80
  193. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +1 -1
  194. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +28 -83
  195. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +1 -1
  196. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +25 -74
  197. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +1 -1
  198. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +31 -76
  199. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +1 -1
  200. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +44 -88
  201. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +1 -1
  202. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +33 -84
  203. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +1 -1
  204. data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +65 -33
  205. data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +5 -5
  206. data/ext/multi_compress/vendor/zstd/lib/module.modulemap +13 -3
  207. data/ext/multi_compress/vendor/zstd/lib/zdict.h +65 -36
  208. data/ext/multi_compress/vendor/zstd/lib/zstd.h +890 -267
  209. data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +28 -16
  210. data/lib/multi_compress/version.rb +1 -1
  211. metadata +29 -2
@@ -1,5 +1,5 @@
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
@@ -13,11 +13,6 @@
13
13
  #ifndef ERROR_H_MODULE
14
14
  #define ERROR_H_MODULE
15
15
 
16
- #if defined (__cplusplus)
17
- extern "C" {
18
- #endif
19
-
20
-
21
16
  /* ****************************************
22
17
  * Dependencies
23
18
  ******************************************/
@@ -26,7 +21,6 @@ extern "C" {
26
21
  #include "debug.h"
27
22
  #include "zstd_deps.h" /* size_t */
28
23
 
29
-
30
24
  /* ****************************************
31
25
  * Compiler-specific
32
26
  ******************************************/
@@ -60,8 +54,13 @@ ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
60
54
  ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
61
55
 
62
56
  /* check and forward error code */
63
- #define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
64
- #define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
57
+ #define CHECK_V_F(e, f) \
58
+ size_t const e = f; \
59
+ do { \
60
+ if (ERR_isError(e)) \
61
+ return e; \
62
+ } while (0)
63
+ #define CHECK_F(f) do { CHECK_V_F(_var_err__, f); } while (0)
65
64
 
66
65
 
67
66
  /*-****************************************
@@ -95,10 +94,12 @@ void _force_has_format_string(const char *format, ...) {
95
94
  * We want to force this function invocation to be syntactically correct, but
96
95
  * we don't want to force runtime evaluation of its arguments.
97
96
  */
98
- #define _FORCE_HAS_FORMAT_STRING(...) \
99
- if (0) { \
100
- _force_has_format_string(__VA_ARGS__); \
101
- }
97
+ #define _FORCE_HAS_FORMAT_STRING(...) \
98
+ do { \
99
+ if (0) { \
100
+ _force_has_format_string(__VA_ARGS__); \
101
+ } \
102
+ } while (0)
102
103
 
103
104
  #define ERR_QUOTE(str) #str
104
105
 
@@ -109,51 +110,49 @@ void _force_has_format_string(const char *format, ...) {
109
110
  * In order to do that (particularly, printing the conditional that failed),
110
111
  * this can't just wrap RETURN_ERROR().
111
112
  */
112
- #define RETURN_ERROR_IF(cond, err, ...) \
113
- if (cond) { \
114
- RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
115
- __FILE__, __LINE__, ERR_QUOTE(cond), ERR_QUOTE(ERROR(err))); \
116
- _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
117
- RAWLOG(3, ": " __VA_ARGS__); \
118
- RAWLOG(3, "\n"); \
119
- return ERROR(err); \
120
- }
113
+ #define RETURN_ERROR_IF(cond, err, ...) \
114
+ do { \
115
+ if (cond) { \
116
+ RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
117
+ __FILE__, __LINE__, ERR_QUOTE(cond), ERR_QUOTE(ERROR(err))); \
118
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
119
+ RAWLOG(3, ": " __VA_ARGS__); \
120
+ RAWLOG(3, "\n"); \
121
+ return ERROR(err); \
122
+ } \
123
+ } while (0)
121
124
 
122
125
  /**
123
126
  * Unconditionally return the specified error.
124
127
  *
125
128
  * In debug modes, prints additional information.
126
129
  */
127
- #define RETURN_ERROR(err, ...) \
128
- do { \
129
- RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
130
- __FILE__, __LINE__, ERR_QUOTE(ERROR(err))); \
131
- _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
132
- RAWLOG(3, ": " __VA_ARGS__); \
133
- RAWLOG(3, "\n"); \
134
- return ERROR(err); \
135
- } while(0);
130
+ #define RETURN_ERROR(err, ...) \
131
+ do { \
132
+ RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
133
+ __FILE__, __LINE__, ERR_QUOTE(ERROR(err))); \
134
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
135
+ RAWLOG(3, ": " __VA_ARGS__); \
136
+ RAWLOG(3, "\n"); \
137
+ return ERROR(err); \
138
+ } while(0)
136
139
 
137
140
  /**
138
141
  * If the provided expression evaluates to an error code, returns that error code.
139
142
  *
140
143
  * In debug modes, prints additional information.
141
144
  */
142
- #define FORWARD_IF_ERROR(err, ...) \
143
- do { \
144
- size_t const err_code = (err); \
145
- if (ERR_isError(err_code)) { \
146
- RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
147
- __FILE__, __LINE__, ERR_QUOTE(err), ERR_getErrorName(err_code)); \
148
- _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
149
- RAWLOG(3, ": " __VA_ARGS__); \
150
- RAWLOG(3, "\n"); \
151
- return err_code; \
152
- } \
153
- } while(0);
154
-
155
- #if defined (__cplusplus)
156
- }
157
- #endif
145
+ #define FORWARD_IF_ERROR(err, ...) \
146
+ do { \
147
+ size_t const err_code = (err); \
148
+ if (ERR_isError(err_code)) { \
149
+ RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
150
+ __FILE__, __LINE__, ERR_QUOTE(err), ERR_getErrorName(err_code)); \
151
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
152
+ RAWLOG(3, ": " __VA_ARGS__); \
153
+ RAWLOG(3, "\n"); \
154
+ return err_code; \
155
+ } \
156
+ } while(0)
158
157
 
159
158
  #endif /* ERROR_H_MODULE */
@@ -1,7 +1,7 @@
1
1
  /* ******************************************************************
2
2
  * FSE : Finite State Entropy codec
3
3
  * Public Prototypes declaration
4
- * Copyright (c) Yann Collet, Facebook, Inc.
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
5
  *
6
6
  * You can contact the author at :
7
7
  * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -11,11 +11,6 @@
11
11
  * in the COPYING file in the root directory of this source tree).
12
12
  * You may select, at your option, one of the above-listed licenses.
13
13
  ****************************************************************** */
14
-
15
- #if defined (__cplusplus)
16
- extern "C" {
17
- #endif
18
-
19
14
  #ifndef FSE_H
20
15
  #define FSE_H
21
16
 
@@ -25,7 +20,6 @@ extern "C" {
25
20
  ******************************************/
26
21
  #include "zstd_deps.h" /* size_t, ptrdiff_t */
27
22
 
28
-
29
23
  /*-*****************************************
30
24
  * FSE_PUBLIC_API : control library symbols visibility
31
25
  ******************************************/
@@ -53,34 +47,6 @@ extern "C" {
53
47
  FSE_PUBLIC_API unsigned FSE_versionNumber(void); /**< library version number; to be used when checking dll version */
54
48
 
55
49
 
56
- /*-****************************************
57
- * FSE simple functions
58
- ******************************************/
59
- /*! FSE_compress() :
60
- Compress content of buffer 'src', of size 'srcSize', into destination buffer 'dst'.
61
- 'dst' buffer must be already allocated. Compression runs faster is dstCapacity >= FSE_compressBound(srcSize).
62
- @return : size of compressed data (<= dstCapacity).
63
- Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!!
64
- if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression instead.
65
- if FSE_isError(return), compression failed (more details using FSE_getErrorName())
66
- */
67
- FSE_PUBLIC_API size_t FSE_compress(void* dst, size_t dstCapacity,
68
- const void* src, size_t srcSize);
69
-
70
- /*! FSE_decompress():
71
- Decompress FSE data from buffer 'cSrc', of size 'cSrcSize',
72
- into already allocated destination buffer 'dst', of size 'dstCapacity'.
73
- @return : size of regenerated data (<= maxDstSize),
74
- or an error code, which can be tested using FSE_isError() .
75
-
76
- ** Important ** : FSE_decompress() does not decompress non-compressible nor RLE data !!!
77
- Why ? : making this distinction requires a header.
78
- Header management is intentionally delegated to the user layer, which can better manage special cases.
79
- */
80
- FSE_PUBLIC_API size_t FSE_decompress(void* dst, size_t dstCapacity,
81
- const void* cSrc, size_t cSrcSize);
82
-
83
-
84
50
  /*-*****************************************
85
51
  * Tool functions
86
52
  ******************************************/
@@ -91,20 +57,6 @@ FSE_PUBLIC_API unsigned FSE_isError(size_t code); /* tells if a return
91
57
  FSE_PUBLIC_API const char* FSE_getErrorName(size_t code); /* provides error code string (useful for debugging) */
92
58
 
93
59
 
94
- /*-*****************************************
95
- * FSE advanced functions
96
- ******************************************/
97
- /*! FSE_compress2() :
98
- Same as FSE_compress(), but allows the selection of 'maxSymbolValue' and 'tableLog'
99
- Both parameters can be defined as '0' to mean : use default value
100
- @return : size of compressed data
101
- Special values : if return == 0, srcData is not compressible => Nothing is stored within cSrc !!!
102
- if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression.
103
- if FSE_isError(return), it's an error code.
104
- */
105
- FSE_PUBLIC_API size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
106
-
107
-
108
60
  /*-*****************************************
109
61
  * FSE detailed API
110
62
  ******************************************/
@@ -164,8 +116,6 @@ FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize,
164
116
  /*! Constructor and Destructor of FSE_CTable.
165
117
  Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */
166
118
  typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */
167
- FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog);
168
- FSE_PUBLIC_API void FSE_freeCTable (FSE_CTable* ct);
169
119
 
170
120
  /*! FSE_buildCTable():
171
121
  Builds `ct`, which must be already allocated, using FSE_createCTable().
@@ -241,23 +191,7 @@ FSE_PUBLIC_API size_t FSE_readNCount_bmi2(short* normalizedCounter,
241
191
  unsigned* maxSymbolValuePtr, unsigned* tableLogPtr,
242
192
  const void* rBuffer, size_t rBuffSize, int bmi2);
243
193
 
244
- /*! Constructor and Destructor of FSE_DTable.
245
- Note that its size depends on 'tableLog' */
246
194
  typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be more restrictive than void* */
247
- FSE_PUBLIC_API FSE_DTable* FSE_createDTable(unsigned tableLog);
248
- FSE_PUBLIC_API void FSE_freeDTable(FSE_DTable* dt);
249
-
250
- /*! FSE_buildDTable():
251
- Builds 'dt', which must be already allocated, using FSE_createDTable().
252
- return : 0, or an errorCode, which can be tested using FSE_isError() */
253
- FSE_PUBLIC_API size_t FSE_buildDTable (FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
254
-
255
- /*! FSE_decompress_usingDTable():
256
- Decompress compressed source `cSrc` of size `cSrcSize` using `dt`
257
- into `dst` which must be already allocated.
258
- @return : size of regenerated data (necessarily <= `dstCapacity`),
259
- or an errorCode, which can be tested using FSE_isError() */
260
- FSE_PUBLIC_API size_t FSE_decompress_usingDTable(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, const FSE_DTable* dt);
261
195
 
262
196
  /*!
263
197
  Tutorial :
@@ -289,13 +223,11 @@ If there is an error, the function will return an error code, which can be teste
289
223
 
290
224
  #endif /* FSE_H */
291
225
 
226
+
292
227
  #if defined(FSE_STATIC_LINKING_ONLY) && !defined(FSE_H_FSE_STATIC_LINKING_ONLY)
293
228
  #define FSE_H_FSE_STATIC_LINKING_ONLY
294
-
295
- /* *** Dependency *** */
296
229
  #include "bitstream.h"
297
230
 
298
-
299
231
  /* *****************************************
300
232
  * Static allocation
301
233
  *******************************************/
@@ -320,16 +252,6 @@ If there is an error, the function will return an error code, which can be teste
320
252
  unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus);
321
253
  /**< same as FSE_optimalTableLog(), which used `minus==2` */
322
254
 
323
- /* FSE_compress_wksp() :
324
- * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
325
- * FSE_COMPRESS_WKSP_SIZE_U32() provides the minimum size required for `workSpace` as a table of FSE_CTable.
326
- */
327
- #define FSE_COMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + ((maxTableLog > 12) ? (1 << (maxTableLog - 2)) : 1024) )
328
- size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
329
-
330
- size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits);
331
- /**< build a fake FSE_CTable, designed for a flat distribution, where each symbol uses nbBits */
332
-
333
255
  size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue);
334
256
  /**< build a fake FSE_CTable, designed to compress always the same symbolValue */
335
257
 
@@ -347,19 +269,11 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct, const short* normalizedCounter, unsi
347
269
  FSE_PUBLIC_API size_t FSE_buildDTable_wksp(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
348
270
  /**< Same as FSE_buildDTable(), using an externally allocated `workspace` produced with `FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxSymbolValue)` */
349
271
 
350
- size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits);
351
- /**< build a fake FSE_DTable, designed to read a flat distribution where each symbol uses nbBits */
352
-
353
- size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue);
354
- /**< build a fake FSE_DTable, designed to always generate the same symbolValue */
355
-
356
- #define FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) (FSE_DTABLE_SIZE_U32(maxTableLog) + FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) + (FSE_MAX_SYMBOL_VALUE + 1) / 2 + 1)
272
+ #define FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) (FSE_DTABLE_SIZE_U32(maxTableLog) + 1 + FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) + (FSE_MAX_SYMBOL_VALUE + 1) / 2 + 1)
357
273
  #define FSE_DECOMPRESS_WKSP_SIZE(maxTableLog, maxSymbolValue) (FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(unsigned))
358
- size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize);
359
- /**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DECOMPRESS_WKSP_SIZE_U32(maxLog, maxSymbolValue)` */
360
-
361
274
  size_t FSE_decompress_wksp_bmi2(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize, int bmi2);
362
- /**< Same as FSE_decompress_wksp() but with dynamic BMI2 support. Pass 1 if your CPU supports BMI2 or 0 if it doesn't. */
275
+ /**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DECOMPRESS_WKSP_SIZE_U32(maxLog, maxSymbolValue)`.
276
+ * Set bmi2 to 1 if your CPU supports BMI2 or 0 if it doesn't */
363
277
 
364
278
  typedef enum {
365
279
  FSE_repeat_none, /**< Cannot use the previous table */
@@ -542,20 +456,20 @@ MEM_STATIC void FSE_encodeSymbol(BIT_CStream_t* bitC, FSE_CState_t* statePtr, un
542
456
  FSE_symbolCompressionTransform const symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol];
543
457
  const U16* const stateTable = (const U16*)(statePtr->stateTable);
544
458
  U32 const nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16);
545
- BIT_addBits(bitC, statePtr->value, nbBitsOut);
459
+ BIT_addBits(bitC, (BitContainerType)statePtr->value, nbBitsOut);
546
460
  statePtr->value = stateTable[ (statePtr->value >> nbBitsOut) + symbolTT.deltaFindState];
547
461
  }
548
462
 
549
463
  MEM_STATIC void FSE_flushCState(BIT_CStream_t* bitC, const FSE_CState_t* statePtr)
550
464
  {
551
- BIT_addBits(bitC, statePtr->value, statePtr->stateLog);
465
+ BIT_addBits(bitC, (BitContainerType)statePtr->value, statePtr->stateLog);
552
466
  BIT_flushBits(bitC);
553
467
  }
554
468
 
555
469
 
556
470
  /* FSE_getMaxNbBits() :
557
471
  * Approximate maximum cost of a symbol, in bits.
558
- * Fractional get rounded up (i.e : a symbol with a normalized frequency of 3 gives the same result as a frequency of 2)
472
+ * Fractional get rounded up (i.e. a symbol with a normalized frequency of 3 gives the same result as a frequency of 2)
559
473
  * note 1 : assume symbolValue is valid (<= maxSymbolValue)
560
474
  * note 2 : if freq[symbolValue]==0, @return a fake cost of tableLog+1 bits */
561
475
  MEM_STATIC U32 FSE_getMaxNbBits(const void* symbolTTPtr, U32 symbolValue)
@@ -708,10 +622,4 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
708
622
 
709
623
  #define FSE_TABLESTEP(tableSize) (((tableSize)>>1) + ((tableSize)>>3) + 3)
710
624
 
711
-
712
625
  #endif /* FSE_STATIC_LINKING_ONLY */
713
-
714
-
715
- #if defined (__cplusplus)
716
- }
717
- #endif
@@ -1,6 +1,6 @@
1
1
  /* ******************************************************************
2
2
  * FSE : Finite State Entropy decoder
3
- * Copyright (c) Yann Collet, Facebook, Inc.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
  *
5
5
  * You can contact the author at :
6
6
  * - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
@@ -22,8 +22,8 @@
22
22
  #define FSE_STATIC_LINKING_ONLY
23
23
  #include "fse.h"
24
24
  #include "error_private.h"
25
- #define ZSTD_DEPS_NEED_MALLOC
26
- #include "zstd_deps.h"
25
+ #include "zstd_deps.h" /* ZSTD_memcpy */
26
+ #include "bits.h" /* ZSTD_highbit32 */
27
27
 
28
28
 
29
29
  /* **************************************************************
@@ -55,19 +55,6 @@
55
55
  #define FSE_FUNCTION_NAME(X,Y) FSE_CAT(X,Y)
56
56
  #define FSE_TYPE_NAME(X,Y) FSE_CAT(X,Y)
57
57
 
58
-
59
- /* Function templates */
60
- FSE_DTable* FSE_createDTable (unsigned tableLog)
61
- {
62
- if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
63
- return (FSE_DTable*)ZSTD_malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) );
64
- }
65
-
66
- void FSE_freeDTable (FSE_DTable* dt)
67
- {
68
- ZSTD_free(dt);
69
- }
70
-
71
58
  static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize)
72
59
  {
73
60
  void* const tdPtr = dt+1; /* because *dt is unsigned, 32-bits aligned on 32-bits */
@@ -96,7 +83,7 @@ static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCo
96
83
  symbolNext[s] = 1;
97
84
  } else {
98
85
  if (normalizedCounter[s] >= largeLimit) DTableH.fastMode=0;
99
- symbolNext[s] = normalizedCounter[s];
86
+ symbolNext[s] = (U16)normalizedCounter[s];
100
87
  } } }
101
88
  ZSTD_memcpy(dt, &DTableH, sizeof(DTableH));
102
89
  }
@@ -111,8 +98,7 @@ static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCo
111
98
  * all symbols have counts <= 8. We ensure we have 8 bytes at the end of
112
99
  * our buffer to handle the over-write.
113
100
  */
114
- {
115
- U64 const add = 0x0101010101010101ull;
101
+ { U64 const add = 0x0101010101010101ull;
116
102
  size_t pos = 0;
117
103
  U64 sv = 0;
118
104
  U32 s;
@@ -123,14 +109,13 @@ static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCo
123
109
  for (i = 8; i < n; i += 8) {
124
110
  MEM_write64(spread + pos + i, sv);
125
111
  }
126
- pos += n;
127
- }
128
- }
112
+ pos += (size_t)n;
113
+ } }
129
114
  /* Now we spread those positions across the table.
130
- * The benefit of doing it in two stages is that we avoid the the
115
+ * The benefit of doing it in two stages is that we avoid the
131
116
  * variable size inner loop, which caused lots of branch misses.
132
117
  * Now we can run through all the positions without any branch misses.
133
- * We unroll the loop twice, since that is what emperically worked best.
118
+ * We unroll the loop twice, since that is what empirically worked best.
134
119
  */
135
120
  {
136
121
  size_t position = 0;
@@ -166,7 +151,7 @@ static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCo
166
151
  for (u=0; u<tableSize; u++) {
167
152
  FSE_FUNCTION_TYPE const symbol = (FSE_FUNCTION_TYPE)(tableDecode[u].symbol);
168
153
  U32 const nextState = symbolNext[symbol]++;
169
- tableDecode[u].nbBits = (BYTE) (tableLog - BIT_highbit32(nextState) );
154
+ tableDecode[u].nbBits = (BYTE) (tableLog - ZSTD_highbit32(nextState) );
170
155
  tableDecode[u].newState = (U16) ( (nextState << tableDecode[u].nbBits) - tableSize);
171
156
  } }
172
157
 
@@ -184,49 +169,6 @@ size_t FSE_buildDTable_wksp(FSE_DTable* dt, const short* normalizedCounter, unsi
184
169
  /*-*******************************************************
185
170
  * Decompression (Byte symbols)
186
171
  *********************************************************/
187
- size_t FSE_buildDTable_rle (FSE_DTable* dt, BYTE symbolValue)
188
- {
189
- void* ptr = dt;
190
- FSE_DTableHeader* const DTableH = (FSE_DTableHeader*)ptr;
191
- void* dPtr = dt + 1;
192
- FSE_decode_t* const cell = (FSE_decode_t*)dPtr;
193
-
194
- DTableH->tableLog = 0;
195
- DTableH->fastMode = 0;
196
-
197
- cell->newState = 0;
198
- cell->symbol = symbolValue;
199
- cell->nbBits = 0;
200
-
201
- return 0;
202
- }
203
-
204
-
205
- size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits)
206
- {
207
- void* ptr = dt;
208
- FSE_DTableHeader* const DTableH = (FSE_DTableHeader*)ptr;
209
- void* dPtr = dt + 1;
210
- FSE_decode_t* const dinfo = (FSE_decode_t*)dPtr;
211
- const unsigned tableSize = 1 << nbBits;
212
- const unsigned tableMask = tableSize - 1;
213
- const unsigned maxSV1 = tableMask+1;
214
- unsigned s;
215
-
216
- /* Sanity checks */
217
- if (nbBits < 1) return ERROR(GENERIC); /* min size */
218
-
219
- /* Build Decoding Table */
220
- DTableH->tableLog = (U16)nbBits;
221
- DTableH->fastMode = 1;
222
- for (s=0; s<maxSV1; s++) {
223
- dinfo[s].newState = 0;
224
- dinfo[s].symbol = (BYTE)s;
225
- dinfo[s].nbBits = (BYTE)nbBits;
226
- }
227
-
228
- return 0;
229
- }
230
172
 
231
173
  FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
232
174
  void* dst, size_t maxDstSize,
@@ -248,6 +190,8 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
248
190
  FSE_initDState(&state1, &bitD, dt);
249
191
  FSE_initDState(&state2, &bitD, dt);
250
192
 
193
+ RETURN_ERROR_IF(BIT_reloadDStream(&bitD)==BIT_DStream_overflow, corruption_detected, "");
194
+
251
195
  #define FSE_GETSYMBOL(statePtr) fast ? FSE_decodeSymbolFast(statePtr, &bitD) : FSE_decodeSymbol(statePtr, &bitD)
252
196
 
253
197
  /* 4 symbols per loop */
@@ -287,32 +231,12 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
287
231
  break;
288
232
  } }
289
233
 
290
- return op-ostart;
291
- }
292
-
293
-
294
- size_t FSE_decompress_usingDTable(void* dst, size_t originalSize,
295
- const void* cSrc, size_t cSrcSize,
296
- const FSE_DTable* dt)
297
- {
298
- const void* ptr = dt;
299
- const FSE_DTableHeader* DTableH = (const FSE_DTableHeader*)ptr;
300
- const U32 fastMode = DTableH->fastMode;
301
-
302
- /* select fast mode (static) */
303
- if (fastMode) return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 1);
304
- return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 0);
305
- }
306
-
307
-
308
- size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize)
309
- {
310
- return FSE_decompress_wksp_bmi2(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, /* bmi2 */ 0);
234
+ assert(op >= ostart);
235
+ return (size_t)(op-ostart);
311
236
  }
312
237
 
313
238
  typedef struct {
314
239
  short ncount[FSE_MAX_SYMBOL_VALUE + 1];
315
- FSE_DTable dtable[1]; /* Dynamically sized */
316
240
  } FSE_DecompressWksp;
317
241
 
318
242
 
@@ -327,13 +251,18 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_wksp_body(
327
251
  unsigned tableLog;
328
252
  unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
329
253
  FSE_DecompressWksp* const wksp = (FSE_DecompressWksp*)workSpace;
254
+ size_t const dtablePos = sizeof(FSE_DecompressWksp) / sizeof(FSE_DTable);
255
+ FSE_DTable* const dtable = (FSE_DTable*)workSpace + dtablePos;
330
256
 
331
- DEBUG_STATIC_ASSERT((FSE_MAX_SYMBOL_VALUE + 1) % 2 == 0);
257
+ FSE_STATIC_ASSERT((FSE_MAX_SYMBOL_VALUE + 1) % 2 == 0);
332
258
  if (wkspSize < sizeof(*wksp)) return ERROR(GENERIC);
333
259
 
260
+ /* correct offset to dtable depends on this property */
261
+ FSE_STATIC_ASSERT(sizeof(FSE_DecompressWksp) % sizeof(FSE_DTable) == 0);
262
+
334
263
  /* normal FSE decoding mode */
335
- {
336
- size_t const NCountLength = FSE_readNCount_bmi2(wksp->ncount, &maxSymbolValue, &tableLog, istart, cSrcSize, bmi2);
264
+ { size_t const NCountLength =
265
+ FSE_readNCount_bmi2(wksp->ncount, &maxSymbolValue, &tableLog, istart, cSrcSize, bmi2);
337
266
  if (FSE_isError(NCountLength)) return NCountLength;
338
267
  if (tableLog > maxLog) return ERROR(tableLog_tooLarge);
339
268
  assert(NCountLength <= cSrcSize);
@@ -342,19 +271,20 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_wksp_body(
342
271
  }
343
272
 
344
273
  if (FSE_DECOMPRESS_WKSP_SIZE(tableLog, maxSymbolValue) > wkspSize) return ERROR(tableLog_tooLarge);
345
- workSpace = wksp->dtable + FSE_DTABLE_SIZE_U32(tableLog);
274
+ assert(sizeof(*wksp) + FSE_DTABLE_SIZE(tableLog) <= wkspSize);
275
+ workSpace = (BYTE*)workSpace + sizeof(*wksp) + FSE_DTABLE_SIZE(tableLog);
346
276
  wkspSize -= sizeof(*wksp) + FSE_DTABLE_SIZE(tableLog);
347
277
 
348
- CHECK_F( FSE_buildDTable_internal(wksp->dtable, wksp->ncount, maxSymbolValue, tableLog, workSpace, wkspSize) );
278
+ CHECK_F( FSE_buildDTable_internal(dtable, wksp->ncount, maxSymbolValue, tableLog, workSpace, wkspSize) );
349
279
 
350
280
  {
351
- const void* ptr = wksp->dtable;
281
+ const void* ptr = dtable;
352
282
  const FSE_DTableHeader* DTableH = (const FSE_DTableHeader*)ptr;
353
283
  const U32 fastMode = DTableH->fastMode;
354
284
 
355
285
  /* select fast mode (static) */
356
- if (fastMode) return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, wksp->dtable, 1);
357
- return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, wksp->dtable, 0);
286
+ if (fastMode) return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 1);
287
+ return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 0);
358
288
  }
359
289
  }
360
290
 
@@ -382,22 +312,4 @@ size_t FSE_decompress_wksp_bmi2(void* dst, size_t dstCapacity, const void* cSrc,
382
312
  return FSE_decompress_wksp_body_default(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize);
383
313
  }
384
314
 
385
-
386
- typedef FSE_DTable DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
387
-
388
- #ifndef ZSTD_NO_UNUSED_FUNCTIONS
389
- size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog) {
390
- U32 wksp[FSE_BUILD_DTABLE_WKSP_SIZE_U32(FSE_TABLELOG_ABSOLUTE_MAX, FSE_MAX_SYMBOL_VALUE)];
391
- return FSE_buildDTable_wksp(dt, normalizedCounter, maxSymbolValue, tableLog, wksp, sizeof(wksp));
392
- }
393
-
394
- size_t FSE_decompress(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize)
395
- {
396
- /* Static analyzer seems unable to understand this table will be properly initialized later */
397
- U32 wksp[FSE_DECOMPRESS_WKSP_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)];
398
- return FSE_decompress_wksp(dst, dstCapacity, cSrc, cSrcSize, FSE_MAX_TABLELOG, wksp, sizeof(wksp));
399
- }
400
- #endif
401
-
402
-
403
315
  #endif /* FSE_COMMONDEFS_ONLY */