From c97522f7fb797cde035ab26f0ba97addb718c174 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 10 Dec 2024 13:58:11 -0800 Subject: [PATCH] codemod: ZSTD_sequenceFormat_e -> ZSTD_SequenceFormat_e since it's a type name. Note: in contrast with previous names, this one is on the Public API side. So there is a #define, so that existing programs using ZSTD_sequenceFormat_e still work. --- doc/zstd_manual.html | 2 +- lib/compress/zstd_compress.c | 16 +++++++++------- lib/compress/zstd_compress_internal.h | 2 +- lib/zstd.h | 3 ++- tests/fuzz/sequence_compression_api.c | 10 +++++----- tests/fuzzer.c | 2 +- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/doc/zstd_manual.html b/doc/zstd_manual.html index bcd1f05da..e6f8fc504 100644 --- a/doc/zstd_manual.html +++ b/doc/zstd_manual.html @@ -1317,7 +1317,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr,
typedef enum {
   ZSTD_sf_noBlockDelimiters = 0,         /* Representation of ZSTD_Sequence has no block delimiters, sequences only */
   ZSTD_sf_explicitBlockDelimiters = 1    /* Representation of ZSTD_Sequence contains explicit block delimiters */
-} ZSTD_sequenceFormat_e;
+} ZSTD_SequenceFormat_e;
 

ZSTDLIB_STATIC_API size_t ZSTD_sequenceBound(size_t srcSize);
 

`srcSize` : size of the input buffer diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 4f9f17447..5976a8e5c 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -974,7 +974,7 @@ size_t ZSTD_CCtxParams_setParameter(ZSTD_CCtx_params* CCtxParams, case ZSTD_c_blockDelimiters: BOUNDCHECK(ZSTD_c_blockDelimiters, value); - CCtxParams->blockDelimiters = (ZSTD_sequenceFormat_e)value; + CCtxParams->blockDelimiters = (ZSTD_SequenceFormat_e)value; return CCtxParams->blockDelimiters; case ZSTD_c_validateSequences: @@ -6815,10 +6815,10 @@ ZSTD_copySequencesToSeqStoreNoBlockDelim(ZSTD_CCtx* cctx, typedef size_t (*ZSTD_sequenceCopier) (ZSTD_CCtx* cctx, ZSTD_sequencePosition* seqPos, const ZSTD_Sequence* const inSeqs, size_t inSeqsSize, const void* src, size_t blockSize, ZSTD_paramSwitch_e externalRepSearch); -static ZSTD_sequenceCopier ZSTD_selectSequenceCopier(ZSTD_sequenceFormat_e mode) +static ZSTD_sequenceCopier ZSTD_selectSequenceCopier(ZSTD_SequenceFormat_e mode) { ZSTD_sequenceCopier sequenceCopier = NULL; - assert(ZSTD_cParam_withinBounds(ZSTD_c_blockDelimiters, mode)); + assert(ZSTD_cParam_withinBounds(ZSTD_c_blockDelimiters, (int)mode)); if (mode == ZSTD_sf_explicitBlockDelimiters) { return ZSTD_copySequencesToSeqStoreExplicitBlockDelim; } else if (mode == ZSTD_sf_noBlockDelimiters) { @@ -6862,7 +6862,7 @@ static size_t blockSize_noDelimiter(size_t blockSize, size_t remaining) return lastBlock ? remaining : blockSize; } -static size_t determine_blockSize(ZSTD_sequenceFormat_e mode, +static size_t determine_blockSize(ZSTD_SequenceFormat_e mode, size_t blockSize, size_t remaining, const ZSTD_Sequence* inSeqs, size_t inSeqsSize, ZSTD_sequencePosition seqPos) { @@ -6941,11 +6941,13 @@ ZSTD_compressSequences_internal(ZSTD_CCtx* cctx, } RETURN_ERROR_IF(dstCapacity < ZSTD_blockHeaderSize, dstSize_tooSmall, "not enough dstCapacity to write a new compressed block"); - compressedSeqsSize = ZSTD_entropyCompressSeqStore(&cctx->seqStore, + compressedSeqsSize = ZSTD_entropyCompressSeqStore_wExtLitBuffer( + op + ZSTD_blockHeaderSize /* Leave space for block header */, dstCapacity - ZSTD_blockHeaderSize, + cctx->seqStore.litStart, (size_t)(cctx->seqStore.lit - cctx->seqStore.litStart), + blockSize, + &cctx->seqStore, &cctx->blockState.prevCBlock->entropy, &cctx->blockState.nextCBlock->entropy, &cctx->appliedParams, - op + ZSTD_blockHeaderSize /* Leave space for block header */, dstCapacity - ZSTD_blockHeaderSize, - blockSize, cctx->tmpWorkspace, cctx->tmpWkspSize /* statically allocated in resetCCtx */, cctx->bmi2); FORWARD_IF_ERROR(compressedSeqsSize, "Compressing sequences of block failed"); diff --git a/lib/compress/zstd_compress_internal.h b/lib/compress/zstd_compress_internal.h index 3dcd52c95..2d7e0230d 100644 --- a/lib/compress/zstd_compress_internal.h +++ b/lib/compress/zstd_compress_internal.h @@ -404,7 +404,7 @@ struct ZSTD_CCtx_params_s { ZSTD_bufferMode_e outBufferMode; /* Sequence compression API */ - ZSTD_sequenceFormat_e blockDelimiters; + ZSTD_SequenceFormat_e blockDelimiters; int validateSequences; /* Block splitting diff --git a/lib/zstd.h b/lib/zstd.h index cfacd58d0..94058a1b2 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -1562,7 +1562,8 @@ ZSTDLIB_STATIC_API size_t ZSTD_decompressionMargin(const void* src, size_t srcSi typedef enum { ZSTD_sf_noBlockDelimiters = 0, /* Representation of ZSTD_Sequence has no block delimiters, sequences only */ ZSTD_sf_explicitBlockDelimiters = 1 /* Representation of ZSTD_Sequence contains explicit block delimiters */ -} ZSTD_sequenceFormat_e; +} ZSTD_SequenceFormat_e; +#define ZSTD_sequenceFormat_e ZSTD_SequenceFormat_e /* old name */ /*! ZSTD_sequenceBound() : * `srcSize` : size of the input buffer diff --git a/tests/fuzz/sequence_compression_api.c b/tests/fuzz/sequence_compression_api.c index 3c60f42c6..5e5e1e604 100644 --- a/tests/fuzz/sequence_compression_api.c +++ b/tests/fuzz/sequence_compression_api.c @@ -76,7 +76,7 @@ static char* generatePseudoRandomString(char* str, size_t size, FUZZ_dataProduce static size_t decodeSequences(void* dst, size_t nbSequences, size_t literalsSize, const void* dict, size_t dictSize, - ZSTD_sequenceFormat_e mode) + ZSTD_SequenceFormat_e mode) { const uint8_t* litPtr = literalsBuffer; const uint8_t* const litBegin = literalsBuffer; @@ -141,7 +141,7 @@ static size_t decodeSequences(void* dst, size_t nbSequences, */ static size_t generateRandomSequences(FUZZ_dataProducer_t* producer, size_t literalsSizeLimit, size_t dictSize, - size_t windowLog, ZSTD_sequenceFormat_e mode) + size_t windowLog, ZSTD_SequenceFormat_e mode) { const uint32_t repCode = 0; /* not used by sequence ingestion api */ size_t windowSize = 1ULL << windowLog; @@ -232,7 +232,7 @@ static size_t roundTripTest(void* result, size_t resultCapacity, const void* src, size_t srcSize, const ZSTD_Sequence* seqs, size_t seqSize, unsigned hasDict, - ZSTD_sequenceFormat_e mode) + ZSTD_SequenceFormat_e mode) { size_t cSize; size_t dSize; @@ -276,7 +276,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* src, size_t size) unsigned hasDict; unsigned wLog; int cLevel; - ZSTD_sequenceFormat_e mode; + ZSTD_SequenceFormat_e mode; FUZZ_dataProducer_t* const producer = FUZZ_dataProducer_create(src, size); FUZZ_ASSERT(producer); @@ -293,7 +293,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* src, size_t size) /* Generate window log first so we don't generate offsets too large */ wLog = FUZZ_dataProducer_uint32Range(producer, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX); cLevel = FUZZ_dataProducer_int32Range(producer, -3, 22); - mode = (ZSTD_sequenceFormat_e)FUZZ_dataProducer_int32Range(producer, 0, 1); + mode = (ZSTD_SequenceFormat_e)FUZZ_dataProducer_int32Range(producer, 0, 1); ZSTD_CCtx_reset(cctx, ZSTD_reset_session_and_parameters); ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, 0); diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 4a6ebd69c..2180d1edb 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -310,7 +310,7 @@ static int FUZ_mallocTests(unsigned seed, double compressibility, unsigned part) #endif static void FUZ_decodeSequences(BYTE* dst, ZSTD_Sequence* seqs, size_t seqsSize, - BYTE* src, size_t size, ZSTD_sequenceFormat_e format) + BYTE* src, size_t size, ZSTD_SequenceFormat_e format) { size_t i; size_t j;