Commit 9b6f4293 authored by avi's avatar avi Committed by Commit bot

Switch to standard integer types in base/.

BUG=138542
TBR=mark@chromium.org
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1538743002

Cr-Commit-Position: refs/heads/master@{#366910}
parent 28523e2c
......@@ -387,7 +387,7 @@ deps_os = {
# For Linux and Chromium OS.
'src/third_party/cros_system_api':
Var('chromium_git') + '/chromiumos/platform/system_api.git' + '@' + 'ed198c46f73e67d9a494c3c0623e3ba16e4da5e8',
Var('chromium_git') + '/chromiumos/platform/system_api.git' + '@' + 'd9ecb3bd87504815d4c58a6a8b9031deb2498d19',
# Note that this is different from Android's freetype repo.
'src/third_party/freetype2/src':
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <limits.h>
#include <malloc.h>
#include <new.h>
#include <windows.h>
#include "base/basictypes.h"
#include <stddef.h>
// This shim make it possible to perform additional checks on allocations
// before passing them to the Heap functions.
......
......@@ -6,6 +6,7 @@
// of other libraries
#include <config.h>
#include <stddef.h>
inline int snprintf(char* buffer, size_t count, const char* format, ...) {
int result;
......
......@@ -8,8 +8,8 @@
#include <stack>
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/synchronization/lock.h"
namespace base {
......
......@@ -6,7 +6,7 @@
#define BASE_ATOMIC_SEQUENCE_NUM_H_
#include "base/atomicops.h"
#include "base/basictypes.h"
#include "base/macros.h"
namespace base {
......
......@@ -7,7 +7,11 @@
#ifndef BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
#define BASE_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_
// AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32,
#include <stdint.h>
#include "build/build_config.h"
// AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32_t,
// which in turn means int. On some LP32 platforms, intptr_t is an int, but
// on others, it's a long. When AtomicWord and Atomic32 are based on different
// fundamental types, their pointers are incompatible.
......
......@@ -34,6 +34,8 @@
#include <atomic>
#include "build/build_config.h"
namespace base {
namespace subtle {
......
......@@ -12,6 +12,7 @@
#include <intrin.h>
#include "base/macros.h"
#include "build/build_config.h"
#if defined(ARCH_CPU_64_BITS)
// windows.h #defines this (only on x64). This causes problems because the
......
......@@ -5,7 +5,7 @@
#ifndef BASE_AUTO_RESET_H_
#define BASE_AUTO_RESET_H_
#include "base/basictypes.h"
#include "base/macros.h"
// base::AutoReset<> is useful for setting a variable to a new value only within
// a particular scope. An base::AutoReset<> object resets a variable to its
......
......@@ -4,6 +4,8 @@
#include "base/base64.h"
#include <stddef.h>
#include "third_party/modp_b64/modp_b64.h"
namespace base {
......
......@@ -4,7 +4,10 @@
#include "base/base64url.h"
#include <stddef.h>
#include "base/base64.h"
#include "base/macros.h"
#include "base/numerics/safe_math.h"
#include "base/strings/string_util.h"
#include "third_party/modp_b64/modp_b64.h"
......
......@@ -9,6 +9,7 @@
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/strings/string_piece.h"
namespace base {
......
......@@ -4,6 +4,7 @@
#include "base/base64url.h"
#include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
......
......@@ -8,6 +8,7 @@
#include <dlfcn.h>
#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>
#include <stdint.h>
#include "base/base_paths.h"
#include "base/compiler_specific.h"
......
......@@ -7,6 +7,7 @@
// Android).
#include <limits.h>
#include <stddef.h>
#include <ostream>
#include <string>
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/base_switches.h"
#include "build/build_config.h"
namespace switches {
......
......@@ -43,19 +43,19 @@ bool BigEndianReader::Read(T* value) {
return true;
}
bool BigEndianReader::ReadU8(uint8* value) {
bool BigEndianReader::ReadU8(uint8_t* value) {
return Read(value);
}
bool BigEndianReader::ReadU16(uint16* value) {
bool BigEndianReader::ReadU16(uint16_t* value) {
return Read(value);
}
bool BigEndianReader::ReadU32(uint32* value) {
bool BigEndianReader::ReadU32(uint32_t* value) {
return Read(value);
}
bool BigEndianReader::ReadU64(uint64* value) {
bool BigEndianReader::ReadU64(uint64_t* value) {
return Read(value);
}
......@@ -86,19 +86,19 @@ bool BigEndianWriter::Write(T value) {
return true;
}
bool BigEndianWriter::WriteU8(uint8 value) {
bool BigEndianWriter::WriteU8(uint8_t value) {
return Write(value);
}
bool BigEndianWriter::WriteU16(uint16 value) {
bool BigEndianWriter::WriteU16(uint16_t value) {
return Write(value);
}
bool BigEndianWriter::WriteU32(uint32 value) {
bool BigEndianWriter::WriteU32(uint32_t value) {
return Write(value);
}
bool BigEndianWriter::WriteU64(uint64 value) {
bool BigEndianWriter::WriteU64(uint64_t value) {
return Write(value);
}
......
......@@ -5,8 +5,10 @@
#ifndef BASE_BIG_ENDIAN_H_
#define BASE_BIG_ENDIAN_H_
#include <stddef.h>
#include <stdint.h>
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/strings/string_piece.h"
namespace base {
......@@ -21,8 +23,8 @@ inline void ReadBigEndian(const char buf[], T* out) {
*out = buf[0];
for (size_t i = 1; i < sizeof(T); ++i) {
*out <<= 8;
// Must cast to uint8 to avoid clobbering by sign extension.
*out |= static_cast<uint8>(buf[i]);
// Must cast to uint8_t to avoid clobbering by sign extension.
*out |= static_cast<uint8_t>(buf[i]);
}
}
......@@ -37,13 +39,13 @@ inline void WriteBigEndian(char buf[], T val) {
}
// Specializations to make clang happy about the (dead code) shifts above.
template<>
inline void ReadBigEndian<uint8>(const char buf[], uint8* out) {
template <>
inline void ReadBigEndian<uint8_t>(const char buf[], uint8_t* out) {
*out = buf[0];
}
template<>
inline void WriteBigEndian<uint8>(char buf[], uint8 val) {
template <>
inline void WriteBigEndian<uint8_t>(char buf[], uint8_t val) {
buf[0] = static_cast<char>(val);
}
......@@ -60,10 +62,10 @@ class BASE_EXPORT BigEndianReader {
bool ReadBytes(void* out, size_t len);
// Creates a StringPiece in |out| that points to the underlying buffer.
bool ReadPiece(base::StringPiece* out, size_t len);
bool ReadU8(uint8* value);
bool ReadU16(uint16* value);
bool ReadU32(uint32* value);
bool ReadU64(uint64* value);
bool ReadU8(uint8_t* value);
bool ReadU16(uint16_t* value);
bool ReadU32(uint32_t* value);
bool ReadU64(uint64_t* value);
private:
// Hidden to promote type safety.
......@@ -85,10 +87,10 @@ class BASE_EXPORT BigEndianWriter {
bool Skip(size_t len);
bool WriteBytes(const void* buf, size_t len);
bool WriteU8(uint8 value);
bool WriteU16(uint16 value);
bool WriteU32(uint32 value);
bool WriteU64(uint64 value);
bool WriteU8(uint8_t value);
bool WriteU16(uint16_t value);
bool WriteU32(uint32_t value);
bool WriteU64(uint64_t value);
private:
// Hidden to promote type safety.
......
......@@ -4,6 +4,8 @@
#include "base/big_endian.h"
#include <stdint.h>
#include "base/strings/string_piece.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -13,10 +15,10 @@ TEST(BigEndianReaderTest, ReadsValues) {
char data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF,
0x1A, 0x2B, 0x3C, 0x4D, 0x5E };
char buf[2];
uint8 u8;
uint16 u16;
uint32 u32;
uint64 u64;
uint8_t u8;
uint16_t u16;
uint32_t u32;
uint64_t u64;
base::StringPiece piece;
BigEndianReader reader(data, sizeof(data));
......@@ -43,10 +45,10 @@ TEST(BigEndianReaderTest, ReadsValues) {
TEST(BigEndianReaderTest, RespectsLength) {
char data[8];
char buf[2];
uint8 u8;
uint16 u16;
uint32 u32;
uint64 u64;
uint8_t u8;
uint16_t u16;
uint32_t u32;
uint64_t u64;
base::StringPiece piece;
BigEndianReader reader(data, sizeof(data));
// 8 left
......@@ -88,10 +90,10 @@ TEST(BigEndianWriterTest, WritesValues) {
TEST(BigEndianWriterTest, RespectsLength) {
char data[8];
char buf[2];
uint8 u8 = 0;
uint16 u16 = 0;
uint32 u32 = 0;
uint64 u64 = 0;
uint8_t u8 = 0;
uint16_t u16 = 0;
uint32_t u32 = 0;
uint64_t u64 = 0;
BigEndianWriter writer(data, sizeof(data));
// 8 left
EXPECT_FALSE(writer.Skip(9));
......
......@@ -143,13 +143,15 @@
#ifndef BASE_BIND_HELPERS_H_
#define BASE_BIND_HELPERS_H_
#include <stddef.h>
#include <type_traits>
#include <utility>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/template_util.h"
#include "build/build_config.h"
namespace base {
namespace internal {
......
......@@ -5,6 +5,8 @@
#ifndef BASE_BIND_INTERNAL_H_
#define BASE_BIND_INTERNAL_H_
#include <stddef.h>
#include <type_traits>
#include "base/bind_helpers.h"
......
......@@ -8,6 +8,8 @@
#ifndef BASE_BIND_INTERNAL_WIN_H_
#define BASE_BIND_INTERNAL_WIN_H_
#include "build/build_config.h"
// In the x64 architecture in Windows, __fastcall, __stdcall, etc, are all
// the same as __cdecl which would turn the following specializations into
// multiple definitions.
......
......@@ -8,9 +8,11 @@
#include <utility>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -5,8 +5,9 @@
// This is a "No Compile Test" suite.
// http://dev.chromium.org/developers/testing/no-compile-tests
#include "base/callback.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
namespace base {
......
......@@ -7,21 +7,23 @@
#ifndef BASE_BITS_H_
#define BASE_BITS_H_
#include "base/basictypes.h"
#include <stddef.h>
#include <stdint.h>
#include "base/logging.h"
namespace base {
namespace bits {
// Returns the integer i such as 2^i <= n < 2^(i+1)
inline int Log2Floor(uint32 n) {
inline int Log2Floor(uint32_t n) {
if (n == 0)
return -1;
int log = 0;
uint32 value = n;
uint32_t value = n;
for (int i = 4; i >= 0; --i) {
int shift = (1 << i);
uint32 x = value >> shift;
uint32_t x = value >> shift;
if (x != 0) {
value = x;
log += shift;
......@@ -32,7 +34,7 @@ inline int Log2Floor(uint32 n) {
}
// Returns the integer i such as 2^(i-1) < n <= 2^i
inline int Log2Ceiling(uint32 n) {
inline int Log2Ceiling(uint32_t n) {
if (n == 0) {
return -1;
} else {
......
......@@ -6,6 +6,8 @@
#include "base/bits.h"
#include <stddef.h>
#include <limits>
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -14,9 +14,9 @@
#ifndef BASE_CALLBACK_HELPERS_H_
#define BASE_CALLBACK_HELPERS_H_
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
namespace base {
......
......@@ -7,11 +7,11 @@
#include <list>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/callback_internal.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
// OVERVIEW:
......
......@@ -6,9 +6,9 @@
#include <utility>
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
namespace base {
......
......@@ -48,6 +48,7 @@
#include "base/callback_internal.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
namespace base {
......
......@@ -7,9 +7,9 @@
#include <algorithm>
#include <ostream>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
......
......@@ -5,11 +5,12 @@
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
......
......@@ -112,7 +112,7 @@
// Return the byte alignment of the given type (available at compile time).
// Use like:
// ALIGNOF(int32) // this would be 4
// ALIGNOF(int32_t) // this would be 4
#if defined(COMPILER_MSVC)
#define ALIGNOF(type) __alignof(type)
#elif defined(COMPILER_GCC)
......
......@@ -21,9 +21,11 @@
#ifndef BASE_CONTAINERS_HASH_TABLES_H_
#define BASE_CONTAINERS_HASH_TABLES_H_
#include <stddef.h>
#include <stdint.h>
#include <utility>
#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
......@@ -196,19 +198,19 @@ using hash_set = BASE_HASH_IMPL_NAMESPACE::hash_set<Key, Hash, Pred, Alloc>;
// h32(x32, y32) = (h64(x32, y32) * rand_odd64 + rand16 * 2^16) % 2^64 / 2^32
//
// Contact danakj@chromium.org for any questions.
inline std::size_t HashInts32(uint32 value1, uint32 value2) {
uint64 value1_64 = value1;
uint64 hash64 = (value1_64 << 32) | value2;
inline std::size_t HashInts32(uint32_t value1, uint32_t value2) {
uint64_t value1_64 = value1;
uint64_t hash64 = (value1_64 << 32) | value2;
if (sizeof(std::size_t) >= sizeof(uint64))
if (sizeof(std::size_t) >= sizeof(uint64_t))
return static_cast<std::size_t>(hash64);
uint64 odd_random = 481046412LL << 32 | 1025306955LL;
uint32 shift_random = 10121U << 16;
uint64_t odd_random = 481046412LL << 32 | 1025306955LL;
uint32_t shift_random = 10121U << 16;
hash64 = hash64 * odd_random + shift_random;
std::size_t high_bits = static_cast<std::size_t>(
hash64 >> (8 * (sizeof(uint64) - sizeof(std::size_t))));
hash64 >> (8 * (sizeof(uint64_t) - sizeof(std::size_t))));
return high_bits;
}
......@@ -217,33 +219,33 @@ inline std::size_t HashInts32(uint32 value1, uint32 value2) {
// breaking the two 64-bit inputs into 4 32-bit values:
// http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECTION00832000000000000000
// Then we reduce our result to 32 bits if required, similar to above.
inline std::size_t HashInts64(uint64 value1, uint64 value2) {
uint32 short_random1 = 842304669U;
uint32 short_random2 = 619063811U;
uint32 short_random3 = 937041849U;
uint32 short_random4 = 3309708029U;
inline std::size_t HashInts64(uint64_t value1, uint64_t value2) {
uint32_t short_random1 = 842304669U;
uint32_t short_random2 = 619063811U;
uint32_t short_random3 = 937041849U;
uint32_t short_random4 = 3309708029U;
uint32 value1a = static_cast<uint32>(value1 & 0xffffffff);
uint32 value1b = static_cast<uint32>((value1 >> 32) & 0xffffffff);
uint32 value2a = static_cast<uint32>(value2 & 0xffffffff);
uint32 value2b = static_cast<uint32>((value2 >> 32) & 0xffffffff);