zstdlib 0.7.0-x64-mingw32 → 0.10.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +20 -0
  3. data/README.md +7 -1
  4. data/Rakefile +38 -8
  5. data/ext/{zstdlib → zstdlib_c}/extconf.rb +11 -6
  6. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.2/zstdlib.c +2 -2
  7. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.3/zstdlib.c +2 -2
  8. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.4/zstdlib.c +2 -2
  9. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.5/zstdlib.c +2 -2
  10. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.6/zstdlib.c +2 -2
  11. data/ext/{zstdlib → zstdlib_c}/ruby/zlib-2.7/zstdlib.c +2 -2
  12. data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
  13. data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
  14. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/adler32.c +0 -0
  15. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/compress.c +0 -0
  16. data/ext/zstdlib_c/zlib-1.2.12/crc32.c +1116 -0
  17. data/ext/zstdlib_c/zlib-1.2.12/crc32.h +9446 -0
  18. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/deflate.c +78 -30
  19. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/deflate.h +12 -15
  20. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzclose.c +0 -0
  21. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzguts.h +3 -2
  22. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzlib.c +5 -3
  23. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzread.c +5 -7
  24. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/gzwrite.c +25 -13
  25. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/infback.c +2 -1
  26. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inffast.c +14 -14
  27. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inffast.h +0 -0
  28. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inffixed.h +0 -0
  29. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inflate.c +39 -8
  30. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inflate.h +3 -2
  31. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inftrees.c +3 -3
  32. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/inftrees.h +0 -0
  33. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/trees.c +27 -48
  34. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/trees.h +0 -0
  35. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/uncompr.c +0 -0
  36. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zconf.h +0 -0
  37. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zlib.h +123 -100
  38. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zutil.c +2 -2
  39. data/ext/{zstdlib/zlib-1.2.11 → zstdlib_c/zlib-1.2.12}/zutil.h +12 -9
  40. data/ext/{zstdlib → zstdlib_c}/zlib.mk +0 -0
  41. data/ext/{zstdlib → zstdlib_c}/zlibwrapper/zlibwrapper.c +1 -5
  42. data/ext/{zstdlib → zstdlib_c}/zlibwrapper.mk +0 -0
  43. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/bitstream.h +46 -22
  44. data/ext/zstdlib_c/zstd-1.5.2/lib/common/compiler.h +335 -0
  45. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/cpu.h +1 -3
  46. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/debug.c +1 -1
  47. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/debug.h +12 -19
  48. data/ext/zstdlib_c/zstd-1.5.2/lib/common/entropy_common.c +368 -0
  49. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/error_private.c +2 -1
  50. data/ext/zstdlib_c/zstd-1.5.2/lib/common/error_private.h +159 -0
  51. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/fse.h +41 -12
  52. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/fse_decompress.c +139 -22
  53. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/huf.h +47 -23
  54. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/mem.h +87 -98
  55. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/pool.c +34 -23
  56. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/pool.h +4 -4
  57. data/ext/zstdlib_c/zstd-1.5.2/lib/common/portability_macros.h +137 -0
  58. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/threading.c +6 -5
  59. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/threading.h +0 -0
  60. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.c +24 -0
  61. data/ext/zstdlib_c/zstd-1.5.2/lib/common/xxhash.h +5686 -0
  62. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_common.c +10 -10
  63. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_deps.h +111 -0
  64. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/common/zstd_internal.h +191 -145
  65. data/ext/zstdlib_c/zstd-1.5.2/lib/common/zstd_trace.h +163 -0
  66. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/clevels.h +134 -0
  67. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/fse_compress.c +89 -46
  68. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.c +27 -29
  69. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/hist.h +2 -2
  70. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/huf_compress.c +1370 -0
  71. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress.c +2917 -868
  72. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_internal.h +458 -125
  73. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.c +12 -11
  74. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_literals.h +4 -2
  75. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.c +41 -18
  76. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_sequences.h +1 -1
  77. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_superblock.c +26 -298
  78. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_compress_superblock.h +1 -1
  79. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_cwksp.h +234 -83
  80. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.c +313 -138
  81. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_double_fast.h +1 -1
  82. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.c +329 -150
  83. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_fast.h +1 -1
  84. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.c +2104 -0
  85. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_lazy.h +125 -0
  86. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.c +321 -216
  87. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_ldm.h +9 -2
  88. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstd_ldm_geartab.h +106 -0
  89. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.c +412 -166
  90. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstd_opt.h +1 -1
  91. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/compress/zstdmt_compress.c +169 -453
  92. data/ext/zstdlib_c/zstd-1.5.2/lib/compress/zstdmt_compress.h +113 -0
  93. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/huf_decompress.c +1044 -403
  94. data/ext/zstdlib_c/zstd-1.5.2/lib/decompress/huf_decompress_amd64.S +585 -0
  95. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.c +9 -9
  96. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_ddict.h +2 -2
  97. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress.c +450 -105
  98. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.c +913 -273
  99. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_block.h +14 -5
  100. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/decompress/zstd_decompress_internal.h +59 -12
  101. data/ext/zstdlib_c/zstd-1.5.2/lib/zdict.h +452 -0
  102. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/lib/zstd.h +699 -214
  103. data/ext/{zstdlib/zstd-1.4.5/lib/common → zstdlib_c/zstd-1.5.2/lib}/zstd_errors.h +2 -1
  104. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzclose.c +0 -0
  105. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzcompatibility.h +1 -1
  106. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzguts.h +0 -0
  107. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzlib.c +0 -0
  108. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzread.c +0 -0
  109. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/gzwrite.c +0 -0
  110. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.c +133 -44
  111. data/ext/{zstdlib/zstd-1.4.5 → zstdlib_c/zstd-1.5.2}/zlibWrapper/zstd_zlibwrapper.h +1 -1
  112. data/ext/zstdlib_c/zstd.mk +15 -0
  113. data/lib/2.4/zstdlib_c.so +0 -0
  114. data/lib/2.5/zstdlib_c.so +0 -0
  115. data/lib/2.6/zstdlib_c.so +0 -0
  116. data/lib/2.7/zstdlib_c.so +0 -0
  117. data/lib/3.0/zstdlib_c.so +0 -0
  118. data/lib/zstdlib.rb +2 -2
  119. metadata +124 -116
  120. data/ext/zstdlib/zlib-1.2.11/crc32.c +0 -442
  121. data/ext/zstdlib/zlib-1.2.11/crc32.h +0 -441
  122. data/ext/zstdlib/zstd-1.4.5/lib/common/compiler.h +0 -175
  123. data/ext/zstdlib/zstd-1.4.5/lib/common/entropy_common.c +0 -216
  124. data/ext/zstdlib/zstd-1.4.5/lib/common/error_private.h +0 -80
  125. data/ext/zstdlib/zstd-1.4.5/lib/common/xxhash.c +0 -864
  126. data/ext/zstdlib/zstd-1.4.5/lib/common/xxhash.h +0 -285
  127. data/ext/zstdlib/zstd-1.4.5/lib/compress/huf_compress.c +0 -798
  128. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_lazy.c +0 -1138
  129. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstd_lazy.h +0 -67
  130. data/ext/zstdlib/zstd-1.4.5/lib/compress/zstdmt_compress.h +0 -192
  131. data/ext/zstdlib/zstd.mk +0 -14
  132. data/lib/2.2/zstdlib.so +0 -0
  133. data/lib/2.3/zstdlib.so +0 -0
  134. data/lib/2.4/zstdlib.so +0 -0
  135. data/lib/2.5/zstdlib.so +0 -0
  136. data/lib/2.6/zstdlib.so +0 -0
  137. data/lib/2.7/zstdlib.so +0 -0
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -77,6 +77,7 @@ typedef enum {
77
77
  ZSTD_error_frameIndex_tooLarge = 100,
78
78
  ZSTD_error_seekableIO = 102,
79
79
  ZSTD_error_dstBuffer_wrong = 104,
80
+ ZSTD_error_srcBuffer_wrong = 105,
80
81
  ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
81
82
  } ZSTD_ErrorCode;
82
83
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-2020, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-2020, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -19,13 +19,13 @@
19
19
  #include <stdlib.h>
20
20
  #include <stdio.h> /* vsprintf */
21
21
  #include <stdarg.h> /* va_list, for z_gzprintf */
22
+ #include <string.h>
22
23
  #define NO_DUMMY_DECL
23
24
  #define ZLIB_CONST
24
25
  #include <zlib.h> /* without #define Z_PREFIX */
25
26
  #include "zstd_zlibwrapper.h"
26
- #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_isFrame, ZSTD_MAGICNUMBER */
27
+ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_isFrame, ZSTD_MAGICNUMBER, ZSTD_customMem */
27
28
  #include "zstd.h"
28
- #include "zstd_internal.h" /* ZSTD_malloc, ZSTD_free */
29
29
 
30
30
 
31
31
  /* === Constants === */
@@ -42,6 +42,45 @@
42
42
  #define FINISH_WITH_GZ_ERR(msg) { (void)msg; return Z_STREAM_ERROR; }
43
43
  #define FINISH_WITH_NULL_ERR(msg) { (void)msg; return NULL; }
44
44
 
45
+ /* === Utility === */
46
+
47
+ #define MIN(x,y) ((x) < (y) ? (x) : (y))
48
+
49
+ static unsigned ZWRAP_isLittleEndian(void)
50
+ {
51
+ const union { unsigned u; char c[4]; } one = { 1 }; /* don't use static : performance detrimental */
52
+ return one.c[0];
53
+ }
54
+
55
+ #ifndef __has_builtin
56
+ # define __has_builtin(x) 0
57
+ #endif
58
+
59
+ static unsigned ZWRAP_swap32(unsigned in)
60
+ {
61
+ #if defined(_MSC_VER) /* Visual Studio */
62
+ return _byteswap_ulong(in);
63
+ #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \
64
+ || (defined(__clang__) && __has_builtin(__builtin_bswap32))
65
+ return __builtin_bswap32(in);
66
+ #else
67
+ return ((in << 24) & 0xff000000 ) |
68
+ ((in << 8) & 0x00ff0000 ) |
69
+ ((in >> 8) & 0x0000ff00 ) |
70
+ ((in >> 24) & 0x000000ff );
71
+ #endif
72
+ }
73
+
74
+ static unsigned ZWRAP_readLE32(const void* ptr)
75
+ {
76
+ unsigned value;
77
+ memcpy(&value, ptr, sizeof(value));
78
+ if (ZWRAP_isLittleEndian())
79
+ return value;
80
+ else
81
+ return ZWRAP_swap32(value);
82
+ }
83
+
45
84
 
46
85
  /* === Wrapper === */
47
86
  static int g_ZWRAP_useZSTDcompression = ZWRAP_USE_ZSTD; /* 0 = don't use ZSTD */
@@ -64,8 +103,6 @@ const char * zstdVersion(void) { return ZSTD_VERSION_STRING; }
64
103
 
65
104
  ZEXTERN const char * ZEXPORT z_zlibVersion OF((void)) { return zlibVersion(); }
66
105
 
67
-
68
-
69
106
  static void* ZWRAP_allocFunction(void* opaque, size_t size)
70
107
  {
71
108
  z_streamp strm = (z_streamp) opaque;
@@ -81,6 +118,35 @@ static void ZWRAP_freeFunction(void* opaque, void* address)
81
118
  /* if (address) LOG_WRAPPERC("ZWRAP free %p \n", address); */
82
119
  }
83
120
 
121
+ static void* ZWRAP_customMalloc(size_t size, ZSTD_customMem customMem)
122
+ {
123
+ if (customMem.customAlloc)
124
+ return customMem.customAlloc(customMem.opaque, size);
125
+ return malloc(size);
126
+ }
127
+
128
+ static void* ZWRAP_customCalloc(size_t size, ZSTD_customMem customMem)
129
+ {
130
+ if (customMem.customAlloc) {
131
+ /* calloc implemented as malloc+memset;
132
+ * not as efficient as calloc, but next best guess for custom malloc */
133
+ void* const ptr = customMem.customAlloc(customMem.opaque, size);
134
+ memset(ptr, 0, size);
135
+ return ptr;
136
+ }
137
+ return calloc(1, size);
138
+ }
139
+
140
+ static void ZWRAP_customFree(void* ptr, ZSTD_customMem customMem)
141
+ {
142
+ if (ptr!=NULL) {
143
+ if (customMem.customFree)
144
+ customMem.customFree(customMem.opaque, ptr);
145
+ else
146
+ free(ptr);
147
+ }
148
+ }
149
+
84
150
 
85
151
 
86
152
  /* === Compression === */
@@ -107,7 +173,7 @@ static size_t ZWRAP_freeCCtx(ZWRAP_CCtx* zwc)
107
173
  {
108
174
  if (zwc==NULL) return 0; /* support free on NULL */
109
175
  ZSTD_freeCStream(zwc->zbc);
110
- ZSTD_free(zwc, zwc->customMem);
176
+ ZWRAP_customFree(zwc, zwc->customMem);
111
177
  return 0;
112
178
  }
113
179
 
@@ -115,20 +181,19 @@ static size_t ZWRAP_freeCCtx(ZWRAP_CCtx* zwc)
115
181
  static ZWRAP_CCtx* ZWRAP_createCCtx(z_streamp strm)
116
182
  {
117
183
  ZWRAP_CCtx* zwc;
184
+ ZSTD_customMem customMem = { NULL, NULL, NULL };
118
185
 
119
186
  if (strm->zalloc && strm->zfree) {
120
- zwc = (ZWRAP_CCtx*)strm->zalloc(strm->opaque, 1, sizeof(ZWRAP_CCtx));
121
- if (zwc==NULL) return NULL;
122
- memset(zwc, 0, sizeof(ZWRAP_CCtx));
123
- memcpy(&zwc->allocFunc, strm, sizeof(z_stream));
124
- { ZSTD_customMem ZWRAP_customMem = { ZWRAP_allocFunction, ZWRAP_freeFunction, NULL };
125
- ZWRAP_customMem.opaque = &zwc->allocFunc;
126
- zwc->customMem = ZWRAP_customMem;
127
- }
128
- } else {
129
- zwc = (ZWRAP_CCtx*)calloc(1, sizeof(*zwc));
130
- if (zwc==NULL) return NULL;
187
+ customMem.customAlloc = ZWRAP_allocFunction;
188
+ customMem.customFree = ZWRAP_freeFunction;
131
189
  }
190
+ customMem.opaque = strm;
191
+
192
+ zwc = (ZWRAP_CCtx*)ZWRAP_customCalloc(sizeof(ZWRAP_CCtx), customMem);
193
+ if (zwc == NULL) return NULL;
194
+ zwc->allocFunc = *strm;
195
+ customMem.opaque = &zwc->allocFunc;
196
+ zwc->customMem = customMem;
132
197
 
133
198
  return zwc;
134
199
  }
@@ -140,12 +205,21 @@ static int ZWRAP_initializeCStream(ZWRAP_CCtx* zwc, const void* dict, size_t dic
140
205
  if (zwc == NULL || zwc->zbc == NULL) return Z_STREAM_ERROR;
141
206
 
142
207
  if (!pledgedSrcSize) pledgedSrcSize = zwc->pledgedSrcSize;
143
- { ZSTD_parameters const params = ZSTD_getParams(zwc->compressionLevel, pledgedSrcSize, dictSize);
144
- size_t initErr;
208
+ { unsigned initErr = 0;
209
+ ZSTD_parameters const params = ZSTD_getParams(zwc->compressionLevel, pledgedSrcSize, dictSize);
210
+ ZSTD_CCtx_params* cctxParams = ZSTD_createCCtxParams();
211
+ if (!cctxParams) return Z_STREAM_ERROR;
145
212
  LOG_WRAPPERC("pledgedSrcSize=%d windowLog=%d chainLog=%d hashLog=%d searchLog=%d minMatch=%d strategy=%d\n",
146
213
  (int)pledgedSrcSize, params.cParams.windowLog, params.cParams.chainLog, params.cParams.hashLog, params.cParams.searchLog, params.cParams.minMatch, params.cParams.strategy);
147
- initErr = ZSTD_initCStream_advanced(zwc->zbc, dict, dictSize, params, pledgedSrcSize);
148
- if (ZSTD_isError(initErr)) return Z_STREAM_ERROR;
214
+
215
+ initErr |= ZSTD_isError(ZSTD_CCtx_reset(zwc->zbc, ZSTD_reset_session_only));
216
+ initErr |= ZSTD_isError(ZSTD_CCtxParams_init_advanced(cctxParams, params));
217
+ initErr |= ZSTD_isError(ZSTD_CCtx_setParametersUsingCCtxParams(zwc->zbc, cctxParams));
218
+ initErr |= ZSTD_isError(ZSTD_CCtx_setPledgedSrcSize(zwc->zbc, pledgedSrcSize));
219
+ initErr |= ZSTD_isError(ZSTD_CCtx_loadDictionary(zwc->zbc, dict, dictSize));
220
+
221
+ ZSTD_freeCCtxParams(cctxParams);
222
+ if (initErr) return Z_STREAM_ERROR;
149
223
  }
150
224
 
151
225
  return Z_OK;
@@ -181,6 +255,10 @@ int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize)
181
255
  return Z_OK;
182
256
  }
183
257
 
258
+ static struct internal_state* convert_into_sis(void* ptr)
259
+ {
260
+ return (struct internal_state*) ptr;
261
+ }
184
262
 
185
263
  ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
186
264
  const char *version, int stream_size))
@@ -201,7 +279,7 @@ ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
201
279
  zwc->streamEnd = 0;
202
280
  zwc->totalInBytes = 0;
203
281
  zwc->compressionLevel = level;
204
- strm->state = (struct internal_state*) zwc; /* use state which in not used by user */
282
+ strm->state = convert_into_sis(zwc); /* use state which in not used by user */
205
283
  strm->total_in = 0;
206
284
  strm->total_out = 0;
207
285
  strm->adler = 0;
@@ -303,9 +381,15 @@ ZEXTERN int ZEXPORT z_deflate OF((z_streamp strm, int flush))
303
381
  } else {
304
382
  if (zwc->totalInBytes == 0) {
305
383
  if (zwc->comprState == ZWRAP_useReset) {
306
- size_t const resetErr = ZSTD_resetCStream(zwc->zbc, (flush == Z_FINISH) ? strm->avail_in : zwc->pledgedSrcSize);
384
+ size_t resetErr = ZSTD_CCtx_reset(zwc->zbc, ZSTD_reset_session_only);
385
+ if (ZSTD_isError(resetErr)) {
386
+ LOG_WRAPPERC("ERROR: ZSTD_CCtx_reset errorCode=%s\n",
387
+ ZSTD_getErrorName(resetErr));
388
+ return ZWRAPC_finishWithError(zwc, strm, 0);
389
+ }
390
+ resetErr = ZSTD_CCtx_setPledgedSrcSize(zwc->zbc, (flush == Z_FINISH) ? strm->avail_in : zwc->pledgedSrcSize);
307
391
  if (ZSTD_isError(resetErr)) {
308
- LOG_WRAPPERC("ERROR: ZSTD_resetCStream errorCode=%s\n",
392
+ LOG_WRAPPERC("ERROR: ZSTD_CCtx_setPledgedSrcSize errorCode=%s\n",
309
393
  ZSTD_getErrorName(resetErr));
310
394
  return ZWRAPC_finishWithError(zwc, strm, 0);
311
395
  }
@@ -457,21 +541,19 @@ static void ZWRAP_initDCtx(ZWRAP_DCtx* zwd)
457
541
  static ZWRAP_DCtx* ZWRAP_createDCtx(z_streamp strm)
458
542
  {
459
543
  ZWRAP_DCtx* zwd;
460
- MEM_STATIC_ASSERT(sizeof(zwd->headerBuf) >= ZSTD_HEADERSIZE); /* check static buffer size condition */
544
+ ZSTD_customMem customMem = { NULL, NULL, NULL };
461
545
 
462
546
  if (strm->zalloc && strm->zfree) {
463
- zwd = (ZWRAP_DCtx*)strm->zalloc(strm->opaque, 1, sizeof(ZWRAP_DCtx));
464
- if (zwd==NULL) return NULL;
465
- memset(zwd, 0, sizeof(ZWRAP_DCtx));
466
- zwd->allocFunc = *strm; /* just to copy zalloc, zfree & opaque */
467
- { ZSTD_customMem ZWRAP_customMem = { ZWRAP_allocFunction, ZWRAP_freeFunction, NULL };
468
- ZWRAP_customMem.opaque = &zwd->allocFunc;
469
- zwd->customMem = ZWRAP_customMem;
470
- }
471
- } else {
472
- zwd = (ZWRAP_DCtx*)calloc(1, sizeof(*zwd));
473
- if (zwd==NULL) return NULL;
547
+ customMem.customAlloc = ZWRAP_allocFunction;
548
+ customMem.customFree = ZWRAP_freeFunction;
474
549
  }
550
+ customMem.opaque = strm;
551
+
552
+ zwd = (ZWRAP_DCtx*)ZWRAP_customCalloc(sizeof(ZWRAP_DCtx), customMem);
553
+ if (zwd == NULL) return NULL;
554
+ zwd->allocFunc = *strm;
555
+ customMem.opaque = &zwd->allocFunc;
556
+ zwd->customMem = customMem;
475
557
 
476
558
  ZWRAP_initDCtx(zwd);
477
559
  return zwd;
@@ -481,8 +563,8 @@ static size_t ZWRAP_freeDCtx(ZWRAP_DCtx* zwd)
481
563
  {
482
564
  if (zwd==NULL) return 0; /* support free on null */
483
565
  ZSTD_freeDStream(zwd->zbd);
484
- ZSTD_free(zwd->version, zwd->customMem);
485
- ZSTD_free(zwd, zwd->customMem);
566
+ ZWRAP_customFree(zwd->version, zwd->customMem);
567
+ ZWRAP_customFree(zwd, zwd->customMem);
486
568
  return 0;
487
569
  }
488
570
 
@@ -524,13 +606,13 @@ ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
524
606
  LOG_WRAPPERD("- inflateInit\n");
525
607
  if (zwd == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
526
608
 
527
- zwd->version = (char*)ZSTD_malloc(strlen(version)+1, zwd->customMem);
609
+ zwd->version = (char*)ZWRAP_customMalloc(strlen(version)+1, zwd->customMem);
528
610
  if (zwd->version == NULL) return ZWRAPD_finishWithError(zwd, strm, 0);
529
611
  strcpy(zwd->version, version);
530
612
 
531
613
  zwd->stream_size = stream_size;
532
614
  zwd->totalInBytes = 0;
533
- strm->state = (struct internal_state*) zwd;
615
+ strm->state = convert_into_sis(zwd);
534
616
  strm->total_in = 0;
535
617
  strm->total_out = 0;
536
618
  strm->reserved = ZWRAP_UNKNOWN_STREAM;
@@ -670,7 +752,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
670
752
 
671
753
  if (zwd->totalInBytes < ZLIB_HEADERSIZE) {
672
754
  if (zwd->totalInBytes == 0 && strm->avail_in >= ZLIB_HEADERSIZE) {
673
- if (MEM_readLE32(strm->next_in) != ZSTD_MAGICNUMBER) {
755
+ if (ZWRAP_readLE32(strm->next_in) != ZSTD_MAGICNUMBER) {
674
756
  { int const initErr = (zwd->windowBits) ?
675
757
  inflateInit2_(strm, zwd->windowBits, zwd->version, zwd->stream_size) :
676
758
  inflateInit_(strm, zwd->version, zwd->stream_size);
@@ -698,7 +780,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
698
780
  strm->avail_in -= srcSize;
699
781
  if (zwd->totalInBytes < ZLIB_HEADERSIZE) return Z_OK;
700
782
 
701
- if (MEM_readLE32(zwd->headerBuf) != ZSTD_MAGICNUMBER) {
783
+ if (ZWRAP_readLE32(zwd->headerBuf) != ZSTD_MAGICNUMBER) {
702
784
  z_stream strm2;
703
785
  strm2.next_in = strm->next_in;
704
786
  strm2.avail_in = strm->avail_in;
@@ -762,7 +844,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
762
844
  goto error;
763
845
  }
764
846
  } else {
765
- size_t const resetErr = ZSTD_resetDStream(zwd->zbd);
847
+ size_t const resetErr = ZSTD_DCtx_reset(zwd->zbd, ZSTD_reset_session_only);
766
848
  if (ZSTD_isError(resetErr)) goto error;
767
849
  }
768
850
  } else {
@@ -782,7 +864,7 @@ ZEXTERN int ZEXPORT z_inflate OF((z_streamp strm, int flush))
782
864
  goto error;
783
865
  }
784
866
  } else {
785
- size_t const resetErr = ZSTD_resetDStream(zwd->zbd);
867
+ size_t const resetErr = ZSTD_DCtx_reset(zwd->zbd, ZSTD_reset_session_only);
786
868
  if (ZSTD_isError(resetErr)) goto error;
787
869
  }
788
870
 
@@ -1107,3 +1189,10 @@ ZEXTERN const z_crc_t FAR * ZEXPORT z_get_crc_table OF((void))
1107
1189
  return get_crc_table();
1108
1190
  }
1109
1191
  #endif
1192
+
1193
+ /* Error function */
1194
+ ZEXTERN const char * ZEXPORT z_zError OF((int err))
1195
+ {
1196
+ /* Just use zlib Error function */
1197
+ return zError(err);
1198
+ }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2016-2020, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
2
+ * Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under both the BSD-style license (found in the
@@ -0,0 +1,15 @@
1
+ VPATH := $(SRCDIR)/common $(SRCDIR)/compress $(SRCDIR)/decompress
2
+
3
+ CSRCS := $(foreach dir,$(VPATH),$(wildcard $(dir)/*.c))
4
+ SSRCS := $(foreach dir,$(VPATH),$(wildcard $(dir)/*.S))
5
+ OBJS := $(patsubst %.c,%.o,$(foreach file,$(CSRCS),$(notdir $(file)))) $(patsubst %.S,%.o,$(foreach file,$(SSRCS),$(notdir $(file))))
6
+
7
+ CPPFLAGS += -I$(SRCDIR) -I$(SRCDIR)/common
8
+
9
+ LIB = ../libzstd.a
10
+
11
+ $(LIB) : $(OBJS)
12
+ $(AR) cr $@ $^
13
+
14
+ clean :
15
+ $(RM) -f $(LIB) $(OBJS)
Binary file
Binary file
Binary file
Binary file
Binary file
data/lib/zstdlib.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  begin
2
2
  RUBY_VERSION =~ /(\d+\.\d+)/
3
- require "#{$1}/zstdlib.so"
3
+ require "#{$1}/zstdlib_c"
4
4
  rescue LoadError
5
- require 'zstdlib.so'
5
+ require 'zstdlib_c'
6
6
  end