Add .clang-format and run clang-format on runtime/platform.

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2470663006 .
This commit is contained in:
Zachary Anderson 2016-11-03 14:25:16 -07:00
parent 0de5c9a03f
commit 6953586716
16 changed files with 212 additions and 193 deletions

16
.clang-format Normal file
View file

@ -0,0 +1,16 @@
# Defines the Chromium style for automatic reformatting.
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Chromium
# Keep up to 2 blank lines. More blank lines are removed.
MaxEmptyLinesToKeep: 2
# clang-format doesn't seem to do a good job of this for longer comments.
ReflowComments: 'false'
# We have lots of these. Though we need to put them all in curly braces,
# clang-format can't do that.
AllowShortIfStatementsOnASingleLine: 'true'
# Put escaped newlines into the rightmost column.
AlignEscapedNewlinesLeft: false

View file

@ -11,13 +11,17 @@
// told about areas where the VM does the equivalent of a long-jump.
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
extern "C" void __asan_unpoison_memory_region(void *, size_t);
extern "C" void __asan_unpoison_memory_region(void*, size_t);
#define ASAN_UNPOISON(ptr, len) __asan_unpoison_memory_region(ptr, len)
#else // __has_feature(address_sanitizer)
#define ASAN_UNPOISON(ptr, len) do {} while (false && (ptr) == 0 && (len) == 0)
#define ASAN_UNPOISON(ptr, len) \
do { \
} while (false && (ptr) == 0 && (len) == 0)
#endif // __has_feature(address_sanitizer)
#else // defined(__has_feature)
#define ASAN_UNPOISON(ptr, len) do {} while (false && (ptr) == 0 && (len) == 0)
#else // defined(__has_feature)
#define ASAN_UNPOISON(ptr, len) \
do { \
} while (false && (ptr) == 0 && (len) == 0)
#endif // defined(__has_feature)
#endif // RUNTIME_PLATFORM_ADDRESS_SANITIZER_H_

View file

@ -28,9 +28,7 @@ void DynamicAssertionHelper::Fail(const char* format, ...) {
va_list arguments;
va_start(arguments, format);
vsnprintf(buffer + file_and_line_length,
sizeof(buffer) - file_and_line_length,
format,
arguments);
sizeof(buffer) - file_and_line_length, format, arguments);
va_end(arguments);
// Print the buffer on stderr and/or syslog.

View file

@ -26,51 +26,48 @@ namespace dart {
class DynamicAssertionHelper {
public:
enum Kind {
ASSERT,
EXPECT
};
enum Kind { ASSERT, EXPECT };
DynamicAssertionHelper(const char* file, int line, Kind kind)
: file_(file), line_(line), kind_(kind) { }
: file_(file), line_(line), kind_(kind) {}
void Fail(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
static bool failed() { return failed_; }
#if defined(TESTING)
template<typename E, typename A>
template <typename E, typename A>
void Equals(const E& expected, const A& actual);
template<typename E, typename A>
template <typename E, typename A>
void NotEquals(const E& not_expected, const A& actual);
template<typename E, typename A, typename T>
template <typename E, typename A, typename T>
void FloatEquals(const E& expected, const A& actual, const T& tol);
template<typename E, typename A>
template <typename E, typename A>
void StringEquals(const E& expected, const A& actual);
template<typename E, typename A>
template <typename E, typename A>
void IsSubstring(const E& needle, const A& haystack);
template<typename E, typename A>
template <typename E, typename A>
void IsNotSubstring(const E& needle, const A& haystack);
template<typename E, typename A>
template <typename E, typename A>
void LessThan(const E& left, const A& right);
template<typename E, typename A>
template <typename E, typename A>
void LessEqual(const E& left, const A& right);
template<typename E, typename A>
template <typename E, typename A>
void GreaterThan(const E& left, const A& right);
template<typename E, typename A>
template <typename E, typename A>
void GreaterEqual(const E& left, const A& right);
#endif
template<typename T>
template <typename T>
T NotNull(const T p);
private:
@ -84,24 +81,24 @@ class DynamicAssertionHelper {
};
class Assert: public DynamicAssertionHelper {
class Assert : public DynamicAssertionHelper {
public:
Assert(const char* file, int line)
: DynamicAssertionHelper(file, line, ASSERT) { }
: DynamicAssertionHelper(file, line, ASSERT) {}
};
class Expect: public DynamicAssertionHelper {
class Expect : public DynamicAssertionHelper {
public:
Expect(const char* file, int line)
: DynamicAssertionHelper(file, line, EXPECT) { }
: DynamicAssertionHelper(file, line, EXPECT) {}
};
#if defined(TESTING)
// Only allow the expensive (with respect to code size) assertions
// in testing code.
template<typename E, typename A>
template <typename E, typename A>
void DynamicAssertionHelper::Equals(const E& expected, const A& actual) {
if (actual == expected) return;
std::ostringstream ess, ass;
@ -112,9 +109,8 @@ void DynamicAssertionHelper::Equals(const E& expected, const A& actual) {
}
template<typename E, typename A>
void DynamicAssertionHelper::NotEquals(const E& not_expected,
const A& actual) {
template <typename E, typename A>
void DynamicAssertionHelper::NotEquals(const E& not_expected, const A& actual) {
if (actual != not_expected) return;
std::ostringstream ness;
ness << not_expected;
@ -123,7 +119,7 @@ void DynamicAssertionHelper::NotEquals(const E& not_expected,
}
template<typename E, typename A, typename T>
template <typename E, typename A, typename T>
void DynamicAssertionHelper::FloatEquals(const E& expected,
const A& actual,
const T& tol) {
@ -135,16 +131,14 @@ void DynamicAssertionHelper::FloatEquals(const E& expected,
ass << actual;
tolss << tol;
std::string es = ess.str(), as = ass.str(), tols = tolss.str();
Fail("expected: <%s> but was: <%s> (tolerance: <%s>)",
es.c_str(),
as.c_str(),
Fail("expected: <%s> but was: <%s> (tolerance: <%s>)", es.c_str(), as.c_str(),
tols.c_str());
}
template<typename E, typename A>
NO_SANITIZE_MEMORY
void DynamicAssertionHelper::StringEquals(const E& expected, const A& actual) {
template <typename E, typename A>
NO_SANITIZE_MEMORY void DynamicAssertionHelper::StringEquals(const E& expected,
const A& actual) {
std::ostringstream ess, ass;
ess << expected;
ass << actual;
@ -154,34 +148,34 @@ void DynamicAssertionHelper::StringEquals(const E& expected, const A& actual) {
}
template<typename E, typename A>
NO_SANITIZE_MEMORY
void DynamicAssertionHelper::IsSubstring(const E& needle, const A& haystack) {
template <typename E, typename A>
NO_SANITIZE_MEMORY void DynamicAssertionHelper::IsSubstring(const E& needle,
const A& haystack) {
std::ostringstream ess, ass;
ess << needle;
ass << haystack;
std::string es = ess.str(), as = ass.str();
if (as.find(es) != std::string::npos) return;
Fail("expected <\"%s\"> to be a substring of <\"%s\">",
es.c_str(), as.c_str());
Fail("expected <\"%s\"> to be a substring of <\"%s\">", es.c_str(),
as.c_str());
}
template<typename E, typename A>
NO_SANITIZE_MEMORY
void DynamicAssertionHelper::IsNotSubstring(const E& needle,
const A& haystack) {
template <typename E, typename A>
NO_SANITIZE_MEMORY void DynamicAssertionHelper::IsNotSubstring(
const E& needle,
const A& haystack) {
std::ostringstream ess, ass;
ess << needle;
ass << haystack;
std::string es = ess.str(), as = ass.str();
if (as.find(es) == std::string::npos) return;
Fail("expected <\"%s\"> to not be a substring of <\"%s\">",
es.c_str(), as.c_str());
Fail("expected <\"%s\"> to not be a substring of <\"%s\">", es.c_str(),
as.c_str());
}
template<typename E, typename A>
template <typename E, typename A>
void DynamicAssertionHelper::LessThan(const E& left, const A& right) {
if (left < right) return;
std::ostringstream ess, ass;
@ -192,7 +186,7 @@ void DynamicAssertionHelper::LessThan(const E& left, const A& right) {
}
template<typename E, typename A>
template <typename E, typename A>
void DynamicAssertionHelper::LessEqual(const E& left, const A& right) {
if (left <= right) return;
std::ostringstream ess, ass;
@ -203,7 +197,7 @@ void DynamicAssertionHelper::LessEqual(const E& left, const A& right) {
}
template<typename E, typename A>
template <typename E, typename A>
void DynamicAssertionHelper::GreaterThan(const E& left, const A& right) {
if (left > right) return;
std::ostringstream ess, ass;
@ -214,7 +208,7 @@ void DynamicAssertionHelper::GreaterThan(const E& left, const A& right) {
}
template<typename E, typename A>
template <typename E, typename A>
void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) {
if (left >= right) return;
std::ostringstream ess, ass;
@ -226,7 +220,7 @@ void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) {
#endif
template<typename T>
template <typename T>
T DynamicAssertionHelper::NotNull(const T p) {
if (p != NULL) return p;
Fail("expected: not NULL, found NULL");
@ -236,11 +230,9 @@ T DynamicAssertionHelper::NotNull(const T p) {
} // namespace dart
#define FATAL(error) \
dart::Assert(__FILE__, __LINE__).Fail("%s", error)
#define FATAL(error) dart::Assert(__FILE__, __LINE__).Fail("%s", error)
#define FATAL1(format, p1) \
dart::Assert(__FILE__, __LINE__).Fail(format, (p1))
#define FATAL1(format, p1) dart::Assert(__FILE__, __LINE__).Fail(format, (p1))
#define FATAL2(format, p1, p2) \
dart::Assert(__FILE__, __LINE__).Fail(format, (p1), (p2))
@ -248,14 +240,11 @@ T DynamicAssertionHelper::NotNull(const T p) {
#define FATAL3(format, p1, p2, p3) \
dart::Assert(__FILE__, __LINE__).Fail(format, (p1), (p2), (p3))
#define UNIMPLEMENTED() \
FATAL("unimplemented code")
#define UNIMPLEMENTED() FATAL("unimplemented code")
#define UNREACHABLE() \
FATAL("unreachable code")
#define UNREACHABLE() FATAL("unreachable code")
#define OUT_OF_MEMORY() \
FATAL("Out of memory.")
#define OUT_OF_MEMORY() FATAL("Out of memory.")
#if defined(DEBUG)
@ -275,15 +264,16 @@ T DynamicAssertionHelper::NotNull(const T p) {
// Returns 'ptr'; useful for initializer lists:
// class Foo { Foo(int* ptr) : ptr_(ASSERT_NOTNULL(ptr)) ...
#define ASSERT_NOTNULL(ptr) \
dart::Assert(__FILE__, __LINE__).NotNull((ptr))
#define ASSERT_NOTNULL(ptr) dart::Assert(__FILE__, __LINE__).NotNull((ptr))
#else // if defined(DEBUG)
// In order to avoid variable unused warnings for code that only uses
// a variable in an ASSERT or EXPECT, we make sure to use the macro
// argument.
#define ASSERT(condition) do {} while (false && (condition))
#define ASSERT(condition) \
do { \
} while (false && (condition))
#define DEBUG_ASSERT(cond)
@ -310,8 +300,7 @@ T DynamicAssertionHelper::NotNull(const T p) {
//
template <bool>
struct CompileAssert {
};
struct CompileAssert {};
// Macro to concatenate two tokens. The helper is need to proper expansion
// in case an argument is a macro itself.
#if !defined(COMPILE_ASSERT)
@ -319,8 +308,8 @@ struct CompileAssert {
#define COMPILE_ASSERT_JOIN_HELPER(a, b) a##b
#define COMPILE_ASSERT(expr) \
DART_UNUSED typedef CompileAssert<(static_cast<bool>(expr))> \
COMPILE_ASSERT_JOIN(CompileAssertTypeDef, __LINE__)[static_cast<bool>(expr) \
? 1 : -1]
COMPILE_ASSERT_JOIN(CompileAssertTypeDef, \
__LINE__)[static_cast<bool>(expr) ? 1 : -1]
#endif // !defined(COMPILE_ASSERT)
#if defined(TESTING)
@ -365,14 +354,11 @@ struct CompileAssert {
#define EXPECT_GE(left, right) \
dart::Expect(__FILE__, __LINE__).GreaterEqual((left), (right))
#define EXPECT_NOTNULL(ptr) \
dart::Expect(__FILE__, __LINE__).NotNull((ptr))
#define EXPECT_NOTNULL(ptr) dart::Expect(__FILE__, __LINE__).NotNull((ptr))
#define FAIL(error) \
dart::Expect(__FILE__, __LINE__).Fail("%s", error)
#define FAIL(error) dart::Expect(__FILE__, __LINE__).Fail("%s", error)
#define FAIL1(format, p1) \
dart::Expect(__FILE__, __LINE__).Fail(format, (p1))
#define FAIL1(format, p1) dart::Expect(__FILE__, __LINE__).Fail(format, (p1))
#define FAIL2(format, p1, p2) \
dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2))

View file

@ -21,11 +21,10 @@ static const unsigned __int64 kQuietNaNMask =
#ifndef va_copy
#define va_copy(dst, src) (memmove(&(dst), &(src), sizeof(dst)))
#endif /* va_copy */
#endif /* va_copy */
#define NAN \
*reinterpret_cast<const double*>(&kQuietNaNMask)
#define NAN *reinterpret_cast<const double*>(&kQuietNaNMask)
namespace std {

View file

@ -5,7 +5,11 @@
#ifndef RUNTIME_PLATFORM_FLOATING_POINT_H_
#define RUNTIME_PLATFORM_FLOATING_POINT_H_
inline double fmod_ieee(double x, double y) { return fmod(x, y); }
inline double atan2_ieee(double y, double x) { return atan2(y, x); }
inline double fmod_ieee(double x, double y) {
return fmod(x, y);
}
inline double atan2_ieee(double y, double x) {
return atan2(y, x);
}
#endif // RUNTIME_PLATFORM_FLOATING_POINT_H_

View file

@ -38,9 +38,8 @@ double atan2_ieee(double x, double y) {
// Same is with index_y.
int index_x = (cls_x & _FPCLASS_PINF) != 0 ? 0 : 1;
int index_y = (cls_y & _FPCLASS_PINF) != 0 ? 0 : 1;
static double atans_at_infinities[2][2] =
{ { atan2(1., 1.), atan2(1., -1.) },
{ atan2(-1., 1.), atan2(-1., -1.) } };
static double atans_at_infinities[2][2] = {
{atan2(1., 1.), atan2(1., -1.)}, {atan2(-1., 1.), atan2(-1., -1.)}};
return atans_at_infinities[index_x][index_y];
} else {
return atan2(x, y);

View file

@ -195,9 +195,7 @@ struct simd128_value_t {
v[0] = double_storage[0];
v[1] = double_storage[1];
}
void writeTo(simd128_value_t* v) {
*v = *this;
}
void writeTo(simd128_value_t* v) { *v = *this; }
};
// Processor architecture detection. For more info on what's defined, see:
@ -228,18 +226,17 @@ typedef simd128_value_t fpu_register_t;
typedef struct {
union {
uint32_t u;
float f;
float f;
} data_[4];
} simd_value_t;
typedef simd_value_t fpu_register_t;
#define simd_value_safe_load(addr) \
(*reinterpret_cast<simd_value_t *>(addr))
#define simd_value_safe_load(addr) (*reinterpret_cast<simd_value_t*>(addr))
#define simd_value_safe_store(addr, value) \
do { \
reinterpret_cast<simd_value_t *>(addr)->data_[0] = value.data_[0]; \
reinterpret_cast<simd_value_t *>(addr)->data_[1] = value.data_[1]; \
reinterpret_cast<simd_value_t *>(addr)->data_[2] = value.data_[2]; \
reinterpret_cast<simd_value_t *>(addr)->data_[3] = value.data_[3]; \
reinterpret_cast<simd_value_t*>(addr)->data_[0] = value.data_[0]; \
reinterpret_cast<simd_value_t*>(addr)->data_[1] = value.data_[1]; \
reinterpret_cast<simd_value_t*>(addr)->data_[2] = value.data_[2]; \
reinterpret_cast<simd_value_t*>(addr)->data_[3] = value.data_[3]; \
} while (0)
#elif defined(__MIPSEL__)
@ -335,14 +332,12 @@ typedef simd128_value_t fpu_register_t;
// Verify that host and target architectures match, we cannot
// have a 64 bit Dart VM generating 32 bit code or vice-versa.
#if defined(TARGET_ARCH_X64) || \
defined(TARGET_ARCH_ARM64)
#if defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM64)
#if !defined(ARCH_IS_64_BIT)
#error Mismatched Host/Target architectures.
#endif
#elif defined(TARGET_ARCH_IA32) || \
defined(TARGET_ARCH_ARM) || \
defined(TARGET_ARCH_MIPS)
#elif defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM) || \
defined(TARGET_ARCH_MIPS)
#if !defined(ARCH_IS_32_BIT)
#error Mismatched Host/Target architectures.
#endif
@ -350,9 +345,9 @@ typedef simd128_value_t fpu_register_t;
// Determine whether we will be using the simulator.
#if defined(TARGET_ARCH_IA32)
// No simulator used.
// No simulator used.
#elif defined(TARGET_ARCH_X64)
// No simulator used.
// No simulator used.
#elif defined(TARGET_ARCH_ARM)
#if !defined(HOST_ARCH_ARM)
#define USING_SIMULATOR 1
@ -429,7 +424,7 @@ typedef simd128_value_t fpu_register_t;
// Usage: instead of writing 0x1234567890123456ULL
// write DART_2PART_UINT64_C(0x12345678,90123456);
#define DART_2PART_UINT64_C(a, b) \
(((static_cast<uint64_t>(a) << 32) + 0x##b##u))
(((static_cast<uint64_t>(a) << 32) + 0x##b##u))
// Integer constants.
const int32_t kMinInt32 = 0x80000000;
@ -457,11 +452,11 @@ typedef uint32_t classid_t;
// Byte sizes.
const int kWordSize = sizeof(word);
const int kDoubleSize = sizeof(double); // NOLINT
const int kFloatSize = sizeof(float); // NOLINT
const int kFloatSize = sizeof(float); // NOLINT
const int kQuadSize = 4 * kFloatSize;
const int kSimd128Size = sizeof(simd128_value_t); // NOLINT
const int kInt32Size = sizeof(int32_t); // NOLINT
const int kInt16Size = sizeof(int16_t); // NOLINT
const int kInt32Size = sizeof(int32_t); // NOLINT
const int kInt16Size = sizeof(int16_t); // NOLINT
#ifdef ARCH_IS_32_BIT
const int kWordSizeLog2 = 2;
const uword kUwordMax = kMaxUint32;
@ -510,13 +505,13 @@ const intptr_t kIntptrMax = ~kIntptrMin;
// Time constants.
const int kMillisecondsPerSecond = 1000;
const int kMicrosecondsPerMillisecond = 1000;
const int kMicrosecondsPerSecond = (kMicrosecondsPerMillisecond *
kMillisecondsPerSecond);
const int kMicrosecondsPerSecond =
(kMicrosecondsPerMillisecond * kMillisecondsPerSecond);
const int kNanosecondsPerMicrosecond = 1000;
const int kNanosecondsPerMillisecond = (kNanosecondsPerMicrosecond *
kMicrosecondsPerMillisecond);
const int kNanosecondsPerSecond = (kNanosecondsPerMicrosecond *
kMicrosecondsPerSecond);
const int kNanosecondsPerMillisecond =
(kNanosecondsPerMicrosecond * kMicrosecondsPerMillisecond);
const int kNanosecondsPerSecond =
(kNanosecondsPerMicrosecond * kMicrosecondsPerSecond);
// Helpers to scale micro second times to human understandable values.
inline double MicrosecondsToSeconds(int64_t micros) {
@ -530,7 +525,7 @@ inline double MicrosecondsToMilliseconds(int64_t micros) {
// This should be used in the private: declarations for a class.
#if !defined(DISALLOW_COPY_AND_ASSIGN)
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
private: \
private: \
TypeName(const TypeName&); \
void operator=(const TypeName&)
#endif // !defined(DISALLOW_COPY_AND_ASSIGN)
@ -542,7 +537,7 @@ private: \
// containing only static methods.
#if !defined(DISALLOW_IMPLICIT_CONSTRUCTORS)
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
private: \
private: \
TypeName(); \
DISALLOW_COPY_AND_ASSIGN(TypeName)
#endif // !defined(DISALLOW_IMPLICIT_CONSTRUCTORS)
@ -553,19 +548,20 @@ private: \
// platform/assert.h.
#if !defined(DISALLOW_ALLOCATION)
#define DISALLOW_ALLOCATION() \
public: \
public: \
void operator delete(void* pointer) { \
fprintf(stderr, "unreachable code\n"); \
abort(); \
} \
private: \
\
private: \
void* operator new(size_t size);
#endif // !defined(DISALLOW_ALLOCATION)
// The USE(x) template is used to silence C++ compiler warnings issued
// for unused variables.
template <typename T>
static inline void USE(T) { }
static inline void USE(T) {}
// Use implicit_cast as a safe version of static_cast or const_cast
@ -585,15 +581,15 @@ static inline void USE(T) { }
// implicit_cast would have been part of the C++ standard library,
// but the proposal was submitted too late. It will probably make
// its way into the language in the future.
template<typename To, typename From>
inline To implicit_cast(From const &f) {
template <typename To, typename From>
inline To implicit_cast(From const& f) {
return f;
}
// Use like this: down_cast<T*>(foo);
template<typename To, typename From> // use like this: down_cast<T*>(foo);
inline To down_cast(From* f) { // so we only accept pointers
template <typename To, typename From> // use like this: down_cast<T*>(foo);
inline To down_cast(From* f) { // so we only accept pointers
// Ensures that To is a sub-type of From *. This test is here only
// for compile-time type checking, and has no overhead in an
// optimized build at run-time, as it will be optimized away completely.
@ -647,12 +643,11 @@ inline D bit_cast(const S& source) {
// optimizations of GCC 4.4. Basically, GCC mindlessly relies on
// obscure details in the C++ standard that make reinterpret_cast
// virtually useless.
template<class D, class S>
template <class D, class S>
inline D bit_copy(const S& source) {
D destination;
// This use of memcpy is safe: source and destination cannot overlap.
memcpy(&destination,
reinterpret_cast<const void*>(&source),
memcpy(&destination, reinterpret_cast<const void*>(&source),
sizeof(destination));
return destination;
}
@ -691,7 +686,7 @@ static inline T ReadUnaligned(const T* ptr) {
// N.B.: As the GCC manual states, "[s]ince non-static C++ methods
// have an implicit 'this' argument, the arguments of such methods
// should be counted from two, not one."
#define PRINTF_ATTRIBUTE(string_index, first_to_check) \
#define PRINTF_ATTRIBUTE(string_index, first_to_check) \
__attribute__((__format__(__printf__, string_index, first_to_check)))
#else
#define PRINTF_ATTRIBUTE(string_index, first_to_check)

View file

@ -11,9 +11,9 @@ namespace dart {
class HashMap {
public:
typedef bool (*MatchFun) (void* key1, void* key2);
typedef bool (*MatchFun)(void* key1, void* key2);
typedef void (*ClearFun) (void* value);
typedef void (*ClearFun)(void* value);
// initial_capacity is the size of the initial hash map;
// it must be a power of 2 (and thus must not be 0).
@ -21,9 +21,7 @@ class HashMap {
~HashMap();
static bool SamePointerValue(void* key1, void* key2) {
return key1 == key2;
}
static bool SamePointerValue(void* key1, void* key2) { return key1 == key2; }
static uint32_t StringHash(char* key) {
uint32_t hash_ = 0;

View file

@ -11,15 +11,19 @@
// told about areas that are initialized by generated code.
#if defined(__has_feature)
#if __has_feature(memory_sanitizer)
extern "C" void __msan_unpoison(void *, size_t);
extern "C" void __msan_unpoison(void*, size_t);
#define MSAN_UNPOISON(ptr, len) __msan_unpoison(ptr, len)
#define NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
#else // __has_feature(memory_sanitizer)
#define MSAN_UNPOISON(ptr, len) do {} while (false && (ptr) == 0 && (len) == 0)
#define MSAN_UNPOISON(ptr, len) \
do { \
} while (false && (ptr) == 0 && (len) == 0)
#define NO_SANITIZE_MEMORY
#endif // __has_feature(memory_sanitizer)
#else // defined(__has_feature)
#define MSAN_UNPOISON(ptr, len) do {} while (false && (ptr) == 0 && (len) == 0)
#else // defined(__has_feature)
#define MSAN_UNPOISON(ptr, len) \
do { \
} while (false && (ptr) == 0 && (len) == 0)
#define NO_SANITIZE_MEMORY
#endif // defined(__has_feature)

View file

@ -57,51 +57,59 @@ class ThreadSignalBlocker {
// errors (type long int changed to intptr_t and do/while split on
// separate lines with body in {}s) and to also block signals.
#define TEMP_FAILURE_RETRY(expression) \
({ ThreadSignalBlocker tsb(SIGPROF); \
intptr_t __result; \
do { \
__result = (expression); \
} while ((__result == -1L) && (errno == EINTR)); \
__result; })
({ \
ThreadSignalBlocker tsb(SIGPROF); \
intptr_t __result; \
do { \
__result = (expression); \
} while ((__result == -1L) && (errno == EINTR)); \
__result; \
})
// This is a version of TEMP_FAILURE_RETRY which does not use the value
// returned from the expression.
#define VOID_TEMP_FAILURE_RETRY(expression) \
(static_cast<void>(TEMP_FAILURE_RETRY(expression)))
(static_cast<void>(TEMP_FAILURE_RETRY(expression)))
// This macro can be used to insert checks that a call is made, that
// was expected to not return EINTR, but did it anyway.
#define NO_RETRY_EXPECTED(expression) \
({ intptr_t __result = (expression); \
if (__result == -1L && errno == EINTR) { \
FATAL("Unexpected EINTR errno"); \
} \
__result; })
({ \
intptr_t __result = (expression); \
if (__result == -1L && errno == EINTR) { \
FATAL("Unexpected EINTR errno"); \
} \
__result; \
})
#define VOID_NO_RETRY_EXPECTED(expression) \
(static_cast<void>(NO_RETRY_EXPECTED(expression)))
(static_cast<void>(NO_RETRY_EXPECTED(expression)))
// Define to check in debug mode, if a signal is currently being blocked.
#define CHECK_IS_BLOCKING(signal) \
({ sigset_t signal_mask; \
int __r = pthread_sigmask(SIG_BLOCK, NULL, &signal_mask); \
USE(__r); \
ASSERT(__r == 0); \
sigismember(&signal_mask, signal); }) \
({ \
sigset_t signal_mask; \
int __r = pthread_sigmask(SIG_BLOCK, NULL, &signal_mask); \
USE(__r); \
ASSERT(__r == 0); \
sigismember(&signal_mask, signal); \
})
// Versions of the above, that does not enter a signal blocking scope. Use only
// when a signal blocking scope is entered manually.
#define TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression) \
({ intptr_t __result; \
ASSERT(CHECK_IS_BLOCKING(SIGPROF)); \
do { \
__result = (expression); \
} while ((__result == -1L) && (errno == EINTR)); \
__result; })
({ \
intptr_t __result; \
ASSERT(CHECK_IS_BLOCKING(SIGPROF)); \
do { \
__result = (expression); \
} while ((__result == -1L) && (errno == EINTR)); \
__result; \
})
#define VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression) \
(static_cast<void>(TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression)))
(static_cast<void>(TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression)))
} // namespace dart

View file

@ -52,8 +52,7 @@ void TextBuffer::AddChar(char ch) {
}
void TextBuffer::AddRaw(const uint8_t* buffer,
intptr_t buffer_length) {
void TextBuffer::AddRaw(const uint8_t* buffer, intptr_t buffer_length) {
EnsureCapacity(buffer_length);
memmove(&buf_[msg_len_], buffer, buffer_length);
msg_len_ += buffer_length;

View file

@ -24,8 +24,7 @@ class TextBuffer : ValueObject {
void EscapeAndAddCodeUnit(uint32_t cu);
void AddString(const char* s);
void AddEscapedString(const char* s);
void AddRaw(const uint8_t* buffer,
intptr_t buffer_length);
void AddRaw(const uint8_t* buffer, intptr_t buffer_length);
void Clear();

View file

@ -39,11 +39,26 @@ int Utils::HighestBit(int64_t v) {
uint64_t x = static_cast<uint64_t>((v > 0) ? v : -v);
uint64_t t;
int r = 0;
if ((t = x >> 32) != 0) { x = t; r += 32; }
if ((t = x >> 16) != 0) { x = t; r += 16; }
if ((t = x >> 8) != 0) { x = t; r += 8; }
if ((t = x >> 4) != 0) { x = t; r += 4; }
if ((t = x >> 2) != 0) { x = t; r += 2; }
if ((t = x >> 32) != 0) {
x = t;
r += 32;
}
if ((t = x >> 16) != 0) {
x = t;
r += 16;
}
if ((t = x >> 8) != 0) {
x = t;
r += 8;
}
if ((t = x >> 4) != 0) {
x = t;
r += 4;
}
if ((t = x >> 2) != 0) {
x = t;
r += 2;
}
if (x > 1) r += 1;
return r;
}

View file

@ -12,28 +12,28 @@ namespace dart {
class Utils {
public:
template<typename T>
template <typename T>
static inline T Minimum(T x, T y) {
return x < y ? x : y;
}
template<typename T>
template <typename T>
static inline T Maximum(T x, T y) {
return x > y ? x : y;
}
template<typename T>
template <typename T>
static inline T Abs(T x) {
if (x < 0) return -x;
return x;
}
template<typename T>
template <typename T>
static inline bool IsPowerOfTwo(T x) {
return ((x & (x - 1)) == 0) && (x != 0);
}
template<typename T>
template <typename T>
static inline int ShiftForPowerOfTwo(T x) {
ASSERT(IsPowerOfTwo(x));
int num_shifts = 0;
@ -44,34 +44,34 @@ class Utils {
return num_shifts;
}
template<typename T>
template <typename T>
static inline bool IsAligned(T x, intptr_t n) {
ASSERT(IsPowerOfTwo(n));
return (x & (n - 1)) == 0;
}
template<typename T>
template <typename T>
static inline bool IsAligned(T* x, intptr_t n) {
return IsAligned(reinterpret_cast<uword>(x), n);
}
template<typename T>
template <typename T>
static inline T RoundDown(T x, intptr_t n) {
ASSERT(IsPowerOfTwo(n));
return (x & -n);
}
template<typename T>
template <typename T>
static inline T* RoundDown(T* x, intptr_t n) {
return reinterpret_cast<T*>(RoundDown(reinterpret_cast<uword>(x), n));
}
template<typename T>
template <typename T>
static inline T RoundUp(T x, intptr_t n) {
return RoundDown(x + n - 1, n);
}
template<typename T>
template <typename T>
static inline T* RoundUp(T* x, intptr_t n) {
return reinterpret_cast<T*>(RoundUp(reinterpret_cast<uword>(x), n));
}
@ -97,7 +97,7 @@ class Utils {
static uint32_t WordHash(intptr_t key);
// Check whether an N-bit two's-complement representation can hold value.
template<typename T>
template <typename T>
static inline bool IsInt(int N, T value) {
ASSERT((0 < N) &&
(static_cast<unsigned int>(N) < (kBitsPerByte * sizeof(value))));
@ -105,7 +105,7 @@ class Utils {
return (-limit <= value) && (value < limit);
}
template<typename T>
template <typename T>
static inline bool IsUint(int N, T value) {
ASSERT((0 < N) &&
(static_cast<unsigned int>(N) < (kBitsPerByte * sizeof(value))));
@ -115,7 +115,7 @@ class Utils {
// Check whether the magnitude of value fits in N bits, i.e., whether an
// (N+1)-bit sign-magnitude representation can hold value.
template<typename T>
template <typename T>
static inline bool IsAbsoluteUint(int N, T value) {
ASSERT((0 < N) &&
(static_cast<unsigned int>(N) < (kBitsPerByte * sizeof(value))));
@ -143,14 +143,11 @@ class Utils {
return (static_cast<int64_t>(high) << 32) | (low & 0x0ffffffffLL);
}
static bool IsDecimalDigit(char c) {
return ('0' <= c) && (c <= '9');
}
static bool IsDecimalDigit(char c) { return ('0' <= c) && (c <= '9'); }
static bool IsHexDigit(char c) {
return IsDecimalDigit(c)
|| (('A' <= c) && (c <= 'F'))
|| (('a' <= c) && (c <= 'f'));
return IsDecimalDigit(c) || (('A' <= c) && (c <= 'F')) ||
(('a' <= c) && (c <= 'f'));
}
static int HexDigitToInt(char c) {
@ -172,9 +169,7 @@ class Utils {
static inline bool RangeCheck(intptr_t offset,
intptr_t count,
intptr_t length) {
return offset >= 0 &&
count >= 0 &&
length >= 0 &&
return offset >= 0 && count >= 0 && length >= 0 &&
count <= (length - offset);
}

View file

@ -62,8 +62,8 @@ inline uint64_t Utils::HostToLittleEndian64(uint64_t value) {
inline char* Utils::StrError(int err, char* buffer, size_t bufsize) {
#if !defined(__GLIBC__) || \
((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)
#if !defined(__GLIBC__) || \
((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)
// Use the XSI version.
if (strerror_r(err, buffer, bufsize) != 0) {
snprintf(buffer, bufsize, "%s", "strerror_r failed");