mirror of
https://github.com/google/benchmark.git
synced 2025-03-31 06:30:35 +08:00
parent
c45f01866b
commit
95a1435b81
@ -73,22 +73,14 @@ BENCHMARK_NORETURN void PrintErrorAndDie(Args&&... args) {
|
|||||||
|
|
||||||
#ifdef BENCHMARK_HAS_SYSCTL
|
#ifdef BENCHMARK_HAS_SYSCTL
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
// Suppress the warning generated by the C11 flexible array member below.
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// ValueUnion - A type used to correctly alias the byte-for-byte output of
|
/// ValueUnion - A type used to correctly alias the byte-for-byte output of
|
||||||
/// `sysctl` with the result type it's to be interpreted as.
|
/// `sysctl` with the result type it's to be interpreted as.
|
||||||
struct ValueUnion {
|
struct ValueUnion {
|
||||||
union DataT {
|
union DataT {
|
||||||
uint32_t uint32_value;
|
uint32_t uint32_value;
|
||||||
uint64_t uint64_value;
|
uint64_t uint64_value;
|
||||||
// FIXME (Maybe?): This is a C11 flexible array member, and not technically
|
// For correct aliasing of union members from bytes.
|
||||||
// C++. However, all compilers support it and it allows for correct aliasing
|
char bytes[8];
|
||||||
// of union members from bytes.
|
|
||||||
char bytes[];
|
|
||||||
};
|
};
|
||||||
using DataPtr = std::unique_ptr<DataT, decltype(&std::free)>;
|
using DataPtr = std::unique_ptr<DataT, decltype(&std::free)>;
|
||||||
|
|
||||||
@ -137,10 +129,6 @@ struct ValueUnion {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ValueUnion GetSysctlImp(std::string const& Name) {
|
ValueUnion GetSysctlImp(std::string const& Name) {
|
||||||
size_t CurBuffSize = 0;
|
size_t CurBuffSize = 0;
|
||||||
if (sysctlbyname(Name.c_str(), nullptr, &CurBuffSize, nullptr, 0) == -1)
|
if (sysctlbyname(Name.c_str(), nullptr, &CurBuffSize, nullptr, 0) == -1)
|
||||||
@ -177,7 +165,7 @@ bool GetSysctl(std::string const& Name, std::array<Tp, N>* Out) {
|
|||||||
if (!Buff) return false;
|
if (!Buff) return false;
|
||||||
*Out = Buff.GetAsArray<Tp, N>();
|
*Out = Buff.GetAsArray<Tp, N>();
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <class ArgT>
|
template <class ArgT>
|
||||||
|
Loading…
Reference in New Issue
Block a user