Skip to content

Commit 8a3a741

Browse files
authored
Merge pull request #7 from SpringMT/update-zstd-for-v1.3.0
Update zstd version to v1.3.0
2 parents aac79de + 07327d9 commit 8a3a741

30 files changed

+2949
-1421
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.2.0 (https://github.com/facebook/zstd/tree/v1.2.0)
12+
v1.3.0 (https://github.com/facebook/zstd/tree/v1.3.0)
1313

1414
## Installation
1515

ext/zstdruby/libzstd/Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ VERSION?= $(LIBVER)
2222

2323
CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_
2424
CFLAGS ?= -O3
25-
DEBUGFLAGS = -g -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
26-
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
27-
-Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security
25+
DEBUGFLAGS = -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
26+
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
27+
-Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \
28+
-Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
29+
-Wredundant-decls
2830
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
2931
FLAGS = $(CPPFLAGS) $(CFLAGS)
3032

@@ -71,7 +73,7 @@ libzstd.a: $(ZSTD_OBJ)
7173
@echo compiling static library
7274
@$(AR) $(ARFLAGS) $@ $^
7375

74-
libzstd.a-mt: CPPFLAGS += -DZSTD_MULTHREAD
76+
libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD
7577
libzstd.a-mt: libzstd.a
7678

7779
$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
@@ -147,7 +149,7 @@ install: libzstd.a libzstd libzstd.pc
147149
@$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ $(DESTDIR)$(INCLUDEDIR)/
148150
@$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
149151
@echo Installing libraries
150-
@$(INSTALL_LIB) libzstd.a $(DESTDIR)$(LIBDIR)
152+
@$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
151153
@$(INSTALL_LIB) libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)
152154
@ln -sf libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
153155
@ln -sf libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)

ext/zstdruby/libzstd/common/bitstream.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
extern "C" {
4040
#endif
4141

42-
4342
/*
4443
* This API consists of small unitary functions, which must be inlined for best performance.
4544
* Since link-time-optimization is not available for all compilers,
@@ -59,7 +58,9 @@ extern "C" {
5958
#if defined(BIT_DEBUG) && (BIT_DEBUG>=1)
6059
# include <assert.h>
6160
#else
62-
# define assert(condition) ((void)0)
61+
# ifndef assert
62+
# define assert(condition) ((void)0)
63+
# endif
6364
#endif
6465

6566

@@ -74,6 +75,7 @@ extern "C" {
7475
#define STREAM_ACCUMULATOR_MIN_64 57
7576
#define STREAM_ACCUMULATOR_MIN ((U32)(MEM_32bits() ? STREAM_ACCUMULATOR_MIN_32 : STREAM_ACCUMULATOR_MIN_64))
7677

78+
7779
/*-******************************************
7880
* bitStream encoding API (write forward)
7981
********************************************/
@@ -303,13 +305,25 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
303305
bitD->bitContainer = *(const BYTE*)(bitD->start);
304306
switch(srcSize)
305307
{
306-
case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
307-
case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
308-
case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
309-
case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
310-
case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
311-
case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
312-
default:;
308+
case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
309+
/* fall-through */
310+
311+
case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
312+
/* fall-through */
313+
314+
case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
315+
/* fall-through */
316+
317+
case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
318+
/* fall-through */
319+
320+
case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
321+
/* fall-through */
322+
323+
case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
324+
/* fall-through */
325+
326+
default: break;
313327
}
314328
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
315329
bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;

ext/zstdruby/libzstd/common/error_private.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const char* ERR_getErrorString(ERR_enum code)
2424
case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
2525
case PREFIX(frameParameter_unsupportedBy32bits): return "Frame parameter unsupported in 32-bits mode";
2626
case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
27-
case PREFIX(compressionParameter_unsupported): return "Compression parameter is out of bound";
27+
case PREFIX(compressionParameter_unsupported): return "Compression parameter is not supported";
28+
case PREFIX(compressionParameter_outOfBound): return "Compression parameter is out of bound";
2829
case PREFIX(init_missing): return "Context should be init first";
2930
case PREFIX(memory_allocation): return "Allocation error : not enough memory";
3031
case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
@@ -38,6 +39,8 @@ const char* ERR_getErrorString(ERR_enum code)
3839
case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
3940
case PREFIX(dictionary_wrong): return "Dictionary mismatch";
4041
case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
42+
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
43+
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
4144
case PREFIX(maxCode):
4245
default: return notErrorCode;
4346
}

ext/zstdruby/libzstd/common/huf.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity, const void*
111111
#define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32))
112112
HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
113113

114+
/**
115+
* The minimum workspace size for the `workSpace` used in
116+
* HUF_readDTableX2_wksp() and HUF_readDTableX4_wksp().
117+
*
118+
* The space used depends on HUF_TABLELOG_MAX, ranging from ~1500 bytes when
119+
* HUF_TABLE_LOG_MAX=12 to ~1850 bytes when HUF_TABLE_LOG_MAX=15.
120+
* Buffer overflow errors may potentially occur if code modifications result in
121+
* a required workspace size greater than that specified in the following
122+
* macro.
123+
*/
124+
#define HUF_DECOMPRESS_WORKSPACE_SIZE (2 << 10)
125+
#define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32))
114126

115127

116128
/* ******************************************************************
@@ -170,8 +182,11 @@ size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, size_t cS
170182

171183
size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */
172184
size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */
185+
size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< considers RLE and uncompressed as errors */
173186
size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
187+
size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */
174188
size_t HUF_decompress4X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
189+
size_t HUF_decompress4X4_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */
175190

176191

177192
/* ****************************************
@@ -243,7 +258,9 @@ HUF_decompress() does the following:
243258
U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize);
244259

245260
size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize);
261+
size_t HUF_readDTableX2_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
246262
size_t HUF_readDTableX4 (HUF_DTable* DTable, const void* src, size_t srcSize);
263+
size_t HUF_readDTableX4_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
247264

248265
size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
249266
size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
@@ -266,8 +283,11 @@ size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cS
266283
size_t HUF_decompress1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */
267284

268285
size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
286+
size_t HUF_decompress1X_DCtx_wksp (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize);
269287
size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
288+
size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */
270289
size_t HUF_decompress1X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
290+
size_t HUF_decompress1X4_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */
271291

272292
size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); /**< automatic selection of sing or double symbol decoder, based on DTable */
273293
size_t HUF_decompress1X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);

ext/zstdruby/libzstd/common/mem.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -352,20 +352,6 @@ MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val)
352352
}
353353

354354

355-
/* function safe only for comparisons */
356-
MEM_STATIC U32 MEM_readMINMATCH(const void* memPtr, U32 length)
357-
{
358-
switch (length)
359-
{
360-
default :
361-
case 4 : return MEM_read32(memPtr);
362-
case 3 : if (MEM_isLittleEndian())
363-
return MEM_read32(memPtr)<<8;
364-
else
365-
return MEM_read32(memPtr)>>8;
366-
}
367-
}
368-
369355
#if defined (__cplusplus)
370356
}
371357
#endif

ext/zstdruby/libzstd/common/pool.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ void POOL_free(POOL_ctx *ctx) {
146146
free(ctx);
147147
}
148148

149+
size_t POOL_sizeof(POOL_ctx *ctx) {
150+
if (ctx==NULL) return 0; /* supports sizeof NULL */
151+
return sizeof(*ctx)
152+
+ ctx->queueSize * sizeof(POOL_job)
153+
+ ctx->numThreads * sizeof(pthread_t);
154+
}
155+
149156
void POOL_add(void *ctxVoid, POOL_function function, void *opaque) {
150157
POOL_ctx *ctx = (POOL_ctx *)ctxVoid;
151158
if (!ctx) { return; }
@@ -191,4 +198,9 @@ void POOL_add(void *ctx, POOL_function function, void *opaque) {
191198
function(opaque);
192199
}
193200

201+
size_t POOL_sizeof(POOL_ctx *ctx) {
202+
if (ctx==NULL) return 0; /* supports sizeof NULL */
203+
return sizeof(*ctx);
204+
}
205+
194206
#endif /* ZSTD_MULTITHREAD */

ext/zstdruby/libzstd/common/pool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ POOL_ctx *POOL_create(size_t numThreads, size_t queueSize);
3232
*/
3333
void POOL_free(POOL_ctx *ctx);
3434

35+
/*! POOL_sizeof() :
36+
return memory usage of pool returned by POOL_create().
37+
*/
38+
size_t POOL_sizeof(POOL_ctx *ctx);
39+
3540
/*! POOL_function :
3641
The function type that can be added to a thread pool.
3742
*/

ext/zstdruby/libzstd/common/threading.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Copyright (c) 2016 Tino Reichardt
43
* All rights reserved.

ext/zstdruby/libzstd/common/zstd_common.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@
1212
/*-*************************************
1313
* Dependencies
1414
***************************************/
15-
#include <stdlib.h> /* malloc */
15+
#include <stdlib.h> /* malloc, calloc, free */
16+
#include <string.h> /* memset */
1617
#include "error_private.h"
1718
#define ZSTD_STATIC_LINKING_ONLY
18-
#include "zstd.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
19+
#include "zstd.h"
1920

2021

2122
/*-****************************************
2223
* Version
2324
******************************************/
24-
unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
25+
unsigned ZSTD_versionNumber(void) { return ZSTD_VERSION_NUMBER; }
26+
27+
const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
2528

2629

2730
/*-****************************************
@@ -47,27 +50,31 @@ const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString
4750
/*=**************************************************************
4851
* Custom allocator
4952
****************************************************************/
50-
/* default uses stdlib */
51-
void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
52-
{
53-
void* address = malloc(size);
54-
(void)opaque;
55-
return address;
56-
}
57-
58-
void ZSTD_defaultFreeFunction(void* opaque, void* address)
53+
void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
5954
{
60-
(void)opaque;
61-
free(address);
55+
if (customMem.customAlloc)
56+
return customMem.customAlloc(customMem.opaque, size);
57+
return malloc(size);
6258
}
6359

64-
void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
60+
void* ZSTD_calloc(size_t size, ZSTD_customMem customMem)
6561
{
66-
return customMem.customAlloc(customMem.opaque, size);
62+
if (customMem.customAlloc) {
63+
/* calloc implemented as malloc+memset;
64+
* not as efficient as calloc, but next best guess for custom malloc */
65+
void* const ptr = customMem.customAlloc(customMem.opaque, size);
66+
memset(ptr, 0, size);
67+
return ptr;
68+
}
69+
return calloc(1, size);
6770
}
6871

6972
void ZSTD_free(void* ptr, ZSTD_customMem customMem)
7073
{
71-
if (ptr!=NULL)
72-
customMem.customFree(customMem.opaque, ptr);
74+
if (ptr!=NULL) {
75+
if (customMem.customFree)
76+
customMem.customFree(customMem.opaque, ptr);
77+
else
78+
free(ptr);
79+
}
7380
}

0 commit comments

Comments
 (0)