extzstd 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +18 -0
  3. data/README.md +15 -50
  4. data/contrib/zstd/CONTRIBUTING.md +1 -1
  5. data/contrib/zstd/COPYING +339 -0
  6. data/contrib/zstd/Makefile +82 -51
  7. data/contrib/zstd/NEWS +92 -5
  8. data/contrib/zstd/README.md +50 -41
  9. data/contrib/zstd/appveyor.yml +164 -102
  10. data/contrib/zstd/circle.yml +10 -22
  11. data/contrib/zstd/lib/BUCK +31 -10
  12. data/contrib/zstd/lib/Makefile +57 -31
  13. data/contrib/zstd/lib/README.md +68 -37
  14. data/contrib/zstd/lib/common/bitstream.h +130 -76
  15. data/contrib/zstd/lib/common/compiler.h +86 -0
  16. data/contrib/zstd/lib/common/error_private.c +15 -11
  17. data/contrib/zstd/lib/common/error_private.h +8 -8
  18. data/contrib/zstd/lib/common/fse.h +19 -9
  19. data/contrib/zstd/lib/common/fse_decompress.c +3 -22
  20. data/contrib/zstd/lib/common/huf.h +68 -26
  21. data/contrib/zstd/lib/common/mem.h +23 -35
  22. data/contrib/zstd/lib/common/pool.c +123 -63
  23. data/contrib/zstd/lib/common/pool.h +19 -10
  24. data/contrib/zstd/lib/common/threading.c +11 -16
  25. data/contrib/zstd/lib/common/threading.h +52 -33
  26. data/contrib/zstd/lib/common/xxhash.c +28 -22
  27. data/contrib/zstd/lib/common/zstd_common.c +40 -27
  28. data/contrib/zstd/lib/common/zstd_errors.h +43 -34
  29. data/contrib/zstd/lib/common/zstd_internal.h +131 -123
  30. data/contrib/zstd/lib/compress/fse_compress.c +17 -33
  31. data/contrib/zstd/lib/compress/huf_compress.c +15 -9
  32. data/contrib/zstd/lib/compress/zstd_compress.c +2096 -2363
  33. data/contrib/zstd/lib/compress/zstd_compress_internal.h +462 -0
  34. data/contrib/zstd/lib/compress/zstd_double_fast.c +309 -0
  35. data/contrib/zstd/lib/compress/zstd_double_fast.h +29 -0
  36. data/contrib/zstd/lib/compress/zstd_fast.c +243 -0
  37. data/contrib/zstd/lib/compress/zstd_fast.h +31 -0
  38. data/contrib/zstd/lib/compress/zstd_lazy.c +765 -0
  39. data/contrib/zstd/lib/compress/zstd_lazy.h +39 -0
  40. data/contrib/zstd/lib/compress/zstd_ldm.c +707 -0
  41. data/contrib/zstd/lib/compress/zstd_ldm.h +68 -0
  42. data/contrib/zstd/lib/compress/zstd_opt.c +785 -0
  43. data/contrib/zstd/lib/compress/zstd_opt.h +19 -908
  44. data/contrib/zstd/lib/compress/zstdmt_compress.c +737 -327
  45. data/contrib/zstd/lib/compress/zstdmt_compress.h +88 -26
  46. data/contrib/zstd/lib/decompress/huf_decompress.c +158 -50
  47. data/contrib/zstd/lib/decompress/zstd_decompress.c +884 -699
  48. data/contrib/zstd/lib/deprecated/zbuff.h +5 -4
  49. data/contrib/zstd/lib/deprecated/zbuff_common.c +5 -5
  50. data/contrib/zstd/lib/deprecated/zbuff_compress.c +6 -4
  51. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +5 -4
  52. data/contrib/zstd/lib/dictBuilder/cover.c +93 -77
  53. data/contrib/zstd/lib/dictBuilder/zdict.c +107 -92
  54. data/contrib/zstd/lib/dictBuilder/zdict.h +112 -102
  55. data/contrib/zstd/lib/legacy/zstd_legacy.h +9 -4
  56. data/contrib/zstd/lib/legacy/zstd_v01.c +7 -6
  57. data/contrib/zstd/lib/legacy/zstd_v01.h +5 -4
  58. data/contrib/zstd/lib/legacy/zstd_v02.c +27 -99
  59. data/contrib/zstd/lib/legacy/zstd_v02.h +5 -4
  60. data/contrib/zstd/lib/legacy/zstd_v03.c +26 -98
  61. data/contrib/zstd/lib/legacy/zstd_v03.h +5 -4
  62. data/contrib/zstd/lib/legacy/zstd_v04.c +22 -91
  63. data/contrib/zstd/lib/legacy/zstd_v04.h +5 -4
  64. data/contrib/zstd/lib/legacy/zstd_v05.c +23 -99
  65. data/contrib/zstd/lib/legacy/zstd_v05.h +5 -4
  66. data/contrib/zstd/lib/legacy/zstd_v06.c +22 -96
  67. data/contrib/zstd/lib/legacy/zstd_v06.h +5 -4
  68. data/contrib/zstd/lib/legacy/zstd_v07.c +19 -95
  69. data/contrib/zstd/lib/legacy/zstd_v07.h +5 -4
  70. data/contrib/zstd/lib/zstd.h +895 -271
  71. data/ext/extconf.rb +11 -2
  72. data/ext/extzstd.c +45 -128
  73. data/ext/extzstd.h +74 -31
  74. data/ext/extzstd_stream.c +401 -142
  75. data/ext/zstd_common.c +5 -0
  76. data/ext/zstd_compress.c +8 -0
  77. data/ext/zstd_decompress.c +1 -0
  78. data/ext/zstd_dictbuilder.c +2 -0
  79. data/lib/extzstd/version.rb +1 -1
  80. data/lib/extzstd.rb +48 -1
  81. data/test/test_basic.rb +9 -1
  82. metadata +17 -7
  83. data/HISTORY.ja +0 -10
  84. data/contrib/zstd/LICENSE-examples +0 -11
  85. data/contrib/zstd/PATENTS +0 -33
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
 
@@ -331,17 +332,6 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
331
332
  MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
332
333
 
333
334
 
334
- /*
335
- * Start by invoking BIT_initDStream().
336
- * A chunk of the bitStream is then stored into a local register.
337
- * Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
338
- * You can then retrieve bitFields stored into the local register, **in reverse order**.
339
- * Local register is manually filled from memory by the BIT_reloadDStream() method.
340
- * A reload guarantee a minimum of ((8*sizeof(size_t))-7) bits when its result is BIT_DStream_unfinished.
341
- * Otherwise, it can be less than that, so proceed accordingly.
342
- * Checking if DStream has reached its end can be performed with BIT_endOfDStream()
343
- */
344
-
345
335
 
346
336
  /******************************************
347
337
  * unsafe API
@@ -354,7 +344,7 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
354
344
  /****************************************************************
355
345
  * Helper functions
356
346
  ****************************************************************/
357
- MEM_STATIC unsigned BIT_highbit32 (register U32 val)
347
+ MEM_STATIC unsigned BIT_highbit32 (U32 val)
358
348
  {
359
349
  # if defined(_MSC_VER) /* Visual */
360
350
  unsigned long r=0;
@@ -427,14 +417,6 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
427
417
 
428
418
  return srcSize;
429
419
  }
430
-
431
- /*!BIT_lookBits
432
- * Provides next n bits from local register
433
- * local register is not modified (bits are still present for next read/look)
434
- * On 32-bits, maxNbBits==25
435
- * On 64-bits, maxNbBits==57
436
- * @return : value extracted
437
- */
438
420
  MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
439
421
  {
440
422
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -454,11 +436,6 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
454
436
  bitD->bitsConsumed += nbBits;
455
437
  }
456
438
 
457
- /*!BIT_readBits
458
- * Read next n bits from local register.
459
- * pay attention to not read more than nbBits contained into local register.
460
- * @return : extracted value.
461
- */
462
439
  MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
463
440
  {
464
441
  size_t value = BIT_lookBits(bitD, nbBits);
@@ -477,8 +454,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
477
454
 
478
455
  MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
479
456
  {
480
- if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* should never happen */
481
- return BIT_DStream_overflow;
457
+ if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* should never happen */
458
+ return BIT_DStream_overflow;
482
459
 
483
460
  if (bitD->ptr >= bitD->start + sizeof(bitD->bitContainer))
484
461
  {
@@ -696,55 +673,6 @@ static unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bi
696
673
 
697
674
  static unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr);
698
675
 
699
- /*
700
- Let's now decompose FSE_decompress_usingDTable() into its unitary components.
701
- You will decode FSE-encoded symbols from the bitStream,
702
- and also any other bitFields you put in, **in reverse order**.
703
-
704
- You will need a few variables to track your bitStream. They are :
705
-
706
- BIT_DStream_t DStream; // Stream context
707
- FSE_DState_t DState; // State context. Multiple ones are possible
708
- FSE_DTable* DTablePtr; // Decoding table, provided by FSE_buildDTable()
709
-
710
- The first thing to do is to init the bitStream.
711
- errorCode = BIT_initDStream(&DStream, srcBuffer, srcSize);
712
-
713
- You should then retrieve your initial state(s)
714
- (in reverse flushing order if you have several ones) :
715
- errorCode = FSE_initDState(&DState, &DStream, DTablePtr);
716
-
717
- You can then decode your data, symbol after symbol.
718
- For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'.
719
- Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out).
720
- unsigned char symbol = FSE_decodeSymbol(&DState, &DStream);
721
-
722
- You can retrieve any bitfield you eventually stored into the bitStream (in reverse order)
723
- Note : maximum allowed nbBits is 25, for 32-bits compatibility
724
- size_t bitField = BIT_readBits(&DStream, nbBits);
725
-
726
- All above operations only read from local register (which size depends on size_t).
727
- Refueling the register from memory is manually performed by the reload method.
728
- endSignal = FSE_reloadDStream(&DStream);
729
-
730
- BIT_reloadDStream() result tells if there is still some more data to read from DStream.
731
- BIT_DStream_unfinished : there is still some data left into the DStream.
732
- BIT_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled.
733
- BIT_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed.
734
- BIT_DStream_tooFar : Dstream went too far. Decompression result is corrupted.
735
-
736
- When reaching end of buffer (BIT_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop,
737
- to properly detect the exact end of stream.
738
- After each decoded symbol, check if DStream is fully consumed using this simple test :
739
- BIT_reloadDStream(&DStream) >= BIT_DStream_completed
740
-
741
- When it's done, verify decompression is fully completed, by checking both DStream and the relevant states.
742
- Checking if DStream has reached its end is performed by :
743
- BIT_endOfDStream(&DStream);
744
- Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible.
745
- FSE_endOfDState(&DState);
746
- */
747
-
748
676
 
749
677
  /******************************************
750
678
  * FSE unsafe API
@@ -1335,8 +1263,8 @@ static size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsi
1335
1263
  else
1336
1264
  {
1337
1265
  bitCount -= (int)(8 * (iend - 4 - ip));
1338
- ip = iend - 4;
1339
- }
1266
+ ip = iend - 4;
1267
+ }
1340
1268
  bitStream = MEM_readLE32(ip) >> (bitCount & 31);
1341
1269
  }
1342
1270
  }
@@ -2037,7 +1965,7 @@ static size_t HUF_readDTableX4 (U32* DTable, const void* src, size_t srcSize)
2037
1965
  rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */
2038
1966
  }
2039
1967
 
2040
- /* Build rankVal */
1968
+ /* Build rankVal */
2041
1969
  {
2042
1970
  const U32 minBits = tableLog+1 - maxW;
2043
1971
  U32 nextRankVal = 0;
@@ -2589,14 +2517,14 @@ static size_t ZSTD_decodeLiteralsBlock(void* ctx,
2589
2517
  const size_t litSize = (MEM_readLE32(istart) & 0xFFFFFF) >> 2; /* no buffer issue : srcSize >= MIN_CBLOCK_SIZE */
2590
2518
  if (litSize > srcSize-11) /* risk of reading too far with wildcopy */
2591
2519
  {
2592
- if (litSize > srcSize-3) return ERROR(corruption_detected);
2593
- memcpy(dctx->litBuffer, istart, litSize);
2594
- dctx->litPtr = dctx->litBuffer;
2595
- dctx->litSize = litSize;
2596
- memset(dctx->litBuffer + dctx->litSize, 0, 8);
2597
- return litSize+3;
2598
- }
2599
- /* direct reference into compressed stream */
2520
+ if (litSize > srcSize-3) return ERROR(corruption_detected);
2521
+ memcpy(dctx->litBuffer, istart, litSize);
2522
+ dctx->litPtr = dctx->litBuffer;
2523
+ dctx->litSize = litSize;
2524
+ memset(dctx->litBuffer + dctx->litSize, 0, 8);
2525
+ return litSize+3;
2526
+ }
2527
+ /* direct reference into compressed stream */
2600
2528
  dctx->litPtr = istart+3;
2601
2529
  dctx->litSize = litSize;
2602
2530
  return litSize+3;
@@ -3156,13 +3084,13 @@ static size_t ZSTD_decompressContinue(ZSTD_DCtx* ctx, void* dst, size_t maxDstSi
3156
3084
 
3157
3085
  unsigned ZSTDv03_isError(size_t code)
3158
3086
  {
3159
- return ZSTD_isError(code);
3087
+ return ZSTD_isError(code);
3160
3088
  }
3161
3089
 
3162
3090
  size_t ZSTDv03_decompress( void* dst, size_t maxOriginalSize,
3163
3091
  const void* src, size_t compressedSize)
3164
3092
  {
3165
- return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize);
3093
+ return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize);
3166
3094
  }
3167
3095
 
3168
3096
  size_t ZSTDv03_findFrameCompressedSize(const void* src, size_t srcSize)
@@ -3172,25 +3100,25 @@ size_t ZSTDv03_findFrameCompressedSize(const void* src, size_t srcSize)
3172
3100
 
3173
3101
  ZSTDv03_Dctx* ZSTDv03_createDCtx(void)
3174
3102
  {
3175
- return (ZSTDv03_Dctx*)ZSTD_createDCtx();
3103
+ return (ZSTDv03_Dctx*)ZSTD_createDCtx();
3176
3104
  }
3177
3105
 
3178
3106
  size_t ZSTDv03_freeDCtx(ZSTDv03_Dctx* dctx)
3179
3107
  {
3180
- return ZSTD_freeDCtx((ZSTD_DCtx*)dctx);
3108
+ return ZSTD_freeDCtx((ZSTD_DCtx*)dctx);
3181
3109
  }
3182
3110
 
3183
3111
  size_t ZSTDv03_resetDCtx(ZSTDv03_Dctx* dctx)
3184
3112
  {
3185
- return ZSTD_resetDCtx((ZSTD_DCtx*)dctx);
3113
+ return ZSTD_resetDCtx((ZSTD_DCtx*)dctx);
3186
3114
  }
3187
3115
 
3188
3116
  size_t ZSTDv03_nextSrcSizeToDecompress(ZSTDv03_Dctx* dctx)
3189
3117
  {
3190
- return ZSTD_nextSrcSizeToDecompress((ZSTD_DCtx*)dctx);
3118
+ return ZSTD_nextSrcSizeToDecompress((ZSTD_DCtx*)dctx);
3191
3119
  }
3192
3120
 
3193
3121
  size_t ZSTDv03_decompressContinue(ZSTDv03_Dctx* dctx, void* dst, size_t maxDstSize, const void* src, size_t srcSize)
3194
3122
  {
3195
- return ZSTD_decompressContinue((ZSTD_DCtx*)dctx, dst, maxDstSize, src, srcSize);
3123
+ return ZSTD_decompressContinue((ZSTD_DCtx*)dctx, dst, maxDstSize, src, srcSize);
3196
3124
  }
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
  #ifndef ZSTD_V03_H_298734209782
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
 
@@ -737,16 +738,6 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
737
738
  MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);
738
739
 
739
740
 
740
- /*
741
- * Start by invoking BIT_initDStream().
742
- * A chunk of the bitStream is then stored into a local register.
743
- * Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
744
- * You can then retrieve bitFields stored into the local register, **in reverse order**.
745
- * Local register is manually filled from memory by the BIT_reloadDStream() method.
746
- * A reload guarantee a minimum of ((8*sizeof(size_t))-7) bits when its result is BIT_DStream_unfinished.
747
- * Otherwise, it can be less than that, so proceed accordingly.
748
- * Checking if DStream has reached its end can be performed with BIT_endOfDStream()
749
- */
750
741
 
751
742
 
752
743
  /******************************************
@@ -760,7 +751,7 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
760
751
  /****************************************************************
761
752
  * Helper functions
762
753
  ****************************************************************/
763
- MEM_STATIC unsigned BIT_highbit32 (register U32 val)
754
+ MEM_STATIC unsigned BIT_highbit32 (U32 val)
764
755
  {
765
756
  # if defined(_MSC_VER) /* Visual */
766
757
  unsigned long r=0;
@@ -816,13 +807,13 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
816
807
  bitD->bitContainer = *(const BYTE*)(bitD->start);
817
808
  switch(srcSize)
818
809
  {
819
- case 7: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[6]) << (sizeof(size_t)*8 - 16);
820
- case 6: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[5]) << (sizeof(size_t)*8 - 24);
821
- case 5: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[4]) << (sizeof(size_t)*8 - 32);
822
- case 4: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[3]) << 24;
823
- case 3: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[2]) << 16;
824
- case 2: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[1]) << 8;
825
- default:;
810
+ case 7: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[6]) << (sizeof(size_t)*8 - 16);/* fall-through */
811
+ case 6: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[5]) << (sizeof(size_t)*8 - 24);/* fall-through */
812
+ case 5: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[4]) << (sizeof(size_t)*8 - 32);/* fall-through */
813
+ case 4: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[3]) << 24; /* fall-through */
814
+ case 3: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[2]) << 16; /* fall-through */
815
+ case 2: bitD->bitContainer += (size_t)(((const BYTE*)(bitD->start))[1]) << 8; /* fall-through */
816
+ default: break;
826
817
  }
827
818
  contain32 = ((const BYTE*)srcBuffer)[srcSize-1];
828
819
  if (contain32 == 0) return ERROR(GENERIC); /* endMark not present */
@@ -833,13 +824,6 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
833
824
  return srcSize;
834
825
  }
835
826
 
836
- /*!BIT_lookBits
837
- * Provides next n bits from local register
838
- * local register is not modified (bits are still present for next read/look)
839
- * On 32-bits, maxNbBits==25
840
- * On 64-bits, maxNbBits==57
841
- * @return : value extracted
842
- */
843
827
  MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
844
828
  {
845
829
  const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
@@ -859,11 +843,6 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
859
843
  bitD->bitsConsumed += nbBits;
860
844
  }
861
845
 
862
- /*!BIT_readBits
863
- * Read next n bits from local register.
864
- * pay attention to not read more than nbBits contained into local register.
865
- * @return : extracted value.
866
- */
867
846
  MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
868
847
  {
869
848
  size_t value = BIT_lookBits(bitD, nbBits);
@@ -882,8 +861,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
882
861
 
883
862
  MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
884
863
  {
885
- if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* should never happen */
886
- return BIT_DStream_overflow;
864
+ if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* should never happen */
865
+ return BIT_DStream_overflow;
887
866
 
888
867
  if (bitD->ptr >= bitD->start + sizeof(bitD->bitContainer))
889
868
  {
@@ -1010,55 +989,6 @@ static unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr, BIT_DStream_t* bi
1010
989
 
1011
990
  static unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr);
1012
991
 
1013
- /*!
1014
- Let's now decompose FSE_decompress_usingDTable() into its unitary components.
1015
- You will decode FSE-encoded symbols from the bitStream,
1016
- and also any other bitFields you put in, **in reverse order**.
1017
-
1018
- You will need a few variables to track your bitStream. They are :
1019
-
1020
- BIT_DStream_t DStream; // Stream context
1021
- FSE_DState_t DState; // State context. Multiple ones are possible
1022
- FSE_DTable* DTablePtr; // Decoding table, provided by FSE_buildDTable()
1023
-
1024
- The first thing to do is to init the bitStream.
1025
- errorCode = BIT_initDStream(&DStream, srcBuffer, srcSize);
1026
-
1027
- You should then retrieve your initial state(s)
1028
- (in reverse flushing order if you have several ones) :
1029
- errorCode = FSE_initDState(&DState, &DStream, DTablePtr);
1030
-
1031
- You can then decode your data, symbol after symbol.
1032
- For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'.
1033
- Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out).
1034
- unsigned char symbol = FSE_decodeSymbol(&DState, &DStream);
1035
-
1036
- You can retrieve any bitfield you eventually stored into the bitStream (in reverse order)
1037
- Note : maximum allowed nbBits is 25, for 32-bits compatibility
1038
- size_t bitField = BIT_readBits(&DStream, nbBits);
1039
-
1040
- All above operations only read from local register (which size depends on size_t).
1041
- Refueling the register from memory is manually performed by the reload method.
1042
- endSignal = FSE_reloadDStream(&DStream);
1043
-
1044
- BIT_reloadDStream() result tells if there is still some more data to read from DStream.
1045
- BIT_DStream_unfinished : there is still some data left into the DStream.
1046
- BIT_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled.
1047
- BIT_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed.
1048
- BIT_DStream_tooFar : Dstream went too far. Decompression result is corrupted.
1049
-
1050
- When reaching end of buffer (BIT_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop,
1051
- to properly detect the exact end of stream.
1052
- After each decoded symbol, check if DStream is fully consumed using this simple test :
1053
- BIT_reloadDStream(&DStream) >= BIT_DStream_completed
1054
-
1055
- When it's done, verify decompression is fully completed, by checking both DStream and the relevant states.
1056
- Checking if DStream has reached its end is performed by :
1057
- BIT_endOfDStream(&DStream);
1058
- Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible.
1059
- FSE_endOfDState(&DState);
1060
- */
1061
-
1062
992
 
1063
993
  /* *****************************************
1064
994
  * FSE unsafe API
@@ -1451,8 +1381,8 @@ static size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsi
1451
1381
  else
1452
1382
  {
1453
1383
  bitCount -= (int)(8 * (iend - 4 - ip));
1454
- ip = iend - 4;
1455
- }
1384
+ ip = iend - 4;
1385
+ }
1456
1386
  bitStream = MEM_readLE32(ip) >> (bitCount & 31);
1457
1387
  }
1458
1388
  }
@@ -2776,7 +2706,7 @@ static size_t ZSTD_decodeFrameHeader_Part2(ZSTD_DCtx* zc, const void* src, size_
2776
2706
  size_t result;
2777
2707
  if (srcSize != zc->headerSize) return ERROR(srcSize_wrong);
2778
2708
  result = ZSTD_getFrameParams(&(zc->params), src, srcSize);
2779
- if ((MEM_32bits()) && (zc->params.windowLog > 25)) return ERROR(frameParameter_unsupportedBy32bits);
2709
+ if ((MEM_32bits()) && (zc->params.windowLog > 25)) return ERROR(frameParameter_unsupported);
2780
2710
  return result;
2781
2711
  }
2782
2712
 
@@ -3665,7 +3595,7 @@ static size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbc, void* dst, size_t* maxDs
3665
3595
  break;
3666
3596
  }
3667
3597
  zbc->stage = ZBUFFds_read;
3668
-
3598
+ /* fall-through */
3669
3599
  case ZBUFFds_read:
3670
3600
  {
3671
3601
  size_t neededInSize = ZSTD_nextSrcSizeToDecompress(zbc->zc);
@@ -3691,7 +3621,7 @@ static size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbc, void* dst, size_t* maxDs
3691
3621
  if (ip==iend) { notDone = 0; break; } /* no more input */
3692
3622
  zbc->stage = ZBUFFds_load;
3693
3623
  }
3694
-
3624
+ /* fall-through */
3695
3625
  case ZBUFFds_load:
3696
3626
  {
3697
3627
  size_t neededInSize = ZSTD_nextSrcSizeToDecompress(zbc->zc);
@@ -3711,9 +3641,10 @@ static size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbc, void* dst, size_t* maxDs
3711
3641
  if (!decodedSize) { zbc->stage = ZBUFFds_read; break; } /* this was just a header */
3712
3642
  zbc->outEnd = zbc->outStart + decodedSize;
3713
3643
  zbc->stage = ZBUFFds_flush;
3714
- // break; /* ZBUFFds_flush follows */
3644
+ /* ZBUFFds_flush follows */
3715
3645
  }
3716
3646
  }
3647
+ /* fall-through */
3717
3648
  case ZBUFFds_flush:
3718
3649
  {
3719
3650
  size_t toFlushSize = zbc->outEnd - zbc->outStart;
@@ -1,10 +1,11 @@
1
- /**
1
+ /*
2
2
  * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
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.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
8
9
  */
9
10
 
10
11
  #ifndef ZSTD_V04_H_91868324769238