From a78db582d321446b5167de67eec8ba3239b14bbe Mon Sep 17 00:00:00 2001 From: "yann.collet.73@gmail.com" Date: Mon, 21 Oct 2013 08:03:40 +0000 Subject: Makefile : support DESTDIR for staged installs. Thanks Jorge Aparicio. Makefile : make install installs both lz4 and lz4c (Jorge Aparicio) Makefile : removed -Wno-implicit-declaration compilation switch lz4cli.c : include for isatty() (Luca Barbato) lz4.h : introduced LZ4_MAX_INPUT_SIZE constant (Shay Green) lz4.h : LZ4_compressBound() : unified macro and inline definitions (Shay Green) lz4.h : LZ4_decompressSafe_partial() : clarify comments (Shay Green) lz4.c : LZ4_compress() verify input size condition (Shay Green) bench.c : corrected a bug in free memory size evaluation cmake : install into bin/ directory (Richard Yao) cmake : check for just C compiler (Elan Ruusamae) git-svn-id: https://lz4.googlecode.com/svn/trunk@107 650e7d94-2a16-8b24-b05c-7c0b3f6821cd --- Makefile | 11 +++++++---- NEWS | 13 +++++++++++++ bench.c | 4 ++-- cmake/CMakeLists.txt | 12 ++++++------ cmake/pack/CMakeLists.txt | 8 ++++---- lz4.c | 1 + lz4.h | 16 ++++++++-------- lz4cli.c | 11 +++++++---- 8 files changed, 48 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 545a781..cca2a30 100644 --- a/Makefile +++ b/Makefile @@ -30,13 +30,14 @@ # fullbench32: Same as fullbench, but forced to compile in 32-bits mode # ################################################################ -RELEASE=r106 -PREFIX=/usr +RELEASE=r107 +DESTDIR= +PREFIX=${DESTDIR}/usr BINDIR=$(PREFIX)/bin MANDIR=$(PREFIX)/share/man/man1 DISTRIBNAME=lz4-$(RELEASE).tar.gz CC=gcc -CFLAGS=-I. -std=c99 -Wall -W -Wundef -Wno-implicit-function-declaration +CFLAGS=-I. -std=c99 -Wall -W -Wundef # Define *.exe as extension for Windows systems # ifeq ($(OS),Windows_NT) @@ -90,13 +91,15 @@ clean: ifeq ($(shell uname),Linux) -install: lz4 +install: lz4 lz4c @install -d -m 755 $(BINDIR)/ $(MANDIR)/ @install -m 755 lz4 $(BINDIR)/lz4 + @install -m 755 lz4c $(BINDIR)/lz4c @install -m 644 lz4.1 $(MANDIR)/lz4.1 uninstall: [ -x $(BINDIR)/lz4 ] && rm -f $(BINDIR)/lz4 + [ -x $(BINDIR)/lz4c ] && rm -f $(BINDIR)/lz4c [ -f $(MANDIR)/lz4.1 ] && rm -f $(MANDIR)/lz4.1 dist: clean diff --git a/NEWS b/NEWS index 25a3e0a..c158a94 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,16 @@ +r107 : +Makefile : support DESTDIR for staged installs. Thanks Jorge Aparicio. +Makefile : make install installs both lz4 and lz4c (Jorge Aparicio) +Makefile : removed -Wno-implicit-declaration compilation switch +lz4cli.c : include for isatty() (Luca Barbato) +lz4.h : introduced LZ4_MAX_INPUT_SIZE constant (Shay Green) +lz4.h : LZ4_compressBound() : unified macro and inline definitions (Shay Green) +lz4.h : LZ4_decompressSafe_partial() : clarify comments (Shay Green) +lz4.c : LZ4_compress() verify input size condition (Shay Green) +bench.c : corrected a bug in free memory size evaluation +cmake : install into bin/ directory (Richard Yao) +cmake : check for just C compiler (Elan Ruusamae) + r106 : Makefile : make dist modify text files in the package to respect Unix EoL convention lz4cli : corrected small display bug in HC mode diff --git a/bench.c b/bench.c index bc42475..182b69e 100644 --- a/bench.c +++ b/bench.c @@ -207,9 +207,9 @@ static size_t BMK_findMaxMem(U64 requiredMem) BYTE* testmem=NULL; requiredMem = (((requiredMem >> 26) + 1) << 26); + requiredMem += 2*step; if (requiredMem > MAX_MEM) requiredMem = MAX_MEM; - requiredMem += 2*step; while (!testmem) { requiredMem -= step; @@ -292,7 +292,7 @@ int BMK_benchFile(char** fileNamesTable, int nbFiles, int cLevel) // Memory allocation & restrictions inFileSize = BMK_GetFileSize(inFileName); - benchedSize = (size_t) BMK_findMaxMem(inFileSize) / 2; + benchedSize = (size_t) BMK_findMaxMem(inFileSize * 2) / 2; if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize; if (benchedSize < inFileSize) { diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 496c076..dd26bd9 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1,8 +1,8 @@ -PROJECT(LZ4) -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ASN.1 Compiler") +PROJECT(LZ4 C) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LZ4 compression library") set(CPACK_PACKAGE_VERSION_MAJOR 0) set(CPACK_PACKAGE_VERSION_MINOR 0) -set(CPACK_PACKAGE_VERSION_PATCH r52) +set(CPACK_PACKAGE_VERSION_PATCH r107) #set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING_LGPL) set(VERSION_STRING " \"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\" ") include(CPack) @@ -41,11 +41,11 @@ endif() if (CMAKE_SYSTEM_PROCESSOR STREQUAL "64bit") message(STATUS "Build 64bit executable binary") add_executable(lz4c64 ${LZ4_SRCS}) - install(TARGETS lz4c64 RUNTIME DESTINATION "./") + install(TARGETS lz4c64 RUNTIME DESTINATION "bin/") if(NOT BUILD_SHARED_LIBS) message(STATUS "Build 32bit executable binary") add_executable(lz4c32 ${LZ4_SRCS}) - install(TARGETS lz4c32 RUNTIME DESTINATION "./") + install(TARGETS lz4c32 RUNTIME DESTINATION "bin/") SET_TARGET_PROPERTIES(lz4c32 PROPERTIES COMPILE_FLAGS PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32") @@ -53,7 +53,7 @@ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "64bit") else() message(STATUS "Build 32bit executable binary") add_executable(lz4c32 ${LZ4_SRCS}) - install(TARGETS lz4c32 RUNTIME DESTINATION "./") + install(TARGETS lz4c32 RUNTIME DESTINATION "bin/") endif() if(BUILD_SHARED_LIBS) diff --git a/cmake/pack/CMakeLists.txt b/cmake/pack/CMakeLists.txt index a9b0557..7b93cba 100644 --- a/cmake/pack/CMakeLists.txt +++ b/cmake/pack/CMakeLists.txt @@ -6,7 +6,7 @@ set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LZ4 Packer") set(CPACK_PACKAGE_VERSION_MAJOR 0) set(CPACK_PACKAGE_VERSION_MINOR 0) -set(CPACK_PACKAGE_VERSION_PATCH r89) +set(CPACK_PACKAGE_VERSION_PATCH r107) #set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING_LGPL) ############################## FIND_PACKAGE(Subversion) @@ -48,16 +48,16 @@ set(FUZZER_SRCS ${SRC_DIR}lz4.c ${SRC_DIR}lz4hc.c ${SRC_DIR}lz4.h ${SRC_DIR}fuzz # EXECUTABLES FOR 32 Bit and 64 versions if(CMAKE_SYSTEM_PROCESSOR STREQUAL "64bit") add_executable(lz4c32 ${LZ4_SRCS}) - install(TARGETS lz4c32 RUNTIME DESTINATION "./") + install(TARGETS lz4c32 RUNTIME DESTINATION "bin/") SET_TARGET_PROPERTIES(lz4c32 PROPERTIES COMPILE_FLAGS PROPERTIES COMPILE_FLAGS "-m32 -Os" LINK_FLAGS "-m32") endif() add_executable(lz4c ${LZ4_SRCS}) -install(TARGETS lz4c RUNTIME DESTINATION "./") +install(TARGETS lz4c RUNTIME DESTINATION "bin/") add_executable(fuzzer ${FUZZER_SRCS}) -install(TARGETS fuzzer RUNTIME DESTINATION "./") +install(TARGETS fuzzer RUNTIME DESTINATION "bin/") #target_link_libraries(lz4 ${LZ4_SRCS_LIB}) ####################### CPACK PACKAGING ################### diff --git a/lz4.c b/lz4.c index 606633d..2d014ca 100644 --- a/lz4.c +++ b/lz4.c @@ -430,6 +430,7 @@ FORCE_INLINE int LZ4_compress_generic( U32 forwardH; // Init conditions + if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; // Unsupported input size, too large (or negative) if ((prefix==withPrefix) && (ip != ((LZ4_Data_Structure*)ctx)->nextBlock)) return 0; // must continue from end of previous block if (prefix==withPrefix) ((LZ4_Data_Structure*)ctx)->nextBlock=iend; // do it now, due to potential early exit if ((tableType == byU16) && (inputSize>=LZ4_64KLIMIT)) return 0; // Size too large (not within 64K limit) diff --git a/lz4.h b/lz4.h index a897bc3..9ef5886 100644 --- a/lz4.h +++ b/lz4.h @@ -59,7 +59,7 @@ LZ4_compress() : 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 ~1.9GB + inputSize : Max supported value is LZ4_MAX_INPUT_VALUE return : the number of bytes written in buffer dest or 0 if the compression fails @@ -74,9 +74,9 @@ LZ4_decompress_safe() : //**************************** // Advanced Functions //**************************** - -static inline int LZ4_compressBound(int isize) { return ((isize) + ((isize)/255) + 16); } -#define LZ4_COMPRESSBOUND( isize) ((isize) + ((isize)/255) + 16) +#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) +static inline int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); } /* LZ4_compressBound() : @@ -85,9 +85,9 @@ LZ4_compressBound() : 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 ~1.9GB + isize : is the input size. Max supported value is LZ4_MAX_INPUT_SIZE return : maximum output size in a "worst case" scenario - note : this function is limited by "int" range (2^31-1) + or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE) */ @@ -99,7 +99,7 @@ LZ4_compress_limitedOutput() : 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.9GB + 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 @@ -125,7 +125,7 @@ int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, 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 stops decompressing operation as soon as 'targetOutputSize' has been reached, + 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. diff --git a/lz4cli.c b/lz4cli.c index 9bf0aaf..4743115 100644 --- a/lz4cli.c +++ b/lz4cli.c @@ -48,9 +48,8 @@ # pragma warning(disable : 4127) // disable: C4127: conditional expression is constant #endif -// Large file support on 32-bits unix -#define _FILE_OFFSET_BITS 64 - +#define _FILE_OFFSET_BITS 64 // Large file support on 32-bits unix +#define _POSIX_SOURCE 1 // for fileno() within on unix //**************************** // Includes @@ -71,9 +70,13 @@ #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) # include // _O_BINARY # include // _setmode, _isatty +# ifdef __MINGW32__ + int _fileno(FILE *stream); // MINGW somehow forgets to include this windows declaration into +# endif # define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY) # define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream)) #else +# include // isatty # define SET_BINARY_MODE(file) # define IS_CONSOLE(stdStream) isatty(fileno(stdStream)) #endif @@ -103,7 +106,7 @@ // Constants //**************************** #define COMPRESSOR_NAME "LZ4 Compression CLI" -#define COMPRESSOR_VERSION "v1.0.6" +#define COMPRESSOR_VERSION "v1.0.7" #define COMPILED __DATE__ #define AUTHOR "Yann Collet" #define LZ4_EXTENSION ".lz4" -- cgit v0.12