mirror of
https://github.com/facebook/zstd.git
synced 2025-12-09 00:03:18 -05:00
added ZSTD_createDCtx_advanced
This commit is contained in:
parent
50e82c015d
commit
107e243195
@ -103,9 +103,12 @@ typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; }
|
|||||||
* Advanced functions
|
* Advanced functions
|
||||||
***************************************/
|
***************************************/
|
||||||
/*! ZSTD_createCCtx_advanced() :
|
/*! ZSTD_createCCtx_advanced() :
|
||||||
* Create ZSTD context using external alloc and free functions */
|
* Create a ZSTD compression context using external alloc and free functions */
|
||||||
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
|
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
|
||||||
|
|
||||||
|
/*! ZSTD_createDCtx_advanced() :
|
||||||
|
* Create a ZSTD decompression context using external alloc and free functions */
|
||||||
|
ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);
|
||||||
|
|
||||||
ZSTDLIB_API unsigned ZSTD_maxCLevel (void);
|
ZSTDLIB_API unsigned ZSTD_maxCLevel (void);
|
||||||
|
|
||||||
|
|||||||
@ -120,20 +120,25 @@ struct ZSTD_CCtx_s
|
|||||||
|
|
||||||
ZSTD_CCtx* ZSTD_createCCtx(void)
|
ZSTD_CCtx* ZSTD_createCCtx(void)
|
||||||
{
|
{
|
||||||
ZSTD_CCtx* ctx = (ZSTD_CCtx*) calloc(1, sizeof(ZSTD_CCtx));
|
ZSTD_customMem customMem = { NULL, NULL };
|
||||||
if (!ctx) return NULL;
|
return ZSTD_createCCtx_advanced(customMem);
|
||||||
|
|
||||||
ctx->customAlloc = malloc;
|
|
||||||
ctx->customFree = free;
|
|
||||||
return ctx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
|
ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
|
||||||
{
|
{
|
||||||
if (!customMem.customAlloc || !customMem.customFree)
|
ZSTD_CCtx* ctx;
|
||||||
return ZSTD_createCCtx();
|
|
||||||
|
|
||||||
ZSTD_CCtx* ctx = (ZSTD_CCtx*) customMem.customAlloc(sizeof(ZSTD_CCtx));
|
if (!customMem.customAlloc || !customMem.customFree)
|
||||||
|
{
|
||||||
|
ctx = (ZSTD_CCtx*) calloc(1, sizeof(ZSTD_CCtx));
|
||||||
|
if (!ctx) return NULL;
|
||||||
|
|
||||||
|
ctx->customAlloc = malloc;
|
||||||
|
ctx->customFree = free;
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = (ZSTD_CCtx*) customMem.customAlloc(sizeof(ZSTD_CCtx));
|
||||||
if (!ctx) return NULL;
|
if (!ctx) return NULL;
|
||||||
|
|
||||||
memset(ctx, 0, sizeof(ZSTD_CCtx));
|
memset(ctx, 0, sizeof(ZSTD_CCtx));
|
||||||
@ -307,7 +312,9 @@ size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx)
|
|||||||
{
|
{
|
||||||
if (srcCCtx->stage!=1) return ERROR(stage_wrong);
|
if (srcCCtx->stage!=1) return ERROR(stage_wrong);
|
||||||
|
|
||||||
dstCCtx->hashLog3 = srcCCtx->hashLog3; /* must be before ZSTD_resetCCtx_advanced */
|
dstCCtx->hashLog3 = srcCCtx->hashLog3; /* must be before ZSTD_resetCCtx_advanced */
|
||||||
|
dstCCtx->customAlloc = srcCCtx->customAlloc;
|
||||||
|
dstCCtx->customFree = srcCCtx->customFree;
|
||||||
ZSTD_resetCCtx_advanced(dstCCtx, srcCCtx->params, 0);
|
ZSTD_resetCCtx_advanced(dstCCtx, srcCCtx->params, 0);
|
||||||
dstCCtx->params.fParams.contentSizeFlag = 0; /* content size different from the one set during srcCCtx init */
|
dstCCtx->params.fParams.contentSizeFlag = 0; /* content size different from the one set during srcCCtx init */
|
||||||
|
|
||||||
|
|||||||
@ -116,6 +116,8 @@ struct ZSTD_DCtx_s
|
|||||||
size_t expected;
|
size_t expected;
|
||||||
size_t headerSize;
|
size_t headerSize;
|
||||||
ZSTD_frameParams fParams;
|
ZSTD_frameParams fParams;
|
||||||
|
ZSTD_allocFunction customAlloc;
|
||||||
|
ZSTD_freeFunction customFree;
|
||||||
blockType_t bType; /* used in ZSTD_decompressContinue(), to transfer blockType between header decoding and block decoding stages */
|
blockType_t bType; /* used in ZSTD_decompressContinue(), to transfer blockType between header decoding and block decoding stages */
|
||||||
ZSTD_dStage stage;
|
ZSTD_dStage stage;
|
||||||
U32 flagRepeatTable;
|
U32 flagRepeatTable;
|
||||||
@ -143,15 +145,38 @@ size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx)
|
|||||||
|
|
||||||
ZSTD_DCtx* ZSTD_createDCtx(void)
|
ZSTD_DCtx* ZSTD_createDCtx(void)
|
||||||
{
|
{
|
||||||
ZSTD_DCtx* dctx = (ZSTD_DCtx*)malloc(sizeof(ZSTD_DCtx));
|
ZSTD_customMem customMem = { NULL, NULL };
|
||||||
if (dctx==NULL) return NULL;
|
return ZSTD_createDCtx_advanced(customMem);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
|
||||||
|
{
|
||||||
|
ZSTD_DCtx* dctx;
|
||||||
|
|
||||||
|
if (!customMem.customAlloc || !customMem.customFree)
|
||||||
|
{
|
||||||
|
dctx = (ZSTD_DCtx*) malloc(sizeof(ZSTD_DCtx));
|
||||||
|
if (!dctx) return NULL;
|
||||||
|
dctx->customAlloc = malloc;
|
||||||
|
dctx->customFree = free;
|
||||||
|
|
||||||
|
ZSTD_decompressBegin(dctx);
|
||||||
|
return dctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
dctx = (ZSTD_DCtx*) customMem.customAlloc(sizeof(ZSTD_DCtx));
|
||||||
|
if (!dctx) return NULL;
|
||||||
|
dctx->customAlloc = customMem.customAlloc;
|
||||||
|
dctx->customFree = customMem.customFree;
|
||||||
|
|
||||||
ZSTD_decompressBegin(dctx);
|
ZSTD_decompressBegin(dctx);
|
||||||
return dctx;
|
return dctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx)
|
size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx)
|
||||||
{
|
{
|
||||||
free(dctx);
|
dctx->customFree(dctx);
|
||||||
return 0; /* reserved as a potential error code in the future */
|
return 0; /* reserved as a potential error code in the future */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user