mirror of
https://github.com/facebook/zstd.git
synced 2025-03-07 01:10:04 +02:00
Merge pull request #2415 from facebook/fix_aliasing
fix gcc-10 strict aliasing warnings
This commit is contained in:
commit
b86e3c9304
@ -261,11 +261,12 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|||||||
return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, wksp, sizeof(wksp), /* bmi2 */ 0);
|
return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, wksp, sizeof(wksp), /* bmi2 */ 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE size_t HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
FORCE_INLINE_TEMPLATE size_t
|
||||||
U32* nbSymbolsPtr, U32* tableLogPtr,
|
HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
||||||
const void* src, size_t srcSize,
|
U32* nbSymbolsPtr, U32* tableLogPtr,
|
||||||
void* workSpace, size_t wkspSize,
|
const void* src, size_t srcSize,
|
||||||
int bmi2)
|
void* workSpace, size_t wkspSize,
|
||||||
|
int bmi2)
|
||||||
{
|
{
|
||||||
U32 weightTotal;
|
U32 weightTotal;
|
||||||
const BYTE* ip = (const BYTE*) src;
|
const BYTE* ip = (const BYTE*) src;
|
||||||
@ -289,7 +290,8 @@ FORCE_INLINE_TEMPLATE size_t HUF_readStats_body(BYTE* huffWeight, size_t hwSize,
|
|||||||
} } }
|
} } }
|
||||||
else { /* header compressed with FSE (normal case) */
|
else { /* header compressed with FSE (normal case) */
|
||||||
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
||||||
oSize = FSE_decompress_wksp_bmi2(huffWeight, hwSize-1, ip+1, iSize, 6, workSpace, wkspSize, bmi2); /* max (hwSize-1) values decoded, as last one is implied */
|
/* max (hwSize-1) values decoded, as last one is implied */
|
||||||
|
oSize = FSE_decompress_wksp_bmi2(huffWeight, hwSize-1, ip+1, iSize, 6, workSpace, wkspSize, bmi2);
|
||||||
if (FSE_isError(oSize)) return oSize;
|
if (FSE_isError(oSize)) return oSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,12 +135,16 @@ HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
|||||||
#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
||||||
|
|
||||||
/* static allocation of HUF's Compression Table */
|
/* static allocation of HUF's Compression Table */
|
||||||
|
/* this is a private definition, just exposed for allocation and strict aliasing purpose. never EVER access its members directly */
|
||||||
|
struct HUF_CElt_s {
|
||||||
|
U16 val;
|
||||||
|
BYTE nbBits;
|
||||||
|
}; /* typedef'd to HUF_CElt */
|
||||||
|
typedef struct HUF_CElt_s HUF_CElt; /* consider it an incomplete type */
|
||||||
#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */
|
#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */
|
||||||
#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32))
|
#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32))
|
||||||
#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
|
#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
|
||||||
U32 name##hb[HUF_CTABLE_SIZE_U32(maxSymbolValue)]; \
|
HUF_CElt name[HUF_CTABLE_SIZE_U32(maxSymbolValue)] /* no final ; */
|
||||||
void* name##hv = &(name##hb); \
|
|
||||||
HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */
|
|
||||||
|
|
||||||
/* static allocation of HUF's DTable */
|
/* static allocation of HUF's DTable */
|
||||||
typedef U32 HUF_DTable;
|
typedef U32 HUF_DTable;
|
||||||
@ -186,7 +190,6 @@ size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize,
|
|||||||
* or to save and regenerate 'CTable' using external methods.
|
* or to save and regenerate 'CTable' using external methods.
|
||||||
*/
|
*/
|
||||||
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
|
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
|
||||||
typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */
|
|
||||||
size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */
|
size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */
|
||||||
size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
|
size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
|
||||||
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
||||||
|
@ -102,11 +102,6 @@ static size_t HUF_compressWeights (void* dst, size_t dstSize, const void* weight
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct HUF_CElt_s {
|
|
||||||
U16 val;
|
|
||||||
BYTE nbBits;
|
|
||||||
}; /* typedef'd to HUF_CElt within "huf.h" */
|
|
||||||
|
|
||||||
/*! HUF_writeCTable() :
|
/*! HUF_writeCTable() :
|
||||||
`CTable` : Huffman tree to save, using huf representation.
|
`CTable` : Huffman tree to save, using huf representation.
|
||||||
@return : size of saved CTable */
|
@return : size of saved CTable */
|
||||||
@ -155,6 +150,7 @@ size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void
|
|||||||
|
|
||||||
/* get symbol weights */
|
/* get symbol weights */
|
||||||
CHECK_V_F(readSize, HUF_readStats(huffWeight, HUF_SYMBOLVALUE_MAX+1, rankVal, &nbSymbols, &tableLog, src, srcSize));
|
CHECK_V_F(readSize, HUF_readStats(huffWeight, HUF_SYMBOLVALUE_MAX+1, rankVal, &nbSymbols, &tableLog, src, srcSize));
|
||||||
|
*hasZeroWeights = (rankVal[0] > 0);
|
||||||
|
|
||||||
/* check result */
|
/* check result */
|
||||||
if (tableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
|
if (tableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
|
||||||
@ -169,10 +165,8 @@ size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void
|
|||||||
} }
|
} }
|
||||||
|
|
||||||
/* fill nbBits */
|
/* fill nbBits */
|
||||||
*hasZeroWeights = 0;
|
|
||||||
{ U32 n; for (n=0; n<nbSymbols; n++) {
|
{ U32 n; for (n=0; n<nbSymbols; n++) {
|
||||||
const U32 w = huffWeight[n];
|
const U32 w = huffWeight[n];
|
||||||
*hasZeroWeights |= (w == 0);
|
|
||||||
CTable[n].nbBits = (BYTE)(tableLog + 1 - w) & -(w != 0);
|
CTable[n].nbBits = (BYTE)(tableLog + 1 - w) & -(w != 0);
|
||||||
} }
|
} }
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ typedef struct {
|
|||||||
} ZSTD_localDict;
|
} ZSTD_localDict;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
U32 CTable[HUF_CTABLE_SIZE_U32(255)];
|
HUF_CElt CTable[HUF_CTABLE_SIZE_U32(255)];
|
||||||
HUF_repeat repeatMode;
|
HUF_repeat repeatMode;
|
||||||
} ZSTD_hufCTables_t;
|
} ZSTD_hufCTables_t;
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ typedef struct {
|
|||||||
int hufInit;
|
int hufInit;
|
||||||
/* the distribution used in the previous block for repeat mode */
|
/* the distribution used in the previous block for repeat mode */
|
||||||
BYTE hufDist[DISTSIZE];
|
BYTE hufDist[DISTSIZE];
|
||||||
U32 hufTable [256]; /* HUF_CElt is an incomplete type */
|
HUF_CElt hufTable [256];
|
||||||
|
|
||||||
int fseInit;
|
int fseInit;
|
||||||
FSE_CTable offcodeCTable [FSE_CTABLE_SIZE_U32(OffFSELog, MaxOff)];
|
FSE_CTable offcodeCTable [FSE_CTABLE_SIZE_U32(OffFSELog, MaxOff)];
|
||||||
@ -535,7 +535,7 @@ static size_t writeLiteralsBlockCompressed(U32* seed, frame_t* frame, size_t con
|
|||||||
* actual data to avoid bugs with symbols that were in the
|
* actual data to avoid bugs with symbols that were in the
|
||||||
* distribution but never showed up in the output */
|
* distribution but never showed up in the output */
|
||||||
hufHeaderSize = writeHufHeader(
|
hufHeaderSize = writeHufHeader(
|
||||||
seed, (HUF_CElt*)frame->stats.hufTable, op, opend - op,
|
seed, frame->stats.hufTable, op, opend - op,
|
||||||
frame->stats.hufDist, DISTSIZE);
|
frame->stats.hufDist, DISTSIZE);
|
||||||
CHECKERR(hufHeaderSize);
|
CHECKERR(hufHeaderSize);
|
||||||
/* repeat until a valid header is written */
|
/* repeat until a valid header is written */
|
||||||
@ -558,10 +558,10 @@ static size_t writeLiteralsBlockCompressed(U32* seed, frame_t* frame, size_t con
|
|||||||
sizeFormat == 0
|
sizeFormat == 0
|
||||||
? HUF_compress1X_usingCTable(
|
? HUF_compress1X_usingCTable(
|
||||||
op, opend - op, LITERAL_BUFFER, litSize,
|
op, opend - op, LITERAL_BUFFER, litSize,
|
||||||
(HUF_CElt*)frame->stats.hufTable)
|
frame->stats.hufTable)
|
||||||
: HUF_compress4X_usingCTable(
|
: HUF_compress4X_usingCTable(
|
||||||
op, opend - op, LITERAL_BUFFER, litSize,
|
op, opend - op, LITERAL_BUFFER, litSize,
|
||||||
(HUF_CElt*)frame->stats.hufTable);
|
frame->stats.hufTable);
|
||||||
CHECKERR(compressedSize);
|
CHECKERR(compressedSize);
|
||||||
/* this only occurs when it could not compress or similar */
|
/* this only occurs when it could not compress or similar */
|
||||||
} while (compressedSize <= 0);
|
} while (compressedSize <= 0);
|
||||||
|
@ -182,7 +182,7 @@ static ZWRAP_CCtx* ZWRAP_createCCtx(z_streamp strm)
|
|||||||
{
|
{
|
||||||
ZWRAP_CCtx* zwc;
|
ZWRAP_CCtx* zwc;
|
||||||
ZSTD_customMem customMem = { NULL, NULL, NULL };
|
ZSTD_customMem customMem = { NULL, NULL, NULL };
|
||||||
|
|
||||||
if (strm->zalloc && strm->zfree) {
|
if (strm->zalloc && strm->zfree) {
|
||||||
customMem.customAlloc = ZWRAP_allocFunction;
|
customMem.customAlloc = ZWRAP_allocFunction;
|
||||||
customMem.customFree = ZWRAP_freeFunction;
|
customMem.customFree = ZWRAP_freeFunction;
|
||||||
@ -246,6 +246,10 @@ int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize)
|
|||||||
return Z_OK;
|
return Z_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct internal_state* convert_into_sis(void* ptr)
|
||||||
|
{
|
||||||
|
return (struct internal_state*) ptr;
|
||||||
|
}
|
||||||
|
|
||||||
ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
|
ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
|
||||||
const char *version, int stream_size))
|
const char *version, int stream_size))
|
||||||
@ -266,7 +270,7 @@ ZEXTERN int ZEXPORT z_deflateInit_ OF((z_streamp strm, int level,
|
|||||||
zwc->streamEnd = 0;
|
zwc->streamEnd = 0;
|
||||||
zwc->totalInBytes = 0;
|
zwc->totalInBytes = 0;
|
||||||
zwc->compressionLevel = level;
|
zwc->compressionLevel = level;
|
||||||
strm->state = (struct internal_state*) zwc; /* use state which in not used by user */
|
strm->state = convert_into_sis(zwc); /* use state which in not used by user */
|
||||||
strm->total_in = 0;
|
strm->total_in = 0;
|
||||||
strm->total_out = 0;
|
strm->total_out = 0;
|
||||||
strm->adler = 0;
|
strm->adler = 0;
|
||||||
@ -593,7 +597,7 @@ ZEXTERN int ZEXPORT z_inflateInit_ OF((z_streamp strm,
|
|||||||
|
|
||||||
zwd->stream_size = stream_size;
|
zwd->stream_size = stream_size;
|
||||||
zwd->totalInBytes = 0;
|
zwd->totalInBytes = 0;
|
||||||
strm->state = (struct internal_state*) zwd;
|
strm->state = convert_into_sis(zwd);
|
||||||
strm->total_in = 0;
|
strm->total_in = 0;
|
||||||
strm->total_out = 0;
|
strm->total_out = 0;
|
||||||
strm->reserved = ZWRAP_UNKNOWN_STREAM;
|
strm->reserved = ZWRAP_UNKNOWN_STREAM;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user