Skip to content

Commit

Permalink
Remove arraysize.
Browse files Browse the repository at this point in the history
BUG=837308

Change-Id: I91071794afd9915486548196ae09831c7093664b
Reviewed-on: https://chromium-review.googlesource.com/c/1390417
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Mark Mentovai <[email protected]>
Commit-Queue: Avi Drissman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#621760}
  • Loading branch information
Avi Drissman authored and Commit Bot committed Jan 10, 2019
1 parent ad40660 commit 72b4cba
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 68 deletions.
9 changes: 0 additions & 9 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,6 @@
r'.*[\\/]tools[\\/].*\.(cc|h)$',
),
),
(
r'/\barraysize\b',
(
"arraysize is deprecated, please use base::size(array) instead ",
"(https://crbug.com/837308). ",
),
False,
(),
),
(
r'std::random_shuffle',
(
Expand Down
6 changes: 3 additions & 3 deletions base/debug/stack_trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <sstream>

#include "base/logging.h"
#include "base/macros.h"
#include "base/stl_util.h"

#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)

Expand Down Expand Up @@ -200,10 +200,10 @@ uintptr_t GetStackEnd() {
}
#endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)

StackTrace::StackTrace() : StackTrace(arraysize(trace_)) {}
StackTrace::StackTrace() : StackTrace(base::size(trace_)) {}

StackTrace::StackTrace(const void* const* trace, size_t count) {
count = std::min(count, arraysize(trace_));
count = std::min(count, base::size(trace_));
if (count)
memcpy(trace_, trace, count * sizeof(trace_[0]));
count_ = count;
Expand Down
3 changes: 2 additions & 1 deletion base/debug/stack_trace_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <ostream>

#include "base/debug/proc_maps_linux.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"

Expand Down Expand Up @@ -70,7 +71,7 @@ bool EnableInProcessStackDumping() {
}

StackTrace::StackTrace(size_t count) {
count = std::min(arraysize(trace_), count);
count = std::min(base::size(trace_), count);

StackCrawlState state(reinterpret_cast<uintptr_t*>(trace_), count);
_Unwind_Backtrace(&TraceStackFrame, &state);
Expand Down
6 changes: 4 additions & 2 deletions base/debug/stack_trace_fuchsia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
#include <array>
#include <iomanip>
#include <iostream>
#include <type_traits>

#include "base/logging.h"
#include "base/stl_util.h"

namespace base {
namespace debug {

namespace {

const char kProcessNamePrefix[] = "app:";
const size_t kProcessNamePrefixLen = arraysize(kProcessNamePrefix) - 1;
const size_t kProcessNamePrefixLen = base::size(kProcessNamePrefix) - 1;

struct BacktraceData {
void** trace_array;
Expand Down Expand Up @@ -105,7 +107,7 @@ void SymbolMap::Populate() {
// TODO(wez): Object names can only have up to ZX_MAX_NAME_LEN characters, so
// if we keep hitting problems with truncation, find a way to plumb argv[0]
// through to here instead, e.g. using CommandLine::GetProgramName().
char app_name[arraysize(SymbolMap::Entry::name)];
char app_name[std::extent<decltype(SymbolMap::Entry::name)>()];
strcpy(app_name, kProcessNamePrefix);
zx_status_t status = zx_object_get_property(
process, ZX_PROP_NAME, app_name + kProcessNamePrefixLen,
Expand Down
12 changes: 6 additions & 6 deletions base/debug/stack_trace_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
#include "base/debug/debugger.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/free_deleter.h"
#include "base/memory/singleton.h"
#include "base/numerics/safe_conversions.h"
#include "base/posix/eintr_wrapper.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
Expand Down Expand Up @@ -400,7 +400,7 @@ void StackDumpSignalHandler(int signal, siginfo_t* info, void* void_context) {
const int kRegisterPadding = 16;
#endif

for (size_t i = 0; i < arraysize(registers); i++) {
for (size_t i = 0; i < base::size(registers); i++) {
PrintToStderr(registers[i].label);
internal::itoa_r(registers[i].value, buf, sizeof(buf),
16, kRegisterPadding);
Expand Down Expand Up @@ -813,11 +813,11 @@ StackTrace::StackTrace(size_t count) {
// stack dumping signal handler). NO malloc or stdio is allowed here.

#if !defined(__UCLIBC__) && !defined(_AIX)
count = std::min(arraysize(trace_), count);
count = std::min(base::size(trace_), count);

// Though the backtrace API man page does not list any possible negative
// return values, we take no chance.
count_ = base::saturated_cast<size_t>(backtrace(trace_, count));
// Though the backtrace API man page does not list any possible negative
// return values, we take no chance.
count_ = base::saturated_cast<size_t>(backtrace(trace_, count));
#else
count_ = 0;
#endif
Expand Down
20 changes: 7 additions & 13 deletions base/debug/stack_trace_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "base/stl_util.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"

Expand Down Expand Up @@ -275,7 +275,7 @@ bool EnableInProcessStackDumping() {
}

NOINLINE StackTrace::StackTrace(size_t count) {
count = std::min(arraysize(trace_), count);
count = std::min(base::size(trace_), count);

// When walking our own stack, use CaptureStackBackTrace().
count_ = CaptureStackBackTrace(0, count, trace_, NULL);
Expand Down Expand Up @@ -324,20 +324,14 @@ void StackTrace::InitTrace(const CONTEXT* context_record) {
stack_frame.AddrPC.Mode = AddrModeFlat;
stack_frame.AddrFrame.Mode = AddrModeFlat;
stack_frame.AddrStack.Mode = AddrModeFlat;
while (StackWalk64(machine_type,
GetCurrentProcess(),
GetCurrentThread(),
&stack_frame,
&context_copy,
NULL,
&SymFunctionTableAccess64,
&SymGetModuleBase64,
NULL) &&
count_ < arraysize(trace_)) {
while (StackWalk64(machine_type, GetCurrentProcess(), GetCurrentThread(),
&stack_frame, &context_copy, NULL,
&SymFunctionTableAccess64, &SymGetModuleBase64, NULL) &&
count_ < base::size(trace_)) {
trace_[count_++] = reinterpret_cast<void*>(stack_frame.AddrPC.Offset);
}

for (size_t i = count_; i < arraysize(trace_); ++i)
for (size_t i = count_; i < base::size(trace_); ++i)
trace_[i] = NULL;
}

Expand Down
3 changes: 2 additions & 1 deletion base/i18n/utf8_validator_tables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// DO NOT EDIT.

#include "base/i18n/utf8_validator_tables.h"
#include "base/stl_util.h"

namespace base {
namespace internal {
Expand Down Expand Up @@ -49,7 +50,7 @@ const uint8_t kUtf8ValidatorTables[] = {
0x81, // 0xa8
};

const size_t kUtf8ValidatorTablesSize = arraysize(kUtf8ValidatorTables);
const size_t kUtf8ValidatorTablesSize = base::size(kUtf8ValidatorTables);

} // namespace internal
} // namespace base
17 changes: 0 additions & 17 deletions base/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#ifndef BASE_MACROS_H_
#define BASE_MACROS_H_

#include <stddef.h> // For size_t.

// Put this in the declarations for a class to be uncopyable.
#define DISALLOW_COPY(TypeName) \
TypeName(const TypeName&) = delete
Expand All @@ -31,21 +29,6 @@
TypeName() = delete; \
DISALLOW_COPY_AND_ASSIGN(TypeName)

// The arraysize(arr) macro returns the # of elements in an array arr. The
// expression is a compile-time constant, and therefore can be used in defining
// new arrays, for example. If you use arraysize on a pointer by mistake, you
// will get a compile-time error. For the technical details, refer to
// http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx.

// This template function declaration is used in defining arraysize.
// Note that the function doesn't need an implementation, as we only
// use its type.
//
// DEPRECATED, please use base::size(array) instead.
// TODO(https://crbug.com/837308): Replace existing arraysize usages.
template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))

// Used to explicitly mark the return value of a function as unused. If you are
// really sure you don't want to do anything with the return value of a function
// that has been marked WARN_UNUSED_RESULT, wrap it with this. Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/callback.h"
#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/atomic_flag.h"
#include "base/task/task_scheduler/delayed_task_manager.h"
Expand Down Expand Up @@ -371,14 +372,17 @@ SchedulerSingleThreadTaskRunnerManager::SchedulerSingleThreadTaskRunnerManager(
DCHECK(task_tracker_);
DCHECK(delayed_task_manager_);
#if defined(OS_WIN)
static_assert(arraysize(shared_com_scheduler_workers_) ==
arraysize(shared_scheduler_workers_),
"The size of |shared_com_scheduler_workers_| must match "
"|shared_scheduler_workers_|");
static_assert(arraysize(shared_com_scheduler_workers_[0]) ==
arraysize(shared_scheduler_workers_[0]),
static_assert(std::extent<decltype(shared_com_scheduler_workers_)>() ==
std::extent<decltype(shared_scheduler_workers_)>(),
"The size of |shared_com_scheduler_workers_| must match "
"|shared_scheduler_workers_|");
static_assert(
std::extent<std::remove_reference<decltype(
shared_com_scheduler_workers_[0])>>() ==
std::extent<
std::remove_reference<decltype(shared_scheduler_workers_[0])>>(),
"The size of |shared_com_scheduler_workers_| must match "
"|shared_scheduler_workers_|");
#endif // defined(OS_WIN)
DCHECK(!g_manager_is_alive);
g_manager_is_alive = true;
Expand Down Expand Up @@ -610,8 +614,8 @@ void SchedulerSingleThreadTaskRunnerManager::ReleaseSharedSchedulerWorkers() {
#endif
{
AutoSchedulerLock auto_lock(lock_);
for (size_t i = 0; i < arraysize(shared_scheduler_workers_); ++i) {
for (size_t j = 0; j < arraysize(shared_scheduler_workers_[i]); ++j) {
for (size_t i = 0; i < base::size(shared_scheduler_workers_); ++i) {
for (size_t j = 0; j < base::size(shared_scheduler_workers_[i]); ++j) {
local_shared_scheduler_workers[i][j] = shared_scheduler_workers_[i][j];
shared_scheduler_workers_[i][j] = nullptr;
#if defined(OS_WIN)
Expand All @@ -623,8 +627,8 @@ void SchedulerSingleThreadTaskRunnerManager::ReleaseSharedSchedulerWorkers() {
}
}

for (size_t i = 0; i < arraysize(local_shared_scheduler_workers); ++i) {
for (size_t j = 0; j < arraysize(local_shared_scheduler_workers[i]); ++j) {
for (size_t i = 0; i < base::size(local_shared_scheduler_workers); ++i) {
for (size_t j = 0; j < base::size(local_shared_scheduler_workers[i]); ++j) {
if (local_shared_scheduler_workers[i][j])
UnregisterSchedulerWorker(local_shared_scheduler_workers[i][j]);
#if defined(OS_WIN)
Expand Down
7 changes: 4 additions & 3 deletions base/task/task_scheduler/task_scheduler_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ TaskSchedulerImpl::TaskSchedulerImpl(
tracked_ref_factory_(this) {
DCHECK(!histogram_label.empty());

static_assert(arraysize(environment_to_worker_pool_) == ENVIRONMENT_COUNT,
"The size of |environment_to_worker_pool_| must match "
"ENVIRONMENT_COUNT.");
static_assert(
std::extent<decltype(environment_to_worker_pool_)>() == ENVIRONMENT_COUNT,
"The size of |environment_to_worker_pool_| must match "
"ENVIRONMENT_COUNT.");
static_assert(
size(kEnvironmentParams) == ENVIRONMENT_COUNT,
"The size of |kEnvironmentParams| must match ENVIRONMENT_COUNT.");
Expand Down
2 changes: 1 addition & 1 deletion chrome/app/nibs/generate_localizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
static const UILocalizerResourceMap kUIResources[] = {
%(resource_map_list)s };
static const size_t kUIResourcesSize = arraysize(kUIResources);
static const size_t kUIResourcesSize = base::size(kUIResources);
#endif // CHROME_APP_NIBS_LOCALIZER_TABLE_H_
'''
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/cocoa/ui_localizer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdlib.h>

#include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
Expand Down
3 changes: 2 additions & 1 deletion chrome_elf/nt_registry/nt_registry_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stddef.h>

#include "base/callback_helpers.h"
#include "base/stl_util.h"
#include "base/test/test_reg_util_win.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down Expand Up @@ -623,7 +624,7 @@ TEST_F(NtRegistryTest, ApiEnumeration) {
ASSERT_TRUE(nt::QueryRegSubkey(key_handle, i, &subkey_name));

bool found = false;
for (size_t index = 0; index < arraysize(check_names); index++) {
for (size_t index = 0; index < base::size(check_names); index++) {
if (0 == subkey_name.compare(check_names[index])) {
found = true;
break;
Expand Down
2 changes: 2 additions & 0 deletions mojo/core/ports/user_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef MOJO_CORE_PORTS_USER_MESSAGE_H_
#define MOJO_CORE_PORTS_USER_MESSAGE_H_

#include <stddef.h>

#include "base/component_export.h"
#include "base/macros.h"

Expand Down
3 changes: 2 additions & 1 deletion third_party/sudden_motion_sensor/sudden_motion_sensor_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

#include "base/logging.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/stl_util.h"

struct SuddenMotionSensor::GenericMacbookSensor {
// Name of device to be read.
Expand Down Expand Up @@ -338,7 +339,7 @@ bool SuddenMotionSensor::Init() {

// Look for the current model in the supported sensor list.
base::ScopedCFTypeRef<CFDataRef> board_id_data;
const int kNumSensors = arraysize(kSupportedSensors);
const int kNumSensors = base::size(kSupportedSensors);

for (int i = 0; i < kNumSensors; ++i) {
// Check if the supported sensor model name is a prefix
Expand Down

0 comments on commit 72b4cba

Please sign in to comment.