]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Implemented ZSTD_HEAPMODE for zstd_decompress.c
authorYann Collet <yann.collet.73@gmail.com>
Mon, 11 Jan 2016 11:56:11 +0000 (12:56 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Mon, 11 Jan 2016 11:56:11 +0000 (12:56 +0100)
Reduce cmake version requirement to 2.8.7

contrib/cmake/CMakeLists.txt
lib/zstd_decompress.c

index 9b5e063d044113ece4da28144037b59f55bc5d38..5cb8cc09742a3af12d68bc6f1902204483cc5a56 100644 (file)
@@ -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)
 
index 14918cb42ffbdd29aecdd5cbb23b85afabb032db..d11f6500960f1157e68c9b1364b0a95dea47b871 100644 (file)
 *****************************************************************/
 /*!
  * 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
 }