Skip to content

Commit ad0437e

Browse files
authored
Merge pull request #57 from SpringMT/update-zstd-for-v1.5.5
Update zstd to v1.5.5
2 parents 93d601f + 080a434 commit ad0437e

25 files changed

+921
-567
lines changed

README.md

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

1212
## Zstd version
13-
v1.5.4 (https://github.com/facebook/zstd/tree/v1.5.4)
13+
v1.5.5 (https://github.com/facebook/zstd/tree/v1.5.5)
1414

1515
## Installation
1616

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
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+
* You may select, at your option, one of the above-listed licenses.
9+
*/
10+
11+
/* This file provides custom allocation primitives
12+
*/
13+
14+
#define ZSTD_DEPS_NEED_MALLOC
15+
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
16+
17+
#include "mem.h" /* MEM_STATIC */
18+
#define ZSTD_STATIC_LINKING_ONLY
19+
#include "../zstd.h" /* ZSTD_customMem */
20+
21+
#ifndef ZSTD_ALLOCATIONS_H
22+
#define ZSTD_ALLOCATIONS_H
23+
24+
/* custom memory allocation functions */
25+
26+
MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
27+
{
28+
if (customMem.customAlloc)
29+
return customMem.customAlloc(customMem.opaque, size);
30+
return ZSTD_malloc(size);
31+
}
32+
33+
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
34+
{
35+
if (customMem.customAlloc) {
36+
/* calloc implemented as malloc+memset;
37+
* not as efficient as calloc, but next best guess for custom malloc */
38+
void* const ptr = customMem.customAlloc(customMem.opaque, size);
39+
ZSTD_memset(ptr, 0, size);
40+
return ptr;
41+
}
42+
return ZSTD_calloc(1, size);
43+
}
44+
45+
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
46+
{
47+
if (ptr!=NULL) {
48+
if (customMem.customFree)
49+
customMem.customFree(customMem.opaque, ptr);
50+
else
51+
ZSTD_free(ptr);
52+
}
53+
}
54+
55+
#endif /* ZSTD_ALLOCATIONS_H */

ext/zstdruby/libzstd/common/bits.h

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ MEM_STATIC unsigned ZSTD_countTrailingZeros32_fallback(U32 val)
1717
{
1818
assert(val != 0);
1919
{
20-
static const int DeBruijnBytePos[32] = {0, 1, 28, 2, 29, 14, 24, 3,
20+
static const U32 DeBruijnBytePos[32] = {0, 1, 28, 2, 29, 14, 24, 3,
2121
30, 22, 20, 15, 25, 17, 4, 8,
2222
31, 27, 13, 23, 21, 19, 16, 7,
2323
26, 12, 18, 6, 11, 5, 10, 9};
@@ -30,7 +30,7 @@ MEM_STATIC unsigned ZSTD_countTrailingZeros32(U32 val)
3030
assert(val != 0);
3131
# if defined(_MSC_VER)
3232
# if STATIC_BMI2 == 1
33-
return _tzcnt_u32(val);
33+
return (unsigned)_tzcnt_u32(val);
3434
# else
3535
if (val != 0) {
3636
unsigned long r;
@@ -69,7 +69,7 @@ MEM_STATIC unsigned ZSTD_countLeadingZeros32(U32 val)
6969
assert(val != 0);
7070
# if defined(_MSC_VER)
7171
# if STATIC_BMI2 == 1
72-
return _lzcnt_u32(val);
72+
return (unsigned)_lzcnt_u32(val);
7373
# else
7474
if (val != 0) {
7575
unsigned long r;
@@ -92,7 +92,7 @@ MEM_STATIC unsigned ZSTD_countTrailingZeros64(U64 val)
9292
assert(val != 0);
9393
# if defined(_MSC_VER) && defined(_WIN64)
9494
# if STATIC_BMI2 == 1
95-
return _tzcnt_u64(val);
95+
return (unsigned)_tzcnt_u64(val);
9696
# else
9797
if (val != 0) {
9898
unsigned long r;
@@ -123,7 +123,7 @@ MEM_STATIC unsigned ZSTD_countLeadingZeros64(U64 val)
123123
assert(val != 0);
124124
# if defined(_MSC_VER) && defined(_WIN64)
125125
# if STATIC_BMI2 == 1
126-
return _lzcnt_u64(val);
126+
return (unsigned)_lzcnt_u64(val);
127127
# else
128128
if (val != 0) {
129129
unsigned long r;
@@ -172,4 +172,29 @@ MEM_STATIC unsigned ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCo
172172
return 31 - ZSTD_countLeadingZeros32(val);
173173
}
174174

175+
/* ZSTD_rotateRight_*():
176+
* Rotates a bitfield to the right by "count" bits.
177+
* https://en.wikipedia.org/w/index.php?title=Circular_shift&oldid=991635599#Implementing_circular_shifts
178+
*/
179+
MEM_STATIC
180+
U64 ZSTD_rotateRight_U64(U64 const value, U32 count) {
181+
assert(count < 64);
182+
count &= 0x3F; /* for fickle pattern recognition */
183+
return (value >> count) | (U64)(value << ((0U - count) & 0x3F));
184+
}
185+
186+
MEM_STATIC
187+
U32 ZSTD_rotateRight_U32(U32 const value, U32 count) {
188+
assert(count < 32);
189+
count &= 0x1F; /* for fickle pattern recognition */
190+
return (value >> count) | (U32)(value << ((0U - count) & 0x1F));
191+
}
192+
193+
MEM_STATIC
194+
U16 ZSTD_rotateRight_U16(U16 const value, U32 count) {
195+
assert(count < 16);
196+
count &= 0x0F; /* for fickle pattern recognition */
197+
return (value >> count) | (U16)(value << ((0U - count) & 0x0F));
198+
}
199+
175200
#endif /* ZSTD_BITS_H */

ext/zstdruby/libzstd/common/bitstream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t* bitD)
396396
* This function is safe, it guarantees it will not read beyond src buffer.
397397
* @return : status of `BIT_DStream_t` internal register.
398398
* when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */
399-
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
399+
MEM_STATIC FORCE_INLINE_ATTR BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
400400
{
401401
if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* overflow detected, like end of stream */
402402
return BIT_DStream_overflow;

ext/zstdruby/libzstd/common/compiler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ void __msan_poison(const volatile void *a, size_t size);
311311
/* Returns the offset of the first (at least partially) poisoned byte in the
312312
memory range, or -1 if the whole range is good. */
313313
intptr_t __msan_test_shadow(const volatile void *x, size_t size);
314+
315+
/* Print shadow and origin for the memory range to stderr in a human-readable
316+
format. */
317+
void __msan_print_shadow(const volatile void *x, size_t size);
314318
#endif
315319

316320
#if ZSTD_ADDRESS_SANITIZER && !defined(ZSTD_ASAN_DONT_POISON_WORKSPACE)

ext/zstdruby/libzstd/common/pool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111

1212
/* ====== Dependencies ======= */
13+
#include "../common/allocations.h" /* ZSTD_customCalloc, ZSTD_customFree */
1314
#include "zstd_deps.h" /* size_t */
1415
#include "debug.h" /* assert */
15-
#include "zstd_internal.h" /* ZSTD_customCalloc, ZSTD_customFree */
1616
#include "pool.h"
1717

1818
/* ====== Compiler specifics ====== */

ext/zstdruby/libzstd/common/threading.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static unsigned __stdcall worker(void *arg)
4747
void* (*start_routine)(void*);
4848
void* thread_arg;
4949

50-
/* Inialized thread_arg and start_routine and signal main thread that we don't need it
50+
/* Initialized thread_arg and start_routine and signal main thread that we don't need it
5151
* to wait any longer.
5252
*/
5353
{

ext/zstdruby/libzstd/common/zstd_common.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* Dependencies
1515
***************************************/
1616
#define ZSTD_DEPS_NEED_MALLOC
17-
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
1817
#include "error_private.h"
1918
#include "zstd_internal.h"
2019

@@ -47,37 +46,3 @@ ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
4746
/*! ZSTD_getErrorString() :
4847
* provides error code string from enum */
4948
const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
50-
51-
52-
53-
/*=**************************************************************
54-
* Custom allocator
55-
****************************************************************/
56-
void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
57-
{
58-
if (customMem.customAlloc)
59-
return customMem.customAlloc(customMem.opaque, size);
60-
return ZSTD_malloc(size);
61-
}
62-
63-
void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
64-
{
65-
if (customMem.customAlloc) {
66-
/* calloc implemented as malloc+memset;
67-
* not as efficient as calloc, but next best guess for custom malloc */
68-
void* const ptr = customMem.customAlloc(customMem.opaque, size);
69-
ZSTD_memset(ptr, 0, size);
70-
return ptr;
71-
}
72-
return ZSTD_calloc(1, size);
73-
}
74-
75-
void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
76-
{
77-
if (ptr!=NULL) {
78-
if (customMem.customFree)
79-
customMem.customFree(customMem.opaque, ptr);
80-
else
81-
ZSTD_free(ptr);
82-
}
83-
}

ext/zstdruby/libzstd/common/zstd_internal.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,6 @@ typedef struct {
350350
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
351351
int ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
352352

353-
/* custom memory allocation functions */
354-
void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem);
355-
void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem);
356-
void ZSTD_customFree(void* ptr, ZSTD_customMem customMem);
357-
358353

359354
/* ZSTD_invalidateRepCodes() :
360355
* ensures next compression will not use repcodes from previous block.

0 commit comments

Comments
 (0)