Makefile : library correctly compiled with -O3 switch (issue 114)
authoryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Wed, 12 Mar 2014 14:51:59 +0000 (14:51 +0000)
committeryann.collet.73@gmail.com <yann.collet.73@gmail.com@650e7d94-2a16-8b24-b05c-7c0b3f6821cd>
Wed, 12 Mar 2014 14:51:59 +0000 (14:51 +0000)
Makefile : library compilation compatible with clang
Makefile : library is versioned and linked (issue 119)
lz4.h : no more static inline prototypes (issue 116)
man : improved header/footer (issue 111)
Makefile : Use system default $(CC) & $(MAKE) variables (issue 112)
xxhash : updated to r34

git-svn-id: https://lz4.googlecode.com/svn/trunk@114 650e7d94-2a16-8b24-b05c-7c0b3f6821cd

Makefile
NEWS
lz4.c
lz4.h
lz4hc.h
programs/Makefile
programs/bench.c
programs/fullbench.c
programs/fuzzer.c
programs/lz4.1
programs/xxhash.h

index a24e503..380e1fe 100644 (file)
--- a/Makefile
+++ b/Makefile
 #  - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c
 # ################################################################
 
-RELEASE=r113
+export RELEASE=r114
+LIBVER_MAJOR=1
+LIBVER_MINOR=0
+LIBVER_PATCH=0
+LIBVER=$(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH)
+
 DESTDIR=
 PREFIX=/usr
-CC=gcc
-CFLAGS+= -I. -std=c99 -Wall -W -Wundef -DLZ4_VERSION=\"$(RELEASE)\"
+CC:=$(CC)
+CFLAGS+= -I. -std=c99 -O3 -Wall -W -Wundef -DLZ4_VERSION=\"$(RELEASE)\"
 
 LIBDIR=$(PREFIX)/lib
 INCLUDEDIR=$(PREFIX)/include
@@ -62,34 +67,38 @@ SOURCES = $(TEXT) $(NONTEXT)
 
 
 default: liblz4
-       @cd $(PRGDIR); make
+       @cd $(PRGDIR); $(MAKE) -e
 
 all: liblz4 lz4programs
 
 liblz4: liblz4.a liblz4.so
 
 lz4programs: lz4.c lz4hc.c
-       @cd $(PRGDIR); make all
+       @cd $(PRGDIR); $(MAKE) -e all
 
 liblz4.a: lz4.c lz4hc.c
-       $(CC) -O3 -c $(CFLAGS) $^
+       $(CC) $(CFLAGS) -c $^
        ar rcs liblz4.a lz4.o lz4hc.o
 
 liblz4.so: lz4.c lz4hc.c
-       $(CC) -shared -fPIC -Wl,--soname=liblz4.so.1 $(CFLAGS) $^ -o $@
+       $(CC) $(CFLAGS) -shared $^ -fPIC -Wl,-soname=liblz4.so.$(LIBVER_MAJOR) -o $@.$(LIBVER)
+       @ln -s $@.$(LIBVER) $@.$(LIBVER_MAJOR)
+       @ln -s $@.$(LIBVER) $@
 
 clean:
-       @rm -f core *.o *.a *.so $(DISTRIBNAME)
+       @rm -f core *.o *.a *.so *.so.* $(DISTRIBNAME)
        @cd $(PRGDIR); make clean
        @echo Cleaning completed
 
 
-#ifeq ($(shell uname),Linux)
+#make install option is reserved to Linux & OSX targets
 ifneq (,$(filter $(shell uname),Linux Darwin))
 
 install: liblz4
        @install -d -m 755 $(DESTDIR)$(LIBDIR)/ $(DESTDIR)$(INCLUDEDIR)/
        @install -m 755 liblz4.a $(DESTDIR)$(LIBDIR)/liblz4.a
+       @install -m 755 liblz4.so.$(LIBVER) $(DESTDIR)$(LIBDIR)/liblz4.so.$(LIBVER)
+       @install -m 755 liblz4.so.$(LIBVER_MAJOR) $(DESTDIR)$(LIBDIR)/liblz4.so.$(LIBVER_MAJOR)
        @install -m 755 liblz4.so $(DESTDIR)$(LIBDIR)/liblz4.so
        @install -m 755 lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4.h
        @install -m 755 lz4hc.h $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
@@ -98,6 +107,8 @@ install: liblz4
 
 uninstall:
        [ -x $(DESTDIR)$(LIBDIR)/liblz4.a ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.a
+       [ -x $(DESTDIR)$(LIBDIR)/liblz4.so.$(LIBVER) ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.so.$(LIBVER)
+       [ -x $(DESTDIR)$(LIBDIR)/liblz4.so.$(LIBVER_MAJOR) ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.so.$(LIBVER_MAJOR)
        [ -x $(DESTDIR)$(LIBDIR)/liblz4.so ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.so
        [ -f $(DESTDIR)$(INCLUDEDIR)/lz4.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4.h
        [ -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
diff --git a/NEWS b/NEWS
index 23d059e..092acf2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,12 @@
+r114:
+Makefile : library correctly compiled with -O3 switch (issue 114)
+Makefile : library compilation compatible with clang
+Makefile : library is versioned and linked (issue 119)
+lz4.h : no more static inline prototypes (issue 116)
+man : improved header/footer (issue 111)
+Makefile : Use system default $(CC) & $(MAKE) variables (issue 112)
+xxhash : updated to r34
+
 r113:
 Large decompression speed improvement for GCC 32-bits. Thanks to Valery Croizier !
 LZ4HC : Compression Level is now a programmable parameter (CLI from 4 to 9)
diff --git a/lz4.c b/lz4.c
index ee37895..fd229ef 100644 (file)
--- a/lz4.c
+++ b/lz4.c
@@ -369,6 +369,8 @@ FORCE_INLINE int LZ4_NbCommonBytes (register U32 val)
 /****************************
    Compression functions
 ****************************/
+int LZ4_compressBound(int isize)  { return LZ4_COMPRESSBOUND(isize); }
+
 FORCE_INLINE int LZ4_hashSequence(U32 sequence, tableType_t tableType)
 {
     if (tableType == byU16)
@@ -709,7 +711,6 @@ int LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, cha
 /****************************
    Decompression functions
 ****************************/
-
 /*
  * This generic decompression function cover all use cases.
  * It shall be instanciated several times, using different sets of directives
@@ -875,3 +876,5 @@ int LZ4_decompress_fast(const char* source, char* dest, int outputSize)
 #endif
 }
 
+int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }
+int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }
diff --git a/lz4.h b/lz4.h
index 0bfe44a..4b8a15b 100644 (file)
--- a/lz4.h
+++ b/lz4.h
-/*\r
-   LZ4 - Fast LZ compression algorithm\r
-   Header File\r
-   Copyright (C) 2011-2013, Yann Collet.\r
-   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)\r
-\r
-   Redistribution and use in source and binary forms, with or without\r
-   modification, are permitted provided that the following conditions are\r
-   met:\r
-\r
-       * Redistributions of source code must retain the above copyright\r
-   notice, this list of conditions and the following disclaimer.\r
-       * Redistributions in binary form must reproduce the above\r
-   copyright notice, this list of conditions and the following disclaimer\r
-   in the documentation and/or other materials provided with the\r
-   distribution.\r
-\r
-   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
-   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
-   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
-   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
-   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
-   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
-   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
-   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
-   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
-   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
-   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-   You can contact the author at :\r
-   - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html\r
-   - LZ4 source repository : http://code.google.com/p/lz4/\r
-*/\r
-#pragma once\r
-\r
-#if defined (__cplusplus)\r
-extern "C" {\r
-#endif\r
-\r
-\r
+/*
+   LZ4 - Fast LZ compression algorithm
+   Header File
+   Copyright (C) 2011-2013, Yann Collet.
+   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are
+   met:
+
+       * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above
+   copyright notice, this list of conditions and the following disclaimer
+   in the documentation and/or other materials provided with the
+   distribution.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+   You can contact the author at :
+   - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
+   - LZ4 source repository : http://code.google.com/p/lz4/
+*/
+#pragma once
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
+
 /**************************************
    Version
 **************************************/
 #define LZ4_VERSION_MAJOR    1    /* for major interface/format changes  */
 #define LZ4_VERSION_MINOR    1    /* for minor interface/format changes  */
 #define LZ4_VERSION_RELEASE  3    /* for tweaks, bug-fixes, or development */
-\r
-\r
-/**************************************\r
-   Compiler Options\r
-**************************************/\r
-#if (defined(__GNUC__) && defined(__STRICT_ANSI__)) || (defined(_MSC_VER) && !defined(__cplusplus))   /* Visual Studio */\r
-#  define inline __inline           /* Visual C is not C99, but supports some kind of inline */\r
-#endif\r
-\r
-\r
-/**************************************\r
-   Simple Functions\r
-**************************************/\r
-\r
-int LZ4_compress        (const char* source, char* dest, int inputSize);\r
-int LZ4_decompress_safe (const char* source, char* dest, int inputSize, int maxOutputSize);\r
-\r
-/*\r
-LZ4_compress() :\r
-    Compresses 'inputSize' bytes from 'source' into 'dest'.\r
-    Destination buffer must be already allocated,\r
-    and must be sized to handle worst cases situations (input data not compressible)\r
-    Worst case size evaluation is provided by function LZ4_compressBound()\r
-    inputSize : Max supported value is LZ4_MAX_INPUT_VALUE\r
-    return : the number of bytes written in buffer dest\r
-             or 0 if the compression fails\r
-\r
-LZ4_decompress_safe() :\r
-    maxOutputSize : is the size of the destination buffer (which must be already allocated)\r
-    return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)\r
-             If the source stream is detected malformed, the function will stop decoding and return a negative result.\r
-             This function is protected against buffer overflow exploits (never writes outside of output buffer, and never reads outside of input buffer). Therefore, it is protected against malicious data packets\r
-*/\r
-\r
-\r
-/**************************************\r
-   Advanced Functions\r
-**************************************/\r
-#define LZ4_MAX_INPUT_SIZE        0x7E000000   /* 2 113 929 216 bytes */\r
-#define LZ4_COMPRESSBOUND(isize)  ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)\r
-static inline int LZ4_compressBound(int isize)  { return LZ4_COMPRESSBOUND(isize); }\r
-\r
-/*\r
-LZ4_compressBound() :\r
-    Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)\r
-    primarily useful for memory allocation of output buffer.\r
-    inline function is recommended for the general case,\r
-    macro is also provided when result needs to be evaluated at compilation (such as stack memory allocation).\r
-\r
-    isize  : is the input size. Max supported value is LZ4_MAX_INPUT_SIZE\r
-    return : maximum output size in a "worst case" scenario\r
-             or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)\r
-*/\r
-\r
-\r
-int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);\r
-\r
-/*\r
-LZ4_compress_limitedOutput() :\r
-    Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.\r
-    If it cannot achieve it, compression will stop, and result of the function will be zero.\r
-    This function never writes outside of provided output buffer.\r
-\r
-    inputSize  : Max supported value is LZ4_MAX_INPUT_VALUE\r
-    maxOutputSize : is the size of the destination buffer (which must be already allocated)\r
-    return : the number of bytes written in buffer 'dest'\r
-             or 0 if the compression fails\r
-*/\r
-\r
-\r
-int LZ4_decompress_fast (const char* source, char* dest, int outputSize);\r
-\r
-/*\r
-LZ4_decompress_fast() :\r
-    outputSize : is the original (uncompressed) size\r
-    return : the number of bytes read from the source buffer (in other words, the compressed size)\r
-             If the source stream is malformed, the function will stop decoding and return a negative result.\r
-    note : This function is a bit faster than LZ4_decompress_safe()\r
-           This function never writes outside of output buffers, but may read beyond input buffer in case of malicious data packet.\r
-           Use this function preferably into a trusted environment (data to decode comes from a trusted source).\r
-           Destination buffer must be already allocated. Its size must be a minimum of 'outputSize' bytes.\r
-*/\r
-\r
-int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize);\r
-\r
-/*\r
-LZ4_decompress_safe_partial() :\r
-    This function decompress a compressed block of size 'inputSize' at position 'source'\r
-    into output buffer 'dest' of size 'maxOutputSize'.\r
-    The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached,\r
-    reducing decompression time.\r
-    return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)\r
-       Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.\r
-             Always control how many bytes were decoded.\r
-             If the source stream is detected malformed, the function will stop decoding and return a negative result.\r
-             This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets\r
-*/\r
-\r
-\r
-int LZ4_sizeofState();\r
-int LZ4_compress_withState               (void* state, const char* source, char* dest, int inputSize);\r
-int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);\r
-\r
-/*\r
-These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods.\r
-To know how much memory must be allocated for the compression tables, use :\r
-int LZ4_sizeofState();\r
-\r
-Note that tables must be aligned on 4-bytes boundaries, otherwise compression will fail (return code 0).\r
-\r
-The allocated memory can be provided to the compressions functions using 'void* state' parameter.\r
-LZ4_compress_withState() and LZ4_compress_limitedOutput_withState() are equivalent to previously described functions.\r
-They just use the externally allocated memory area instead of allocating their own (on stack, or on heap).\r
-*/\r
-\r
-\r
-/**************************************\r
-   Streaming Functions\r
-**************************************/\r
-void* LZ4_create (const char* inputBuffer);\r
-int   LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize);\r
-int   LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize);\r
-char* LZ4_slideInputBuffer (void* LZ4_Data);\r
-int   LZ4_free (void* LZ4_Data);\r
-\r
-/*\r
-These functions allow the compression of dependent blocks, where each block benefits from prior 64 KB within preceding blocks.\r
-In order to achieve this, it is necessary to start creating the LZ4 Data Structure, thanks to the function :\r
-\r
-void* LZ4_create (const char* inputBuffer);\r
-The result of the function is the (void*) pointer on the LZ4 Data Structure.\r
-This pointer will be needed in all other functions.\r
-If the pointer returned is NULL, then the allocation has failed, and compression must be aborted.\r
-The only parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.\r
-The input buffer must be already allocated, and size at least 192KB.\r
-'inputBuffer' will also be the 'const char* source' of the first block.\r
-\r
-All blocks are expected to lay next to each other within the input buffer, starting from 'inputBuffer'.\r
-To compress each block, use either LZ4_compress_continue() or LZ4_compress_limitedOutput_continue().\r
-Their behavior are identical to LZ4_compress() or LZ4_compress_limitedOutput(),\r
-but require the LZ4 Data Structure as their first argument, and check that each block starts right after the previous one.\r
-If next block does not begin immediately after the previous one, the compression will fail (return 0).\r
-\r
-When it's no longer possible to lay the next block after the previous one (not enough space left into input buffer), a call to :\r
-char* LZ4_slideInputBuffer(void* LZ4_Data);\r
-must be performed. It will typically copy the latest 64KB of input at the beginning of input buffer.\r
-Note that, for this function to work properly, minimum size of an input buffer must be 192KB.\r
-==> The memory position where the next input data block must start is provided as the result of the function.\r
-\r
-Compression can then resume, using LZ4_compress_continue() or LZ4_compress_limitedOutput_continue(), as usual.\r
-\r
-When compression is completed, a call to LZ4_free() will release the memory used by the LZ4 Data Structure.\r
-*/\r
-\r
-int LZ4_sizeofStreamState();\r
-int LZ4_resetStreamState(void* state, const char* inputBuffer);\r
-\r
-/*\r
-These functions achieve the same result as :\r
-void* LZ4_create (const char* inputBuffer);\r
-\r
-They are provided here to allow the user program to allocate memory using its own routines.\r
-\r
-To know how much space must be allocated, use LZ4_sizeofStreamState();\r
-Note also that space must be 4-bytes aligned.\r
-\r
-Once space is allocated, you must initialize it using : LZ4_resetStreamState(void* state, const char* inputBuffer);\r
-void* state is a pointer to the space allocated.\r
-It must be aligned on 4-bytes boundaries, and be large enough.\r
-The parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.\r
-The input buffer must be already allocated, and size at least 192KB.\r
-'inputBuffer' will also be the 'const char* source' of the first block.\r
-\r
-The same space can be re-used multiple times, just by initializing it each time with LZ4_resetStreamState().\r
-return value of LZ4_resetStreamState() must be 0 is OK.\r
-Any other value means there was an error (typically, pointer is not aligned on 4-bytes boundaries).\r
-*/\r
-\r
-\r
-int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int inputSize, int maxOutputSize);\r
-int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int outputSize);\r
-\r
-/*\r
-*_withPrefix64k() :\r
-    These decoding functions work the same as their "normal name" versions,\r
-    but can use up to 64KB of data in front of 'char* dest'.\r
-    These functions are necessary to decode inter-dependant blocks.\r
-*/\r
-\r
-\r
-/**************************************\r
-   Obsolete Functions\r
-**************************************/\r
-/*\r
-These functions are deprecated and should no longer be used.\r
-They are provided here for compatibility with existing user programs.\r
-*/\r
-static inline int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }\r
-static inline int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }\r
-\r
-\r
-\r
-#if defined (__cplusplus)\r
-}\r
-#endif\r
+
+
+/**************************************
+   Compiler Options
+**************************************/
+#if (defined(__GNUC__) && defined(__STRICT_ANSI__)) || (defined(_MSC_VER) && !defined(__cplusplus))   /* Visual Studio */
+#  define inline __inline           /* Visual C is not C99, but supports some kind of inline */
+#endif
+
+
+/**************************************
+   Simple Functions
+**************************************/
+
+int LZ4_compress        (const char* source, char* dest, int inputSize);
+int LZ4_decompress_safe (const char* source, char* dest, int inputSize, int maxOutputSize);
+
+/*
+LZ4_compress() :
+    Compresses 'inputSize' bytes from 'source' into 'dest'.
+    Destination buffer must be already allocated,
+    and must be sized to handle worst cases situations (input data not compressible)
+    Worst case size evaluation is provided by function LZ4_compressBound()
+    inputSize : Max supported value is LZ4_MAX_INPUT_VALUE
+    return : the number of bytes written in buffer dest
+             or 0 if the compression fails
+
+LZ4_decompress_safe() :
+    maxOutputSize : is the size of the destination buffer (which must be already allocated)
+    return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
+             If the source stream is detected malformed, the function will stop decoding and return a negative result.
+             This function is protected against buffer overflow exploits (never writes outside of output buffer, and never reads outside of input buffer). Therefore, it is protected against malicious data packets
+*/
+
+
+/**************************************
+   Advanced Functions
+**************************************/
+#define LZ4_MAX_INPUT_SIZE        0x7E000000   /* 2 113 929 216 bytes */
+#define LZ4_COMPRESSBOUND(isize)  ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
+
+/*
+LZ4_compressBound() :
+    Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
+    primarily useful for memory allocation of output buffer.
+    inline function is recommended for the general case,
+    macro is also provided when result needs to be evaluated at compilation (such as stack memory allocation).
+
+    isize  : is the input size. Max supported value is LZ4_MAX_INPUT_SIZE
+    return : maximum output size in a "worst case" scenario
+             or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)
+*/
+int LZ4_compressBound(int isize);
+
+
+/*
+LZ4_compress_limitedOutput() :
+    Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
+    If it cannot achieve it, compression will stop, and result of the function will be zero.
+    This function never writes outside of provided output buffer.
+
+    inputSize  : Max supported value is LZ4_MAX_INPUT_VALUE
+    maxOutputSize : is the size of the destination buffer (which must be already allocated)
+    return : the number of bytes written in buffer 'dest'
+             or 0 if the compression fails
+*/
+int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
+
+
+/*
+LZ4_decompress_fast() :
+    originalSize : is the original and therefore uncompressed size
+    return : the number of bytes read from the source buffer (in other words, the compressed size)
+             If the source stream is malformed, the function will stop decoding and return a negative result.
+    note : This function is a bit faster than LZ4_decompress_safe()
+           This function never writes outside of output buffers, but may read beyond input buffer in case of malicious data packet.
+           Use this function preferably into a trusted environment (data to decode comes from a trusted source).
+           Destination buffer must be already allocated. Its size must be a minimum of 'outputSize' bytes.
+*/
+int LZ4_decompress_fast (const char* source, char* dest, int originalSize);
+
+
+/*
+LZ4_decompress_safe_partial() :
+    This function decompress a compressed block of size 'inputSize' at position 'source'
+    into output buffer 'dest' of size 'maxOutputSize'.
+    The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached,
+    reducing decompression time.
+    return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
+       Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.
+             Always control how many bytes were decoded.
+             If the source stream is detected malformed, the function will stop decoding and return a negative result.
+             This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets
+*/
+int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize);
+
+
+/*
+These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods.
+To know how much memory must be allocated for the compression tables, use :
+int LZ4_sizeofState();
+
+Note that tables must be aligned on 4-bytes boundaries, otherwise compression will fail (return code 0).
+
+The allocated memory can be provided to the compressions functions using 'void* state' parameter.
+LZ4_compress_withState() and LZ4_compress_limitedOutput_withState() are equivalent to previously described functions.
+They just use the externally allocated memory area instead of allocating their own (on stack, or on heap).
+*/
+int LZ4_sizeofState(void);
+int LZ4_compress_withState               (void* state, const char* source, char* dest, int inputSize);
+int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
+
+
+/**************************************
+   Streaming Functions
+**************************************/
+void* LZ4_create (const char* inputBuffer);
+int   LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize);
+int   LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize);
+char* LZ4_slideInputBuffer (void* LZ4_Data);
+int   LZ4_free (void* LZ4_Data);
+
+/*
+These functions allow the compression of dependent blocks, where each block benefits from prior 64 KB within preceding blocks.
+In order to achieve this, it is necessary to start creating the LZ4 Data Structure, thanks to the function :
+
+void* LZ4_create (const char* inputBuffer);
+The result of the function is the (void*) pointer on the LZ4 Data Structure.
+This pointer will be needed in all other functions.
+If the pointer returned is NULL, then the allocation has failed, and compression must be aborted.
+The only parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
+The input buffer must be already allocated, and size at least 192KB.
+'inputBuffer' will also be the 'const char* source' of the first block.
+
+All blocks are expected to lay next to each other within the input buffer, starting from 'inputBuffer'.
+To compress each block, use either LZ4_compress_continue() or LZ4_compress_limitedOutput_continue().
+Their behavior are identical to LZ4_compress() or LZ4_compress_limitedOutput(),
+but require the LZ4 Data Structure as their first argument, and check that each block starts right after the previous one.
+If next block does not begin immediately after the previous one, the compression will fail (return 0).
+
+When it's no longer possible to lay the next block after the previous one (not enough space left into input buffer), a call to :
+char* LZ4_slideInputBuffer(void* LZ4_Data);
+must be performed. It will typically copy the latest 64KB of input at the beginning of input buffer.
+Note that, for this function to work properly, minimum size of an input buffer must be 192KB.
+==> The memory position where the next input data block must start is provided as the result of the function.
+
+Compression can then resume, using LZ4_compress_continue() or LZ4_compress_limitedOutput_continue(), as usual.
+
+When compression is completed, a call to LZ4_free() will release the memory used by the LZ4 Data Structure.
+*/
+
+
+int LZ4_sizeofStreamState(void);
+int LZ4_resetStreamState(void* state, const char* inputBuffer);
+
+/*
+These functions achieve the same result as :
+void* LZ4_create (const char* inputBuffer);
+
+They are provided here to allow the user program to allocate memory using its own routines.
+
+To know how much space must be allocated, use LZ4_sizeofStreamState();
+Note also that space must be 4-bytes aligned.
+
+Once space is allocated, you must initialize it using : LZ4_resetStreamState(void* state, const char* inputBuffer);
+void* state is a pointer to the space allocated.
+It must be aligned on 4-bytes boundaries, and be large enough.
+The parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
+The input buffer must be already allocated, and size at least 192KB.
+'inputBuffer' will also be the 'const char* source' of the first block.
+
+The same space can be re-used multiple times, just by initializing it each time with LZ4_resetStreamState().
+return value of LZ4_resetStreamState() must be 0 is OK.
+Any other value means there was an error (typically, pointer is not aligned on 4-bytes boundaries).
+*/
+
+
+int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int inputSize, int maxOutputSize);
+int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int outputSize);
+
+/*
+*_withPrefix64k() :
+    These decoding functions work the same as their "normal name" versions,
+    but can use up to 64KB of data in front of 'char* dest'.
+    These functions are necessary to decode inter-dependant blocks.
+*/
+
+
+/**************************************
+   Obsolete Functions
+**************************************/
+/*
+These functions are deprecated and should no longer be used.
+They are provided here for compatibility with existing user programs.
+*/
+int LZ4_uncompress (const char* source, char* dest, int outputSize);
+int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
+
+
+#if defined (__cplusplus)
+}
+#endif
diff --git a/lz4hc.h b/lz4hc.h
index da1a159..d3f81a8 100644 (file)
--- a/lz4hc.h
+++ b/lz4hc.h
-/*\r
-   LZ4 HC - High Compression Mode of LZ4\r
-   Header File\r
-   Copyright (C) 2011-2013, Yann Collet.\r
-   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)\r
-\r
-   Redistribution and use in source and binary forms, with or without\r
-   modification, are permitted provided that the following conditions are\r
-   met:\r
-\r
-       * Redistributions of source code must retain the above copyright\r
-   notice, this list of conditions and the following disclaimer.\r
-       * Redistributions in binary form must reproduce the above\r
-   copyright notice, this list of conditions and the following disclaimer\r
-   in the documentation and/or other materials provided with the\r
-   distribution.\r
-\r
-   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
-   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
-   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
-   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
-   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
-   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
-   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
-   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
-   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
-   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
-   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-   You can contact the author at :\r
-   - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html\r
-   - LZ4 source repository : http://code.google.com/p/lz4/\r
-*/\r
-#pragma once\r
-\r
-\r
-#if defined (__cplusplus)\r
-extern "C" {\r
-#endif\r
-\r
-\r
-int LZ4_compressHC (const char* source, char* dest, int inputSize);\r
-/*\r
-LZ4_compressHC :\r
-    return : the number of bytes in compressed buffer dest\r
-             or 0 if compression fails.\r
-    note : destination buffer must be already allocated.\r
-        To avoid any problem, size it to handle worst cases situations (input data not compressible)\r
-        Worst case size evaluation is provided by function LZ4_compressBound() (see "lz4.h")\r
-*/\r
-\r
-int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);\r
-/*\r
-LZ4_compress_limitedOutput() :\r
-    Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.\r
-    If it cannot achieve it, compression will stop, and result of the function will be zero.\r
-    This function never writes outside of provided output buffer.\r
-\r
-    inputSize  : Max supported value is 1 GB\r
-    maxOutputSize : is maximum allowed size into the destination buffer (which must be already allocated)\r
-    return : the number of output bytes written in buffer 'dest'\r
-             or 0 if compression fails.\r
-*/\r
-\r
-\r
-int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);\r
-int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);\r
-/*\r
-    Same functions as above, but with programmable 'compressionLevel'.\r
-    Recommended values are between 4 and 9, although any value between 0 and 16 will work.\r
-    'compressionLevel'==0 means use default 'compressionLevel' value.\r
-    Values above 16 behave the same as 16.\r
-    Equivalent variants exist for all other compression functions below.\r
-*/\r
-\r
-/* Note :\r
-Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license)\r
-*/\r
-\r
-\r
-/**************************************\r
-   Using an external allocation\r
-**************************************/\r
-int LZ4_sizeofStateHC();\r
-int LZ4_compressHC_withStateHC               (void* state, const char* source, char* dest, int inputSize);\r
-int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);\r
-\r
-int LZ4_compressHC2_withStateHC              (void* state, const char* source, char* dest, int inputSize, int compressionLevel);\r
-int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);\r
-\r
-/*\r
-These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods.\r
-To know how much memory must be allocated for the compression tables, use :\r
-int LZ4_sizeofStateHC();\r
-\r
-Note that tables must be aligned for pointer (32 or 64 bits), otherwise compression will fail (return code 0).\r
-\r
-The allocated memory can be provided to the compressions functions using 'void* state' parameter.\r
-LZ4_compress_withStateHC() and LZ4_compress_limitedOutput_withStateHC() are equivalent to previously described functions.\r
-They just use the externally allocated memory area instead of allocating their own (on stack, or on heap).\r
-*/\r
-\r
-\r
-/**************************************\r
-   Streaming Functions\r
-**************************************/\r
-void* LZ4_createHC (const char* inputBuffer);\r
-int   LZ4_compressHC_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize);\r
-int   LZ4_compressHC_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize);\r
-char* LZ4_slideInputBufferHC (void* LZ4HC_Data);\r
-int   LZ4_freeHC (void* LZ4HC_Data);\r
-\r
-int   LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);\r
-int   LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);\r
-\r
-/*\r
-These functions allow the compression of dependent blocks, where each block benefits from prior 64 KB within preceding blocks.\r
-In order to achieve this, it is necessary to start creating the LZ4HC Data Structure, thanks to the function :\r
-\r
-void* LZ4_createHC (const char* inputBuffer);\r
-The result of the function is the (void*) pointer on the LZ4HC Data Structure.\r
-This pointer will be needed in all other functions.\r
-If the pointer returned is NULL, then the allocation has failed, and compression must be aborted.\r
-The only parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.\r
-The input buffer must be already allocated, and size at least 192KB.\r
-'inputBuffer' will also be the 'const char* source' of the first block.\r
-\r
-All blocks are expected to lay next to each other within the input buffer, starting from 'inputBuffer'.\r
-To compress each block, use either LZ4_compressHC_continue() or LZ4_compressHC_limitedOutput_continue().\r
-Their behavior are identical to LZ4_compressHC() or LZ4_compressHC_limitedOutput(),\r
-but require the LZ4HC Data Structure as their first argument, and check that each block starts right after the previous one.\r
-If next block does not begin immediately after the previous one, the compression will fail (return 0).\r
-\r
-When it's no longer possible to lay the next block after the previous one (not enough space left into input buffer), a call to :\r
-char* LZ4_slideInputBufferHC(void* LZ4HC_Data);\r
-must be performed. It will typically copy the latest 64KB of input at the beginning of input buffer.\r
-Note that, for this function to work properly, minimum size of an input buffer must be 192KB.\r
-==> The memory position where the next input data block must start is provided as the result of the function.\r
-\r
-Compression can then resume, using LZ4_compressHC_continue() or LZ4_compressHC_limitedOutput_continue(), as usual.\r
-\r
-When compression is completed, a call to LZ4_freeHC() will release the memory used by the LZ4HC Data Structure.\r
-*/\r
-\r
-int LZ4_sizeofStreamStateHC();\r
-int LZ4_resetStreamStateHC(void* state, const char* inputBuffer);\r
-\r
-/*\r
-These functions achieve the same result as :\r
-void* LZ4_createHC (const char* inputBuffer);\r
-\r
-They are provided here to allow the user program to allocate memory using its own routines.\r
-\r
-To know how much space must be allocated, use LZ4_sizeofStreamStateHC();\r
-Note also that space must be aligned for pointers (32 or 64 bits).\r
-\r
-Once space is allocated, you must initialize it using : LZ4_resetStreamStateHC(void* state, const char* inputBuffer);\r
-void* state is a pointer to the space allocated.\r
-It must be aligned for pointers (32 or 64 bits), and be large enough.\r
-The parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.\r
-The input buffer must be already allocated, and size at least 192KB.\r
-'inputBuffer' will also be the 'const char* source' of the first block.\r
-\r
-The same space can be re-used multiple times, just by initializing it each time with LZ4_resetStreamState().\r
-return value of LZ4_resetStreamStateHC() must be 0 is OK.\r
-Any other value means there was an error (typically, state is not aligned for pointers (32 or 64 bits)).\r
-*/\r
-\r
-\r
-#if defined (__cplusplus)\r
-}\r
-#endif\r
+/*
+   LZ4 HC - High Compression Mode of LZ4
+   Header File
+   Copyright (C) 2011-2013, Yann Collet.
+   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are
+   met:
+
+       * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above
+   copyright notice, this list of conditions and the following disclaimer
+   in the documentation and/or other materials provided with the
+   distribution.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+   You can contact the author at :
+   - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
+   - LZ4 source repository : http://code.google.com/p/lz4/
+*/
+#pragma once
+
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
+
+int LZ4_compressHC (const char* source, char* dest, int inputSize);
+/*
+LZ4_compressHC :
+    return : the number of bytes in compressed buffer dest
+             or 0 if compression fails.
+    note : destination buffer must be already allocated.
+        To avoid any problem, size it to handle worst cases situations (input data not compressible)
+        Worst case size evaluation is provided by function LZ4_compressBound() (see "lz4.h")
+*/
+
+int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
+/*
+LZ4_compress_limitedOutput() :
+    Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
+    If it cannot achieve it, compression will stop, and result of the function will be zero.
+    This function never writes outside of provided output buffer.
+
+    inputSize  : Max supported value is 1 GB
+    maxOutputSize : is maximum allowed size into the destination buffer (which must be already allocated)
+    return : the number of output bytes written in buffer 'dest'
+             or 0 if compression fails.
+*/
+
+
+int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
+int LZ4_compressHC2_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
+/*
+    Same functions as above, but with programmable 'compressionLevel'.
+    Recommended values are between 4 and 9, although any value between 0 and 16 will work.
+    'compressionLevel'==0 means use default 'compressionLevel' value.
+    Values above 16 behave the same as 16.
+    Equivalent variants exist for all other compression functions below.
+*/
+
+/* Note :
+Decompression functions are provided within LZ4 source code (see "lz4.h") (BSD license)
+*/
+
+
+/**************************************
+   Using an external allocation
+**************************************/
+int LZ4_sizeofStateHC(void);
+int LZ4_compressHC_withStateHC               (void* state, const char* source, char* dest, int inputSize);
+int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
+
+int LZ4_compressHC2_withStateHC              (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
+int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
+
+/*
+These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods.
+To know how much memory must be allocated for the compression tables, use :
+int LZ4_sizeofStateHC();
+
+Note that tables must be aligned for pointer (32 or 64 bits), otherwise compression will fail (return code 0).
+
+The allocated memory can be provided to the compressions functions using 'void* state' parameter.
+LZ4_compress_withStateHC() and LZ4_compress_limitedOutput_withStateHC() are equivalent to previously described functions.
+They just use the externally allocated memory area instead of allocating their own (on stack, or on heap).
+*/
+
+
+/**************************************
+   Streaming Functions
+**************************************/
+void* LZ4_createHC (const char* inputBuffer);
+int   LZ4_compressHC_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize);
+int   LZ4_compressHC_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize);
+char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
+int   LZ4_freeHC (void* LZ4HC_Data);
+
+int   LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
+int   LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
+
+/*
+These functions allow the compression of dependent blocks, where each block benefits from prior 64 KB within preceding blocks.
+In order to achieve this, it is necessary to start creating the LZ4HC Data Structure, thanks to the function :
+
+void* LZ4_createHC (const char* inputBuffer);
+The result of the function is the (void*) pointer on the LZ4HC Data Structure.
+This pointer will be needed in all other functions.
+If the pointer returned is NULL, then the allocation has failed, and compression must be aborted.
+The only parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
+The input buffer must be already allocated, and size at least 192KB.
+'inputBuffer' will also be the 'const char* source' of the first block.
+
+All blocks are expected to lay next to each other within the input buffer, starting from 'inputBuffer'.
+To compress each block, use either LZ4_compressHC_continue() or LZ4_compressHC_limitedOutput_continue().
+Their behavior are identical to LZ4_compressHC() or LZ4_compressHC_limitedOutput(),
+but require the LZ4HC Data Structure as their first argument, and check that each block starts right after the previous one.
+If next block does not begin immediately after the previous one, the compression will fail (return 0).
+
+When it's no longer possible to lay the next block after the previous one (not enough space left into input buffer), a call to :
+char* LZ4_slideInputBufferHC(void* LZ4HC_Data);
+must be performed. It will typically copy the latest 64KB of input at the beginning of input buffer.
+Note that, for this function to work properly, minimum size of an input buffer must be 192KB.
+==> The memory position where the next input data block must start is provided as the result of the function.
+
+Compression can then resume, using LZ4_compressHC_continue() or LZ4_compressHC_limitedOutput_continue(), as usual.
+
+When compression is completed, a call to LZ4_freeHC() will release the memory used by the LZ4HC Data Structure.
+*/
+
+int LZ4_sizeofStreamStateHC(void);
+int LZ4_resetStreamStateHC(void* state, const char* inputBuffer);
+
+/*
+These functions achieve the same result as :
+void* LZ4_createHC (const char* inputBuffer);
+
+They are provided here to allow the user program to allocate memory using its own routines.
+
+To know how much space must be allocated, use LZ4_sizeofStreamStateHC();
+Note also that space must be aligned for pointers (32 or 64 bits).
+
+Once space is allocated, you must initialize it using : LZ4_resetStreamStateHC(void* state, const char* inputBuffer);
+void* state is a pointer to the space allocated.
+It must be aligned for pointers (32 or 64 bits), and be large enough.
+The parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
+The input buffer must be already allocated, and size at least 192KB.
+'inputBuffer' will also be the 'const char* source' of the first block.
+
+The same space can be re-used multiple times, just by initializing it each time with LZ4_resetStreamState().
+return value of LZ4_resetStreamStateHC() must be 0 is OK.
+Any other value means there was an error (typically, state is not aligned for pointers (32 or 64 bits)).
+*/
+
+
+#if defined (__cplusplus)
+}
+#endif
index 98ed185..868c5fb 100644 (file)
 # fullbench32: Same as fullbench, but forced to compile in 32-bits mode
 # ################################################################
 
-RELEASE=r113
+RELEASE=r114
 DESTDIR=
 PREFIX=/usr
-CC=gcc
-CFLAGS+= -I.. -std=c99 -Wall -W -Wundef -DLZ4_VERSION=\"$(RELEASE)\"
+CC:=$(CC)
+CFLAGS+= -I.. -std=c99 -O3 -Wall -W -Wundef -DLZ4_VERSION=\"$(RELEASE)\"
 
 BINDIR=$(PREFIX)/bin
 MANDIR=$(PREFIX)/share/man/man1
@@ -54,26 +54,25 @@ default: lz4 lz4c
 all: lz4 lz4c lz4c32 fuzzer fuzzer32 fullbench fullbench32
 
 lz4: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c bench.c xxhash.c lz4io.c lz4cli.c
-       $(CC)      -O3 $(CFLAGS) -DDISABLE_LZ4C_LEGACY_OPTIONS $^ -o $@$(EXT)
+       $(CC)      $(CFLAGS) -DDISABLE_LZ4C_LEGACY_OPTIONS $^ -o $@$(EXT)
 
 lz4c  : $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c bench.c xxhash.c lz4io.c lz4cli.c
-       $(CC)      -O3 $(CFLAGS) $^ -o $@$(EXT)
+       $(CC)      $(CFLAGS) $^ -o $@$(EXT)
 
 lz4c32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c bench.c xxhash.c lz4io.c lz4cli.c
-       $(CC) -m32 -O3 $(CFLAGS) $^ -o $@$(EXT)
+       $(CC) -m32 $(CFLAGS) $^ -o $@$(EXT)
 
 fuzzer  : $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c fuzzer.c
-       @echo fuzzer is a test tool to check lz4 integrity on target platform
-       $(CC)      -O3 $(CFLAGS) $^ -o $@$(EXT)
+       $(CC)      $(CFLAGS) $^ -o $@$(EXT)
 
 fuzzer32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c fuzzer.c
-       $(CC) -m32 -O3 $(CFLAGS) $^ -o $@$(EXT)
+       $(CC) -m32 $(CFLAGS) $^ -o $@$(EXT)
 
 fullbench  : $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c xxhash.c fullbench.c
-       $(CC)      -O3 $(CFLAGS) $^ -o $@$(EXT)
+       $(CC)      $(CFLAGS) $^ -o $@$(EXT)
 
 fullbench32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c xxhash.c fullbench.c
-       $(CC) -m32 -O3 $(CFLAGS) $^ -o $@$(EXT)
+       $(CC) -m32 $(CFLAGS) $^ -o $@$(EXT)
 
 clean:
        @rm -f core *.o \
index ea6a1ca..2eabf61 100644 (file)
@@ -300,9 +300,9 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel)
       }
 
       // Alloc
-      chunkP = (struct chunkParameters*) malloc(((benchedSize / chunkSize)+1) * sizeof(struct chunkParameters));
+      chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)chunkSize)+1) * sizeof(struct chunkParameters));
       orig_buff = (char*)malloc((size_t )benchedSize);
-      nbChunks = (int) (benchedSize / chunkSize) + 1;
+      nbChunks = (int) ((int)benchedSize / chunkSize) + 1;
       maxCompressedChunkSize = LZ4_compressBound(chunkSize);
       compressedBuffSize = nbChunks * maxCompressedChunkSize;
       compressedBuffer = (char*)malloc((size_t )compressedBuffSize);
index c465c88..8e87019 100644 (file)
@@ -385,9 +385,9 @@ int fullSpeedBench(char** fileNamesTable, int nbFiles)
       }
 
       // Alloc
-      chunkP = (struct chunkParameters*) malloc(((benchedSize / chunkSize)+1) * sizeof(struct chunkParameters));
+      chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)chunkSize)+1) * sizeof(struct chunkParameters));
       orig_buff = (char*) malloc((size_t)benchedSize);
-      nbChunks = (int) (benchedSize / chunkSize) + 1;
+      nbChunks = (int) ((int)benchedSize / chunkSize) + 1;
       maxCompressedChunkSize = LZ4_compressBound(chunkSize);
       compressedBuffSize = nbChunks * maxCompressedChunkSize;
       compressed_buff = (char*)malloc((size_t)compressedBuffSize);
index 7b06cbe..a2bd33a 100644 (file)
@@ -145,7 +145,7 @@ int main() {
         fflush(stdout);
         if ( fgets(userInput, sizeof userInput, stdin) )
         {
-            if ( sscanf(userInput, "%d", &seed) == 1 ) {}
+            if ( sscanf(userInput, "%u", &seed) == 1 ) {}
             else seed = FUZ_GetMilliSpan(timestamp);
         }
         printf("Seed = %u\n", seed);
index 69c58c3..298cbf6 100644 (file)
@@ -7,7 +7,7 @@
 .hy 0
 .nr HY 0
 
-.TH lz4 man
+.TH lz4 "1" "2014-02-27" "lz4" "User Commands"
 .SH NAME
 \fBlz4\fR - Extremely fast compression algorithm
 
index a319bcc..8491099 100644 (file)
@@ -121,7 +121,7 @@ Memory will be freed by XXH32_digest().
 */
 
 
-int           XXH32_sizeofState();
+int           XXH32_sizeofState(void);
 XXH_errorcode XXH32_resetState(void* state, unsigned int seed);
 
 #define       XXH32_SIZEOFSTATE 48