diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..787052a --- /dev/null +++ b/.gitignore @@ -0,0 +1,86 @@ +### Autotools template +# http://www.gnu.org/software/automake + +Makefile.in + +# http://www.gnu.org/software/autoconf + +/autom4te.cache +/aclocal.m4 +/compile +/configure +/depcomp +/install-sh +/missing +/stamp-h1 +### C++ template +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +### CMake template +CMakeCache.txt +CMakeFiles +CMakeScripts +Makefile +cmake_install.cmake +install_manifest.txt +### C template +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ + +# Created by .ignore support plugin (hsz.mobi) diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4e4a169 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,155 @@ +PROJECT(Snappy C CXX) +CMAKE_MINIMUM_REQUIRED(VERSION 3.0) + +SET(SNAPPY_MAJOR 1) +SET(SNAPPY_MINOR 1) +SET(SNAPPY_PATCHLEVEL 3) + +# I haven't looked at what the soname for the previous +# versions of snappy... let's just start with 1.1.3 +SET(SNAPPY_SONAME "1.1.3") + +INCLUDE(CheckIncludeFiles) +INCLUDE(CheckLibraryExists) +INCLUDE(CheckCXXSourceCompiles) +INCLUDE(TestBigEndian) +INCLUDE(GenerateExportHeader) +INCLUDE(CMakePackageConfigHelpers) + +TEST_BIG_ENDIAN(WORDS_BIG_ENDIAN) +IF (WORDS_BIG_ENDIAN) + MESSAGE(STATUS "Builing on big endian system") + ADD_DEFINITIONS(-DWORDS_BIGENDIAN=1) +ENDIF (WORDS_BIG_ENDIAN) + +CHECK_INCLUDE_FILES("windows.h" HAVE_WINDOWS_H) +CHECK_INCLUDE_FILES("byteswap.h" HAVE_BYTESWAP_H) +CHECK_INCLUDE_FILES("dlfcn.h" HAVE_DLFCN_H) +CHECK_INCLUDE_FILES("inttypes.h" HAVE_INTTYPES_H) +CHECK_INCLUDE_FILES("memory.h" HAVE_MEMORY_H) +CHECK_INCLUDE_FILES("stddef.h" HAVE_STDDEF_H) +CHECK_INCLUDE_FILES("stdint.h" HAVE_STDINT_H) +CHECK_INCLUDE_FILES("stdlib.h" HAVE_STDLIB_H) +CHECK_INCLUDE_FILES("strings.h" HAVE_STRINGS_H) +CHECK_INCLUDE_FILES("string.h" HAVE_STRING_H) +CHECK_INCLUDE_FILES("sys/byteswap.h" HAVE_SYS_BYTESWAP_H) +CHECK_INCLUDE_FILES("sys/endian.h" HAVE_SYS_ENDIAN_H) +CHECK_INCLUDE_FILES("stdint.h" HAVE_STDINT_H) +CHECK_INCLUDE_FILES("sys/mman.h" HAVE_SYS_MMAN_H) +CHECK_INCLUDE_FILES("sys/resource.h" HAVE_SYS_RESOURCE_H) +CHECK_INCLUDE_FILES("sys/stat.h" HAVE_SYS_STAT_H) +CHECK_INCLUDE_FILES("sys/time.h" HAVE_SYS_TIME_H) +CHECK_INCLUDE_FILES("sys/types.h" HAVE_SYS_TYPES_H) +CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_H) +CHECK_INCLUDE_FILES("sys/uio.h" HAVE_SYS_UIO_H) + +IF (NOT HAVE_SYS_UIO_H) + SET(HAVE_SYS_UIO_H 0) +ENDIF (NOT HAVE_SYS_UIO_H) + +IF (NOT HAVE_STDINT_H) + SET(HAVE_STDINT_H 0) +ENDIF (NOT HAVE_STDINT_H) + +IF (NOT HAVE_STDDEF_H) + SET(HAVE_STDDEF_H 0) +ENDIF (NOT HAVE_STDDEF_H) + +CHECK_LIBRARY_EXISTS(z zlibVersion "" HAVE_LIBZ) +CHECK_LIBRARY_EXISTS(lzo2 lzo1x_1_15_compress "" HAVE_LIBLZO2) +CHECK_LIBRARY_EXISTS(lzf lzf_compress "" HAVE_LIBLZF) +CHECK_LIBRARY_EXISTS(fastlz fastlz_compress "" HAVE_LIBFASTLZ) +CHECK_LIBRARY_EXISTS(quicklz qlz_compress "" HAVE_LIBQUICKLZ) + +CHECK_CXX_SOURCE_COMPILES("int main(void) { return __builtin_expect(0, 1) ? 1 : 0; }" + HAVE_BUILTIN_EXPECT) + +CHECK_CXX_SOURCE_COMPILES("int main(void) { return __builtin_ctzll(0) ? 1 : 0; }" + HAVE_BUILTIN_CTZ) + + +CONFIGURE_FILE(${Snappy_SOURCE_DIR}/cmake/config.h.in config.h) +CONFIGURE_FILE(${Snappy_SOURCE_DIR}/cmake/snappy-stubs-public.h.in snappy-stubs-public.h) + +IF (WIN32) + ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) +ENDIF (WIN32) + +ADD_DEFINITIONS(-DHAVE_CONFIG_H) + +INCLUDE_DIRECTORIES(BEFORE ${Snappy_SOURCE_DIR}) +INCLUDE_DIRECTORIES(AFTER ${Snappy_BINARY_DIR}) + +ADD_LIBRARY(snappy SHARED + snappy-c.cc + snappy-c.h + snappy-sinksource.cc + snappy-sinksource.h + snappy-stubs-internal.cc + snappy-stubs-public.h + snappy.cc + snappy.h) + +GENERATE_EXPORT_HEADER(snappy + EXPORT_MACRO_NAME SNAPPY_PUBLIC_API + EXPORT_FILE_NAME snappy-visibility.h) + +INSTALL(FILES snappy.h + snappy-c.h + snappy-sinksource.h + ${Snappy_BINARY_DIR}/snappy-stubs-public.h + ${Snappy_BINARY_DIR}/snappy-visibility.h + DESTINATION include) + +INSTALL(TARGETS snappy + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + +SET_TARGET_PROPERTIES(snappy PROPERTIES SOVERSION + ${SNAPPY_MAJOR}.${SNAPPY_MINOR}.${SNAPPY_PATCHLEVEL}) + +SET(INCLUDE_INSTALL_DIR include) +SET(LIBRARY_INSTALL_DIR lib) +SET(BINARY_INSTALL_DIR bin) + +CONFIGURE_PACKAGE_CONFIG_FILE(cmake/SnappyConfig.cmake.in + ${Snappy_BINARY_DIR}/SnappyConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/Snappy/cmake + PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR BINARY_INSTALL_DIR + ) + +WRITE_BASIC_PACKAGE_VERSION_FILE(${Snappy_BINARY_DIR}/SnappyConfigVersion.cmake + VERSION ${SNAPPY_MAJOR}.${SNAPPY_MINOR}.${SNAPPY_PATCHLEVEL} + COMPATIBILITY SameMajorVersion) +INSTALL(FILES ${Snappy_BINARY_DIR}/SnappyConfig.cmake + ${Snappy_BINARY_DIR}/SnappyConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake) + +ENABLE_TESTING() + +IF (HAVE_LIBZ) + LIST(APPEND COMPRESSION_LIBS z) +ENDIF (HAVE_LIBZ) + +IF (HAVE_LIBLZO2) + LIST(APPEND COMPRESSION_LIBS lzo2) +ENDIF (HAVE_LIBLZO2) + +IF (HAVE_LIBLZF) + LIST(APPEND COMPRESSION_LIBS lzf) +ENDIF (HAVE_LIBLZF) + +IF (HAVE_LIBFASTLZ) + LIST(APPEND COMPRESSION_LIBS fastlz) +ENDIF (HAVE_LIBFASTLZ) + +IF (HAVE_LIBQUICKLZ) + LIST(APPEND COMPRESSION_LIBS quicklz) +ENDIF (HAVE_LIBQUICKLZ) + +ADD_EXECUTABLE(snappy-unittest snappy_unittest.cc snappy-test.cc) +TARGET_LINK_LIBRARIES(snappy-unittest snappy ${COMPRESSION_LIBS}) +ADD_TEST(NAME snappy-unittest + WORKING_DIRECTORY ${Snappy_SOURCE_DIR} + COMMAND ${Snappy_BINARY_DIR}/snappy-unittest) diff --git a/Makefile.am b/Makefile.am index 735bc12..d462622 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,7 @@ ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libsnappy.la libsnappy_la_SOURCES = snappy.cc snappy-sinksource.cc snappy-stubs-internal.cc snappy-c.cc libsnappy_la_LDFLAGS = -version-info $(SNAPPY_LTVERSION) +libsnappy_la_LDFLAGS = -Dsnappy_EXPORTS include_HEADERS = snappy.h snappy-sinksource.h snappy-stubs-public.h snappy-c.h noinst_HEADERS = snappy-internal.h snappy-stubs-internal.h snappy-test.h diff --git a/cmake/SnappyConfig.cmake.in b/cmake/SnappyConfig.cmake.in new file mode 100644 index 0000000..5e604fe --- /dev/null +++ b/cmake/SnappyConfig.cmake.in @@ -0,0 +1,9 @@ +set(SNAPPY_VERSION @SNAPPY_MAJOR@.@SNAPPY_MINOR@.@SNAPPY_PATCHLEVEL@) + +@PACKAGE_INIT@ + +set_and_check(SNAPPY_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set_and_check(SNAPPY_LIBRARY_DIR "@PACKAGE_LIBRARY_INSTALL_DIR@") +set_and_check(SNAPPY_BINARY_DIR "@PACKAGE_BINARY_INSTALL_DIR@") + +check_required_components(SNAPPY) \ No newline at end of file diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 0000000..d9602cf --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,99 @@ +#ifndef SNAPPY_CONFIG_H +#define SNAPPY_CONFIG_H 1 + +/* Define to 1 if the compiler supports __builtin_ctz and friends. */ +#cmakedefine HAVE_BUILTIN_CTZ ${HAVE_BUILTIN_CTZ} + +/* Define to 1 if the compiler supports __builtin_expect. */ +#cmakedefine HAVE_BUILTIN_EXPECT ${HAVE_BUILTIN_EXPECT} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_BYTESWAP_H ${HAVE_BYTESWAP_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H} + +/* Use the gflags package for command-line parsing. */ +/* #undef HAVE_GFLAGS */ + +/* Defined when Google Test is available. */ +/* #undef HAVE_GTEST */ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H ${HAVE_INTTYPES_H} + +/* Define to 1 if you have the `fastlz' library (-lfastlz). */ +#cmakedefine HAVE_LIBFASTLZ ${HAVE_LIBFASTLZ} + +/* Define to 1 if you have the `lzf' library (-llzf). */ +#cmakedefine HAVE_LIBLZF ${HAVE_LIBLZF} + +/* Define to 1 if you have the `lzo2' library (-llzo2). */ +#cmakedefine HAVE_LIBLZO2 ${HAVE_LIBLZO2} + +/* Define to 1 if you have the `quicklz' library (-lquicklz). */ +#cmakedefine HAVE_LIBQUICKLZ ${HAVE_LIBQUICKLZ} + +/* Define to 1 if you have the `z' library (-lz). */ +#cmakedefine HAVE_LIBZ ${HAVE_LIBZ} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_UIO_H ${HAVE_SYS_UIO_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_MEMORY_H ${HAVE_MEMORY_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDDEF_H ${HAVE_STDDEF_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H ${HAVE_STDINT_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H ${HAVE_STDLIB_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H ${HAVE_STRINGS_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H ${HAVE_STRING_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_BYTESWAP_H ${HAVE_SYS_BYTESWAP_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_ENDIAN_H ${HAVE_SYS_ENDIAN_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_MMAN_H ${HAVE_SYS_MMAN_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_RESOURCE_H ${HAVE_SYS_RESOURCE_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H} + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WINDOWS_H ${HAVE_WINDOWS_H} + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ +#cmakedefine WORDS_BIGENDIAN + +#if defined(_MSC_VER) && (_MSC_VER <= 1900) +typedef __int64 ssize_t; +#endif + +#endif diff --git a/cmake/snappy-stubs-public.h.in b/cmake/snappy-stubs-public.h.in new file mode 100644 index 0000000..75c4a24 --- /dev/null +++ b/cmake/snappy-stubs-public.h.in @@ -0,0 +1,98 @@ +// Copyright 2011 Google Inc. All Rights Reserved. +// Author: sesse@google.com (Steinar H. Gunderson) +// +// 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. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// 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. +// +// Various type stubs for the open-source version of Snappy. +// +// This file cannot include config.h, as it is included from snappy.h, +// which is a public header. Instead, snappy-stubs-public.h is generated by +// from snappy-stubs-public.h.in at configure time. + +#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ +#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ + +#if ${HAVE_STDINT_H} +#include +#endif + +#if ${HAVE_STDDEF_H} +#include +#endif + +#if ${HAVE_SYS_UIO_H} +#include +#endif + +#define SNAPPY_MAJOR ${SNAPPY_MAJOR} +#define SNAPPY_MINOR ${SNAPPY_MINOR} +#define SNAPPY_PATCHLEVEL ${SNAPPY_PATCHLEVEL} +#define SNAPPY_VERSION \ + ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) + +#include + +namespace snappy { + +#if ${HAVE_STDINT_H} +typedef int8_t int8; +typedef uint8_t uint8; +typedef int16_t int16; +typedef uint16_t uint16; +typedef int32_t int32; +typedef uint32_t uint32; +typedef int64_t int64; +typedef uint64_t uint64; +#else +typedef signed char int8; +typedef unsigned char uint8; +typedef short int16; +typedef unsigned short uint16; +typedef int int32; +typedef unsigned int uint32; +typedef long long int64; +typedef unsigned long long uint64; +#endif + +typedef std::string string; + +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) + +#if !${HAVE_SYS_UIO_H} +// Windows does not have an iovec type, yet the concept is universally useful. +// It is simple to define it ourselves, so we put it inside our own namespace. +struct iovec { + void* iov_base; + size_t iov_len; +}; +#endif + +} // namespace snappy + +#endif // THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ diff --git a/snappy-c.h b/snappy-c.h index 32aa0c6..d13be71 100644 --- a/snappy-c.h +++ b/snappy-c.h @@ -38,6 +38,7 @@ extern "C" { #endif #include +#include "snappy-visibility.h" /* * Return values; see the documentation for each function to know @@ -68,6 +69,7 @@ typedef enum { * } * free(output); */ +SNAPPY_PUBLIC_API snappy_status snappy_compress(const char* input, size_t input_length, char* compressed, @@ -100,6 +102,7 @@ snappy_status snappy_compress(const char* input, * } * free(output); */ +SNAPPY_PUBLIC_API snappy_status snappy_uncompress(const char* compressed, size_t compressed_length, char* uncompressed, @@ -109,6 +112,7 @@ snappy_status snappy_uncompress(const char* compressed, * Returns the maximal size of the compressed representation of * input data that is "source_length" bytes in length. */ +SNAPPY_PUBLIC_API size_t snappy_max_compressed_length(size_t source_length); /* @@ -117,6 +121,7 @@ size_t snappy_max_compressed_length(size_t source_length); * *result normally. Returns SNAPPY_INVALID_INPUT on parsing error. * This operation takes O(1) time. */ +SNAPPY_PUBLIC_API snappy_status snappy_uncompressed_length(const char* compressed, size_t compressed_length, size_t* result); @@ -128,6 +133,7 @@ snappy_status snappy_uncompressed_length(const char* compressed, * Takes time proportional to compressed_length, but is usually at least a * factor of four faster than actual decompression. */ +SNAPPY_PUBLIC_API snappy_status snappy_validate_compressed_buffer(const char* compressed, size_t compressed_length); diff --git a/snappy-internal.h b/snappy-internal.h index c4d1f6d..9925ffe 100644 --- a/snappy-internal.h +++ b/snappy-internal.h @@ -32,11 +32,12 @@ #define THIRD_PARTY_SNAPPY_SNAPPY_INTERNAL_H_ #include "snappy-stubs-internal.h" +#include "snappy-visibility.h" namespace snappy { namespace internal { -class WorkingMemory { +class SNAPPY_PUBLIC_API WorkingMemory { public: WorkingMemory() : large_table_(NULL) { } ~WorkingMemory() { delete[] large_table_; } @@ -64,6 +65,7 @@ class WorkingMemory { // // Returns an "end" pointer into "op" buffer. // "end - op" is the compressed size of "input". +SNAPPY_PUBLIC_API char* CompressFragment(const char* input, size_t input_length, char* op, diff --git a/snappy-sinksource.h b/snappy-sinksource.h index 8afcdaa..69c7732 100644 --- a/snappy-sinksource.h +++ b/snappy-sinksource.h @@ -30,11 +30,12 @@ #define THIRD_PARTY_SNAPPY_SNAPPY_SINKSOURCE_H_ #include +#include "snappy-visibility.h" namespace snappy { // A Sink is an interface that consumes a sequence of bytes. -class Sink { +class SNAPPY_PUBLIC_API Sink { public: Sink() { } virtual ~Sink(); @@ -108,7 +109,7 @@ class Sink { }; // A Source is an interface that yields a sequence of bytes -class Source { +class SNAPPY_PUBLIC_API Source { public: Source() { } virtual ~Source(); @@ -143,7 +144,7 @@ class Source { }; // A Source implementation that yields the contents of a flat array -class ByteArraySource : public Source { +class SNAPPY_PUBLIC_API ByteArraySource : public Source { public: ByteArraySource(const char* p, size_t n) : ptr_(p), left_(n) { } virtual ~ByteArraySource(); @@ -156,7 +157,7 @@ class ByteArraySource : public Source { }; // A Sink implementation that writes to a flat array without any bound checks. -class UncheckedByteArraySink : public Sink { +class SNAPPY_PUBLIC_API UncheckedByteArraySink : public Sink { public: explicit UncheckedByteArraySink(char* dest) : dest_(dest) { } virtual ~UncheckedByteArraySink(); diff --git a/snappy-stubs-internal.h b/snappy-stubs-internal.h index 1954c63..746fba3 100644 --- a/snappy-stubs-internal.h +++ b/snappy-stubs-internal.h @@ -46,6 +46,7 @@ #endif #include "snappy-stubs-public.h" +#include "snappy-visibility.h" #if defined(__x86_64__) @@ -426,8 +427,9 @@ inline int Bits::FindLSBSetNonZero64(uint64 n) { #endif // End portable versions. -// Variable-length integer encoding. -class Varint { +// Variable-length integer encoding (This is used by the unit tests +// so we need to export it out of the shared object) +class SNAPPY_PUBLIC_API Varint { public: // Maximum lengths of varint encoding of uint32. static const int kMax32 = 5; diff --git a/snappy-test.cc b/snappy-test.cc index 7f1d0a8..6589996 100644 --- a/snappy-test.cc +++ b/snappy-test.cc @@ -36,6 +36,7 @@ #include #endif +#include "snappy.h" #include "snappy-test.h" #include diff --git a/snappy.cc b/snappy.cc index cd01214..640a65b 100644 --- a/snappy.cc +++ b/snappy.cc @@ -36,7 +36,6 @@ #include #include - namespace snappy { using internal::COPY_1_BYTE_OFFSET; diff --git a/snappy.h b/snappy.h index 4568db8..68d7467 100644 --- a/snappy.h +++ b/snappy.h @@ -43,6 +43,7 @@ #include #include "snappy-stubs-public.h" +#include "snappy-visibility.h" namespace snappy { class Source; @@ -54,6 +55,7 @@ namespace snappy { // Compress the bytes read from "*source" and append to "*sink". Return the // number of bytes written. + SNAPPY_PUBLIC_API size_t Compress(Source* source, Sink* sink); // Find the uncompressed length of the given stream, as given by the header. @@ -63,6 +65,7 @@ namespace snappy { // Also note that this leaves "*source" in a state that is unsuitable for // further operations, such as RawUncompress(). You will need to rewind // or recreate the source yourself before attempting any further calls. + SNAPPY_PUBLIC_API bool GetUncompressedLength(Source* source, uint32* result); // ------------------------------------------------------------------------ @@ -73,6 +76,7 @@ namespace snappy { // Original contents of *output are lost. // // REQUIRES: "input[]" is not an alias of "*output". + SNAPPY_PUBLIC_API size_t Compress(const char* input, size_t input_length, string* output); // Decompresses "compressed[0,compressed_length-1]" to "*uncompressed". @@ -81,12 +85,14 @@ namespace snappy { // REQUIRES: "compressed[]" is not an alias of "*uncompressed". // // returns false if the message is corrupted and could not be decompressed + SNAPPY_PUBLIC_API bool Uncompress(const char* compressed, size_t compressed_length, string* uncompressed); // Decompresses "compressed" to "*uncompressed". // // returns false if the message is corrupted and could not be decompressed + SNAPPY_PUBLIC_API bool Uncompress(Source* compressed, Sink* uncompressed); // This routine uncompresses as much of the "compressed" as possible @@ -95,6 +101,7 @@ namespace snappy { // should ignore those). The emitted data typically has length // GetUncompressedLength(), but may be shorter if an error is // encountered. + SNAPPY_PUBLIC_API size_t UncompressAsMuchAsPossible(Source* compressed, Sink* uncompressed); // ------------------------------------------------------------------------ @@ -116,6 +123,7 @@ namespace snappy { // RawCompress(input, input_length, output, &output_length); // ... Process(output, output_length) ... // delete [] output; + SNAPPY_PUBLIC_API void RawCompress(const char* input, size_t input_length, char* compressed, @@ -126,6 +134,7 @@ namespace snappy { // stores the uncompressed data to // uncompressed[0..GetUncompressedLength(compressed)-1] // returns false if the message is corrupted and could not be decrypted + SNAPPY_PUBLIC_API bool RawUncompress(const char* compressed, size_t compressed_length, char* uncompressed); @@ -134,6 +143,7 @@ namespace snappy { // data to // uncompressed[0..GetUncompressedLength(compressed,compressed_length)-1] // returns false if the message is corrupted and could not be decrypted + SNAPPY_PUBLIC_API bool RawUncompress(Source* compressed, char* uncompressed); // Given data in "compressed[0..compressed_length-1]" generated by @@ -144,6 +154,7 @@ namespace snappy { // in "iov" must not overlap with each other. // // returns false if the message is corrupted and could not be decrypted + SNAPPY_PUBLIC_API bool RawUncompressToIOVec(const char* compressed, size_t compressed_length, const struct iovec* iov, size_t iov_cnt); @@ -155,17 +166,20 @@ namespace snappy { // in "iov" must not overlap with each other. // // returns false if the message is corrupted and could not be decrypted + SNAPPY_PUBLIC_API bool RawUncompressToIOVec(Source* compressed, const struct iovec* iov, size_t iov_cnt); // Returns the maximal size of the compressed representation of // input data that is "source_bytes" bytes in length; + SNAPPY_PUBLIC_API size_t MaxCompressedLength(size_t source_bytes); // REQUIRES: "compressed[]" was produced by RawCompress() or Compress() // Returns true and stores the length of the uncompressed data in // *result normally. Returns false on parsing error. // This operation takes O(1) time. + SNAPPY_PUBLIC_API bool GetUncompressedLength(const char* compressed, size_t compressed_length, size_t* result); @@ -173,6 +187,7 @@ namespace snappy { // successfully. Does not return the uncompressed data. Takes // time proportional to compressed_length, but is usually at least // a factor of four faster than actual decompression. + SNAPPY_PUBLIC_API bool IsValidCompressedBuffer(const char* compressed, size_t compressed_length); @@ -182,6 +197,7 @@ namespace snappy { // a factor of four faster than actual decompression. // On success, consumes all of *compressed. On failure, consumes an // unspecified prefix of *compressed. + SNAPPY_PUBLIC_API bool IsValidCompressed(Source* compressed); // The size of a compression block. Note that many parts of the compression