extzstd 0.0.3.CONCEPT → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.ja +5 -0
  3. data/LICENSE +6 -6
  4. data/README.md +35 -22
  5. data/contrib/zstd/LICENSE +13 -9
  6. data/contrib/zstd/README.md +37 -44
  7. data/contrib/zstd/common/entropy_common.c +33 -39
  8. data/contrib/zstd/common/error_private.c +43 -0
  9. data/contrib/zstd/common/error_private.h +11 -60
  10. data/contrib/zstd/common/fse.h +11 -5
  11. data/contrib/zstd/common/fse_decompress.c +14 -16
  12. data/contrib/zstd/common/huf.h +1 -1
  13. data/contrib/zstd/common/mem.h +36 -43
  14. data/contrib/zstd/common/xxhash.c +31 -18
  15. data/contrib/zstd/common/xxhash.h +71 -35
  16. data/contrib/zstd/common/zbuff.h +29 -35
  17. data/contrib/zstd/common/zstd_common.c +24 -32
  18. data/contrib/zstd/common/zstd_errors.h +60 -0
  19. data/contrib/zstd/common/zstd_internal.h +109 -80
  20. data/contrib/zstd/compress/fse_compress.c +9 -6
  21. data/contrib/zstd/compress/huf_compress.c +30 -74
  22. data/contrib/zstd/compress/zbuff_compress.c +43 -51
  23. data/contrib/zstd/compress/zstd_compress.c +953 -763
  24. data/contrib/zstd/compress/zstd_opt.h +115 -261
  25. data/contrib/zstd/decompress/huf_decompress.c +29 -40
  26. data/contrib/zstd/decompress/zbuff_decompress.c +36 -78
  27. data/contrib/zstd/decompress/zstd_decompress.c +976 -496
  28. data/contrib/zstd/dictBuilder/divsufsort.h +5 -5
  29. data/contrib/zstd/dictBuilder/zdict.c +194 -229
  30. data/contrib/zstd/dictBuilder/zdict.h +66 -68
  31. data/contrib/zstd/legacy/zstd_legacy.h +168 -49
  32. data/contrib/zstd/legacy/zstd_v01.c +95 -178
  33. data/contrib/zstd/legacy/zstd_v01.h +12 -32
  34. data/contrib/zstd/legacy/zstd_v02.c +48 -274
  35. data/contrib/zstd/legacy/zstd_v02.h +12 -32
  36. data/contrib/zstd/legacy/zstd_v03.c +48 -274
  37. data/contrib/zstd/legacy/zstd_v03.h +12 -32
  38. data/contrib/zstd/legacy/zstd_v04.c +63 -320
  39. data/contrib/zstd/legacy/zstd_v04.h +13 -33
  40. data/contrib/zstd/legacy/zstd_v05.c +80 -345
  41. data/contrib/zstd/legacy/zstd_v05.h +9 -31
  42. data/contrib/zstd/legacy/zstd_v06.c +48 -458
  43. data/contrib/zstd/legacy/zstd_v06.h +41 -67
  44. data/contrib/zstd/legacy/zstd_v07.c +4544 -0
  45. data/contrib/zstd/legacy/zstd_v07.h +173 -0
  46. data/contrib/zstd/zstd.h +640 -0
  47. data/ext/extconf.rb +7 -3
  48. data/ext/extzstd.c +263 -106
  49. data/ext/extzstd.h +8 -6
  50. data/ext/extzstd_nogvls.h +0 -117
  51. data/ext/extzstd_stream.c +347 -0
  52. data/ext/zstd_common.c +8 -0
  53. data/ext/zstd_compress.c +6 -0
  54. data/ext/zstd_decompress.c +5 -0
  55. data/ext/zstd_dictbuilder.c +5 -0
  56. data/ext/zstd_legacy_v07.c +1 -0
  57. data/gemstub.rb +18 -16
  58. data/lib/extzstd/version.rb +1 -1
  59. data/lib/extzstd.rb +77 -43
  60. data/test/test_basic.rb +11 -6
  61. metadata +23 -10
  62. data/contrib/zstd/common/error_public.h +0 -77
  63. data/contrib/zstd/common/zstd.h +0 -475
  64. data/ext/extzstd_buffered.c +0 -265
  65. data/ext/zstd_amalgam.c +0 -18
@@ -1,90 +1,26 @@
1
- /* ******************************************************************
2
- Error codes and messages
3
- Copyright (C) 2013-2015, Yann Collet
4
-
5
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
-
7
- Redistribution and use in source and binary forms, with or without
8
- modification, are permitted provided that the following conditions are
9
- met:
10
-
11
- * Redistributions of source code must retain the above copyright
12
- notice, this list of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above
14
- copyright notice, this list of conditions and the following disclaimer
15
- in the documentation and/or other materials provided with the
16
- distribution.
17
-
18
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ /**
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
29
9
 
30
- You can contact the author at :
31
- - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
32
- - Public forum : https://groups.google.com/forum/#!forum/lz4c
33
- ****************************************************************** */
34
- #ifndef ERROR_H_MODULE
35
- #define ERROR_H_MODULE
36
-
37
- #if defined (__cplusplus)
38
- extern "C" {
39
- #endif
40
10
 
41
11
  #include <stddef.h> /* size_t, ptrdiff_t */
42
12
  #include "zstd_v02.h"
43
-
44
- /******************************************
45
- * Compiler-specific
46
- ******************************************/
47
- #if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
48
- # define ERR_STATIC static inline
49
- #elif defined(_MSC_VER)
50
- # define ERR_STATIC static __inline
51
- #elif defined(__GNUC__)
52
- # define ERR_STATIC static __attribute__((unused))
53
- #else
54
- # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
55
- #endif
13
+ #include "error_private.h"
56
14
 
57
15
 
58
16
  /******************************************
59
- * Error Management
17
+ * Compiler-specific
60
18
  ******************************************/
61
- #define PREFIX(name) ZSTD_error_##name
62
-
63
- #define ERROR(name) (size_t)-PREFIX(name)
64
-
65
- #define ERROR_LIST(ITEM) \
66
- ITEM(PREFIX(No_Error)) ITEM(PREFIX(GENERIC)) \
67
- ITEM(PREFIX(memory_allocation)) \
68
- ITEM(PREFIX(dstSize_tooSmall)) ITEM(PREFIX(srcSize_wrong)) \
69
- ITEM(PREFIX(prefix_unknown)) ITEM(PREFIX(corruption_detected)) \
70
- ITEM(PREFIX(tableLog_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooSmall)) \
71
- ITEM(PREFIX(maxCode))
72
-
73
- #define ERROR_GENERATE_ENUM(ENUM) ENUM,
74
- typedef enum { ERROR_LIST(ERROR_GENERATE_ENUM) } ERR_codes; /* enum is exposed, to detect & handle specific errors; compare function result to -enum value */
75
-
76
- #define ERROR_CONVERTTOSTRING(STRING) #STRING,
77
- #define ERROR_GENERATE_STRING(EXPR) ERROR_CONVERTTOSTRING(EXPR)
78
-
79
- ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
80
-
81
-
82
- #if defined (__cplusplus)
83
- }
19
+ #if defined(_MSC_VER) /* Visual Studio */
20
+ # include <stdlib.h> /* _byteswap_ulong */
21
+ # include <intrin.h> /* _byteswap_* */
84
22
  #endif
85
23
 
86
- #endif /* ERROR_H_MODULE */
87
-
88
24
 
89
25
  /* ******************************************************************
90
26
  mem.h
@@ -190,7 +126,7 @@ extern "C" {
190
126
  #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
191
127
  # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
192
128
  # define MEM_FORCE_MEMORY_ACCESS 2
193
- # elif defined(__INTEL_COMPILER) || \
129
+ # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
194
130
  (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
195
131
  # define MEM_FORCE_MEMORY_ACCESS 1
196
132
  # endif
@@ -214,8 +150,6 @@ MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
214
150
  MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
215
151
 
216
152
  MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
217
- MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; }
218
- MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; }
219
153
 
220
154
  #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
221
155
 
@@ -228,8 +162,6 @@ MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32;
228
162
  MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
229
163
 
230
164
  MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
231
- MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((unalign*)memPtr)->u32 = value; }
232
- MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign*)memPtr)->u64 = value; }
233
165
 
234
166
  #else
235
167
 
@@ -256,16 +188,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
256
188
  memcpy(memPtr, &value, sizeof(value));
257
189
  }
258
190
 
259
- MEM_STATIC void MEM_write32(void* memPtr, U32 value)
260
- {
261
- memcpy(memPtr, &value, sizeof(value));
262
- }
263
-
264
- MEM_STATIC void MEM_write64(void* memPtr, U64 value)
265
- {
266
- memcpy(memPtr, &value, sizeof(value));
267
- }
268
-
269
191
  #endif // MEM_FORCE_MEMORY_ACCESS
270
192
 
271
193
 
@@ -305,21 +227,6 @@ MEM_STATIC U32 MEM_readLE32(const void* memPtr)
305
227
  }
306
228
  }
307
229
 
308
- MEM_STATIC void MEM_writeLE32(void* memPtr, U32 val32)
309
- {
310
- if (MEM_isLittleEndian())
311
- {
312
- MEM_write32(memPtr, val32);
313
- }
314
- else
315
- {
316
- BYTE* p = (BYTE*)memPtr;
317
- p[0] = (BYTE)val32;
318
- p[1] = (BYTE)(val32>>8);
319
- p[2] = (BYTE)(val32>>16);
320
- p[3] = (BYTE)(val32>>24);
321
- }
322
- }
323
230
 
324
231
  MEM_STATIC U64 MEM_readLE64(const void* memPtr)
325
232
  {
@@ -333,25 +240,6 @@ MEM_STATIC U64 MEM_readLE64(const void* memPtr)
333
240
  }
334
241
  }
335
242
 
336
- MEM_STATIC void MEM_writeLE64(void* memPtr, U64 val64)
337
- {
338
- if (MEM_isLittleEndian())
339
- {
340
- MEM_write64(memPtr, val64);
341
- }
342
- else
343
- {
344
- BYTE* p = (BYTE*)memPtr;
345
- p[0] = (BYTE)val64;
346
- p[1] = (BYTE)(val64>>8);
347
- p[2] = (BYTE)(val64>>16);
348
- p[3] = (BYTE)(val64>>24);
349
- p[4] = (BYTE)(val64>>32);
350
- p[5] = (BYTE)(val64>>40);
351
- p[6] = (BYTE)(val64>>48);
352
- p[7] = (BYTE)(val64>>56);
353
- }
354
- }
355
243
 
356
244
  MEM_STATIC size_t MEM_readLEST(const void* memPtr)
357
245
  {
@@ -361,14 +249,6 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
361
249
  return (size_t)MEM_readLE64(memPtr);
362
250
  }
363
251
 
364
- MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val)
365
- {
366
- if (MEM_32bits())
367
- MEM_writeLE32(memPtr, (U32)val);
368
- else
369
- MEM_writeLE64(memPtr, (U64)val);
370
- }
371
-
372
252
  #if defined (__cplusplus)
373
253
  }
374
254
  #endif
@@ -1198,12 +1078,15 @@ typedef struct ZSTD_DCtx_s ZSTD_DCtx;
1198
1078
  # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
1199
1079
  # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
1200
1080
  #else
1201
- # ifdef __GNUC__
1202
- # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
1203
- # define FORCE_INLINE static inline __attribute__((always_inline))
1081
+ # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
1082
+ # ifdef __GNUC__
1083
+ # define FORCE_INLINE static inline __attribute__((always_inline))
1084
+ # else
1085
+ # define FORCE_INLINE static inline
1086
+ # endif
1204
1087
  # else
1205
- # define FORCE_INLINE static inline
1206
- # endif
1088
+ # define FORCE_INLINE static
1089
+ # endif /* __STDC_VERSION__ */
1207
1090
  #endif
1208
1091
 
1209
1092
 
@@ -1350,7 +1233,7 @@ static unsigned FSE_isError(size_t code) { return ERR_isError(code); }
1350
1233
  ****************************************************************/
1351
1234
  static short FSE_abs(short a)
1352
1235
  {
1353
- return a<0 ? -a : a;
1236
+ return (short)(a<0 ? -a : a);
1354
1237
  }
1355
1238
 
1356
1239
  static size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
@@ -1671,15 +1554,7 @@ static size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, siz
1671
1554
 
1672
1555
 
1673
1556
  #ifdef _MSC_VER /* Visual Studio */
1674
- # define FORCE_INLINE static __forceinline
1675
1557
  # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
1676
- #else
1677
- # ifdef __GNUC__
1678
- # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
1679
- # define FORCE_INLINE static inline __attribute__((always_inline))
1680
- # else
1681
- # define FORCE_INLINE static inline
1682
- # endif
1683
1558
  #endif
1684
1559
 
1685
1560
 
@@ -1732,10 +1607,12 @@ static size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
1732
1607
  U32 weightTotal;
1733
1608
  U32 tableLog;
1734
1609
  const BYTE* ip = (const BYTE*) src;
1735
- size_t iSize = ip[0];
1610
+ size_t iSize;
1736
1611
  size_t oSize;
1737
1612
  U32 n;
1738
1613
 
1614
+ if (!srcSize) return ERROR(srcSize_wrong);
1615
+ iSize = ip[0];
1739
1616
  //memset(huffWeight, 0, hwSize); /* is not necessary, even though some analyzer complain ... */
1740
1617
 
1741
1618
  if (iSize >= 128) /* special header */
@@ -1777,6 +1654,7 @@ static size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
1777
1654
  rankStats[huffWeight[n]]++;
1778
1655
  weightTotal += (1 << huffWeight[n]) >> 1;
1779
1656
  }
1657
+ if (weightTotal == 0) return ERROR(corruption_detected);
1780
1658
 
1781
1659
  /* get last non-null symbol weight (implied, total must be 2^n) */
1782
1660
  tableLog = BIT_highbit32(weightTotal) + 1;
@@ -2866,17 +2744,9 @@ static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_
2866
2744
  #endif
2867
2745
 
2868
2746
  #ifdef _MSC_VER /* Visual Studio */
2869
- # define FORCE_INLINE static __forceinline
2870
2747
  # include <intrin.h> /* For Visual 2005 */
2871
2748
  # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
2872
2749
  # pragma warning(disable : 4324) /* disable: C4324: padded structure */
2873
- #else
2874
- # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
2875
- # ifdef __GNUC__
2876
- # define FORCE_INLINE static inline __attribute__((always_inline))
2877
- # else
2878
- # define FORCE_INLINE static inline
2879
- # endif
2880
2750
  #endif
2881
2751
 
2882
2752
 
@@ -2983,98 +2853,6 @@ typedef struct {
2983
2853
  static unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
2984
2854
 
2985
2855
 
2986
- /* *************************************
2987
- * Function body to include
2988
- ***************************************/
2989
- static size_t ZSTD_read_ARCH(const void* p) { size_t r; memcpy(&r, p, sizeof(r)); return r; }
2990
-
2991
- MEM_STATIC unsigned ZSTD_NbCommonBytes (register size_t val)
2992
- {
2993
- if (MEM_isLittleEndian())
2994
- {
2995
- if (MEM_64bits())
2996
- {
2997
- # if defined(_MSC_VER) && defined(_WIN64) && !defined(LZ4_FORCE_SW_BITCOUNT)
2998
- unsigned long r = 0;
2999
- _BitScanForward64( &r, (U64)val );
3000
- return (int)(r>>3);
3001
- # elif defined(__GNUC__) && (__GNUC__ >= 3) && !defined(LZ4_FORCE_SW_BITCOUNT)
3002
- return (__builtin_ctzll((U64)val) >> 3);
3003
- # else
3004
- static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 };
3005
- return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58];
3006
- # endif
3007
- }
3008
- else /* 32 bits */
3009
- {
3010
- # if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
3011
- unsigned long r;
3012
- _BitScanForward( &r, (U32)val );
3013
- return (int)(r>>3);
3014
- # elif defined(__GNUC__) && (__GNUC__ >= 3) && !defined(LZ4_FORCE_SW_BITCOUNT)
3015
- return (__builtin_ctz((U32)val) >> 3);
3016
- # else
3017
- static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 };
3018
- return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];
3019
- # endif
3020
- }
3021
- }
3022
- else /* Big Endian CPU */
3023
- {
3024
- if (MEM_32bits())
3025
- {
3026
- # if defined(_MSC_VER) && defined(_WIN64) && !defined(LZ4_FORCE_SW_BITCOUNT)
3027
- unsigned long r = 0;
3028
- _BitScanReverse64( &r, val );
3029
- return (unsigned)(r>>3);
3030
- # elif defined(__GNUC__) && (__GNUC__ >= 3) && !defined(LZ4_FORCE_SW_BITCOUNT)
3031
- return (__builtin_clzll(val) >> 3);
3032
- # else
3033
- unsigned r;
3034
- const unsigned n32 = sizeof(size_t)*4; /* calculate this way due to compiler complaining in 32-bits mode */
3035
- if (!(val>>n32)) { r=4; } else { r=0; val>>=n32; }
3036
- if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; }
3037
- r += (!val);
3038
- return r;
3039
- # endif
3040
- }
3041
- else /* 32 bits */
3042
- {
3043
- # if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
3044
- unsigned long r = 0;
3045
- _BitScanReverse( &r, (unsigned long)val );
3046
- return (unsigned)(r>>3);
3047
- # elif defined(__GNUC__) && (__GNUC__ >= 3) && !defined(LZ4_FORCE_SW_BITCOUNT)
3048
- return (__builtin_clz((U32)val) >> 3);
3049
- # else
3050
- unsigned r;
3051
- if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }
3052
- r += (!val);
3053
- return r;
3054
- # endif
3055
- }
3056
- }
3057
- }
3058
-
3059
-
3060
- MEM_STATIC size_t ZSTD_count(const BYTE* pIn, const BYTE* pMatch, const BYTE* pInLimit)
3061
- {
3062
- const BYTE* const pStart = pIn;
3063
-
3064
- while ((pIn<pInLimit-(sizeof(size_t)-1)))
3065
- {
3066
- size_t diff = ZSTD_read_ARCH(pMatch) ^ ZSTD_read_ARCH(pIn);
3067
- if (!diff) { pIn+=sizeof(size_t); pMatch+=sizeof(size_t); continue; }
3068
- pIn += ZSTD_NbCommonBytes(diff);
3069
- return (size_t)(pIn - pStart);
3070
- }
3071
-
3072
- if (MEM_32bits()) if ((pIn<(pInLimit-3)) && (MEM_read32(pMatch) == MEM_read32(pIn))) { pIn+=4; pMatch+=4; }
3073
- if ((pIn<(pInLimit-1)) && (MEM_read16(pMatch) == MEM_read16(pIn))) { pIn+=2; pMatch+=2; }
3074
- if ((pIn<pInLimit) && (*pMatch == *pIn)) pIn++;
3075
- return (size_t)(pIn - pStart);
3076
- }
3077
-
3078
2856
 
3079
2857
  /* *************************************************************
3080
2858
  * Decompression section
@@ -3244,7 +3022,6 @@ static size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* d
3244
3022
  /* Build DTables */
3245
3023
  switch(LLtype)
3246
3024
  {
3247
- U32 max;
3248
3025
  case bt_rle :
3249
3026
  LLlog = 0;
3250
3027
  FSE_buildDTable_rle(DTableLL, *ip++); break;
@@ -3252,17 +3029,16 @@ static size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* d
3252
3029
  LLlog = LLbits;
3253
3030
  FSE_buildDTable_raw(DTableLL, LLbits); break;
3254
3031
  default :
3255
- max = MaxLL;
3256
- headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
3257
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
3258
- if (LLlog > LLFSELog) return ERROR(corruption_detected);
3259
- ip += headerSize;
3260
- FSE_buildDTable(DTableLL, norm, max, LLlog);
3261
- }
3032
+ { U32 max = MaxLL;
3033
+ headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
3034
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
3035
+ if (LLlog > LLFSELog) return ERROR(corruption_detected);
3036
+ ip += headerSize;
3037
+ FSE_buildDTable(DTableLL, norm, max, LLlog);
3038
+ } }
3262
3039
 
3263
3040
  switch(Offtype)
3264
3041
  {
3265
- U32 max;
3266
3042
  case bt_rle :
3267
3043
  Offlog = 0;
3268
3044
  if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
@@ -3272,17 +3048,16 @@ static size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* d
3272
3048
  Offlog = Offbits;
3273
3049
  FSE_buildDTable_raw(DTableOffb, Offbits); break;
3274
3050
  default :
3275
- max = MaxOff;
3276
- headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
3277
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
3278
- if (Offlog > OffFSELog) return ERROR(corruption_detected);
3279
- ip += headerSize;
3280
- FSE_buildDTable(DTableOffb, norm, max, Offlog);
3281
- }
3051
+ { U32 max = MaxOff;
3052
+ headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
3053
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
3054
+ if (Offlog > OffFSELog) return ERROR(corruption_detected);
3055
+ ip += headerSize;
3056
+ FSE_buildDTable(DTableOffb, norm, max, Offlog);
3057
+ } }
3282
3058
 
3283
3059
  switch(MLtype)
3284
3060
  {
3285
- U32 max;
3286
3061
  case bt_rle :
3287
3062
  MLlog = 0;
3288
3063
  if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
@@ -3291,14 +3066,13 @@ static size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* d
3291
3066
  MLlog = MLbits;
3292
3067
  FSE_buildDTable_raw(DTableML, MLbits); break;
3293
3068
  default :
3294
- max = MaxML;
3295
- headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
3296
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
3297
- if (MLlog > MLFSELog) return ERROR(corruption_detected);
3298
- ip += headerSize;
3299
- FSE_buildDTable(DTableML, norm, max, MLlog);
3300
- }
3301
- }
3069
+ { U32 max = MaxML;
3070
+ headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
3071
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
3072
+ if (MLlog > MLFSELog) return ERROR(corruption_detected);
3073
+ ip += headerSize;
3074
+ FSE_buildDTable(DTableML, norm, max, MLlog);
3075
+ } } }
3302
3076
 
3303
3077
  return ip-istart;
3304
3078
  }
@@ -1,36 +1,14 @@
1
- /*
2
- zstd_v02 - decoder for 0.2 format
3
- Header File
4
- Copyright (C) 2015, Yann Collet.
5
-
6
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1
+ /**
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
7
9
 
8
- Redistribution and use in source and binary forms, with or without
9
- modification, are permitted provided that the following conditions are
10
- met:
11
- * Redistributions of source code must retain the above copyright
12
- notice, this list of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above
14
- copyright notice, this list of conditions and the following disclaimer
15
- in the documentation and/or other materials provided with the
16
- distribution.
17
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
-
29
- You can contact the author at :
30
- - zstd source repository : https://github.com/Cyan4973/zstd
31
- - ztsd public forum : https://groups.google.com/forum/#!forum/lz4c
32
- */
33
- #pragma once
10
+ #ifndef ZSTD_V02_H_4174539423
11
+ #define ZSTD_V02_H_4174539423
34
12
 
35
13
  #if defined (__cplusplus)
36
14
  extern "C" {
@@ -97,3 +75,5 @@ size_t ZSTDv02_decompressContinue(ZSTDv02_Dctx* dctx, void* dst, size_t maxDstSi
97
75
  #if defined (__cplusplus)
98
76
  }
99
77
  #endif
78
+
79
+ #endif /* ZSTD_V02_H_4174539423 */