From 7fefd231a19a0c9e10273a04204889d138d448b1 Mon Sep 17 00:00:00 2001 From: costan Date: Thu, 16 Aug 2018 10:44:34 -0700 Subject: [PATCH] C++11 guarantees and . The build configuration can be cleaned up a bit. --- CMakeLists.txt | 10 --------- cmake/config.h.in | 6 ------ snappy-stubs-public.h.in | 45 +++++++++++++--------------------------- snappy-test.h | 2 -- snappy.cc | 6 +++--- snappy.h | 2 +- 6 files changed, 18 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62ecd09..41a2124 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,6 @@ test_big_endian(SNAPPY_IS_BIG_ENDIAN) include(CheckIncludeFile) 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/mman.h" HAVE_SYS_MMAN_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 # CMake's variable substitution with 0/1 variables, which will be seen by the # 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}) -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) set(HAVE_SYS_UIO_H_01 0) endif(NOT HAVE_SYS_UIO_H_01) diff --git a/cmake/config.h.in b/cmake/config.h.in index 088ff6f..3027b62 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -28,12 +28,6 @@ /* Define to 1 if you have the `z' library (-lz). */ #cmakedefine HAVE_LIBZ 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_STDDEF_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_STDINT_H 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_ENDIAN_H 1 diff --git a/snappy-stubs-public.h.in b/snappy-stubs-public.h.in index bb5b222..b8fe230 100644 --- a/snappy-stubs-public.h.in +++ b/snappy-stubs-public.h.in @@ -36,13 +36,9 @@ #ifndef 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 -#endif // HAVE_STDDEF_H - -#if ${HAVE_STDDEF_H_01} // HAVE_STDDEF_H -#include -#endif // HAVE_STDDEF_H +#include +#include +#include #if ${HAVE_SYS_UIO_H_01} // HAVE_SYS_UIO_H #include @@ -54,38 +50,25 @@ #define SNAPPY_VERSION \ ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) -#include - namespace snappy { -#if ${HAVE_STDINT_H_01} // 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 // HAVE_STDINT_H +using int8 = std::int8_t; +using uint8 = std::uint8_t; +using int16 = std::int16_t; +using uint16 = std::uint16_t; +using int32 = std::int32_t; +using uint32 = std::uint32_t; +using int64 = std::int64_t; +using uint64 = std::uint64_t; -typedef std::string string; +using string = std::string; #if !${HAVE_SYS_UIO_H_01} // !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; + void* iov_base; + size_t iov_len; }; #endif // !HAVE_SYS_UIO_H diff --git a/snappy-test.h b/snappy-test.h index 078f321..ec9d4db 100644 --- a/snappy-test.h +++ b/snappy-test.h @@ -55,8 +55,6 @@ #include #endif -#include - #ifdef HAVE_GTEST #include diff --git a/snappy.cc b/snappy.cc index df1ff02..19fc963 100644 --- a/snappy.cc +++ b/snappy.cc @@ -509,7 +509,7 @@ char* CompressFragment(const char* input, // "ip" is the input pointer, and "op" is the output pointer. const char* ip = input; 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); assert(static_cast(kuint32max >> shift) == table_size - 1); 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. - // On succcess, stores the length in *result and returns true. + // On success, stores the length in *result and returns true. // On failure, returns false. bool ReadUncompressedLength(uint32* result) { assert(ip_ == NULL); // Must not have read anything yet @@ -1624,4 +1624,4 @@ bool Uncompress(Source* compressed, Sink* uncompressed) { } } -} // end namespace snappy +} // namespace snappy diff --git a/snappy.h b/snappy.h index 4568db8..f4d36ef 100644 --- a/snappy.h +++ b/snappy.h @@ -39,7 +39,7 @@ #ifndef THIRD_PARTY_SNAPPY_SNAPPY_H__ #define THIRD_PARTY_SNAPPY_SNAPPY_H__ -#include +#include #include #include "snappy-stubs-public.h"