Skip to content

Commit

Permalink
allow zstd to be amalgamated
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed Oct 23, 2024
1 parent cf3c5b5 commit d92f3a0
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 27 deletions.
3 changes: 3 additions & 0 deletions third_party/zstd/common/pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@


/* ====== Dependencies ======= */
// DuckDB: just enable everything for amalgamation
#define ZSTD_MULTITHREAD

#include "zstd/common/allocations.h" /* ZSTD_customCalloc, ZSTD_customFree */
#include "zstd/common/zstd_deps.h" /* size_t */
#include "zstd/common/debug.h" /* assert */
Expand Down
23 changes: 12 additions & 11 deletions third_party/zstd/common/xxhash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
# define FORCE_INLINE_ATTR
#endif

#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
// DuckDB: prefixed with XXHASH_ to avoid name conflicts
#define XXHASH_FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR


/* *************************************
Expand Down Expand Up @@ -237,15 +238,15 @@ typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
*****************************/
typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;

FORCE_INLINE_TEMPLATE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
XXHASH_FORCE_INLINE_TEMPLATE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
{
if (align==XXH_unaligned)
return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
else
return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
}

FORCE_INLINE_TEMPLATE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
XXHASH_FORCE_INLINE_TEMPLATE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
{
return XXH_readLE32_align(ptr, endian, XXH_unaligned);
}
Expand All @@ -255,15 +256,15 @@ static U32 XXH_readBE32(const void* ptr)
return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr);
}

FORCE_INLINE_TEMPLATE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
XXHASH_FORCE_INLINE_TEMPLATE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
{
if (align==XXH_unaligned)
return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
else
return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
}

FORCE_INLINE_TEMPLATE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
XXHASH_FORCE_INLINE_TEMPLATE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
{
return XXH_readLE64_align(ptr, endian, XXH_unaligned);
}
Expand Down Expand Up @@ -324,7 +325,7 @@ static U32 XXH32_round(U32 seed, U32 input)
return seed;
}

FORCE_INLINE_TEMPLATE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
XXHASH_FORCE_INLINE_TEMPLATE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
{
const BYTE* p = (const BYTE*)input;
const BYTE* bEnd = p + len;
Expand Down Expand Up @@ -424,7 +425,7 @@ static U64 XXH64_mergeRound(U64 acc, U64 val)
return acc;
}

FORCE_INLINE_TEMPLATE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
XXHASH_FORCE_INLINE_TEMPLATE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
{
const BYTE* p = (const BYTE*)input;
const BYTE* const bEnd = p + len;
Expand Down Expand Up @@ -573,7 +574,7 @@ XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long
}


FORCE_INLINE_TEMPLATE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian)
XXHASH_FORCE_INLINE_TEMPLATE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian)
{
const BYTE* p = (const BYTE*)input;
const BYTE* const bEnd = p + len;
Expand Down Expand Up @@ -643,7 +644,7 @@ XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void*



FORCE_INLINE_TEMPLATE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian)
XXHASH_FORCE_INLINE_TEMPLATE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian)
{
const BYTE * p = (const BYTE*)state->mem32;
const BYTE* const bEnd = (const BYTE*)(state->mem32) + state->memsize;
Expand Down Expand Up @@ -693,7 +694,7 @@ XXH_PUBLIC_API unsigned int XXH32_digest (const XXH32_state_t* state_in)

/* **** XXH64 **** */

FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian)
XXHASH_FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian)
{
const BYTE* p = (const BYTE*)input;
const BYTE* const bEnd = p + len;
Expand Down Expand Up @@ -762,7 +763,7 @@ XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void*



FORCE_INLINE_TEMPLATE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian)
XXHASH_FORCE_INLINE_TEMPLATE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian)
{
const BYTE * p = (const BYTE*)state->mem64;
const BYTE* const bEnd = (const BYTE*)state->mem64 + state->memsize;
Expand Down
2 changes: 1 addition & 1 deletion third_party/zstd/decompress/zstd_ddict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "zstd/decompress/zstd_ddict.h"

#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
// # include "zstd/legacy/zstd_legacy.h"
// # include "zstd/legacy/zstd_legacy.h" // DuckDB: comment out otherwise amalgamation won't be happy
#endif

namespace duckdb_zstd {
Expand Down
2 changes: 1 addition & 1 deletion third_party/zstd/decompress/zstd_decompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#include "zstd/decompress/zstd_decompress_block.h" /* ZSTD_decompressBlock_internal */

#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
// # include "zstd/legacy/zstd_legacy.h"
// # include "zstd/legacy/zstd_legacy.h" // DuckDB: comment out otherwise amalgamation won't be happy
#endif


Expand Down
3 changes: 3 additions & 0 deletions third_party/zstd/include/zstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#ifndef ZSTD_H_235446
#define ZSTD_H_235446

// DuckDB: just enable everything for amalgamation
#define ZSTD_STATIC_LINKING_ONLY

/* ====== Dependencies ======*/
#include <limits.h> /* INT_MAX */
#include <stddef.h> /* size_t */
Expand Down
4 changes: 2 additions & 2 deletions third_party/zstd/include/zstd/common/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

#if (DEBUGLEVEL>=1)
# define ZSTD_DEPS_NEED_ASSERT
# include "zstd/common/zstd_deps.h"
// # include "zstd/common/zstd_deps.h" // DuckDB: comment out otherwise amalgamation won't be happy
#else
# ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
# define assert(condition) ((void)0) /* disable assert (default) */
Expand All @@ -72,7 +72,7 @@

#if (DEBUGLEVEL>=2)
# define ZSTD_DEPS_NEED_IO
// # include "zstd/common/zstd_deps.h"
// # include "zstd/common/zstd_deps.h" // DuckDB: comment out otherwise amalgamation won't be happy

namespace duckdb_zstd {

Expand Down
4 changes: 4 additions & 0 deletions third_party/zstd/include/zstd/common/fse.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
/*-*****************************************
* Dependencies
******************************************/

// DuckDB: just enable everything for amalgamation
#define FSE_STATIC_LINKING_ONLY

#include "zstd/common/zstd_deps.h" /* size_t, ptrdiff_t */

namespace duckdb_zstd {
Expand Down
7 changes: 7 additions & 0 deletions third_party/zstd/include/zstd/common/zstd_deps.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
#include <stddef.h>
#include <string.h>

// DuckDB: just enable everything for amalgamation
#define ZSTD_DEPS_NEED_MALLOC
#define ZSTD_DEPS_NEED_MATH64
#define ZSTD_DEPS_NEED_ASSERT
#define ZSTD_DEPS_NEED_IO
#define ZSTD_DEPS_NEED_STDINT

#if defined(__GNUC__) && __GNUC__ >= 4
# define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))
# define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))
Expand Down
4 changes: 0 additions & 4 deletions third_party/zstd/include/zstd/compress/hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
* in the COPYING file in the root directory of this source tree).
* You may select, at your option, one of the above-listed licenses.
****************************************************************** */
#ifndef ZSTD_HIST_H
#define ZSTD_HIST_H

/* --- dependencies --- */
#include "zstd/common/zstd_deps.h" /* size_t */
Expand Down Expand Up @@ -78,5 +76,3 @@ unsigned HIST_count_simple(unsigned* count, unsigned* maxSymbolValuePtr,
const void* src, size_t srcSize);

} // namespace duckdb_zstd

#endif /* ZSTD_HIST_H */
9 changes: 6 additions & 3 deletions third_party/zstd/include/zstd/deprecated/zbuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
/* *************************************
* Dependencies
***************************************/
// DuckDB: just enable everything for amalgamation
#define ZSTD_STATIC_LINKING_ONLY

#include <stddef.h> /* size_t */
# define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters, ZSTD_customMem */
#include "zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */

namespace duckdb_zstd {
Expand Down Expand Up @@ -184,8 +186,9 @@ ZBUFF_DEPRECATED("use ZSTD_DStreamOutSize") size_t ZBUFF_recommendedDOutSize(voi


/*--- Dependency ---*/
//# define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters, ZSTD_customMem */
//#include "zstd.h"
// DuckDB: comment out otherwise amalgamation won't be happy
// # define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters, ZSTD_customMem */
// #include "zstd.h"

namespace duckdb_zstd {

Expand Down
5 changes: 0 additions & 5 deletions third_party/zstd/include/zstd/dict/cover.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
* You may select, at your option, one of the above-listed licenses.
*/

#ifndef ZSTD_COVER_H
#define ZSTD_COVER_H

#ifndef ZDICT_STATIC_LINKING_ONLY
# define ZDICT_STATIC_LINKING_ONLY
#endif
Expand Down Expand Up @@ -157,5 +154,3 @@ void COVER_dictSelectionFree(COVER_dictSelection_t selection);
size_t nbCheckSamples, size_t nbSamples, ZDICT_cover_params_t params, size_t* offsets, size_t totalCompressedSize);

} // namespace duckdb_zstd

#endif /* ZSTD_COVER_H */

0 comments on commit d92f3a0

Please sign in to comment.