Browse Source

lib: added snappy

Signed-off-by: Leonardo Almiñana <leonardo@calyptia.com>
Signed-off-by: Leonardo Alminana <leonardo@calyptia.com>
cmetrics-0.1.5
Leonardo Alminana 2 months ago
committed by Eduardo Silva
parent
commit
2ede81dd24
  1. 3
      CMakeLists.txt
  2. 1
      cmake/headers.cmake
  3. 1
      cmake/libraries.cmake
  4. 13
      lib/snappy-fef67ac/CMakeLists.txt
  5. 30
      lib/snappy-fef67ac/LICENSE
  6. 87
      lib/snappy-fef67ac/compat.h
  7. 71
      lib/snappy-fef67ac/snappy-int.h
  8. 1619
      lib/snappy-fef67ac/snappy.c
  9. 39
      lib/snappy-fef67ac/snappy.h

3
CMakeLists.txt

@ -393,6 +393,9 @@ set(XXHASH_BUILD_ENABLE_INLINE_API OFF)
set(XXHASH_BUILD_XXHSUM OFF)
add_subdirectory(${FLB_PATH_LIB_XXHASH}/cmake_unofficial EXCLUDE_FROM_ALL)
# snappy
add_subdirectory(${FLB_PATH_LIB_SNAPPY} EXCLUDE_FROM_ALL)
# CMetrics
add_subdirectory(${FLB_PATH_LIB_CMETRICS} EXCLUDE_FROM_ALL)

1
cmake/headers.cmake

@ -17,6 +17,7 @@ include_directories(
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MINIZ}/
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_ONIGMO}
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_XXHASH}
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_SNAPPY}
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_CMETRICS}/include
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_CARES}/include
${CMAKE_CURRENT_BINARY_DIR}/lib/jansson-fd3e9e3/include

1
cmake/libraries.cmake

@ -17,3 +17,4 @@ set(FLB_PATH_LIB_TUTF8E "lib/tutf8e")
set(FLB_PATH_LIB_XXHASH "lib/xxHash-0.8.0")
set(FLB_PATH_LIB_CMETRICS "lib/cmetrics")
set(FLB_PATH_LIB_CARES "lib/c-ares-809d5e84")
set(FLB_PATH_LIB_SNAPPY "lib/snappy-fef67ac")

13
lib/snappy-fef67ac/CMakeLists.txt

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 2.8)
project(snappy-c)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Include helpers
include(CheckCSourceCompiles)
include(GNUInstallDirs)
set(src
snappy.c
)
add_library(snappy-c STATIC ${src})

30
lib/snappy-fef67ac/LICENSE

@ -0,0 +1,30 @@
The snappy-c code is under the same license as the original snappy source
Copyright 2011 Intel Corporation All Rights Reserved.
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 Intel Corporation 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.

87
lib/snappy-fef67ac/compat.h

@ -0,0 +1,87 @@
#ifdef __FreeBSD__
# include <sys/endian.h>
#elif defined(__APPLE_CC_) || defined(__MACH__) /* MacOS/X support */
# include <machine/endian.h>
#if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
# define htole16(x) (x)
# define le32toh(x) (x)
#elif __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN
# define htole16(x) __DARWIN_OSSwapInt16(x)
# define le32toh(x) __DARWIN_OSSwapInt32(x)
#else
# error "Endianness is undefined"
#endif
#elif !defined(__WIN32__)
# include <endian.h>
#endif
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <stdbool.h>
#include <limits.h>
#ifndef __WIN32__
#include <sys/uio.h>
#endif
#ifdef __ANDROID__
#define le32toh letoh32
#endif
#if defined(__WIN32__) && defined(SG)
struct iovec {
void *iov_base; /* Pointer to data. */
size_t iov_len; /* Length of data. */
};
#endif
#define get_unaligned_memcpy(x) ({ \
typeof(*(x)) _ret; \
memcpy(&_ret, (x), sizeof(*(x))); \
_ret; })
#define put_unaligned_memcpy(v,x) ({ \
typeof((v)) _v = (v); \
memcpy((x), &_v, sizeof(*(x))); })
#define get_unaligned get_unaligned_memcpy
#define put_unaligned put_unaligned_memcpy
#define get_unaligned64 get_unaligned_memcpy
#define put_unaligned64 put_unaligned_memcpy
#define get_unaligned_le32(x) (le32toh(get_unaligned((u32 *)(x))))
#define put_unaligned_le16(v,x) (put_unaligned(htole16(v), (u16 *)(x)))
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned u32;
typedef unsigned long long u64;
#define BUG_ON(x) assert(!(x))
#define vmalloc(x) malloc(x)
#define vfree(x) free(x)
#define EXPORT_SYMBOL(x)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#define likely(x) __builtin_expect((x), 1)
#define unlikely(x) __builtin_expect((x), 0)
#define min_t(t,x,y) ((x) < (y) ? (x) : (y))
#define max_t(t,x,y) ((x) > (y) ? (x) : (y))
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define __LITTLE_ENDIAN__ 1
#endif
#if __LITTLE_ENDIAN__ == 1 && (defined(__LSB_VERSION__) || defined(__WIN32__))
#define htole16(x) (x)
#define le32toh(x) (x)
#endif
#define BITS_PER_LONG (__SIZEOF_LONG__ * 8)

71
lib/snappy-fef67ac/snappy-int.h

@ -0,0 +1,71 @@
// Copyright 2011 Google Inc. All Rights Reserved.
//
// 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 stubs for the open-source version of Snappy.
#define likely(x) __builtin_expect(x, 1)
#define unlikely(x) __builtin_expect(x, 0)
#define CRASH_UNLESS(x) assert(x)
#define CHECK(cond) assert(cond)
#define CHECK_LE(a, b) CRASH_UNLESS((a) <= (b))
#define CHECK_GE(a, b) CRASH_UNLESS((a) >= (b))
#define CHECK_EQ(a, b) CRASH_UNLESS((a) == (b))
#define CHECK_NE(a, b) CRASH_UNLESS((a) != (b))
#define CHECK_LT(a, b) CRASH_UNLESS((a) < (b))
#define CHECK_GT(a, b) CRASH_UNLESS((a) > (b))
#define UNALIGNED_LOAD16(_p) (*(const uint16 *)(_p))
#define UNALIGNED_LOAD32(_p) (*(const uint32 *)(_p))
#define UNALIGNED_LOAD64(_p) (*(const uint64 *)(_p))
#define UNALIGNED_STORE16(_p, _val) (*(uint16 *)(_p) = (_val))
#define UNALIGNED_STORE32(_p, _val) (*(uint32 *)(_p) = (_val))
#define UNALIGNED_STORE64(_p, _val) (*(uint64 *)(_p) = (_val))
#ifdef NDEBUG
#define DCHECK(cond) CRASH_UNLESS(true)
#define DCHECK_LE(a, b) CRASH_UNLESS(true)
#define DCHECK_GE(a, b) CRASH_UNLESS(true)
#define DCHECK_EQ(a, b) CRASH_UNLESS(true)
#define DCHECK_NE(a, b) CRASH_UNLESS(true)
#define DCHECK_LT(a, b) CRASH_UNLESS(true)
#define DCHECK_GT(a, b) CRASH_UNLESS(true)
#else
#define DCHECK(cond) CHECK(cond)
#define DCHECK_LE(a, b) CHECK_LE(a, b)
#define DCHECK_GE(a, b) CHECK_GE(a, b)
#define DCHECK_EQ(a, b) CHECK_EQ(a, b)
#define DCHECK_NE(a, b) CHECK_NE(a, b)
#define DCHECK_LT(a, b) CHECK_LT(a, b)
#define DCHECK_GT(a, b) CHECK_GT(a, b)
#endif

1619
lib/snappy-fef67ac/snappy.c

File diff suppressed because it is too large

39
lib/snappy-fef67ac/snappy.h

@ -0,0 +1,39 @@
#ifndef _LINUX_SNAPPY_H
#define _LINUX_SNAPPY_H 1
#include <stdbool.h>
#include <stddef.h>
/* Only needed for compression. This preallocates the worst case */
struct snappy_env {
unsigned short *hash_table;
void *scratch;
void *scratch_output;
};
struct iovec;
int snappy_init_env(struct snappy_env *env);
int snappy_init_env_sg(struct snappy_env *env, bool sg);
void snappy_free_env(struct snappy_env *env);
int snappy_uncompress_iov(struct iovec *iov_in, int iov_in_len,
size_t input_len, char *uncompressed);
int snappy_uncompress(const char *compressed, size_t n, char *uncompressed);
int snappy_compress(struct snappy_env *env,
const char *input,
size_t input_length,
char *compressed,
size_t *compressed_length);
int snappy_compress_iov(struct snappy_env *env,
struct iovec *iov_in,
int iov_in_len,
size_t input_length,
struct iovec *iov_out,
int *iov_out_len,
size_t *compressed_length);
bool snappy_uncompressed_length(const char *buf, size_t len, size_t *result);
size_t snappy_max_compressed_length(size_t source_len);
#endif
Loading…
Cancel
Save