Skip to content

Commit 4c7d314

Browse files
author
haruyama.makoto
committed
Update zstd to v1.3.1
1 parent 8a3a741 commit 4c7d314

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1252
-1116
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ See https://github.com/facebook/zstd
99
Fork from https://github.com/jarredholman/ruby-zstd.
1010

1111
## Zstd version
12-
v1.3.0 (https://github.com/facebook/zstd/tree/v1.3.0)
12+
v1.3.1 (https://github.com/facebook/zstd/tree/v1.3.1)
1313

1414
## Installation
1515

ext/zstdruby/libzstd/common/bitstream.h

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ extern "C" {
8080
* bitStream encoding API (write forward)
8181
********************************************/
8282
/* bitStream can mix input from multiple sources.
83-
* A critical property of these streams is that they encode and decode in **reverse** direction.
84-
* So the first bit sequence you add will be the last to be read, like a LIFO stack.
85-
*/
83+
* A critical property of these streams is that they encode and decode in **reverse** direction.
84+
* So the first bit sequence you add will be the last to be read, like a LIFO stack.
85+
*/
8686
typedef struct
8787
{
8888
size_t bitContainer;
@@ -203,7 +203,7 @@ static const unsigned BIT_mask[] = { 0, 1, 3, 7, 0xF, 0x1F, 0x3F, 0x7F,
203203
/*! BIT_initCStream() :
204204
* `dstCapacity` must be > sizeof(size_t)
205205
* @return : 0 if success,
206-
otherwise an error code (can be tested using ERR_isError() ) */
206+
* otherwise an error code (can be tested using ERR_isError()) */
207207
MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
208208
void* startPtr, size_t dstCapacity)
209209
{
@@ -217,8 +217,8 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
217217
}
218218

219219
/*! BIT_addBits() :
220-
can add up to 26 bits into `bitC`.
221-
Does not check for register overflow ! */
220+
* can add up to 26 bits into `bitC`.
221+
* Note : does not check for register overflow ! */
222222
MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
223223
size_t value, unsigned nbBits)
224224
{
@@ -268,7 +268,7 @@ MEM_STATIC void BIT_flushBits(BIT_CStream_t* bitC)
268268

269269
/*! BIT_closeCStream() :
270270
* @return : size of CStream, in bytes,
271-
or 0 if it could not fit into dstBuffer */
271+
* or 0 if it could not fit into dstBuffer */
272272
MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC)
273273
{
274274
BIT_addBitsFast(bitC, 1, 1); /* endMark */
@@ -279,14 +279,14 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC)
279279

280280

281281
/*-********************************************************
282-
* bitStream decoding
282+
* bitStream decoding
283283
**********************************************************/
284284
/*! BIT_initDStream() :
285-
* Initialize a BIT_DStream_t.
286-
* `bitD` : a pointer to an already allocated BIT_DStream_t structure.
287-
* `srcSize` must be the *exact* size of the bitStream, in bytes.
288-
* @return : size of stream (== srcSize) or an errorCode if a problem is detected
289-
*/
285+
* Initialize a BIT_DStream_t.
286+
* `bitD` : a pointer to an already allocated BIT_DStream_t structure.
287+
* `srcSize` must be the *exact* size of the bitStream, in bytes.
288+
* @return : size of stream (== srcSize), or an errorCode if a problem is detected
289+
*/
290290
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize)
291291
{
292292
if (srcSize < 1) { memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
@@ -305,29 +305,30 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
305305
bitD->bitContainer = *(const BYTE*)(bitD->start);
306306
switch(srcSize)
307307
{
308-
case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
309-
/* fall-through */
308+
case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
309+
/* fall-through */
310310

311-
case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
312-
/* fall-through */
311+
case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
312+
/* fall-through */
313313

314-
case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
315-
/* fall-through */
314+
case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
315+
/* fall-through */
316316

317-
case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
318-
/* fall-through */
317+
case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
318+
/* fall-through */
319319

320-
case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
321-
/* fall-through */
320+
case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
321+
/* fall-through */
322322

323-
case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
324-
/* fall-through */
323+
case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
324+
/* fall-through */
325325

326-
default: break;
326+
default: break;
327+
}
328+
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
329+
bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;
330+
if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */
327331
}
328-
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
329-
bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;
330-
if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
331332
bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
332333
}
333334

@@ -363,9 +364,8 @@ MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
363364
* local register is not modified.
364365
* On 32-bits, maxNbBits==24.
365366
* On 64-bits, maxNbBits==56.
366-
* @return : value extracted
367-
*/
368-
MEM_STATIC size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
367+
* @return : value extracted */
368+
MEM_STATIC size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
369369
{
370370
#if defined(__BMI__) && defined(__GNUC__) /* experimental; fails if bitD->bitsConsumed + nbBits > sizeof(bitD->bitContainer)*8 */
371371
return BIT_getMiddleBits(bitD->bitContainer, (sizeof(bitD->bitContainer)*8) - bitD->bitsConsumed - nbBits, nbBits);
@@ -392,8 +392,7 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
392392
/*! BIT_readBits() :
393393
* Read (consume) next n bits from local register and update.
394394
* Pay attention to not read more than nbBits contained into local register.
395-
* @return : extracted value.
396-
*/
395+
* @return : extracted value. */
397396
MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
398397
{
399398
size_t const value = BIT_lookBits(bitD, nbBits);
@@ -402,7 +401,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
402401
}
403402

404403
/*! BIT_readBitsFast() :
405-
* unsafe version; only works only if nbBits >= 1 */
404+
* unsafe version; only works only if nbBits >= 1 */
406405
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
407406
{
408407
size_t const value = BIT_lookBitsFast(bitD, nbBits);
@@ -412,10 +411,10 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
412411
}
413412

414413
/*! BIT_reloadDStream() :
415-
* Refill `bitD` from buffer previously set in BIT_initDStream() .
416-
* This function is safe, it guarantees it will not read beyond src buffer.
417-
* @return : status of `BIT_DStream_t` internal register.
418-
if status == BIT_DStream_unfinished, internal register is filled with >= (sizeof(bitD->bitContainer)*8 - 7) bits */
414+
* Refill `bitD` from buffer previously set in BIT_initDStream() .
415+
* This function is safe, it guarantees it will not read beyond src buffer.
416+
* @return : status of `BIT_DStream_t` internal register.
417+
* when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */
419418
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
420419
{
421420
if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* overflow detected, like end of stream */
@@ -446,8 +445,8 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
446445
}
447446

448447
/*! BIT_endOfDStream() :
449-
* @return Tells if DStream has exactly reached its end (all bits consumed).
450-
*/
448+
* @return : 1 if DStream has _exactly_ reached its end (all bits consumed).
449+
*/
451450
MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
452451
{
453452
return ((DStream->ptr == DStream->start) && (DStream->bitsConsumed == sizeof(DStream->bitContainer)*8));
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3+
* All rights reserved.
4+
*
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+
*/
9+
10+
#ifndef ZSTD_COMPILER_H
11+
#define ZSTD_COMPILER_H
12+
13+
/*-*******************************************************
14+
* Compiler specifics
15+
*********************************************************/
16+
/* force inlining */
17+
#if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
18+
# define INLINE_KEYWORD inline
19+
#else
20+
# define INLINE_KEYWORD
21+
#endif
22+
23+
#if defined(__GNUC__)
24+
# define FORCE_INLINE_ATTR __attribute__((always_inline))
25+
#elif defined(_MSC_VER)
26+
# define FORCE_INLINE_ATTR __forceinline
27+
#else
28+
# define FORCE_INLINE_ATTR
29+
#endif
30+
31+
/**
32+
* FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
33+
* parameters. They must be inlined for the compiler to elimininate the constant
34+
* branches.
35+
*/
36+
#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
37+
/**
38+
* HINT_INLINE is used to help the compiler generate better code. It is *not*
39+
* used for "templates", so it can be tweaked based on the compilers
40+
* performance.
41+
*
42+
* gcc-4.8 and gcc-4.9 have been shown to benefit from leaving off the
43+
* always_inline attribute.
44+
*
45+
* clang up to 5.0.0 (trunk) benefit tremendously from the always_inline
46+
* attribute.
47+
*/
48+
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5
49+
# define HINT_INLINE static INLINE_KEYWORD
50+
#else
51+
# define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR
52+
#endif
53+
54+
/* force no inlining */
55+
#ifdef _MSC_VER
56+
# define FORCE_NOINLINE static __declspec(noinline)
57+
#else
58+
# ifdef __GNUC__
59+
# define FORCE_NOINLINE static __attribute__((__noinline__))
60+
# else
61+
# define FORCE_NOINLINE static
62+
# endif
63+
#endif
64+
65+
/* prefetch */
66+
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
67+
# include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
68+
# define PREFETCH(ptr) _mm_prefetch((const char*)ptr, _MM_HINT_T0)
69+
#elif defined(__GNUC__)
70+
# define PREFETCH(ptr) __builtin_prefetch(ptr, 0, 0)
71+
#else
72+
# define PREFETCH(ptr) /* disabled */
73+
#endif
74+
75+
/* disable warnings */
76+
#ifdef _MSC_VER /* Visual Studio */
77+
# include <intrin.h> /* For Visual 2005 */
78+
# pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */
79+
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
80+
# pragma warning(disable : 4204) /* disable: C4204: non-constant aggregate initializer */
81+
# pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
82+
# pragma warning(disable : 4324) /* disable: C4324: padded structure */
83+
#endif
84+
85+
#endif /* ZSTD_COMPILER_H */

ext/zstdruby/libzstd/common/error_private.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/**
1+
/*
22
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
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).
88
*/
99

1010
/* The purpose of this file is to have a single list of error strings embedded in binary */
@@ -20,19 +20,17 @@ const char* ERR_getErrorString(ERR_enum code)
2020
case PREFIX(GENERIC): return "Error (generic)";
2121
case PREFIX(prefix_unknown): return "Unknown frame descriptor";
2222
case PREFIX(version_unsupported): return "Version not supported";
23-
case PREFIX(parameter_unknown): return "Unknown parameter type";
2423
case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
25-
case PREFIX(frameParameter_unsupportedBy32bits): return "Frame parameter unsupported in 32-bits mode";
2624
case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
27-
case PREFIX(compressionParameter_unsupported): return "Compression parameter is not supported";
28-
case PREFIX(compressionParameter_outOfBound): return "Compression parameter is out of bound";
25+
case PREFIX(corruption_detected): return "Corrupted block detected";
26+
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
27+
case PREFIX(parameter_unsupported): return "Unsupported parameter";
28+
case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
2929
case PREFIX(init_missing): return "Context should be init first";
3030
case PREFIX(memory_allocation): return "Allocation error : not enough memory";
3131
case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
3232
case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
3333
case PREFIX(srcSize_wrong): return "Src size is incorrect";
34-
case PREFIX(corruption_detected): return "Corrupted block detected";
35-
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
3634
case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
3735
case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
3836
case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";

ext/zstdruby/libzstd/common/error_private.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/**
1+
/*
22
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
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).
88
*/
99

1010
/* Note : this module is expected to remain private, do not expose it */

ext/zstdruby/libzstd/common/fse.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
You can contact the author at :
3232
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
3333
****************************************************************** */
34-
#ifndef FSE_H
35-
#define FSE_H
3634

3735
#if defined (__cplusplus)
3836
extern "C" {
3937
#endif
4038

39+
#ifndef FSE_H
40+
#define FSE_H
41+
4142

4243
/*-*****************************************
4344
* Dependencies
@@ -297,8 +298,10 @@ FSE_decompress_usingDTable() result will tell how many bytes were regenerated (<
297298
If there is an error, the function will return an error code, which can be tested using FSE_isError(). (ex: dst buffer too small)
298299
*/
299300

301+
#endif /* FSE_H */
300302

301-
#ifdef FSE_STATIC_LINKING_ONLY
303+
#if defined(FSE_STATIC_LINKING_ONLY) && !defined(FSE_H_FSE_STATIC_LINKING_ONLY)
304+
#define FSE_H_FSE_STATIC_LINKING_ONLY
302305

303306
/* *** Dependency *** */
304307
#include "bitstream.h"
@@ -381,6 +384,11 @@ size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue);
381384
size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, FSE_DTable* workSpace, unsigned maxLog);
382385
/**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DTABLE_SIZE_U32(maxLog)` */
383386

387+
typedef enum {
388+
FSE_repeat_none, /**< Cannot use the previous table */
389+
FSE_repeat_check, /**< Can use the previous table but it must be checked */
390+
FSE_repeat_valid /**< Can use the previous table and it is asumed to be valid */
391+
} FSE_repeat;
384392

385393
/* *****************************************
386394
* FSE symbol compression API
@@ -694,5 +702,3 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
694702
#if defined (__cplusplus)
695703
}
696704
#endif
697-
698-
#endif /* FSE_H */

0 commit comments

Comments
 (0)