Skip to content

Commit e6101c5

Browse files
authored
Merge branch 'main' into std_func
2 parents a6a05c9 + 8d4fdd6 commit e6101c5

23 files changed

+92
-65
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
repos:
22
- repo: https://github.com/keith/pre-commit-buildifier
3-
rev: 8.0.0
3+
rev: 8.0.1
44
hooks:
55
- id: buildifier
66
- id: buildifier-lint
77
- repo: https://github.com/pre-commit/mirrors-mypy
8-
rev: v1.14.1
8+
rev: v1.15.0
99
hooks:
1010
- id: mypy
1111
types_or: [ python, pyi ]
1212
args: [ "--ignore-missing-imports", "--scripts-are-modules" ]
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.9.2
14+
rev: v0.9.6
1515
hooks:
1616
- id: ruff
1717
args: [ --fix, --exit-non-zero-on-fix ]

BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
13
licenses(["notice"])
24

35
COPTS = [

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ use_repo(pip, "tools_pip_deps")
3838

3939
# -- bazel_dep definitions -- #
4040

41-
bazel_dep(name = "nanobind_bazel", version = "2.4.0", dev_dependency = True)
41+
bazel_dep(name = "nanobind_bazel", version = "2.5.0", dev_dependency = True)

bindings/python/google_benchmark/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@nanobind_bazel//:build_defs.bzl", "nanobind_extension", "nanobind_stubgen")
2+
load("@rules_python//python:defs.bzl", "py_library", "py_test")
23

34
py_library(
45
name = "google_benchmark",

src/benchmark.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,17 @@ BM_DEFINE_int32(v, 0);
150150

151151
namespace internal {
152152

153+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
153154
std::map<std::string, std::string>* global_context = nullptr;
154155

155156
BENCHMARK_EXPORT std::map<std::string, std::string>*& GetGlobalContext() {
156157
return global_context;
157158
}
158159

159-
static void const volatile* volatile global_force_escape_pointer;
160+
namespace {
161+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
162+
void const volatile* volatile global_force_escape_pointer;
163+
} // namespace
160164

161165
// FIXME: Verify if LTO still messes this up?
162166
void UseCharPointer(char const volatile* const v) {

src/check.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace benchmark {
44
namespace internal {
55

6-
static AbortHandlerT* handler = &std::abort;
6+
namespace {
7+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
8+
AbortHandlerT* handler = &std::abort;
9+
} // namespace
710

811
BENCHMARK_EXPORT AbortHandlerT*& GetAbortHandler() { return handler; }
912

src/commandlineflags.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
#define FLAG(name) FLAGS_##name
1212

1313
// Macros for declaring flags.
14+
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
1415
#define BM_DECLARE_bool(name) BENCHMARK_EXPORT extern bool FLAG(name)
1516
#define BM_DECLARE_int32(name) BENCHMARK_EXPORT extern int32_t FLAG(name)
1617
#define BM_DECLARE_double(name) BENCHMARK_EXPORT extern double FLAG(name)
1718
#define BM_DECLARE_string(name) BENCHMARK_EXPORT extern std::string FLAG(name)
1819
#define BM_DECLARE_kvpairs(name) \
1920
BENCHMARK_EXPORT extern std::map<std::string, std::string> FLAG(name)
21+
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
2022

2123
// Macros for defining flags.
24+
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
2225
#define BM_DEFINE_bool(name, default_val) \
2326
BENCHMARK_EXPORT bool FLAG(name) = benchmark::BoolFromEnv(#name, default_val)
2427
#define BM_DEFINE_int32(name, default_val) \
@@ -33,6 +36,7 @@
3336
#define BM_DEFINE_kvpairs(name, default_val) \
3437
BENCHMARK_EXPORT std::map<std::string, std::string> FLAG(name) = \
3538
benchmark::KvPairsFromEnv(#name, default_val)
39+
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
3640

3741
namespace benchmark {
3842

src/cycleclock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
219219
#elif defined(__hexagon__)
220220
uint64_t pcycle;
221221
asm volatile("%0 = C15:14" : "=r"(pcycle));
222-
return static_cast<double>(pcycle);
222+
return static_cast<int64_t>(pcycle);
223223
#elif defined(__alpha__)
224224
// Alpha has a cycle counter, the PCC register, but it is an unsigned 32-bit
225225
// integer and thus wraps every ~4s, making using it for tick counts

src/re.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,13 @@ inline bool Regex::Init(const std::string& spec, std::string* error) {
121121
if (ec != 0) {
122122
if (error) {
123123
size_t needed = regerror(ec, &re_, nullptr, 0);
124-
char* errbuf = new char[needed];
125-
regerror(ec, &re_, errbuf, needed);
124+
std::vector<char> errbuf(needed);
125+
regerror(ec, &re_, errbuf.data(), needed);
126126

127127
// regerror returns the number of bytes necessary to null terminate
128128
// the string, so we move that when assigning to error.
129129
BM_CHECK_NE(needed, 0);
130-
error->assign(errbuf, needed - 1);
131-
132-
delete[] errbuf;
130+
error->assign(errbuf.data(), needed - 1);
133131
}
134132

135133
return false;

src/statistics.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace benchmark {
2828

29-
auto StatisticsSum = [](const std::vector<double>& v) {
29+
const auto StatisticsSum = [](const std::vector<double>& v) {
3030
return std::accumulate(v.begin(), v.end(), 0.0);
3131
};
3232

@@ -59,12 +59,12 @@ double StatisticsMedian(const std::vector<double>& v) {
5959
}
6060

6161
// Return the sum of the squares of this sample set
62-
auto SumSquares = [](const std::vector<double>& v) {
62+
const auto SumSquares = [](const std::vector<double>& v) {
6363
return std::inner_product(v.begin(), v.end(), v.begin(), 0.0);
6464
};
6565

66-
auto Sqr = [](const double dat) { return dat * dat; };
67-
auto Sqrt = [](const double dat) {
66+
const auto Sqr = [](const double dat) { return dat * dat; };
67+
const auto Sqrt = [](const double dat) {
6868
// Avoid NaN due to imprecision in the calculations
6969
if (dat < 0.0) {
7070
return 0.0;

0 commit comments

Comments
 (0)