Skip to content

Commit

Permalink
Switch to standard integer types in base/memory/.
Browse files Browse the repository at this point in the history
BUG=138542
TBR=mark@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#366816}
  • Loading branch information
avi authored and Commit bot committed Dec 24, 2015
1 parent ebe805c commit 9beac25
Show file tree
Hide file tree
Showing 45 changed files with 147 additions and 94 deletions.
1 change: 1 addition & 0 deletions base/memory/aligned_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "base/memory/aligned_memory.h"

#include "base/logging.h"
#include "build/build_config.h"

#if defined(OS_ANDROID)
#include <malloc.h>
Expand Down
43 changes: 23 additions & 20 deletions base/memory/aligned_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
#ifndef BASE_MEMORY_ALIGNED_MEMORY_H_
#define BASE_MEMORY_ALIGNED_MEMORY_H_

#include <stddef.h>
#include <stdint.h>

#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"

#if defined(COMPILER_MSVC)
Expand All @@ -51,25 +53,26 @@ namespace base {
template <size_t Size, size_t ByteAlignment>
struct AlignedMemory {};

#define BASE_DECL_ALIGNED_MEMORY(byte_alignment) \
template <size_t Size> \
class AlignedMemory<Size, byte_alignment> { \
public: \
ALIGNAS(byte_alignment) uint8 data_[Size]; \
void* void_data() { return static_cast<void*>(data_); } \
const void* void_data() const { \
return static_cast<const void*>(data_); \
} \
template<typename Type> \
Type* data_as() { return static_cast<Type*>(void_data()); } \
template<typename Type> \
const Type* data_as() const { \
return static_cast<const Type*>(void_data()); \
} \
private: \
void* operator new(size_t); \
void operator delete(void*); \
}
#define BASE_DECL_ALIGNED_MEMORY(byte_alignment) \
template <size_t Size> \
class AlignedMemory<Size, byte_alignment> { \
public: \
ALIGNAS(byte_alignment) uint8_t data_[Size]; \
void* void_data() { return static_cast<void*>(data_); } \
const void* void_data() const { return static_cast<const void*>(data_); } \
template <typename Type> \
Type* data_as() { \
return static_cast<Type*>(void_data()); \
} \
template <typename Type> \
const Type* data_as() const { \
return static_cast<const Type*>(void_data()); \
} \
\
private: \
void* operator new(size_t); \
void operator delete(void*); \
}

// Specialization for all alignments is required because MSVC (as of VS 2008)
// does not understand ALIGNAS(ALIGNOF(Type)) or ALIGNAS(template_param).
Expand Down
1 change: 1 addition & 0 deletions base/memory/aligned_memory_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "base/memory/aligned_memory.h"
#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"

#define EXPECT_ALIGNED(ptr, align) \
Expand Down
1 change: 0 additions & 1 deletion base/memory/discardable_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define BASE_MEMORY_DISCARDABLE_MEMORY_H_

#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"

namespace base {
Expand Down
2 changes: 2 additions & 0 deletions base/memory/discardable_memory_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_
#define BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_

#include <stddef.h>

#include "base/base_export.h"
#include "base/memory/scoped_ptr.h"

Expand Down
27 changes: 15 additions & 12 deletions base/memory/discardable_shared_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

#include "base/memory/discardable_shared_memory.h"

#if defined(OS_POSIX) && !defined(OS_NACL)
// For madvise() which is available on all POSIX compatible systems.
#include <sys/mman.h>
#endif
#include <stdint.h>

#include <algorithm>

Expand All @@ -16,6 +13,12 @@
#include "base/logging.h"
#include "base/numerics/safe_math.h"
#include "base/process/process_metrics.h"
#include "build/build_config.h"

#if defined(OS_POSIX) && !defined(OS_NACL)
// For madvise() which is available on all POSIX compatible systems.
#include <sys/mman.h>
#endif

#if defined(OS_ANDROID)
#include "third_party/ashmem/ashmem.h"
Expand All @@ -38,28 +41,28 @@ typedef uintptr_t UAtomicType;
// does not have enough precision to contain a timestamp in the standard
// serialized format.
template <int>
Time TimeFromWireFormat(int64 value);
Time TimeFromWireFormat(int64_t value);
template <int>
int64 TimeToWireFormat(Time time);
int64_t TimeToWireFormat(Time time);

// Serialize to Unix time when using 4-byte wire format.
// Note: 19 January 2038, this will cease to work.
template <>
Time ALLOW_UNUSED_TYPE TimeFromWireFormat<4>(int64 value) {
Time ALLOW_UNUSED_TYPE TimeFromWireFormat<4>(int64_t value) {
return value ? Time::UnixEpoch() + TimeDelta::FromSeconds(value) : Time();
}
template <>
int64 ALLOW_UNUSED_TYPE TimeToWireFormat<4>(Time time) {
int64_t ALLOW_UNUSED_TYPE TimeToWireFormat<4>(Time time) {
return time > Time::UnixEpoch() ? (time - Time::UnixEpoch()).InSeconds() : 0;
}

// Standard serialization format when using 8-byte wire format.
template <>
Time ALLOW_UNUSED_TYPE TimeFromWireFormat<8>(int64 value) {
Time ALLOW_UNUSED_TYPE TimeFromWireFormat<8>(int64_t value) {
return Time::FromInternalValue(value);
}
template <>
int64 ALLOW_UNUSED_TYPE TimeToWireFormat<8>(Time time) {
int64_t ALLOW_UNUSED_TYPE TimeToWireFormat<8>(Time time) {
return time.ToInternalValue();
}

Expand All @@ -68,7 +71,7 @@ struct SharedState {

explicit SharedState(AtomicType ivalue) { value.i = ivalue; }
SharedState(LockState lock_state, Time timestamp) {
int64 wire_timestamp = TimeToWireFormat<sizeof(AtomicType)>(timestamp);
int64_t wire_timestamp = TimeToWireFormat<sizeof(AtomicType)>(timestamp);
DCHECK_GE(wire_timestamp, 0);
DCHECK_EQ(lock_state & ~1, 0);
value.u = (static_cast<UAtomicType>(wire_timestamp) << 1) | lock_state;
Expand Down Expand Up @@ -321,7 +324,7 @@ void DiscardableSharedMemory::Unlock(size_t offset, size_t length) {
}

void* DiscardableSharedMemory::memory() const {
return reinterpret_cast<uint8*>(shared_memory_.memory()) +
return reinterpret_cast<uint8_t*>(shared_memory_.memory()) +
AlignToPageSize(sizeof(SharedState));
}

Expand Down
4 changes: 4 additions & 0 deletions base/memory/discardable_shared_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
#ifndef BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_
#define BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_

#include <stddef.h>

#include "base/base_export.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/shared_memory.h"
#include "base/threading/thread_collision_warner.h"
#include "base/time/time.h"
#include "build/build_config.h"

#if DCHECK_IS_ON()
#include <set>
Expand Down
27 changes: 14 additions & 13 deletions base/memory/discardable_shared_memory_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/basictypes.h"
#include <stdint.h>

#include "base/memory/discardable_shared_memory.h"
#include "base/process/process_metrics.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand All @@ -27,7 +28,7 @@ class TestDiscardableSharedMemory : public DiscardableSharedMemory {
};

TEST(DiscardableSharedMemoryTest, CreateAndMap) {
const uint32 kDataSize = 1024;
const uint32_t kDataSize = 1024;

TestDiscardableSharedMemory memory;
bool rv = memory.CreateAndMap(kDataSize);
Expand All @@ -37,7 +38,7 @@ TEST(DiscardableSharedMemoryTest, CreateAndMap) {
}

TEST(DiscardableSharedMemoryTest, CreateFromHandle) {
const uint32 kDataSize = 1024;
const uint32_t kDataSize = 1024;

TestDiscardableSharedMemory memory1;
bool rv = memory1.CreateAndMap(kDataSize);
Expand All @@ -55,7 +56,7 @@ TEST(DiscardableSharedMemoryTest, CreateFromHandle) {
}

TEST(DiscardableSharedMemoryTest, LockAndUnlock) {
const uint32 kDataSize = 1024;
const uint32_t kDataSize = 1024;

TestDiscardableSharedMemory memory1;
bool rv = memory1.CreateAndMap(kDataSize);
Expand Down Expand Up @@ -109,7 +110,7 @@ TEST(DiscardableSharedMemoryTest, LockAndUnlock) {
}

TEST(DiscardableSharedMemoryTest, Purge) {
const uint32 kDataSize = 1024;
const uint32_t kDataSize = 1024;

TestDiscardableSharedMemory memory1;
bool rv = memory1.CreateAndMap(kDataSize);
Expand Down Expand Up @@ -151,7 +152,7 @@ TEST(DiscardableSharedMemoryTest, Purge) {
}

TEST(DiscardableSharedMemoryTest, LastUsed) {
const uint32 kDataSize = 1024;
const uint32_t kDataSize = 1024;

TestDiscardableSharedMemory memory1;
bool rv = memory1.CreateAndMap(kDataSize);
Expand Down Expand Up @@ -219,7 +220,7 @@ TEST(DiscardableSharedMemoryTest, LastUsed) {
}

TEST(DiscardableSharedMemoryTest, LockShouldAlwaysFailAfterSuccessfulPurge) {
const uint32 kDataSize = 1024;
const uint32_t kDataSize = 1024;

TestDiscardableSharedMemory memory1;
bool rv = memory1.CreateAndMap(kDataSize);
Expand All @@ -246,9 +247,9 @@ TEST(DiscardableSharedMemoryTest, LockShouldAlwaysFailAfterSuccessfulPurge) {
}

TEST(DiscardableSharedMemoryTest, LockAndUnlockRange) {
const uint32 kDataSize = 32;
const uint32_t kDataSize = 32;

uint32 data_size_in_bytes = kDataSize * base::GetPageSize();
uint32_t data_size_in_bytes = kDataSize * base::GetPageSize();

TestDiscardableSharedMemory memory1;
bool rv = memory1.CreateAndMap(data_size_in_bytes);
Expand Down Expand Up @@ -307,7 +308,7 @@ TEST(DiscardableSharedMemoryTest, LockAndUnlockRange) {
}

TEST(DiscardableSharedMemoryTest, MappedSize) {
const uint32 kDataSize = 1024;
const uint32_t kDataSize = 1024;

TestDiscardableSharedMemory memory;
bool rv = memory.CreateAndMap(kDataSize);
Expand All @@ -322,7 +323,7 @@ TEST(DiscardableSharedMemoryTest, MappedSize) {
}

TEST(DiscardableSharedMemoryTest, Close) {
const uint32 kDataSize = 1024;
const uint32_t kDataSize = 1024;

TestDiscardableSharedMemory memory;
bool rv = memory.CreateAndMap(kDataSize);
Expand All @@ -348,7 +349,7 @@ TEST(DiscardableSharedMemoryTest, Close) {
// defined and MADV_REMOVE is supported.
#if defined(DISCARDABLE_SHARED_MEMORY_ZERO_FILL_ON_DEMAND_PAGES_AFTER_PURGE)
TEST(DiscardableSharedMemoryTest, ZeroFilledPagesAfterPurge) {
const uint32 kDataSize = 1024;
const uint32_t kDataSize = 1024;

TestDiscardableSharedMemory memory1;
bool rv = memory1.CreateAndMap(kDataSize);
Expand Down Expand Up @@ -379,7 +380,7 @@ TEST(DiscardableSharedMemoryTest, ZeroFilledPagesAfterPurge) {

// Check that reading memory after it has been purged is returning
// zero-filled pages.
uint8 expected_data[kDataSize] = {};
uint8_t expected_data[kDataSize] = {};
EXPECT_EQ(memcmp(memory2.memory(), expected_data, kDataSize), 0);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion base/memory/memory_pressure_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#define BASE_MEMORY_MEMORY_PRESSURE_LISTENER_H_

#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/macros.h"

namespace base {

Expand Down
1 change: 1 addition & 0 deletions base/memory/memory_pressure_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_

#include "base/base_export.h"
#include "base/macros.h"
#include "base/memory/memory_pressure_listener.h"

namespace base {
Expand Down
2 changes: 1 addition & 1 deletion base/memory/memory_pressure_monitor_chromeos_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "base/memory/memory_pressure_monitor_chromeos.h"

#include "base/basictypes.h"
#include "base/macros.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/message_loop/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down
1 change: 1 addition & 0 deletions base/memory/memory_pressure_monitor_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "base/memory/memory_pressure_monitor_mac.h"

#include <dlfcn.h>
#include <stddef.h>
#include <sys/sysctl.h>

#include "base/mac/mac_util.h"
Expand Down
1 change: 1 addition & 0 deletions base/memory/memory_pressure_monitor_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <dispatch/dispatch.h>

#include "base/base_export.h"
#include "base/macros.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/memory_pressure_monitor.h"

Expand Down
1 change: 1 addition & 0 deletions base/memory/memory_pressure_monitor_mac_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "base/memory/memory_pressure_monitor_mac.h"

#include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
Expand Down
1 change: 1 addition & 0 deletions base/memory/memory_pressure_monitor_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_WIN_H_

#include "base/base_export.h"
#include "base/macros.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/memory_pressure_monitor.h"
#include "base/memory/weak_ptr.h"
Expand Down
2 changes: 1 addition & 1 deletion base/memory/memory_pressure_monitor_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "base/memory/memory_pressure_monitor_win.h"

#include "base/basictypes.h"
#include "base/macros.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/message_loop/message_loop.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand Down
2 changes: 2 additions & 0 deletions base/memory/ptr_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "base/memory/ptr_util.h"

#include <stddef.h>

#include "testing/gtest/include/gtest/gtest.h"

namespace base {
Expand Down
1 change: 1 addition & 0 deletions base/memory/ref_counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/atomic_ref_count.h"
#include "base/base_export.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#ifndef NDEBUG
#include "base/logging.h"
#endif
Expand Down
1 change: 1 addition & 0 deletions base/memory/ref_counted_delete_on_message_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"

Expand Down
Loading

0 comments on commit 9beac25

Please sign in to comment.