mirror of https://github.com/google/snappy.git
C++11 guarantees <cstddef> and <cstdint>.
The build configuration can be cleaned up a bit.
This commit is contained in:
parent
db082d2cd6
commit
7fefd231a1
|
@ -19,8 +19,6 @@ test_big_endian(SNAPPY_IS_BIG_ENDIAN)
|
||||||
|
|
||||||
include(CheckIncludeFile)
|
include(CheckIncludeFile)
|
||||||
check_include_file("byteswap.h" HAVE_BYTESWAP_H)
|
check_include_file("byteswap.h" HAVE_BYTESWAP_H)
|
||||||
check_include_file("stddef.h" HAVE_STDDEF_H)
|
|
||||||
check_include_file("stdint.h" HAVE_STDINT_H)
|
|
||||||
check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H)
|
check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H)
|
||||||
check_include_file("sys/mman.h" HAVE_SYS_MMAN_H)
|
check_include_file("sys/mman.h" HAVE_SYS_MMAN_H)
|
||||||
check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H)
|
check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H)
|
||||||
|
@ -90,15 +88,7 @@ configure_file(
|
||||||
# We don't want to define HAVE_ macros in public headers. Instead, we use
|
# We don't want to define HAVE_ macros in public headers. Instead, we use
|
||||||
# CMake's variable substitution with 0/1 variables, which will be seen by the
|
# CMake's variable substitution with 0/1 variables, which will be seen by the
|
||||||
# preprocessor as constants.
|
# preprocessor as constants.
|
||||||
set(HAVE_STDINT_H_01 ${HAVE_STDINT_H})
|
|
||||||
set(HAVE_STDDEF_H_01 ${HAVE_STDDEF_H})
|
|
||||||
set(HAVE_SYS_UIO_H_01 ${HAVE_SYS_UIO_H})
|
set(HAVE_SYS_UIO_H_01 ${HAVE_SYS_UIO_H})
|
||||||
if(NOT HAVE_STDINT_H_01)
|
|
||||||
set(HAVE_STDINT_H_01 0)
|
|
||||||
endif(NOT HAVE_STDINT_H_01)
|
|
||||||
if(NOT HAVE_STDDEF_H_01)
|
|
||||||
set(HAVE_STDDEF_H_01 0)
|
|
||||||
endif(NOT HAVE_STDDEF_H_01)
|
|
||||||
if(NOT HAVE_SYS_UIO_H_01)
|
if(NOT HAVE_SYS_UIO_H_01)
|
||||||
set(HAVE_SYS_UIO_H_01 0)
|
set(HAVE_SYS_UIO_H_01 0)
|
||||||
endif(NOT HAVE_SYS_UIO_H_01)
|
endif(NOT HAVE_SYS_UIO_H_01)
|
||||||
|
|
|
@ -28,12 +28,6 @@
|
||||||
/* Define to 1 if you have the `z' library (-lz). */
|
/* Define to 1 if you have the `z' library (-lz). */
|
||||||
#cmakedefine HAVE_LIBZ 1
|
#cmakedefine HAVE_LIBZ 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <stddef.h> header file. */
|
|
||||||
#cmakedefine HAVE_STDDEF_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <stdint.h> header file. */
|
|
||||||
#cmakedefine HAVE_STDINT_H 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/endian.h> header file. */
|
/* Define to 1 if you have the <sys/endian.h> header file. */
|
||||||
#cmakedefine HAVE_SYS_ENDIAN_H 1
|
#cmakedefine HAVE_SYS_ENDIAN_H 1
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,9 @@
|
||||||
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
|
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
|
||||||
#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
|
#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_
|
||||||
|
|
||||||
#if ${HAVE_STDINT_H_01} // HAVE_STDINT_H
|
#include <cstddef>
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#endif // HAVE_STDDEF_H
|
#include <string>
|
||||||
|
|
||||||
#if ${HAVE_STDDEF_H_01} // HAVE_STDDEF_H
|
|
||||||
#include <stddef.h>
|
|
||||||
#endif // HAVE_STDDEF_H
|
|
||||||
|
|
||||||
#if ${HAVE_SYS_UIO_H_01} // HAVE_SYS_UIO_H
|
#if ${HAVE_SYS_UIO_H_01} // HAVE_SYS_UIO_H
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
@ -54,38 +50,25 @@
|
||||||
#define SNAPPY_VERSION \
|
#define SNAPPY_VERSION \
|
||||||
((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
|
((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL)
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace snappy {
|
namespace snappy {
|
||||||
|
|
||||||
#if ${HAVE_STDINT_H_01} // HAVE_STDINT_H
|
using int8 = std::int8_t;
|
||||||
typedef int8_t int8;
|
using uint8 = std::uint8_t;
|
||||||
typedef uint8_t uint8;
|
using int16 = std::int16_t;
|
||||||
typedef int16_t int16;
|
using uint16 = std::uint16_t;
|
||||||
typedef uint16_t uint16;
|
using int32 = std::int32_t;
|
||||||
typedef int32_t int32;
|
using uint32 = std::uint32_t;
|
||||||
typedef uint32_t uint32;
|
using int64 = std::int64_t;
|
||||||
typedef int64_t int64;
|
using uint64 = std::uint64_t;
|
||||||
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 // HAVE_STDINT_H
|
|
||||||
|
|
||||||
typedef std::string string;
|
using string = std::string;
|
||||||
|
|
||||||
#if !${HAVE_SYS_UIO_H_01} // !HAVE_SYS_UIO_H
|
#if !${HAVE_SYS_UIO_H_01} // !HAVE_SYS_UIO_H
|
||||||
// Windows does not have an iovec type, yet the concept is universally useful.
|
// 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.
|
// It is simple to define it ourselves, so we put it inside our own namespace.
|
||||||
struct iovec {
|
struct iovec {
|
||||||
void* iov_base;
|
void* iov_base;
|
||||||
size_t iov_len;
|
size_t iov_len;
|
||||||
};
|
};
|
||||||
#endif // !HAVE_SYS_UIO_H
|
#endif // !HAVE_SYS_UIO_H
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,6 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifdef HAVE_GTEST
|
#ifdef HAVE_GTEST
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
|
@ -509,7 +509,7 @@ char* CompressFragment(const char* input,
|
||||||
// "ip" is the input pointer, and "op" is the output pointer.
|
// "ip" is the input pointer, and "op" is the output pointer.
|
||||||
const char* ip = input;
|
const char* ip = input;
|
||||||
assert(input_size <= kBlockSize);
|
assert(input_size <= kBlockSize);
|
||||||
assert((table_size & (table_size - 1)) == 0); // table must be power of two
|
assert((table_size & (table_size - 1)) == 0); // table must be power of two
|
||||||
const int shift = 32 - Bits::Log2Floor(table_size);
|
const int shift = 32 - Bits::Log2Floor(table_size);
|
||||||
assert(static_cast<int>(kuint32max >> shift) == table_size - 1);
|
assert(static_cast<int>(kuint32max >> shift) == table_size - 1);
|
||||||
const char* ip_end = input + input_size;
|
const char* ip_end = input + input_size;
|
||||||
|
@ -721,7 +721,7 @@ class SnappyDecompressor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the uncompressed length stored at the start of the compressed data.
|
// Read the uncompressed length stored at the start of the compressed data.
|
||||||
// On succcess, stores the length in *result and returns true.
|
// On success, stores the length in *result and returns true.
|
||||||
// On failure, returns false.
|
// On failure, returns false.
|
||||||
bool ReadUncompressedLength(uint32* result) {
|
bool ReadUncompressedLength(uint32* result) {
|
||||||
assert(ip_ == NULL); // Must not have read anything yet
|
assert(ip_ == NULL); // Must not have read anything yet
|
||||||
|
@ -1624,4 +1624,4 @@ bool Uncompress(Source* compressed, Sink* uncompressed) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace snappy
|
} // namespace snappy
|
||||||
|
|
2
snappy.h
2
snappy.h
|
@ -39,7 +39,7 @@
|
||||||
#ifndef THIRD_PARTY_SNAPPY_SNAPPY_H__
|
#ifndef THIRD_PARTY_SNAPPY_SNAPPY_H__
|
||||||
#define THIRD_PARTY_SNAPPY_SNAPPY_H__
|
#define THIRD_PARTY_SNAPPY_SNAPPY_H__
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <cstddef>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "snappy-stubs-public.h"
|
#include "snappy-stubs-public.h"
|
||||||
|
|
Loading…
Reference in New Issue