zstdlib 0.11.0-x64-mingw-ucrt → 0.13.0-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +16 -0
  3. data/Rakefile +1 -1
  4. data/ext/zstdlib_c/extconf.rb +9 -4
  5. data/ext/zstdlib_c/ruby/zlib-3.3/zstdlib.c +5090 -0
  6. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/adler32.c +5 -27
  7. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/compress.c +5 -16
  8. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/crc32.c +94 -161
  9. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/deflate.c +362 -434
  10. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/deflate.h +43 -12
  11. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzclose.c +1 -3
  12. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzguts.h +13 -18
  13. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzlib.c +28 -85
  14. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzread.c +23 -73
  15. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/gzwrite.c +19 -65
  16. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/infback.c +17 -30
  17. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inffast.c +1 -4
  18. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inffast.h +1 -1
  19. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inflate.c +36 -102
  20. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inftrees.c +6 -11
  21. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inftrees.h +6 -6
  22. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/trees.c +290 -355
  23. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/uncompr.c +4 -12
  24. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zconf.h +23 -14
  25. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zlib.h +202 -199
  26. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zutil.c +18 -44
  27. data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/zutil.h +13 -33
  28. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/allocations.h +1 -1
  29. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/bitstream.h +49 -29
  30. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/compiler.h +114 -22
  31. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/cpu.h +36 -0
  32. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/debug.c +6 -0
  33. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/debug.h +20 -11
  34. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/error_private.h +45 -36
  35. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/fse.h +3 -2
  36. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/fse_decompress.c +19 -17
  37. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/huf.h +14 -1
  38. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/mem.h +0 -9
  39. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/pool.c +1 -1
  40. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/pool.h +1 -1
  41. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/portability_macros.h +2 -0
  42. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/threading.c +8 -2
  43. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/xxhash.c +5 -11
  44. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/xxhash.h +2341 -1007
  45. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/zstd_internal.h +5 -5
  46. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/fse_compress.c +8 -7
  47. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/huf_compress.c +54 -25
  48. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress.c +282 -161
  49. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_internal.h +29 -27
  50. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_superblock.c +224 -113
  51. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_cwksp.h +19 -13
  52. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_double_fast.c +17 -5
  53. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_double_fast.h +11 -0
  54. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_fast.c +14 -6
  55. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_lazy.c +129 -87
  56. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_lazy.h +103 -28
  57. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_ldm.c +8 -2
  58. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_opt.c +216 -112
  59. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_opt.h +31 -7
  60. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstdmt_compress.c +94 -79
  61. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/huf_decompress.c +188 -126
  62. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/huf_decompress_amd64.S +38 -19
  63. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_decompress.c +84 -32
  64. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_decompress_block.c +231 -208
  65. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_decompress_block.h +1 -1
  66. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_decompress_internal.h +2 -0
  67. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/zstd.h +129 -60
  68. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzclose.c +1 -3
  69. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzlib.c +20 -73
  70. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzread.c +17 -58
  71. data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzwrite.c +18 -58
  72. data/lib/3.1/zstdlib_c.so +0 -0
  73. data/lib/3.2/zstdlib_c.so +0 -0
  74. data/lib/3.3/zstdlib_c.so +0 -0
  75. metadata +105 -103
  76. /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/crc32.h +0 -0
  77. /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inffixed.h +0 -0
  78. /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/inflate.h +0 -0
  79. /data/ext/zstdlib_c/{zlib-1.2.12 → zlib-1.3.1}/trees.h +0 -0
  80. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/bits.h +0 -0
  81. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/entropy_common.c +0 -0
  82. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/error_private.c +0 -0
  83. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/threading.h +0 -0
  84. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/zstd_common.c +0 -0
  85. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/zstd_deps.h +0 -0
  86. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/common/zstd_trace.h +0 -0
  87. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/clevels.h +0 -0
  88. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/hist.c +0 -0
  89. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/hist.h +0 -0
  90. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_literals.c +0 -0
  91. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_literals.h +0 -0
  92. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_sequences.c +0 -0
  93. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_sequences.h +0 -0
  94. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_compress_superblock.h +0 -0
  95. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_fast.h +0 -0
  96. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_ldm.h +0 -0
  97. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstd_ldm_geartab.h +0 -0
  98. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/compress/zstdmt_compress.h +0 -0
  99. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_ddict.c +0 -0
  100. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/decompress/zstd_ddict.h +0 -0
  101. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/zdict.h +0 -0
  102. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/lib/zstd_errors.h +0 -0
  103. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzcompatibility.h +0 -0
  104. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/gzguts.h +0 -0
  105. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/zstd_zlibwrapper.c +0 -0
  106. /data/ext/zstdlib_c/{zstd-1.5.5 → zstd-1.5.6}/zlibWrapper/zstd_zlibwrapper.h +0 -0
@@ -35,6 +35,7 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
35
35
  U32 f7b = 0;
36
36
  U32 f7c = 0;
37
37
  #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
38
+ #if !defined(__clang__)
38
39
  int reg[4];
39
40
  __cpuid((int*)reg, 0);
40
41
  {
@@ -50,6 +51,41 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
50
51
  f7c = (U32)reg[2];
51
52
  }
52
53
  }
54
+ #else
55
+ /* Clang compiler has a bug (fixed in https://reviews.llvm.org/D101338) in
56
+ * which the `__cpuid` intrinsic does not save and restore `rbx` as it needs
57
+ * to due to being a reserved register. So in that case, do the `cpuid`
58
+ * ourselves. Clang supports inline assembly anyway.
59
+ */
60
+ U32 n;
61
+ __asm__(
62
+ "pushq %%rbx\n\t"
63
+ "cpuid\n\t"
64
+ "popq %%rbx\n\t"
65
+ : "=a"(n)
66
+ : "a"(0)
67
+ : "rcx", "rdx");
68
+ if (n >= 1) {
69
+ U32 f1a;
70
+ __asm__(
71
+ "pushq %%rbx\n\t"
72
+ "cpuid\n\t"
73
+ "popq %%rbx\n\t"
74
+ : "=a"(f1a), "=c"(f1c), "=d"(f1d)
75
+ : "a"(1)
76
+ :);
77
+ }
78
+ if (n >= 7) {
79
+ __asm__(
80
+ "pushq %%rbx\n\t"
81
+ "cpuid\n\t"
82
+ "movq %%rbx, %%rax\n\t"
83
+ "popq %%rbx"
84
+ : "=a"(f7b), "=c"(f7c)
85
+ : "a"(7), "c"(0)
86
+ : "rdx");
87
+ }
88
+ #endif
53
89
  #elif defined(__i386__) && defined(__PIC__) && !defined(__clang__) && defined(__GNUC__)
54
90
  /* The following block like the normal cpuid branch below, but gcc
55
91
  * reserves ebx for use of its pic register so we must specially
@@ -21,4 +21,10 @@
21
21
 
22
22
  #include "debug.h"
23
23
 
24
+ #if !defined(ZSTD_LINUX_KERNEL) || (DEBUGLEVEL>=2)
25
+ /* We only use this when DEBUGLEVEL>=2, but we get -Werror=pedantic errors if a
26
+ * translation unit is empty. So remove this from Linux kernel builds, but
27
+ * otherwise just leave it in.
28
+ */
24
29
  int g_debuglevel = DEBUGLEVEL;
30
+ #endif
@@ -85,18 +85,27 @@ extern int g_debuglevel; /* the variable is only declared,
85
85
  It's useful when enabling very verbose levels
86
86
  on selective conditions (such as position in src) */
87
87
 
88
- # define RAWLOG(l, ...) { \
89
- if (l<=g_debuglevel) { \
90
- ZSTD_DEBUG_PRINT(__VA_ARGS__); \
91
- } }
92
- # define DEBUGLOG(l, ...) { \
93
- if (l<=g_debuglevel) { \
94
- ZSTD_DEBUG_PRINT(__FILE__ ": " __VA_ARGS__); \
95
- ZSTD_DEBUG_PRINT(" \n"); \
96
- } }
88
+ # define RAWLOG(l, ...) \
89
+ do { \
90
+ if (l<=g_debuglevel) { \
91
+ ZSTD_DEBUG_PRINT(__VA_ARGS__); \
92
+ } \
93
+ } while (0)
94
+
95
+ #define STRINGIFY(x) #x
96
+ #define TOSTRING(x) STRINGIFY(x)
97
+ #define LINE_AS_STRING TOSTRING(__LINE__)
98
+
99
+ # define DEBUGLOG(l, ...) \
100
+ do { \
101
+ if (l<=g_debuglevel) { \
102
+ ZSTD_DEBUG_PRINT(__FILE__ ":" LINE_AS_STRING ": " __VA_ARGS__); \
103
+ ZSTD_DEBUG_PRINT(" \n"); \
104
+ } \
105
+ } while (0)
97
106
  #else
98
- # define RAWLOG(l, ...) {} /* disabled */
99
- # define DEBUGLOG(l, ...) {} /* disabled */
107
+ # define RAWLOG(l, ...) do { } while (0) /* disabled */
108
+ # define DEBUGLOG(l, ...) do { } while (0) /* disabled */
100
109
  #endif
101
110
 
102
111
 
@@ -60,8 +60,13 @@ ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
60
60
  ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
61
61
 
62
62
  /* 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); }
63
+ #define CHECK_V_F(e, f) \
64
+ size_t const e = f; \
65
+ do { \
66
+ if (ERR_isError(e)) \
67
+ return e; \
68
+ } while (0)
69
+ #define CHECK_F(f) do { CHECK_V_F(_var_err__, f); } while (0)
65
70
 
66
71
 
67
72
  /*-****************************************
@@ -95,10 +100,12 @@ void _force_has_format_string(const char *format, ...) {
95
100
  * We want to force this function invocation to be syntactically correct, but
96
101
  * we don't want to force runtime evaluation of its arguments.
97
102
  */
98
- #define _FORCE_HAS_FORMAT_STRING(...) \
99
- if (0) { \
100
- _force_has_format_string(__VA_ARGS__); \
101
- }
103
+ #define _FORCE_HAS_FORMAT_STRING(...) \
104
+ do { \
105
+ if (0) { \
106
+ _force_has_format_string(__VA_ARGS__); \
107
+ } \
108
+ } while (0)
102
109
 
103
110
  #define ERR_QUOTE(str) #str
104
111
 
@@ -109,48 +116,50 @@ void _force_has_format_string(const char *format, ...) {
109
116
  * In order to do that (particularly, printing the conditional that failed),
110
117
  * this can't just wrap RETURN_ERROR().
111
118
  */
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
- }
119
+ #define RETURN_ERROR_IF(cond, err, ...) \
120
+ do { \
121
+ if (cond) { \
122
+ RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
123
+ __FILE__, __LINE__, ERR_QUOTE(cond), ERR_QUOTE(ERROR(err))); \
124
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
125
+ RAWLOG(3, ": " __VA_ARGS__); \
126
+ RAWLOG(3, "\n"); \
127
+ return ERROR(err); \
128
+ } \
129
+ } while (0)
121
130
 
122
131
  /**
123
132
  * Unconditionally return the specified error.
124
133
  *
125
134
  * In debug modes, prints additional information.
126
135
  */
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);
136
+ #define RETURN_ERROR(err, ...) \
137
+ do { \
138
+ RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
139
+ __FILE__, __LINE__, ERR_QUOTE(ERROR(err))); \
140
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
141
+ RAWLOG(3, ": " __VA_ARGS__); \
142
+ RAWLOG(3, "\n"); \
143
+ return ERROR(err); \
144
+ } while(0)
136
145
 
137
146
  /**
138
147
  * If the provided expression evaluates to an error code, returns that error code.
139
148
  *
140
149
  * In debug modes, prints additional information.
141
150
  */
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);
151
+ #define FORWARD_IF_ERROR(err, ...) \
152
+ do { \
153
+ size_t const err_code = (err); \
154
+ if (ERR_isError(err_code)) { \
155
+ RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
156
+ __FILE__, __LINE__, ERR_QUOTE(err), ERR_getErrorName(err_code)); \
157
+ _FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
158
+ RAWLOG(3, ": " __VA_ARGS__); \
159
+ RAWLOG(3, "\n"); \
160
+ return err_code; \
161
+ } \
162
+ } while(0)
154
163
 
155
164
  #if defined (__cplusplus)
156
165
  }
@@ -229,6 +229,7 @@ If there is an error, the function will return an error code, which can be teste
229
229
 
230
230
  #endif /* FSE_H */
231
231
 
232
+
232
233
  #if defined(FSE_STATIC_LINKING_ONLY) && !defined(FSE_H_FSE_STATIC_LINKING_ONLY)
233
234
  #define FSE_H_FSE_STATIC_LINKING_ONLY
234
235
 
@@ -464,13 +465,13 @@ MEM_STATIC void FSE_encodeSymbol(BIT_CStream_t* bitC, FSE_CState_t* statePtr, un
464
465
  FSE_symbolCompressionTransform const symbolTT = ((const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol];
465
466
  const U16* const stateTable = (const U16*)(statePtr->stateTable);
466
467
  U32 const nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16);
467
- BIT_addBits(bitC, statePtr->value, nbBitsOut);
468
+ BIT_addBits(bitC, (size_t)statePtr->value, nbBitsOut);
468
469
  statePtr->value = stateTable[ (statePtr->value >> nbBitsOut) + symbolTT.deltaFindState];
469
470
  }
470
471
 
471
472
  MEM_STATIC void FSE_flushCState(BIT_CStream_t* bitC, const FSE_CState_t* statePtr)
472
473
  {
473
- BIT_addBits(bitC, statePtr->value, statePtr->stateLog);
474
+ BIT_addBits(bitC, (size_t)statePtr->value, statePtr->stateLog);
474
475
  BIT_flushBits(bitC);
475
476
  }
476
477
 
@@ -22,8 +22,7 @@
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 */
27
26
  #include "bits.h" /* ZSTD_highbit32 */
28
27
 
29
28
 
@@ -84,7 +83,7 @@ static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCo
84
83
  symbolNext[s] = 1;
85
84
  } else {
86
85
  if (normalizedCounter[s] >= largeLimit) DTableH.fastMode=0;
87
- symbolNext[s] = normalizedCounter[s];
86
+ symbolNext[s] = (U16)normalizedCounter[s];
88
87
  } } }
89
88
  ZSTD_memcpy(dt, &DTableH, sizeof(DTableH));
90
89
  }
@@ -99,8 +98,7 @@ static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCo
99
98
  * all symbols have counts <= 8. We ensure we have 8 bytes at the end of
100
99
  * our buffer to handle the over-write.
101
100
  */
102
- {
103
- U64 const add = 0x0101010101010101ull;
101
+ { U64 const add = 0x0101010101010101ull;
104
102
  size_t pos = 0;
105
103
  U64 sv = 0;
106
104
  U32 s;
@@ -111,9 +109,8 @@ static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCo
111
109
  for (i = 8; i < n; i += 8) {
112
110
  MEM_write64(spread + pos + i, sv);
113
111
  }
114
- pos += n;
115
- }
116
- }
112
+ pos += (size_t)n;
113
+ } }
117
114
  /* Now we spread those positions across the table.
118
115
  * The benefit of doing it in two stages is that we avoid the
119
116
  * variable size inner loop, which caused lots of branch misses.
@@ -232,12 +229,12 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
232
229
  break;
233
230
  } }
234
231
 
235
- return op-ostart;
232
+ assert(op >= ostart);
233
+ return (size_t)(op-ostart);
236
234
  }
237
235
 
238
236
  typedef struct {
239
237
  short ncount[FSE_MAX_SYMBOL_VALUE + 1];
240
- FSE_DTable dtable[1]; /* Dynamically sized */
241
238
  } FSE_DecompressWksp;
242
239
 
243
240
 
@@ -252,13 +249,18 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_wksp_body(
252
249
  unsigned tableLog;
253
250
  unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
254
251
  FSE_DecompressWksp* const wksp = (FSE_DecompressWksp*)workSpace;
252
+ size_t const dtablePos = sizeof(FSE_DecompressWksp) / sizeof(FSE_DTable);
253
+ FSE_DTable* const dtable = (FSE_DTable*)workSpace + dtablePos;
255
254
 
256
- DEBUG_STATIC_ASSERT((FSE_MAX_SYMBOL_VALUE + 1) % 2 == 0);
255
+ FSE_STATIC_ASSERT((FSE_MAX_SYMBOL_VALUE + 1) % 2 == 0);
257
256
  if (wkspSize < sizeof(*wksp)) return ERROR(GENERIC);
258
257
 
258
+ /* correct offset to dtable depends on this property */
259
+ FSE_STATIC_ASSERT(sizeof(FSE_DecompressWksp) % sizeof(FSE_DTable) == 0);
260
+
259
261
  /* normal FSE decoding mode */
260
- {
261
- size_t const NCountLength = FSE_readNCount_bmi2(wksp->ncount, &maxSymbolValue, &tableLog, istart, cSrcSize, bmi2);
262
+ { size_t const NCountLength =
263
+ FSE_readNCount_bmi2(wksp->ncount, &maxSymbolValue, &tableLog, istart, cSrcSize, bmi2);
262
264
  if (FSE_isError(NCountLength)) return NCountLength;
263
265
  if (tableLog > maxLog) return ERROR(tableLog_tooLarge);
264
266
  assert(NCountLength <= cSrcSize);
@@ -271,16 +273,16 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_wksp_body(
271
273
  workSpace = (BYTE*)workSpace + sizeof(*wksp) + FSE_DTABLE_SIZE(tableLog);
272
274
  wkspSize -= sizeof(*wksp) + FSE_DTABLE_SIZE(tableLog);
273
275
 
274
- CHECK_F( FSE_buildDTable_internal(wksp->dtable, wksp->ncount, maxSymbolValue, tableLog, workSpace, wkspSize) );
276
+ CHECK_F( FSE_buildDTable_internal(dtable, wksp->ncount, maxSymbolValue, tableLog, workSpace, wkspSize) );
275
277
 
276
278
  {
277
- const void* ptr = wksp->dtable;
279
+ const void* ptr = dtable;
278
280
  const FSE_DTableHeader* DTableH = (const FSE_DTableHeader*)ptr;
279
281
  const U32 fastMode = DTableH->fastMode;
280
282
 
281
283
  /* select fast mode (static) */
282
- if (fastMode) return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, wksp->dtable, 1);
283
- return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, wksp->dtable, 0);
284
+ if (fastMode) return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 1);
285
+ return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 0);
284
286
  }
285
287
  }
286
288
 
@@ -197,9 +197,22 @@ size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void
197
197
 
198
198
  /** HUF_getNbBitsFromCTable() :
199
199
  * Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
200
- * Note 1 : is not inlined, as HUF_CElt definition is private */
200
+ * Note 1 : If symbolValue > HUF_readCTableHeader(symbolTable).maxSymbolValue, returns 0
201
+ * Note 2 : is not inlined, as HUF_CElt definition is private
202
+ */
201
203
  U32 HUF_getNbBitsFromCTable(const HUF_CElt* symbolTable, U32 symbolValue);
202
204
 
205
+ typedef struct {
206
+ BYTE tableLog;
207
+ BYTE maxSymbolValue;
208
+ BYTE unused[sizeof(size_t) - 2];
209
+ } HUF_CTableHeader;
210
+
211
+ /** HUF_readCTableHeader() :
212
+ * @returns The header from the CTable specifying the tableLog and the maxSymbolValue.
213
+ */
214
+ HUF_CTableHeader HUF_readCTableHeader(HUF_CElt const* ctable);
215
+
203
216
  /*
204
217
  * HUF_decompress() does the following:
205
218
  * 1. select the decompression algorithm (X1, X2) based on pre-computed heuristics
@@ -31,15 +31,6 @@ extern "C" {
31
31
  # include <stdlib.h> /* _byteswap_ulong */
32
32
  # include <intrin.h> /* _byteswap_* */
33
33
  #endif
34
- #if defined(__GNUC__)
35
- # define MEM_STATIC static __inline __attribute__((unused))
36
- #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
37
- # define MEM_STATIC static inline
38
- #elif defined(_MSC_VER)
39
- # define MEM_STATIC static __inline
40
- #else
41
- # define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
42
- #endif
43
34
 
44
35
  /*-**************************************************************
45
36
  * Basic Types
@@ -223,7 +223,7 @@ static int POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
223
223
  { ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customCalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
224
224
  if (!threadPool) return 1;
225
225
  /* replace existing thread pool */
226
- ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(*threadPool));
226
+ ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(ZSTD_pthread_t));
227
227
  ZSTD_customFree(ctx->threads, ctx->customMem);
228
228
  ctx->threads = threadPool;
229
229
  /* Initialize additional threads */
@@ -47,7 +47,7 @@ void POOL_joinJobs(POOL_ctx* ctx);
47
47
  /*! POOL_resize() :
48
48
  * Expands or shrinks pool's number of threads.
49
49
  * This is more efficient than releasing + creating a new context,
50
- * since it tries to preserve and re-use existing threads.
50
+ * since it tries to preserve and reuse existing threads.
51
51
  * `numThreads` must be at least 1.
52
52
  * @return : 0 when resize was successful,
53
53
  * !0 (typically 1) if there is an error.
@@ -68,6 +68,8 @@
68
68
  /* Mark the internal assembly functions as hidden */
69
69
  #ifdef __ELF__
70
70
  # define ZSTD_HIDE_ASM_FUNCTION(func) .hidden func
71
+ #elif defined(__APPLE__)
72
+ # define ZSTD_HIDE_ASM_FUNCTION(func) .private_extern func
71
73
  #else
72
74
  # define ZSTD_HIDE_ASM_FUNCTION(func)
73
75
  #endif
@@ -73,10 +73,12 @@ int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
73
73
  ZSTD_thread_params_t thread_param;
74
74
  (void)unused;
75
75
 
76
+ if (thread==NULL) return -1;
77
+ *thread = NULL;
78
+
76
79
  thread_param.start_routine = start_routine;
77
80
  thread_param.arg = arg;
78
81
  thread_param.initialized = 0;
79
- *thread = NULL;
80
82
 
81
83
  /* Setup thread initialization synchronization */
82
84
  if(ZSTD_pthread_cond_init(&thread_param.initialized_cond, NULL)) {
@@ -91,7 +93,7 @@ int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
91
93
 
92
94
  /* Spawn thread */
93
95
  *thread = (HANDLE)_beginthreadex(NULL, 0, worker, &thread_param, 0, NULL);
94
- if (!thread) {
96
+ if (*thread==NULL) {
95
97
  ZSTD_pthread_mutex_destroy(&thread_param.initialized_mutex);
96
98
  ZSTD_pthread_cond_destroy(&thread_param.initialized_cond);
97
99
  return errno;
@@ -137,6 +139,7 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread)
137
139
 
138
140
  int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
139
141
  {
142
+ assert(mutex != NULL);
140
143
  *mutex = (pthread_mutex_t*)ZSTD_malloc(sizeof(pthread_mutex_t));
141
144
  if (!*mutex)
142
145
  return 1;
@@ -145,6 +148,7 @@ int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t con
145
148
 
146
149
  int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
147
150
  {
151
+ assert(mutex != NULL);
148
152
  if (!*mutex)
149
153
  return 0;
150
154
  {
@@ -156,6 +160,7 @@ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
156
160
 
157
161
  int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
158
162
  {
163
+ assert(cond != NULL);
159
164
  *cond = (pthread_cond_t*)ZSTD_malloc(sizeof(pthread_cond_t));
160
165
  if (!*cond)
161
166
  return 1;
@@ -164,6 +169,7 @@ int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const*
164
169
 
165
170
  int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond)
166
171
  {
172
+ assert(cond != NULL);
167
173
  if (!*cond)
168
174
  return 0;
169
175
  {
@@ -1,24 +1,18 @@
1
1
  /*
2
- * xxHash - Fast Hash algorithm
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * You can contact the author at :
6
- * - xxHash homepage: https://cyan4973.github.io/xxHash/
7
- * - xxHash source repository : https://github.com/Cyan4973/xxHash
2
+ * xxHash - Extremely Fast Hash algorithm
3
+ * Copyright (c) Yann Collet - Meta Platforms, Inc
8
4
  *
9
5
  * This source code is licensed under both the BSD-style license (found in the
10
6
  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11
7
  * in the COPYING file in the root directory of this source tree).
12
8
  * You may select, at your option, one of the above-listed licenses.
13
- */
14
-
15
-
9
+ */
16
10
 
17
11
  /*
18
12
  * xxhash.c instantiates functions defined in xxhash.h
19
13
  */
20
14
 
21
- #define XXH_STATIC_LINKING_ONLY /* access advanced declarations */
22
- #define XXH_IMPLEMENTATION /* access definitions */
15
+ #define XXH_STATIC_LINKING_ONLY /* access advanced declarations */
16
+ #define XXH_IMPLEMENTATION /* access definitions */
23
17
 
24
18
  #include "xxhash.h"