]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Working on API
authorNick Terrell <terrelln@fb.com>
Fri, 31 Mar 2017 22:01:41 +0000 (15:01 -0700)
committerNick Terrell <terrelln@fb.com>
Sat, 1 Apr 2017 01:07:32 +0000 (18:07 -0700)
16 files changed:
contrib/linux-kernel/include/zstd.h
contrib/linux-kernel/lib/error_private.c [deleted file]
contrib/linux-kernel/lib/error_private.h
contrib/linux-kernel/lib/fse.h
contrib/linux-kernel/lib/fse_compress.c
contrib/linux-kernel/lib/fse_decompress.c
contrib/linux-kernel/lib/huf.h
contrib/linux-kernel/lib/huf_compress.c
contrib/linux-kernel/lib/huf_decompress.c
contrib/linux-kernel/lib/xxhash.c
contrib/linux-kernel/lib/xxhash.h
contrib/linux-kernel/lib/zstd_common.c
contrib/linux-kernel/lib/zstd_compress.c
contrib/linux-kernel/lib/zstd_decompress.c
contrib/linux-kernel/lib/zstd_errors.h [deleted file]
contrib/linux-kernel/lib/zstd_internal.h

index 8b1afa4bac2229314efd87180b0939a4c24b9d32..6594521d6dbfba19fe74e0ab40600bdfeae0763a 100644 (file)
 ZSTDLIB_API unsigned ZSTD_versionNumber(void);   /**< library version number; to be used when checking dll version */
 
 
-/***************************************
-*  Simple API
-***************************************/
-/*! ZSTD_compress() :
-       Compresses `src` content as a single zstd compressed frame into already allocated `dst`.
-       Hint : compression runs faster if `dstCapacity` >=  `ZSTD_compressBound(srcSize)`.
-       @return : compressed size written into `dst` (<= `dstCapacity),
-                         or an error code if it fails (which can be tested using ZSTD_isError()). */
-ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
-                                                       const void* src, size_t srcSize,
-                                                                 int compressionLevel);
-
-/*! ZSTD_decompress() :
-       `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames.
-       `dstCapacity` is an upper bound of originalSize.
-       If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data.
-       @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
-                         or an errorCode if it fails (which can be tested using ZSTD_isError()). */
-ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity,
-                                                         const void* src, size_t compressedSize);
-
-/*! ZSTD_getDecompressedSize() :
-*   NOTE: This function is planned to be obsolete, in favour of ZSTD_getFrameContentSize.
-*   ZSTD_getFrameContentSize functions the same way, returning the decompressed size of a single
-*   frame, but distinguishes empty frames from frames with an unknown size, or errors.
-*
-*   Additionally, ZSTD_findDecompressedSize can be used instead.  It can handle multiple
-*   concatenated frames in one buffer, and so is more general.
-*   As a result however, it requires more computation and entire frames to be passed to it,
-*   as opposed to ZSTD_getFrameContentSize which requires only a single frame's header.
-*
-*   'src' is the start of a zstd compressed frame.
-*   @return : content size to be decompressed, as a 64-bits value _if known_, 0 otherwise.
-*    note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode.
-*             When `return==0`, data to decompress could be any size.
-*             In which case, it's necessary to use streaming mode to decompress data.
-*             Optionally, application can still use ZSTD_decompress() while relying on implied limits.
-*             (For example, data may be necessarily cut into blocks <= 16 KB).
-*    note 2 : decompressed size is always present when compression is done with ZSTD_compress()
-*    note 3 : decompressed size can be very large (64-bits value),
-*             potentially larger than what local system can handle as a single memory segment.
-*             In which case, it's necessary to use streaming mode to decompress data.
-*    note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified.
-*             Always ensure result fits within application's authorized limits.
-*             Each application can set its own limits.
-*    note 5 : when `return==0`, if precise failure cause is needed, use ZSTD_getFrameParams() to know more. */
-ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
-
-
 /*======  Helper functions  ======*/
+typedef enum {
+  ZSTD_error_no_error,
+  ZSTD_error_GENERIC,
+  ZSTD_error_prefix_unknown,
+  ZSTD_error_version_unsupported,
+  ZSTD_error_parameter_unknown,
+  ZSTD_error_frameParameter_unsupported,
+  ZSTD_error_frameParameter_unsupportedBy32bits,
+  ZSTD_error_frameParameter_windowTooLarge,
+  ZSTD_error_compressionParameter_unsupported,
+  ZSTD_error_init_missing,
+  ZSTD_error_memory_allocation,
+  ZSTD_error_stage_wrong,
+  ZSTD_error_dstSize_tooSmall,
+  ZSTD_error_srcSize_wrong,
+  ZSTD_error_corruption_detected,
+  ZSTD_error_checksum_wrong,
+  ZSTD_error_tableLog_tooLarge,
+  ZSTD_error_maxSymbolValue_tooLarge,
+  ZSTD_error_maxSymbolValue_tooSmall,
+  ZSTD_error_dictionary_corrupted,
+  ZSTD_error_dictionary_wrong,
+  ZSTD_error_dictionaryCreation_failed,
+  ZSTD_error_maxCode
+} ZSTD_ErrorCode;
+
 ZSTDLIB_API int         ZSTD_maxCLevel(void);               /*!< maximum compression level available */
 ZSTDLIB_API size_t      ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case scenario */
-ZSTDLIB_API unsigned    ZSTD_isError(size_t code);          /*!< tells if a `size_t` function result is an error code */
-ZSTDLIB_API const char* ZSTD_getErrorName(size_t code);     /*!< provides readable string from an error code */
-
+/*! ZSTD_isError() :
+*   tells if a `size_t` function result is an error code */
+ZSTDLIB_API static __attribute__((unused)) unsigned ZSTD_isError(size_t code) {
+       return code > (size_t)-ZSTD_error_maxCode;
+}
+/*! ZSTD_getErrorCode() :
+*   convert a `size_t` function result into a proper ZSTD_errorCode enum */
+ZSTDLIB_API static __attribute__((unused)) ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult) {
+       if (!ZSTD_isError(functionResult)) {
+               return (ZSTD_ErrorCode)0;
+       }
+       return (ZSTD_ErrorCode)(0 - functionResult);
+}
 
 /***************************************
 *  Explicit memory management
 ***************************************/
+
+typedef enum { ZSTD_fast, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt, ZSTD_btopt2 } ZSTD_strategy;   /* from faster to stronger */
+
+typedef struct {
+       unsigned windowLog;      /**< largest match distance : larger == more compression, more memory needed during decompression */
+       unsigned chainLog;       /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
+       unsigned hashLog;        /**< dispatch table : larger == faster, more memory */
+       unsigned searchLog;      /**< nb of searches : larger == more compression, slower */
+       unsigned searchLength;   /**< match length searched : larger == faster decompression, sometimes less compression */
+       unsigned targetLength;   /**< acceptable match size for optimal parser (only) : larger == more compression, slower */
+       ZSTD_strategy strategy;
+} ZSTD_compressionParameters;
+
+typedef struct {
+       unsigned contentSizeFlag; /**< 1: content size will be in frame header (when known) */
+       unsigned checksumFlag;    /**< 1: generate a 32-bits checksum at end of frame, for error detection */
+       unsigned noDictIDFlag;    /**< 1: no dictID will be saved into frame header (if dictionary compression) */
+} ZSTD_frameParameters;
+
+typedef struct {
+       ZSTD_compressionParameters cParams;
+       ZSTD_frameParameters fParams;
+} ZSTD_parameters;
+
+size_t ZSTD_CCtxWorkspaceBound(ZSTD_compressionParameters params);
+size_t ZSTD_DCtxWorkspaceBound(void);
+
 /*= Compression context
 *   When compressing many times,
 *   it is recommended to allocate a context just once, and re-use it for each successive compression operation.
 *   This will make workload friendlier for system's memory.
 *   Use one context per thread for parallel execution in multi-threaded environments. */
 typedef struct ZSTD_CCtx_s ZSTD_CCtx;
-ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
-ZSTDLIB_API size_t     ZSTD_freeCCtx(ZSTD_CCtx* cctx);
+ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void* workspace, size_t workspaceSize);
 
 /*! ZSTD_compressCCtx() :
        Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). */
-ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel);
+ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, ZSTD_parameters params);
+
+ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void *dict, size_t dictSize, ZSTD_parameters params);
 
 /*= Decompression context
 *   When decompressing many times,
@@ -130,53 +145,28 @@ ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapaci
 *   This will make workload friendlier for system's memory.
 *   Use one context per thread for parallel execution in multi-threaded environments. */
 typedef struct ZSTD_DCtx_s ZSTD_DCtx;
-ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
-ZSTDLIB_API size_t     ZSTD_freeDCtx(ZSTD_DCtx* dctx);
+ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void* workspace, size_t workspaceSize);
 
 /*! ZSTD_decompressDCtx() :
 *   Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()). */
 ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
 
-
-/**************************
-*  Simple dictionary API
-***************************/
-/*! ZSTD_compress_usingDict() :
-*   Compression using a predefined Dictionary (see dictBuilder/zdict.h).
-*   Note : This function loads the dictionary, resulting in significant startup delay.
-*   Note : When `dict == NULL || dictSize < 8` no dictionary is used. */
-ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
-                                                                                  void* dst, size_t dstCapacity,
-                                                                        const void* src, size_t srcSize,
-                                                                        const void* dict,size_t dictSize,
-                                                                                  int compressionLevel);
-
-/*! ZSTD_decompress_usingDict() :
-*   Decompression using a predefined Dictionary (see dictBuilder/zdict.h).
-*   Dictionary must be identical to the one used during compression.
-*   Note : This function loads the dictionary, resulting in significant startup delay.
-*   Note : When `dict == NULL || dictSize < 8` no dictionary is used. */
-ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
-                                                                                        void* dst, size_t dstCapacity,
-                                                                          const void* src, size_t srcSize,
-                                                                          const void* dict,size_t dictSize);
-
+ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void *dict, size_t dictSize);
 
 /****************************
 *  Fast dictionary API
 ****************************/
+size_t ZSTD_CDictWorkspaceBound(ZSTD_compressionParameters params);
+size_t ZSTD_DDictWorkspaceBound(void);
+
 typedef struct ZSTD_CDict_s ZSTD_CDict;
 
 /*! ZSTD_createCDict() :
 *   When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once.
 *   ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay.
 *   ZSTD_CDict can be created once and used by multiple threads concurrently, as its usage is read-only.
-*   `dictBuffer` can be released after ZSTD_CDict creation, as its content is copied within CDict */
-ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize, int compressionLevel);
-
-/*! ZSTD_freeCDict() :
-*   Function frees memory allocated by ZSTD_createCDict(). */
-ZSTDLIB_API size_t      ZSTD_freeCDict(ZSTD_CDict* CDict);
+*   `dictBuffer` content is referenced, and it must remain accessible throughout the lifetime of the CDict */
+ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dictBuffer, size_t dictSize, ZSTD_parameters params, void* workspace, size_t workspaceSize);
 
 /*! ZSTD_compress_usingCDict() :
 *   Compression using a digested Dictionary.
@@ -192,12 +182,8 @@ typedef struct ZSTD_DDict_s ZSTD_DDict;
 
 /*! ZSTD_createDDict() :
 *   Create a digested dictionary, ready to start decompression operation without startup delay.
-*   dictBuffer can be released after DDict creation, as its content is copied inside DDict */
-ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize);
-
-/*! ZSTD_freeDDict() :
-*   Function frees memory allocated with ZSTD_createDDict() */
-ZSTDLIB_API size_t      ZSTD_freeDDict(ZSTD_DDict* ddict);
+*   `dictBuffer` content is referenced, and it must remain accessible throughout the lifetime of the DDict */
+ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dictBuffer, size_t dictSize, void* workspace, size_t workspaceSize);
 
 /*! ZSTD_decompress_usingDDict() :
 *   Decompression using a digested Dictionary.
@@ -265,13 +251,17 @@ typedef struct ZSTD_outBuffer_s {
 *
 * *******************************************************************/
 
+size_t ZSTD_CStreamWorkspaceBound(ZSTD_compressionParameters params);
+size_t ZSTD_DStreamWorkspaceBound(size_t maxWindowSize);
+
 typedef struct ZSTD_CStream_s ZSTD_CStream;
 /*===== ZSTD_CStream management functions =====*/
-ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void);
-ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs);
+ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void* workspace, size_t workspaceSize);
+ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, ZSTD_parameters params, unsigned long long pledgedSrcSize);
+ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, ZSTD_parameters params, const ZSTD_CDict* cdict, unsigned long long pledgedSrcSize);
 
 /*===== Streaming compression functions =====*/
-ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel);
+ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);  /**< re-use compression parameters from previous init; skip dictionary loading stage; zcs must be init at least once before. note: pledgedSrcSize must be correct, a size of 0 means unknown.  for a frame size of 0 use initCStream_advanced */
 ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
 ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
 ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output);
@@ -305,11 +295,12 @@ ZSTDLIB_API size_t ZSTD_CStreamOutSize(void);   /**< recommended size for output
 
 typedef struct ZSTD_DStream_s ZSTD_DStream;
 /*===== ZSTD_DStream management functions =====*/
-ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void);
-ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds);
+ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void* workspace, size_t workspaceSize);
+ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds, size_t maxWindowSize);
+ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, size_t maxWindowSize, const ZSTD_DDict* ddict);
 
 /*===== Streaming decompression functions =====*/
-ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds);
+ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);  /**< re-use decompression parameters from previous init; saves dictionary loading */
 ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
 
 ZSTDLIB_API size_t ZSTD_DStreamInSize(void);    /*!< recommended size for input buffer */
@@ -355,35 +346,6 @@ static const size_t ZSTD_frameHeaderSize_max = ZSTD_FRAMEHEADERSIZE_MAX;
 static const size_t ZSTD_skippableHeaderSize = 8;  /* magic number + skippable frame length */
 
 
-/*--- Advanced types ---*/
-typedef enum { ZSTD_fast, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt, ZSTD_btopt2 } ZSTD_strategy;   /* from faster to stronger */
-
-typedef struct {
-       unsigned windowLog;      /**< largest match distance : larger == more compression, more memory needed during decompression */
-       unsigned chainLog;       /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
-       unsigned hashLog;        /**< dispatch table : larger == faster, more memory */
-       unsigned searchLog;      /**< nb of searches : larger == more compression, slower */
-       unsigned searchLength;   /**< match length searched : larger == faster decompression, sometimes less compression */
-       unsigned targetLength;   /**< acceptable match size for optimal parser (only) : larger == more compression, slower */
-       ZSTD_strategy strategy;
-} ZSTD_compressionParameters;
-
-typedef struct {
-       unsigned contentSizeFlag; /**< 1: content size will be in frame header (when known) */
-       unsigned checksumFlag;    /**< 1: generate a 32-bits checksum at end of frame, for error detection */
-       unsigned noDictIDFlag;    /**< 1: no dictID will be saved into frame header (if dictionary compression) */
-} ZSTD_frameParameters;
-
-typedef struct {
-       ZSTD_compressionParameters cParams;
-       ZSTD_frameParameters fParams;
-} ZSTD_parameters;
-
-/*= Custom memory allocation functions */
-typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
-typedef void  (*ZSTD_freeFunction) (void* opaque, void* address);
-typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
-
 /***************************************
 *  Compressed size functions
 ***************************************/
@@ -432,47 +394,9 @@ ZSTDLIB_API unsigned long long ZSTD_getFrameContentSize(const void *src, size_t
 *             however it does mean that all frame data must be present and valid. */
 ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize);
 
-
 /***************************************
 *  Advanced compression functions
 ***************************************/
-/*! ZSTD_estimateCCtxSize() :
- *  Gives the amount of memory allocated for a ZSTD_CCtx given a set of compression parameters.
- *  `frameContentSize` is an optional parameter, provide `0` if unknown */
-ZSTDLIB_API size_t ZSTD_estimateCCtxSize(ZSTD_compressionParameters cParams);
-
-/*! ZSTD_createCCtx_advanced() :
- *  Create a ZSTD compression context using external alloc and free functions */
-ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
-
-/*! ZSTD_sizeofCCtx() :
- *  Gives the amount of memory used by a given ZSTD_CCtx */
-ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx);
-
-typedef enum {
-       ZSTD_p_forceWindow,   /* Force back-references to remain < windowSize, even when referencing Dictionary content (default:0) */
-       ZSTD_p_forceRawDict   /* Force loading dictionary in "content-only" mode (no header analysis) */
-} ZSTD_CCtxParameter;
-/*! ZSTD_setCCtxParameter() :
- *  Set advanced parameters, selected through enum ZSTD_CCtxParameter
- *  @result : 0, or an error code (which can be tested with ZSTD_isError()) */
-ZSTDLIB_API size_t ZSTD_setCCtxParameter(ZSTD_CCtx* cctx, ZSTD_CCtxParameter param, unsigned value);
-
-/*! ZSTD_createCDict_byReference() :
- *  Create a digested dictionary for compression
- *  Dictionary content is simply referenced, and therefore stays in dictBuffer.
- *  It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict */
-ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
-
-/*! ZSTD_createCDict_advanced() :
- *  Create a ZSTD_CDict using external alloc and free, and customized compression parameters */
-ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize, unsigned byReference,
-                                                                                                 ZSTD_parameters params, ZSTD_customMem customMem);
-
-/*! ZSTD_sizeof_CDict() :
- *  Gives the amount of memory used by a given ZSTD_sizeof_CDict */
-ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict);
-
 /*! ZSTD_getCParams() :
 *   @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
 *   `estimatedSrcSize` value is optional, select 0 if not known */
@@ -492,15 +416,6 @@ ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
 *   both values are optional, select `0` if unknown. */
 ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize);
 
-/*! ZSTD_compress_advanced() :
-*   Same as ZSTD_compress_usingDict(), with fine-tune control of each compression parameter */
-ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
-                                                                                  void* dst, size_t dstCapacity,
-                                                                        const void* src, size_t srcSize,
-                                                                        const void* dict,size_t dictSize,
-                                                                                  ZSTD_parameters params);
-
-
 /*--- Advanced decompression functions ---*/
 
 /*! ZSTD_isFrame() :
@@ -510,33 +425,6 @@ ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
  *  Note 3 : Skippable Frame Identifiers are considered valid. */
 ZSTDLIB_API unsigned ZSTD_isFrame(const void* buffer, size_t size);
 
-/*! ZSTD_estimateDCtxSize() :
- *  Gives the potential amount of memory allocated to create a ZSTD_DCtx */
-ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void);
-
-/*! ZSTD_createDCtx_advanced() :
- *  Create a ZSTD decompression context using external alloc and free functions */
-ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);
-
-/*! ZSTD_sizeof_DCtx() :
- *  Gives the amount of memory used by a given ZSTD_DCtx */
-ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx);
-
-/*! ZSTD_createDDict_byReference() :
- *  Create a digested dictionary, ready to start decompression operation without startup delay.
- *  Dictionary content is simply referenced, and therefore stays in dictBuffer.
- *  It is important that dictBuffer outlives DDict, it must remain read accessible throughout the lifetime of DDict */
-ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize);
-
-/*! ZSTD_createDDict_advanced() :
- *  Create a ZSTD_DDict using external alloc and free, optionally by reference */
-ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
-                                                                                                 unsigned byReference, ZSTD_customMem customMem);
-
-/*! ZSTD_sizeof_DDict() :
- *  Gives the amount of memory used by a given ZSTD_DDict */
-ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
-
 /*! ZSTD_getDictID_fromDict() :
  *  Provides the dictID stored within dictionary.
  *  if @return == 0, the dictionary is not conformant with Zstandard specification.
@@ -562,31 +450,6 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict);
 ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
 
 
-/********************************************************************
-*  Advanced streaming functions
-********************************************************************/
-
-/*=====   Advanced Streaming compression functions  =====*/
-ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
-ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize);   /**< pledgedSrcSize must be correct, a size of 0 means unknown.  for a frame size of 0 use initCStream_advanced */
-ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); /**< note: a dict will not be used if dict == NULL or dictSize < 8 */
-ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
-                                                                                        ZSTD_parameters params, unsigned long long pledgedSrcSize);  /**< pledgedSrcSize is optional and can be 0 (meaning unknown). note: if the contentSizeFlag is set, pledgedSrcSize == 0 means the source size is actually 0 */
-ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict);  /**< note : cdict will just be referenced, and must outlive compression session */
-ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize);  /**< re-use compression parameters from previous init; skip dictionary loading stage; zcs must be init at least once before. note: pledgedSrcSize must be correct, a size of 0 means unknown.  for a frame size of 0 use initCStream_advanced */
-ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs);
-
-
-/*=====   Advanced Streaming decompression functions  =====*/
-typedef enum { DStream_p_maxWindowSize } ZSTD_DStreamParameter_e;
-ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem);
-ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); /**< note: a dict will not be used if dict == NULL or dictSize < 8 */
-ZSTDLIB_API size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue);
-ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict);  /**< note : ddict will just be referenced, and must outlive decompression session */
-ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds);  /**< re-use decompression parameters from previous init; saves dictionary loading */
-ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds);
-
-
 /*********************************************************************
 *  Buffer-less and synchronous inner streaming functions
 *
diff --git a/contrib/linux-kernel/lib/error_private.c b/contrib/linux-kernel/lib/error_private.c
deleted file mode 100644 (file)
index 83e27cb..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
-/* The purpose of this file is to have a single list of error strings embedded in binary */
-
-#include "error_private.h"
-
-const char* ERR_getErrorString(ERR_enum code)
-{
-       static const char* const notErrorCode = "Unspecified error code";
-       switch( code )
-       {
-       case PREFIX(no_error): return "No error detected";
-       case PREFIX(GENERIC):  return "Error (generic)";
-       case PREFIX(prefix_unknown): return "Unknown frame descriptor";
-       case PREFIX(version_unsupported): return "Version not supported";
-       case PREFIX(parameter_unknown): return "Unknown parameter type";
-       case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
-       case PREFIX(frameParameter_unsupportedBy32bits): return "Frame parameter unsupported in 32-bits mode";
-       case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
-       case PREFIX(compressionParameter_unsupported): return "Compression parameter is out of bound";
-       case PREFIX(init_missing): return "Context should be init first";
-       case PREFIX(memory_allocation): return "Allocation error : not enough memory";
-       case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
-       case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
-       case PREFIX(srcSize_wrong): return "Src size incorrect";
-       case PREFIX(corruption_detected): return "Corrupted block detected";
-       case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
-       case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
-       case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
-       case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
-       case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
-       case PREFIX(dictionary_wrong): return "Dictionary mismatch";
-       case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
-       case PREFIX(maxCode):
-       default: return notErrorCode;
-       }
-}
index 7b2ce36d4ca0812f917245cb5332096c85d77a57..680eba1126604855af971b07e6604559da5c153c 100644 (file)
@@ -16,7 +16,7 @@
 *  Dependencies
 ******************************************/
 #include <linux/types.h>        /* size_t */
-#include "zstd_errors.h"  /* enum list */
+#include "zstd.h"  /* enum list */
 
 
 /* ****************************************
index a5c3980a7d58a093e82486df9bf26043999373a4..6df7ff935b32a213455fcf4b3920195bc9dbdc38 100644 (file)
 #define FSE_VERSION_NUMBER  (FSE_VERSION_MAJOR *100*100 + FSE_VERSION_MINOR *100 + FSE_VERSION_RELEASE)
 FSE_PUBLIC_API unsigned FSE_versionNumber(void);   /**< library version number; to be used when checking dll version */
 
-/*-****************************************
-*  FSE simple functions
-******************************************/
-/*! FSE_compress() :
-       Compress content of buffer 'src', of size 'srcSize', into destination buffer 'dst'.
-       'dst' buffer must be already allocated. Compression runs faster is dstCapacity >= FSE_compressBound(srcSize).
-       @return : size of compressed data (<= dstCapacity).
-       Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!!
-                                        if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression instead.
-                                        if FSE_isError(return), compression failed (more details using FSE_getErrorName())
-*/
-FSE_PUBLIC_API size_t FSE_compress(void* dst, size_t dstCapacity,
-                                                        const void* src, size_t srcSize);
-
-/*! FSE_decompress():
-       Decompress FSE data from buffer 'cSrc', of size 'cSrcSize',
-       into already allocated destination buffer 'dst', of size 'dstCapacity'.
-       @return : size of regenerated data (<= maxDstSize),
-                         or an error code, which can be tested using FSE_isError() .
-
-       ** Important ** : FSE_decompress() does not decompress non-compressible nor RLE data !!!
-       Why ? : making this distinction requires a header.
-       Header management is intentionally delegated to the user layer, which can better manage special cases.
-*/
-FSE_PUBLIC_API size_t FSE_decompress(void* dst,  size_t dstCapacity,
-                                                          const void* cSrc, size_t cSrcSize);
-
-
 /*-*****************************************
 *  Tool functions
 ******************************************/
@@ -97,20 +69,6 @@ FSE_PUBLIC_API unsigned    FSE_isError(size_t code);        /* tells if a return
 FSE_PUBLIC_API const char* FSE_getErrorName(size_t code);   /* provides error code string (useful for debugging) */
 
 
-/*-*****************************************
-*  FSE advanced functions
-******************************************/
-/*! FSE_compress2() :
-       Same as FSE_compress(), but allows the selection of 'maxSymbolValue' and 'tableLog'
-       Both parameters can be defined as '0' to mean : use default value
-       @return : size of compressed data
-       Special values : if return == 0, srcData is not compressible => Nothing is stored within cSrc !!!
-                                        if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression.
-                                        if FSE_isError(return), it's an error code.
-*/
-FSE_PUBLIC_API size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
-
-
 /*-*****************************************
 *  FSE detailed API
 ******************************************/
@@ -133,16 +91,6 @@ or to save and provide normalized distribution using external method.
 */
 
 /* *** COMPRESSION *** */
-
-/*! FSE_count():
-       Provides the precise count of each byte within a table 'count'.
-       'count' is a table of unsigned int, of minimum size (*maxSymbolValuePtr+1).
-       *maxSymbolValuePtr will be updated if detected smaller than initial value.
-       @return : the count of the most frequent symbol (which is not identified).
-                         if return == srcSize, there is only one symbol.
-                         Can also return an error code, which can be tested with FSE_isError(). */
-FSE_PUBLIC_API size_t FSE_count(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
-
 /*! FSE_optimalTableLog():
        dynamically downsize 'tableLog' when conditions are met.
        It saves CPU time, by using smaller tables, while preserving or even improving compression ratio.
@@ -171,13 +119,6 @@ FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize, const sh
 /*! Constructor and Destructor of FSE_CTable.
        Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */
 typedef unsigned FSE_CTable;   /* don't allocate that. It's only meant to be more restrictive than void* */
-FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned tableLog, unsigned maxSymbolValue);
-FSE_PUBLIC_API void        FSE_freeCTable (FSE_CTable* ct);
-
-/*! FSE_buildCTable():
-       Builds `ct`, which must be already allocated, using FSE_createCTable().
-       @return : 0, or an errorCode, which can be tested using FSE_isError() */
-FSE_PUBLIC_API size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
 
 /*! FSE_compress_usingCTable():
        Compress `src` using `ct` into `dst` which must be already allocated.
@@ -242,8 +183,6 @@ FSE_PUBLIC_API size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSym
 /*! Constructor and Destructor of FSE_DTable.
        Note that its size depends on 'tableLog' */
 typedef unsigned FSE_DTable;   /* don't allocate that. It's just a way to be more restrictive than void* */
-FSE_PUBLIC_API FSE_DTable* FSE_createDTable(unsigned tableLog);
-FSE_PUBLIC_API void        FSE_freeDTable(FSE_DTable* dt);
 
 /*! FSE_buildDTable():
        Builds 'dt', which must be already allocated, using FSE_createDTable().
@@ -313,11 +252,6 @@ If there is an error, the function will return an error code, which can be teste
 size_t FSE_count_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
                                 const void* source, size_t sourceSize, unsigned* workSpace);
 
-/** FSE_countFast() :
- *  same as FSE_count(), but blindly trusts that all byte values within src are <= *maxSymbolValuePtr
- */
-size_t FSE_countFast(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
-
 /* FSE_countFast_wksp() :
  * Same as FSE_countFast(), but using an externally provided scratch buffer.
  * `workSpace` must be a table of minimum `1024` unsigned
index 8b85b85f10199ab93055a1792dd6c37a78f81de4..7c13a4099adcd5e6eeb059099e79982bf9d92182 100644 (file)
 /* **************************************************************
 *  Compiler specifics
 ****************************************************************/
-#define FORCE_INLINE static __attribute__((always_inline))
+#define FORCE_INLINE static __always_inline
 
 
 /* **************************************************************
 *  Includes
 ****************************************************************/
+#include <linux/compiler.h>
 #include <linux/string.h>     /* memcpy, memset */
 #include "bitstream.h"
 #include "fse.h"
@@ -164,14 +165,6 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct, const short* normalizedCounter, unsi
 }
 
 
-size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
-{
-       FSE_FUNCTION_TYPE tableSymbol[FSE_MAX_TABLESIZE];   /* memset() is not necessary, even if static analyzer complain about it */
-       return FSE_buildCTable_wksp(ct, normalizedCounter, maxSymbolValue, tableLog, tableSymbol, sizeof(tableSymbol));
-}
-
-
-
 #ifndef FSE_COMMONDEFS_ONLY
 
 /*-**************************************************************
@@ -399,14 +392,6 @@ size_t FSE_countFast_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
        return FSE_count_parallel_wksp(count, maxSymbolValuePtr, source, sourceSize, 0, workSpace);
 }
 
-/* fast variant (unsafe : won't check if src contains values beyond count[] limit) */
-size_t FSE_countFast(unsigned* count, unsigned* maxSymbolValuePtr,
-                                        const void* source, size_t sourceSize)
-{
-       unsigned tmpCounters[1024];
-       return FSE_countFast_wksp(count, maxSymbolValuePtr, source, sourceSize, tmpCounters);
-}
-
 /* FSE_count_wksp() :
  * Same as FSE_count(), but using an externally provided scratch buffer.
  * `workSpace` size must be table of >= `1024` unsigned */
@@ -445,16 +430,6 @@ size_t FSE_sizeof_CTable (unsigned maxSymbolValue, unsigned tableLog)
        return FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32);
 }
 
-FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog)
-{
-       size_t size;
-       if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
-       size = FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32);
-       return (FSE_CTable*)malloc(size);
-}
-
-void FSE_freeCTable (FSE_CTable* ct) { free(ct); }
-
 /* provides the minimum logSize to safely represent a distribution */
 static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
 {
@@ -817,23 +792,5 @@ size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t src
        return op-ostart;
 }
 
-typedef struct {
-       FSE_CTable CTable_max[FSE_CTABLE_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)];
-       BYTE scratchBuffer[1 << FSE_MAX_TABLELOG];
-} fseWkspMax_t;
-
-size_t FSE_compress2 (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog)
-{
-       fseWkspMax_t scratchBuffer;
-       FSE_STATIC_ASSERT(sizeof(scratchBuffer) >= FSE_WKSP_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE));   /* compilation failures here means scratchBuffer is not large enough */
-       if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);
-       return FSE_compress_wksp(dst, dstCapacity, src, srcSize, maxSymbolValue, tableLog, &scratchBuffer, sizeof(scratchBuffer));
-}
-
-size_t FSE_compress (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
-{
-       return FSE_compress2(dst, dstCapacity, src, srcSize, FSE_MAX_SYMBOL_VALUE, FSE_DEFAULT_TABLELOG);
-}
-
 
 #endif   /* FSE_COMMONDEFS_ONLY */
index ebc228daf1562b3ea6e650ee50e3931f71e350db..2a35f170391148f55d2a5b9b0029fec0bcd25699 100644 (file)
 /* **************************************************************
 *  Compiler specifics
 ****************************************************************/
-#define FORCE_INLINE static __attribute__((always_inline))
+#define FORCE_INLINE static __always_inline
 
 
 /* **************************************************************
 *  Includes
 ****************************************************************/
+#include <linux/compiler.h>
 #include <linux/string.h>     /* memcpy, memset */
 #include "bitstream.h"
 #include "fse.h"
 
 
 /* Function templates */
-FSE_DTable* FSE_createDTable (unsigned tableLog)
-{
-       if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
-       return (FSE_DTable*)malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) );
-}
-
-void FSE_freeDTable (FSE_DTable* dt)
-{
-       free(dt);
-}
 
 size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
 {
@@ -298,14 +289,4 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size
 }
 
 
-typedef FSE_DTable DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
-
-size_t FSE_decompress(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize)
-{
-       DTable_max_t dt;   /* Static analyzer seems unable to understand this table will be properly initialized later */
-       return FSE_decompress_wksp(dst, dstCapacity, cSrc, cSrcSize, dt, FSE_MAX_TABLELOG);
-}
-
-
-
 #endif   /* FSE_COMMONDEFS_ONLY */
index fd26fcf27d411d71822e61895f8d992d9f67e7d3..e0a30ce0098fb167847472d9fee2b9850671257d 100644 (file)
 #include <linux/types.h>    /* size_t */
 
 
-/* *** simple functions *** */
-/**
-HUF_compress() :
-       Compress content from buffer 'src', of size 'srcSize', into buffer 'dst'.
-       'dst' buffer must be already allocated.
-       Compression runs faster if `dstCapacity` >= HUF_compressBound(srcSize).
-       `srcSize` must be <= `HUF_BLOCKSIZE_MAX` == 128 KB.
-       @return : size of compressed data (<= `dstCapacity`).
-       Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!!
-                                        if return == 1, srcData is a single repeated byte symbol (RLE compression).
-                                        if HUF_isError(return), compression failed (more details using HUF_getErrorName())
-*/
-size_t HUF_compress(void* dst, size_t dstCapacity,
-                         const void* src, size_t srcSize);
-
-/**
-HUF_decompress() :
-       Decompress HUF data from buffer 'cSrc', of size 'cSrcSize',
-       into already allocated buffer 'dst', of minimum size 'dstSize'.
-       `originalSize` : **must** be the ***exact*** size of original (uncompressed) data.
-       Note : in contrast with FSE, HUF_decompress can regenerate
-                  RLE (cSrcSize==1) and uncompressed (cSrcSize==dstSize) data,
-                  because it knows size to regenerate.
-       @return : size of regenerated data (== originalSize),
-                         or an error code, which can be tested using HUF_isError()
-*/
-size_t HUF_decompress(void* dst,  size_t originalSize,
-                               const void* cSrc, size_t cSrcSize);
-
-
 /* ***   Tool functions *** */
 #define HUF_BLOCKSIZE_MAX (128 * 1024)       /**< maximum input size for a single block compressed with HUF_compress */
 size_t HUF_compressBound(size_t size);       /**< maximum compressed size (worst case) */
@@ -80,11 +50,6 @@ const char* HUF_getErrorName(size_t code);   /**< provides error code string (us
 
 /* ***   Advanced function   *** */
 
-/** HUF_compress2() :
- *   Same as HUF_compress(), but offers direct control over `maxSymbolValue` and `tableLog` .
- *   `tableLog` must be `<= HUF_TABLELOG_MAX` . */
-size_t HUF_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
-
 /** HUF_compress4X_wksp() :
 *   Same as HUF_compress2(), but uses externally allocated `workSpace`, which must be a table of >= 1024 unsigned */
 size_t HUF_compress4X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);  /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */
@@ -136,9 +101,6 @@ typedef U32 HUF_DTable;
 /* ****************************************
 *  Advanced decompression functions
 ******************************************/
-size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);   /**< single-symbol decoder */
-size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);   /**< double-symbols decoder */
-
 size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);   /**< decodes RLE and uncompressed */
 size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */
 size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);   /**< single-symbol decoder */
@@ -223,7 +185,6 @@ size_t HUF_decompress4X4_usingDTable(void* dst, size_t maxDstSize, const void* c
 
 /* single stream variants */
 
-size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
 size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);  /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */
 size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
 /** HUF_compress1X_repeat() :
@@ -233,9 +194,6 @@ size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, si
 *   If preferRepeat then the old table will always be used if valid. */
 size_t HUF_compress1X_repeat(void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize, HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat);  /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */
 
-size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);   /* single-symbol decoder */
-size_t HUF_decompress1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);   /* double-symbol decoder */
-
 size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
 size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);   /**< single-symbol decoder */
 size_t HUF_decompress1X4_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);   /**< double-symbols decoder */
index 16576f5799aa8c2a673d2262017d02b7d27bf53d..b2e71405cd1deccaf159e4bc7c8390dabb86365b 100644 (file)
@@ -635,14 +635,6 @@ size_t HUF_compress1X_repeat (void* dst, size_t dstSize,
        return HUF_compress_internal(dst, dstSize, src, srcSize, maxSymbolValue, huffLog, 1 /* single stream */, workSpace, wkspSize, hufTable, repeat, preferRepeat);
 }
 
-size_t HUF_compress1X (void* dst, size_t dstSize,
-                                const void* src, size_t srcSize,
-                                unsigned maxSymbolValue, unsigned huffLog)
-{
-       unsigned workSpace[1024];
-       return HUF_compress1X_wksp(dst, dstSize, src, srcSize, maxSymbolValue, huffLog, workSpace, sizeof(workSpace));
-}
-
 size_t HUF_compress4X_wksp (void* dst, size_t dstSize,
                                          const void* src, size_t srcSize,
                                          unsigned maxSymbolValue, unsigned huffLog,
@@ -659,16 +651,3 @@ size_t HUF_compress4X_repeat (void* dst, size_t dstSize,
 {
        return HUF_compress_internal(dst, dstSize, src, srcSize, maxSymbolValue, huffLog, 0 /* 4 streams */, workSpace, wkspSize, hufTable, repeat, preferRepeat);
 }
-
-size_t HUF_compress2 (void* dst, size_t dstSize,
-                               const void* src, size_t srcSize,
-                               unsigned maxSymbolValue, unsigned huffLog)
-{
-       unsigned workSpace[1024];
-       return HUF_compress4X_wksp(dst, dstSize, src, srcSize, maxSymbolValue, huffLog, workSpace, sizeof(workSpace));
-}
-
-size_t HUF_compress (void* dst, size_t maxDstSize, const void* src, size_t srcSize)
-{
-       return HUF_compress2(dst, maxDstSize, src, (U32)srcSize, 255, HUF_TABLELOG_DEFAULT);
-}
index 4ac28bec9a4cc803a18720101e3fb40190adce72..f73223c4ecd570ba36a29c34e93e1e0877b712bc 100644 (file)
 /* **************************************************************
 *  Compiler specifics
 ****************************************************************/
-#define FORCE_INLINE static __attribute__((always_inline))
+#define FORCE_INLINE static __always_inline
 
 
 /* **************************************************************
 *  Dependencies
 ****************************************************************/
+#include <linux/compiler.h>
 #include <linux/string.h>     /* memcpy, memset */
 #include "bitstream.h"  /* BIT_* */
 #include "fse.h"        /* header compression */
@@ -210,12 +211,6 @@ size_t HUF_decompress1X2_DCtx (HUF_DTable* DCtx, void* dst, size_t dstSize, cons
        return HUF_decompress1X2_usingDTable_internal (dst, dstSize, ip, cSrcSize, DCtx);
 }
 
-size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
-{
-       HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX);
-       return HUF_decompress1X2_DCtx (DTable, dst, dstSize, cSrc, cSrcSize);
-}
-
 
 static size_t HUF_decompress4X2_usingDTable_internal(
                  void* dst,  size_t dstSize,
@@ -333,13 +328,6 @@ size_t HUF_decompress4X2_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, cons
        return HUF_decompress4X2_usingDTable_internal (dst, dstSize, ip, cSrcSize, dctx);
 }
 
-size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
-{
-       HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX);
-       return HUF_decompress4X2_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
-}
-
-
 /* *************************/
 /* double-symbols decoding */
 /* *************************/
@@ -624,12 +612,6 @@ size_t HUF_decompress1X4_DCtx (HUF_DTable* DCtx, void* dst, size_t dstSize, cons
        return HUF_decompress1X4_usingDTable_internal (dst, dstSize, ip, cSrcSize, DCtx);
 }
 
-size_t HUF_decompress1X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
-{
-       HUF_CREATE_STATIC_DTABLEX4(DTable, HUF_TABLELOG_MAX);
-       return HUF_decompress1X4_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
-}
-
 static size_t HUF_decompress4X4_usingDTable_internal(
                  void* dst,  size_t dstSize,
        const void* cSrc, size_t cSrcSize,
@@ -746,12 +728,6 @@ size_t HUF_decompress4X4_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, cons
        return HUF_decompress4X4_usingDTable_internal(dst, dstSize, ip, cSrcSize, dctx);
 }
 
-size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
-{
-       HUF_CREATE_STATIC_DTABLEX4(DTable, HUF_TABLELOG_MAX);
-       return HUF_decompress4X4_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
-}
-
 
 /* ********************************/
 /* Generic decompression selector */
@@ -818,21 +794,6 @@ U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize)
 
 typedef size_t (*decompressionAlgo)(void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
 
-size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
-{
-       static const decompressionAlgo decompress[2] = { HUF_decompress4X2, HUF_decompress4X4 };
-
-       /* validation checks */
-       if (dstSize == 0) return ERROR(dstSize_tooSmall);
-       if (cSrcSize > dstSize) return ERROR(corruption_detected);   /* invalid */
-       if (cSrcSize == dstSize) { memcpy(dst, cSrc, dstSize); return dstSize; }   /* not compressed */
-       if (cSrcSize == 1) { memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; }   /* RLE */
-
-       {   U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
-               return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
-       }
-}
-
 size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
 {
        /* validation checks */
index 44392265ddbbe6706b12f42d22be555dc7fe523a..05ebedf7ff17a1820ad8b18cb11693f6f248a3e7 100644 (file)
@@ -66,9 +66,6 @@
 *  Includes & Memory related functions
 ***************************************/
 /* Modify the local functions below should you wish to use some other memory routines */
-/* for malloc(), free() */
-static void* XXH_malloc(size_t s) { return malloc(s); }
-static void  XXH_free  (void* p)  { free(p); }
 /* for memcpy() */
 #include <linux/string.h>
 static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
@@ -80,7 +77,8 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
 /* *************************************
 *  Compiler Specific Options
 ***************************************/
-#define FORCE_INLINE static __attribute__((always_inline))
+#include <linux/compiler.h>
+#define FORCE_INLINE static __always_inline
 
 
 static U32 XXH_read32(const void* memPtr)
@@ -116,8 +114,10 @@ typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
 *****************************/
 typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;
 
-FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess, XXH_alignment)
+FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
 {
+       (void)endian;
+       (void)align;
        return MEM_readLE32(ptr);
 }
 
@@ -133,6 +133,8 @@ static U32 XXH_readBE32(const void* ptr)
 
 FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
 {
+       (void)endian;
+       (void)align;
        return MEM_readLE64(ptr);
 }
 
@@ -397,26 +399,6 @@ XXH_PUBLIC_API unsigned long long XXH64 (const void* input, size_t len, unsigned
 *  Advanced Hash Functions
 ****************************************************/
 
-XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void)
-{
-       return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
-}
-XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr)
-{
-       XXH_free(statePtr);
-       return XXH_OK;
-}
-
-XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void)
-{
-       return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
-}
-XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
-{
-       XXH_free(statePtr);
-       return XXH_OK;
-}
-
 
 /*** Hash feed ***/
 
index 6c4c79c42b8ee5244fb4fec804ca08a71f25d003..36d140eca872540f9e2648ff00219802490f8f7a 100644 (file)
@@ -140,14 +140,6 @@ XXH64() :
 typedef struct XXH32_state_s XXH32_state_t;   /* incomplete type */
 typedef struct XXH64_state_s XXH64_state_t;   /* incomplete type */
 
-/*! State allocation, compatible with dynamic libraries */
-
-XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void);
-XXH_PUBLIC_API XXH_errorcode  XXH32_freeState(XXH32_state_t* statePtr);
-
-XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void);
-XXH_PUBLIC_API XXH_errorcode  XXH64_freeState(XXH64_state_t* statePtr);
-
 
 /* hash streaming */
 
index 0788b6ef678bac3407f4d14fc5fd188bdf62d43e..c62cbd365aae8fb956c9f3617ecb2d422dea68dc 100644 (file)
@@ -13,7 +13,8 @@
 *  Dependencies
 ***************************************/
 #include "error_private.h"
-#include "zstd.h"           /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
+#include "zstd_internal.h"           /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
+#include <linux/kernel.h>
 
 
 /*-****************************************
 unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
 
 
-/*-****************************************
-*  ZSTD Error Management
-******************************************/
-/*! ZSTD_isError() :
-*   tells if a return value is an error code */
-unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
-
-/*! ZSTD_getErrorName() :
-*   provides error code string from function result (useful for debugging) */
-const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
-
-/*! ZSTD_getError() :
-*   convert a `size_t` function result into a proper ZSTD_errorCode enum */
-ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
-
-/*! ZSTD_getErrorString() :
-*   provides error code string from enum */
-const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
-
-
 /*=**************************************************************
 *  Custom allocator
 ****************************************************************/
-/* default uses stdlib */
-void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
-{
-       void* address = malloc(size);
-       (void)opaque;
-       return address;
+
+#define stack_push(stack, size) ({                                             \
+               void* const ptr = ZSTD_PTR_ALIGN((stack)->ptr);                            \
+               (stack)->ptr = (char*)ptr + (size);                                        \
+               (stack)->ptr <= (stack)->end ? ptr : NULL;                                 \
+       })
+
+ZSTD_customMem ZSTD_initStack(void* workspace, size_t workspaceSize) {
+       ZSTD_customMem stackMem = { ZSTD_stackAlloc, ZSTD_stackFree, workspace };
+       ZSTD_stack* stack = (ZSTD_stack*) workspace;
+       /* Verify preconditions */
+       if (!workspace || workspaceSize < sizeof(ZSTD_stack) || workspace != ZSTD_PTR_ALIGN(workspace)) {
+               ZSTD_customMem error = {NULL, NULL, NULL};
+               return error;
+       }
+       /* Initialize the stack */
+       stack->ptr = workspace;
+       stack->end = (char*)workspace + workspaceSize;
+       stack_push(stack, sizeof(ZSTD_stack));
+       return stackMem;
 }
 
-void ZSTD_defaultFreeFunction(void* opaque, void* address)
-{
+void* ZSTD_stackAlloc(void* opaque, size_t size) {
+       ZSTD_stack* stack = (ZSTD_stack*)opaque;
+       return stack_push(stack, size);
+}
+void ZSTD_stackFree(void* opaque, void* address) {
        (void)opaque;
-       free(address);
+       (void)address;
 }
 
 void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
index 79b7699b88dadde5bfa3d500935b5b0822ea05ae..df258c636e7a10d8c845518e36248de380d8e2ac 100644 (file)
@@ -11,6 +11,7 @@
 /*-*************************************
 *  Dependencies
 ***************************************/
+#include <linux/kernel.h>
 #include <linux/string.h>         /* memset */
 #include "mem.h"
 #include "fse.h"
@@ -84,18 +85,26 @@ struct ZSTD_CCtx_s {
        unsigned tmpCounters[HUF_WORKSPACE_SIZE_U32];
 };
 
-ZSTD_CCtx* ZSTD_createCCtx(void)
-{
-       return ZSTD_createCCtx_advanced(defaultCustomMem);
+size_t ZSTD_CCtxWorkspaceBound(ZSTD_compressionParameters cParams) {
+       size_t const blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, (size_t)1 << cParams.windowLog);
+       U32    const divider = (cParams.searchLength==3) ? 3 : 4;
+       size_t const maxNbSeq = blockSize / divider;
+       size_t const tokenSpace = blockSize + 11*maxNbSeq;
+       size_t const chainSize = (cParams.strategy == ZSTD_fast) ? 0 : (1 << cParams.chainLog);
+       size_t const hSize = ((size_t)1) << cParams.hashLog;
+       U32    const hashLog3 = (cParams.searchLength>3) ? 0 : MIN(ZSTD_HASHLOG3_MAX, cParams.windowLog);
+       size_t const h3Size = ((size_t)1) << hashLog3;
+       size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32);
+       size_t const optSpace = ((MaxML+1) + (MaxLL+1) + (MaxOff+1) + (1<<Litbits))*sizeof(U32) + (ZSTD_OPT_NUM+1)*(sizeof(ZSTD_match_t) + sizeof(ZSTD_optimal_t));
+       size_t const workspaceSize = tableSpace + (256*sizeof(U32)) /* huffTable */ + tokenSpace + (((cParams.strategy == ZSTD_btopt) || (cParams.strategy == ZSTD_btopt2)) ? optSpace : 0);
+
+       return ZSTD_ALIGN(sizeof(ZSTD_stack)) + ZSTD_ALIGN(sizeof(ZSTD_CCtx)) + ZSTD_ALIGN(workspaceSize);
 }
 
-ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
+static ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
 {
        ZSTD_CCtx* cctx;
-
-       if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem;
        if (!customMem.customAlloc || !customMem.customFree) return NULL;
-
        cctx = (ZSTD_CCtx*) ZSTD_malloc(sizeof(ZSTD_CCtx), customMem);
        if (!cctx) return NULL;
        memset(cctx, 0, sizeof(ZSTD_CCtx));
@@ -103,6 +112,12 @@ ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
        return cctx;
 }
 
+ZSTD_CCtx* ZSTD_createCCtx(void* workspace, size_t workspaceSize)
+{
+       ZSTD_customMem const stackMem = ZSTD_initStack(workspace, workspaceSize);
+       return ZSTD_createCCtx_advanced(stackMem);
+}
+
 size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx)
 {
        if (cctx==NULL) return 0;   /* support free on NULL */
@@ -111,22 +126,6 @@ size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx)
        return 0;   /* reserved as a potential error code in the future */
 }
 
-size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx)
-{
-       if (cctx==NULL) return 0;   /* support sizeof on NULL */
-       return sizeof(*cctx) + cctx->workSpaceSize;
-}
-
-size_t ZSTD_setCCtxParameter(ZSTD_CCtx* cctx, ZSTD_CCtxParameter param, unsigned value)
-{
-       switch(param)
-       {
-       case ZSTD_p_forceWindow : cctx->forceWindow = value>0; cctx->loadedDictEnd = 0; return 0;
-       case ZSTD_p_forceRawDict : cctx->forceRawDict = value>0; return 0;
-       default: return ERROR(parameter_unknown);
-       }
-}
-
 const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx)   /* hidden interface */
 {
        return &(ctx->seqStore);
@@ -191,28 +190,6 @@ ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, u
 }
 
 
-size_t ZSTD_estimateCCtxSize(ZSTD_compressionParameters cParams)
-{
-       size_t const blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, (size_t)1 << cParams.windowLog);
-       U32    const divider = (cParams.searchLength==3) ? 3 : 4;
-       size_t const maxNbSeq = blockSize / divider;
-       size_t const tokenSpace = blockSize + 11*maxNbSeq;
-
-       size_t const chainSize = (cParams.strategy == ZSTD_fast) ? 0 : (1 << cParams.chainLog);
-       size_t const hSize = ((size_t)1) << cParams.hashLog;
-       U32    const hashLog3 = (cParams.searchLength>3) ? 0 : MIN(ZSTD_HASHLOG3_MAX, cParams.windowLog);
-       size_t const h3Size = ((size_t)1) << hashLog3;
-       size_t const tableSpace = (chainSize + hSize + h3Size) * sizeof(U32);
-
-       size_t const optSpace = ((MaxML+1) + (MaxLL+1) + (MaxOff+1) + (1<<Litbits))*sizeof(U32)
-                                                 + (ZSTD_OPT_NUM+1)*(sizeof(ZSTD_match_t) + sizeof(ZSTD_optimal_t));
-       size_t const neededSpace = tableSpace + (256*sizeof(U32)) /* huffTable */ + tokenSpace
-                                                        + (((cParams.strategy == ZSTD_btopt) || (cParams.strategy == ZSTD_btopt2)) ? optSpace : 0);
-
-       return sizeof(ZSTD_CCtx) + neededSpace;
-}
-
-
 static U32 ZSTD_equivalentParams(ZSTD_parameters param1, ZSTD_parameters param2)
 {
        return (param1.cParams.hashLog  == param2.cParams.hashLog)
@@ -795,7 +772,6 @@ _check_compressibility:
 
 #if 0 /* for debug */
 #  define STORESEQ_DEBUG
-#include <stdio.h>   /* fprintf */
 U32 g_startDebug = 0;
 const BYTE* g_start = NULL;
 #endif
@@ -2770,37 +2746,15 @@ static size_t ZSTD_compress_internal (ZSTD_CCtx* cctx,
        return ZSTD_compressEnd(cctx, dst,  dstCapacity, src, srcSize);
 }
 
-size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
-                                                          void* dst, size_t dstCapacity,
-                                                const void* src, size_t srcSize,
-                                                const void* dict,size_t dictSize,
-                                                          ZSTD_parameters params)
+size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize, ZSTD_parameters params)
 {
-       CHECK_F(ZSTD_checkCParams(params.cParams));
-       return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, params);
-}
-
-size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize, int compressionLevel)
-{
-       ZSTD_parameters params = ZSTD_getParams(compressionLevel, srcSize, dict ? dictSize : 0);
-       params.fParams.contentSizeFlag = 1;
        return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, params);
 }
 
-size_t ZSTD_compressCCtx (ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel)
-{
-       return ZSTD_compress_usingDict(ctx, dst, dstCapacity, src, srcSize, NULL, 0, compressionLevel);
-}
 
-size_t ZSTD_compress(void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel)
+size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, ZSTD_parameters params)
 {
-       size_t result;
-       ZSTD_CCtx ctxBody;
-       memset(&ctxBody, 0, sizeof(ctxBody));
-       memcpy(&ctxBody.customMem, &defaultCustomMem, sizeof(ZSTD_customMem));
-       result = ZSTD_compressCCtx(&ctxBody, dst, dstCapacity, src, srcSize, compressionLevel);
-       ZSTD_free(ctxBody.workSpace, defaultCustomMem);  /* can't free ctxBody itself, as it's on stack; free only heap content */
-       return result;
+       return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, NULL, 0, params);
 }
 
 
@@ -2813,16 +2767,14 @@ struct ZSTD_CDict_s {
        ZSTD_CCtx* refContext;
 };  /* typedef'd tp ZSTD_CDict within "zstd.h" */
 
-size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict)
+size_t ZSTD_CDictWorkspaceBound(ZSTD_compressionParameters cParams)
 {
-       if (cdict==NULL) return 0;   /* support sizeof on NULL */
-       return ZSTD_sizeof_CCtx(cdict->refContext) + (cdict->dictBuffer ? cdict->dictContentSize : 0) + sizeof(*cdict);
+       return ZSTD_CCtxWorkspaceBound(cParams) + ZSTD_ALIGN(sizeof(ZSTD_CDict));
 }
 
-ZSTD_CDict* ZSTD_createCDict_advanced(const void* dictBuffer, size_t dictSize, unsigned byReference,
-                                                                         ZSTD_parameters params, ZSTD_customMem customMem)
+static ZSTD_CDict* ZSTD_createCDict_advanced(const void* dictBuffer, size_t dictSize, unsigned byReference,
+                                                                                        ZSTD_parameters params, ZSTD_customMem customMem)
 {
-       if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem;
        if (!customMem.customAlloc || !customMem.customFree) return NULL;
 
        {   ZSTD_CDict* const cdict = (ZSTD_CDict*) ZSTD_malloc(sizeof(ZSTD_CDict), customMem);
@@ -2859,20 +2811,10 @@ ZSTD_CDict* ZSTD_createCDict_advanced(const void* dictBuffer, size_t dictSize, u
        }
 }
 
-ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel)
+ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, ZSTD_parameters params, void* workspace, size_t workspaceSize)
 {
-       ZSTD_customMem const allocator = { NULL, NULL, NULL };
-       ZSTD_parameters params = ZSTD_getParams(compressionLevel, 0, dictSize);
-       params.fParams.contentSizeFlag = 1;
-       return ZSTD_createCDict_advanced(dict, dictSize, 0, params, allocator);
-}
-
-ZSTD_CDict* ZSTD_createCDict_byReference(const void* dict, size_t dictSize, int compressionLevel)
-{
-       ZSTD_customMem const allocator = { NULL, NULL, NULL };
-       ZSTD_parameters params = ZSTD_getParams(compressionLevel, 0, dictSize);
-       params.fParams.contentSizeFlag = 1;
-       return ZSTD_createCDict_advanced(dict, dictSize, 1, params, allocator);
+       ZSTD_customMem const stackMem = ZSTD_initStack(workspace, workspaceSize);
+       return ZSTD_createCDict_advanced(dict, dictSize, 1, params, stackMem);
 }
 
 size_t ZSTD_freeCDict(ZSTD_CDict* cdict)
@@ -2951,16 +2893,19 @@ struct ZSTD_CStream_s {
        ZSTD_customMem customMem;
 };   /* typedef'd to ZSTD_CStream within "zstd.h" */
 
-ZSTD_CStream* ZSTD_createCStream(void)
+size_t ZSTD_CStreamWorkspaceBound(ZSTD_compressionParameters cParams)
 {
-       return ZSTD_createCStream_advanced(defaultCustomMem);
+       size_t const inBuffSize = (size_t)1 << cParams.windowLog;
+       size_t const blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, inBuffSize);
+       size_t const outBuffSize = ZSTD_compressBound(blockSize) + 1;
+
+       return ZSTD_CCtxWorkspaceBound(cParams) + ZSTD_ALIGN(sizeof(ZSTD_CStream)) + ZSTD_ALIGN(inBuffSize) + ZSTD_ALIGN(outBuffSize);
 }
 
 ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem)
 {
        ZSTD_CStream* zcs;
 
-       if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem;
        if (!customMem.customAlloc || !customMem.customFree) return NULL;
 
        zcs = (ZSTD_CStream*)ZSTD_malloc(sizeof(ZSTD_CStream), customMem);
@@ -2972,6 +2917,12 @@ ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem)
        return zcs;
 }
 
+ZSTD_CStream* ZSTD_createCStream(void* workspace, size_t workspaceSize)
+{
+       ZSTD_customMem const stackMem = ZSTD_initStack(workspace, workspaceSize);
+       return ZSTD_createCStream_advanced(stackMem);
+}
+
 size_t ZSTD_freeCStream(ZSTD_CStream* zcs)
 {
        if (zcs==NULL) return 0;   /* support free on NULL */
@@ -3021,7 +2972,7 @@ size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize)
        return ZSTD_resetCStream_internal(zcs, pledgedSrcSize);
 }
 
-size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
+static size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
                                                                 const void* dict, size_t dictSize,
                                                                 ZSTD_parameters params, unsigned long long pledgedSrcSize)
 {
@@ -3056,39 +3007,19 @@ size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs,
 }
 
 /* note : cdict must outlive compression session */
-size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict)
+size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, ZSTD_parameters params, const ZSTD_CDict* cdict, unsigned long long pledgedSrcSize)
 {
-       ZSTD_parameters const params = ZSTD_getParamsFromCDict(cdict);
-       size_t const initError =  ZSTD_initCStream_advanced(zcs, NULL, 0, params, 0);
+       size_t const initError = ZSTD_initCStream_advanced(zcs, NULL, 0, params, pledgedSrcSize);
        zcs->cdict = cdict;
        zcs->cctx->dictID = params.fParams.noDictIDFlag ? 0 : cdict->refContext->dictID;
        return initError;
 }
 
-size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel)
+size_t ZSTD_initCStream(ZSTD_CStream* zcs, ZSTD_parameters params, unsigned long long pledgedSrcSize)
 {
-       ZSTD_parameters const params = ZSTD_getParams(compressionLevel, 0, dictSize);
-       return ZSTD_initCStream_advanced(zcs, dict, dictSize, params, 0);
-}
-
-size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize)
-{
-       ZSTD_parameters params = ZSTD_getParams(compressionLevel, pledgedSrcSize, 0);
-       if (pledgedSrcSize) params.fParams.contentSizeFlag = 1;
        return ZSTD_initCStream_advanced(zcs, NULL, 0, params, pledgedSrcSize);
 }
 
-size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel)
-{
-       return ZSTD_initCStream_usingDict(zcs, NULL, 0, compressionLevel);
-}
-
-size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs)
-{
-       if (zcs==NULL) return 0;   /* support sizeof on NULL */
-       return sizeof(*zcs) + ZSTD_sizeof_CCtx(zcs->cctx) + ZSTD_sizeof_CDict(zcs->cdictLocal) + zcs->outBuffSize + zcs->inBuffSize;
-}
-
 /*======   Compression   ======*/
 
 typedef enum { zsf_gather, zsf_flush, zsf_end } ZSTD_flush_e;
index 10700257bc23869908ef182893460ab8fe934554..0d512e8f6752158a18f933bfba32a4dfce1eb734 100644 (file)
@@ -90,9 +90,10 @@ struct ZSTD_DCtx_s
        BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX];
 };  /* typedef'd to ZSTD_DCtx within "zstd.h" */
 
-size_t ZSTD_sizeof_DCtx (const ZSTD_DCtx* dctx) { return (dctx==NULL) ? 0 : sizeof(ZSTD_DCtx); }
-
-size_t ZSTD_estimateDCtxSize(void) { return sizeof(ZSTD_DCtx); }
+size_t ZSTD_DCtxWorkspaceBound(void)
+{
+       return ZSTD_ALIGN(sizeof(ZSTD_stack)) + ZSTD_ALIGN(sizeof(ZSTD_DCtx));
+}
 
 size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx)
 {
@@ -118,7 +119,6 @@ ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
 {
        ZSTD_DCtx* dctx;
 
-       if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem;
        if (!customMem.customAlloc || !customMem.customFree) return NULL;
 
        dctx = (ZSTD_DCtx*)ZSTD_malloc(sizeof(ZSTD_DCtx), customMem);
@@ -128,9 +128,10 @@ ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
        return dctx;
 }
 
-ZSTD_DCtx* ZSTD_createDCtx(void)
+ZSTD_DCtx* ZSTD_createDCtx(void* workspace, size_t workspaceSize)
 {
-       return ZSTD_createDCtx_advanced(defaultCustomMem);
+       ZSTD_customMem const stackMem = ZSTD_initStack(workspace, workspaceSize);
+       return ZSTD_createDCtx_advanced(stackMem);
 }
 
 size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx)
@@ -354,20 +355,6 @@ unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize)
        }
 }
 
-/** ZSTD_getDecompressedSize() :
-*   compatible with legacy mode
-*   @return : decompressed size if known, 0 otherwise
-                         note : 0 can mean any of the following :
-                                  - decompressed size is not present within frame header
-                                  - frame header unknown / not supported
-                                  - frame header not complete (`srcSize` too small) */
-unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize)
-{
-       unsigned long long const ret = ZSTD_getFrameContentSize(src, srcSize);
-       return ret >= ZSTD_CONTENTSIZE_ERROR ? 0 : ret;
-}
-
-
 /** ZSTD_decodeFrameHeader() :
 *   `headerSize` must be the size provided by ZSTD_frameHeaderSize().
 *   @return : 0 if success, or an error code, which can be tested using ZSTD_isError() */
@@ -1620,10 +1607,7 @@ static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx* dctx,
        return (BYTE*)dst - (BYTE*)dststart;
 }
 
-size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
-                                                                void* dst, size_t dstCapacity,
-                                                  const void* src, size_t srcSize,
-                                                  const void* dict, size_t dictSize)
+size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void *dict, size_t dictSize)
 {
        return ZSTD_decompressMultiFrame(dctx, dst, dstCapacity, src, srcSize, dict, dictSize, NULL);
 }
@@ -1635,13 +1619,6 @@ size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const
 }
 
 
-size_t ZSTD_decompress(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
-{
-       ZSTD_DCtx dctx;
-       return ZSTD_decompressDCtx(&dctx, dst, dstCapacity, src, srcSize);
-}
-
-
 /*-**************************************
 *   Advanced Streaming Decompression API
 *   Bufferless and synchronous
@@ -1900,6 +1877,11 @@ struct ZSTD_DDict_s {
        ZSTD_customMem cMem;
 };  /* typedef'd to ZSTD_DDict within "zstd.h" */
 
+size_t ZSTD_DDictWorkspaceBound(void)
+{
+       return ZSTD_ALIGN(sizeof(ZSTD_stack)) + ZSTD_ALIGN(sizeof(ZSTD_DDict));
+}
+
 static const void* ZSTD_DDictDictContent(const ZSTD_DDict* ddict)
 {
        return ddict->dictContent;
@@ -1953,9 +1935,8 @@ static size_t ZSTD_loadEntropy_inDDict(ZSTD_DDict* ddict)
 }
 
 
-ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize, unsigned byReference, ZSTD_customMem customMem)
+static ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize, unsigned byReference, ZSTD_customMem customMem)
 {
-       if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem;
        if (!customMem.customAlloc || !customMem.customFree) return NULL;
 
        {   ZSTD_DDict* const ddict = (ZSTD_DDict*) ZSTD_malloc(sizeof(ZSTD_DDict), customMem);
@@ -1989,21 +1970,10 @@ ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize, unsigne
 *   Create a digested dictionary, to start decompression without startup delay.
 *   `dict` content is copied inside DDict.
 *   Consequently, `dict` can be released after `ZSTD_DDict` creation */
-ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize)
+ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize, void* workspace, size_t workspaceSize)
 {
-       ZSTD_customMem const allocator = { NULL, NULL, NULL };
-       return ZSTD_createDDict_advanced(dict, dictSize, 0, allocator);
-}
-
-
-/*! ZSTD_createDDict_byReference() :
- *  Create a digested dictionary, to start decompression without startup delay.
- *  Dictionary content is simply referenced, it will be accessed during decompression.
- *  Warning : dictBuffer must outlive DDict (DDict must be freed before dictBuffer) */
-ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize)
-{
-       ZSTD_customMem const allocator = { NULL, NULL, NULL };
-       return ZSTD_createDDict_advanced(dictBuffer, dictSize, 1, allocator);
+       ZSTD_customMem const stackMem = ZSTD_initStack(workspace, workspaceSize);
+       return ZSTD_createDDict_advanced(dict, dictSize, 1, stackMem);
 }
 
 
@@ -2017,12 +1987,6 @@ size_t ZSTD_freeDDict(ZSTD_DDict* ddict)
        }
 }
 
-size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict)
-{
-       if (ddict==NULL) return 0;   /* support sizeof on NULL */
-       return sizeof(*ddict) + (ddict->dictBuffer ? ddict->dictSize : 0) ;
-}
-
 /*! ZSTD_getDictID_fromDict() :
  *  Provides the dictID stored within dictionary.
  *  if @return == 0, the dictionary is not conformant with Zstandard specification.
@@ -2110,17 +2074,17 @@ struct ZSTD_DStream_s {
        U32 hostageByte;
 };   /* typedef'd to ZSTD_DStream within "zstd.h" */
 
-
-ZSTD_DStream* ZSTD_createDStream(void)
-{
-       return ZSTD_createDStream_advanced(defaultCustomMem);
+size_t ZSTD_DStreamWorkspaceBound(size_t maxWindowSize) {
+       size_t const blockSize = MIN(maxWindowSize, ZSTD_BLOCKSIZE_ABSOLUTEMAX);
+       size_t const inBuffSize = blockSize;
+       size_t const outBuffSize = maxWindowSize + blockSize + WILDCOPY_OVERLENGTH * 2;
+       return ZSTD_DCtxWorkspaceBound() + ZSTD_ALIGN(sizeof(ZSTD_DStream)) + ZSTD_ALIGN(inBuffSize) + ZSTD_ALIGN(outBuffSize);
 }
 
-ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem)
+static ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem)
 {
        ZSTD_DStream* zds;
 
-       if (!customMem.customAlloc && !customMem.customFree) customMem = defaultCustomMem;
        if (!customMem.customAlloc || !customMem.customFree) return NULL;
 
        zds = (ZSTD_DStream*) ZSTD_malloc(sizeof(ZSTD_DStream), customMem);
@@ -2134,6 +2098,12 @@ ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem)
        return zds;
 }
 
+ZSTD_DStream* ZSTD_createDStream(void* workspace, size_t workspaceSize)
+{
+       ZSTD_customMem const stackMem = ZSTD_initStack(workspace, workspaceSize);
+       return ZSTD_createDStream_advanced(stackMem);
+}
+
 size_t ZSTD_freeDStream(ZSTD_DStream* zds)
 {
        if (zds==NULL) return 0;   /* support free on null */
@@ -2157,29 +2127,22 @@ size_t ZSTD_freeDStream(ZSTD_DStream* zds)
 size_t ZSTD_DStreamInSize(void)  { return ZSTD_BLOCKSIZE_ABSOLUTEMAX + ZSTD_blockHeaderSize; }
 size_t ZSTD_DStreamOutSize(void) { return ZSTD_BLOCKSIZE_ABSOLUTEMAX; }
 
-size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize)
+size_t ZSTD_initDStream(ZSTD_DStream* zds, size_t maxWindowSize)
 {
+       zds->maxWindowSize = maxWindowSize;
        zds->stage = zdss_loadHeader;
        zds->lhSize = zds->inPos = zds->outStart = zds->outEnd = 0;
        ZSTD_freeDDict(zds->ddictLocal);
-       if (dict && dictSize >= 8) {
-               zds->ddictLocal = ZSTD_createDDict(dict, dictSize);
-               if (zds->ddictLocal == NULL) return ERROR(memory_allocation);
-       } else zds->ddictLocal = NULL;
+       zds->ddictLocal = NULL;
        zds->ddict = zds->ddictLocal;
        zds->legacyVersion = 0;
        zds->hostageByte = 0;
        return ZSTD_frameHeaderSize_prefix;
 }
 
-size_t ZSTD_initDStream(ZSTD_DStream* zds)
+size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, size_t maxWindowSize, const ZSTD_DDict* ddict)  /**< note : ddict will just be referenced, and must outlive decompression session */
 {
-       return ZSTD_initDStream_usingDict(zds, NULL, 0);
-}
-
-size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict)  /**< note : ddict will just be referenced, and must outlive decompression session */
-{
-       size_t const initResult = ZSTD_initDStream(zds);
+       size_t const initResult = ZSTD_initDStream(zds, maxWindowSize);
        zds->ddict = ddict;
        return initResult;
 }
@@ -2193,25 +2156,6 @@ size_t ZSTD_resetDStream(ZSTD_DStream* zds)
        return ZSTD_frameHeaderSize_prefix;
 }
 
-size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds,
-                                                               ZSTD_DStreamParameter_e paramType, unsigned paramValue)
-{
-       switch(paramType)
-       {
-               default : return ERROR(parameter_unknown);
-               case DStream_p_maxWindowSize : zds->maxWindowSize = paramValue ? paramValue : (U32)(-1); break;
-       }
-       return 0;
-}
-
-
-size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds)
-{
-       if (zds==NULL) return 0;   /* support sizeof on NULL */
-       return sizeof(*zds) + ZSTD_sizeof_DCtx(zds->dctx) + ZSTD_sizeof_DDict(zds->ddictLocal) + zds->inBuffSize + zds->outBuffSize;
-}
-
-
 /* *****   Decompression   ***** */
 
 MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
diff --git a/contrib/linux-kernel/lib/zstd_errors.h b/contrib/linux-kernel/lib/zstd_errors.h
deleted file mode 100644 (file)
index 37e491b..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- */
-
-#ifndef ZSTD_ERRORS_H_398273423
-#define ZSTD_ERRORS_H_398273423
-
-/*===== dependency =====*/
-#include <linux/types.h>   /* size_t */
-
-
-/* =====   ZSTDERRORLIB_API : control library symbols visibility   ===== */
-#define ZSTDERRORLIB_API
-
-/*-****************************************
-*  error codes list
-******************************************/
-typedef enum {
-  ZSTD_error_no_error,
-  ZSTD_error_GENERIC,
-  ZSTD_error_prefix_unknown,
-  ZSTD_error_version_unsupported,
-  ZSTD_error_parameter_unknown,
-  ZSTD_error_frameParameter_unsupported,
-  ZSTD_error_frameParameter_unsupportedBy32bits,
-  ZSTD_error_frameParameter_windowTooLarge,
-  ZSTD_error_compressionParameter_unsupported,
-  ZSTD_error_init_missing,
-  ZSTD_error_memory_allocation,
-  ZSTD_error_stage_wrong,
-  ZSTD_error_dstSize_tooSmall,
-  ZSTD_error_srcSize_wrong,
-  ZSTD_error_corruption_detected,
-  ZSTD_error_checksum_wrong,
-  ZSTD_error_tableLog_tooLarge,
-  ZSTD_error_maxSymbolValue_tooLarge,
-  ZSTD_error_maxSymbolValue_tooSmall,
-  ZSTD_error_dictionary_corrupted,
-  ZSTD_error_dictionary_wrong,
-  ZSTD_error_dictionaryCreation_failed,
-  ZSTD_error_maxCode
-} ZSTD_ErrorCode;
-
-/*! ZSTD_getErrorCode() :
-       convert a `size_t` function result into a `ZSTD_ErrorCode` enum type,
-       which can be used to compare directly with enum list published into "error_public.h" */
-ZSTDERRORLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult);
-ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code);
-
-#endif /* ZSTD_ERRORS_H_398273423 */
index 57ae7739033e7e824a020c49f53d28a1cd8267d2..b7dcc03e0b131e4ff16f6072f7782b8c0d982bf6 100644 (file)
 /*-*******************************************************
 *  Compiler specifics
 *********************************************************/
-#define FORCE_INLINE static __attribute__((always_inline))
-#define FORCE_NOINLINE static __attribute__((__noinline__))
+#define FORCE_INLINE static __always_inline
+#define FORCE_NOINLINE static noinline
 
 
 /*-*************************************
 *  Dependencies
 ***************************************/
+#include <linux/compiler.h>
+#include <linux/kernel.h>
 #include "mem.h"
 #include "error_private.h"
 #include "zstd.h"
@@ -207,25 +209,35 @@ const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx);
 void ZSTD_seqToCodes(const seqStore_t* seqStorePtr);
 int ZSTD_isSkipFrame(ZSTD_DCtx* dctx);
 
-/* custom memory allocation functions */
-void* ZSTD_defaultAllocFunction(void* opaque, size_t size);
-void ZSTD_defaultFreeFunction(void* opaque, void* address);
-#ifndef ZSTD_DLL_IMPORT
-static const ZSTD_customMem defaultCustomMem = { ZSTD_defaultAllocFunction, ZSTD_defaultFreeFunction, NULL };
-#endif
+/*= Custom memory allocation functions */
+typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
+typedef void  (*ZSTD_freeFunction) (void* opaque, void* address);
+typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
+
 void* ZSTD_malloc(size_t size, ZSTD_customMem customMem);
 void ZSTD_free(void* ptr, ZSTD_customMem customMem);
 
+/*====== stack allocation  ======*/
+
+typedef struct {
+       void* ptr;
+       const void* end;
+} ZSTD_stack;
+
+#define ZSTD_ALIGN(x) ALIGN(x, sizeof(size_t))
+#define ZSTD_PTR_ALIGN(p) PTR_ALIGN(p, sizeof(size_t))
+
+ZSTD_customMem ZSTD_initStack(void* workspace, size_t workspaceSize);
+
+void* ZSTD_stackAlloc(void* opaque, size_t size);
+void ZSTD_stackFree(void* opaque, void* address);
+
 
 /*======  common function  ======*/
 
 MEM_STATIC U32 ZSTD_highbit32(U32 val)
 {
-#   if defined(_MSC_VER)   /* Visual */
-       unsigned long r=0;
-       _BitScanReverse(&r, val);
-       return (unsigned)r;
-#   elif defined(__GNUC__) && (__GNUC__ >= 3)   /* GCC Intrinsic */
+#   if defined(__GNUC__) && (__GNUC__ >= 3)   /* GCC Intrinsic */
        return 31 - __builtin_clz(val);
 #   else   /* Software version */
        static const int DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
@@ -250,5 +262,12 @@ MEM_STATIC U32 ZSTD_highbit32(U32 val)
  *        do not use with extDict variant ! */
 void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx);
 
+size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx);
+size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx);
+size_t ZSTD_freeCDict(ZSTD_CDict* cdict);
+size_t ZSTD_freeDDict(ZSTD_DDict* cdict);
+size_t ZSTD_freeCStream(ZSTD_CStream* zcs);
+size_t ZSTD_freeDStream(ZSTD_DStream* zds);
+
 
 #endif   /* ZSTD_CCOMMON_H_MODULE */