From: Yann Collet Date: Mon, 11 Jan 2016 11:56:11 +0000 (+0100) Subject: Implemented ZSTD_HEAPMODE for zstd_decompress.c X-Git-Tag: v0.4.6~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a3b72f25aaed596088d8f5191bba9fd79c2177d;p=thirdparty%2Fzstd.git Implemented ZSTD_HEAPMODE for zstd_decompress.c Reduce cmake version requirement to 2.8.7 --- diff --git a/contrib/cmake/CMakeLists.txt b/contrib/cmake/CMakeLists.txt index 9b5e063d0..5cb8cc097 100644 --- a/contrib/cmake/CMakeLists.txt +++ b/contrib/cmake/CMakeLists.txt @@ -32,7 +32,7 @@ # ################################################################ PROJECT(zstd) -CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7) OPTION(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF) diff --git a/lib/zstd_decompress.c b/lib/zstd_decompress.c index 14918cb42..d11f65009 100644 --- a/lib/zstd_decompress.c +++ b/lib/zstd_decompress.c @@ -35,13 +35,12 @@ *****************************************************************/ /*! * HEAPMODE : - * Select how default compression functions will allocate memory for their hash table, - * in memory stack (0, fastest), or in memory heap (1, requires malloc()) - * Note that compression context is fairly large, as a consequence heap memory is recommended. + * Select how default decompression function ZSTD_decompress() will allocate memory, + * in memory stack (0), or in memory heap (1, requires malloc()) */ #ifndef ZSTD_HEAPMODE # define ZSTD_HEAPMODE 1 -#endif /* ZSTD_HEAPMODE */ +#endif /*! * LEGACY_SUPPORT : @@ -790,8 +789,17 @@ size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx, void* dst, size_t maxDstSize, const size_t ZSTD_decompress(void* dst, size_t maxDstSize, const void* src, size_t srcSize) { +#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE==1) + size_t regenSize; + ZSTD_DCtx* dctx = ZSTD_createDCtx(); + if (dctx==NULL) return ERROR(memory_allocation); + regenSize = ZSTD_decompressDCtx(dctx, dst, maxDstSize, src, srcSize); + ZSTD_freeDCtx(dctx); + return regenSize; +#else ZSTD_DCtx dctx; return ZSTD_decompressDCtx(&dctx, dst, maxDstSize, src, srcSize); +#endif // defined }