diff options
author | costan <costan@google.com> | 2018-08-16 10:44:34 -0700 |
---|---|---|
committer | Victor Costan <pwnall@chromium.org> | 2018-08-16 11:36:45 -0700 |
commit | 7fefd231a19a0c9e10273a04204889d138d448b1 (patch) | |
tree | 2d8aa443b424dab37058b9547e0d521f78e0ec52 | |
parent | db082d2cd6512981c28849d00dd47a4216768e10 (diff) | |
download | snappy-git-7fefd231a19a0c9e10273a04204889d138d448b1.tar.gz |
C++11 guarantees <cstddef> and <cstdint>.
The build configuration can be cleaned up a bit.
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | cmake/config.h.in | 6 | ||||
-rw-r--r-- | snappy-stubs-public.h.in | 45 | ||||
-rw-r--r-- | snappy-test.h | 2 | ||||
-rw-r--r-- | snappy.cc | 6 | ||||
-rw-r--r-- | 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 <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. */ #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 <stdint.h> -#endif // HAVE_STDDEF_H - -#if ${HAVE_STDDEF_H_01} // HAVE_STDDEF_H -#include <stddef.h> -#endif // HAVE_STDDEF_H +#include <cstddef> +#include <cstdint> +#include <string> #if ${HAVE_SYS_UIO_H_01} // HAVE_SYS_UIO_H #include <sys/uio.h> @@ -54,38 +50,25 @@ #define SNAPPY_VERSION \ ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) -#include <string> - 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 <windows.h> #endif -#include <string> - #ifdef HAVE_GTEST #include <gtest/gtest.h> @@ -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<int>(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 @@ -39,7 +39,7 @@ #ifndef THIRD_PARTY_SNAPPY_SNAPPY_H__ #define THIRD_PARTY_SNAPPY_SNAPPY_H__ -#include <stddef.h> +#include <cstddef> #include <string> #include "snappy-stubs-public.h" |