mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
3e510176c2
Prevent Android's STLPort from undefining global functions from math.h when cmath is included after math.h. The Android STLPort does not provide std::assert or std::atexit. Use the C versions of these functions on Android. BUG= Review URL: https://codereview.chromium.org//10968027 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@12741 260f80e4-7a28-3924-810f-c04153c831b5
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/assert.h"
|
|
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
#include "platform/globals.h"
|
|
|
|
namespace dart {
|
|
|
|
// Exit with a failure code when we miss an EXPECT check.
|
|
static void failed_exit(void) {
|
|
exit(255);
|
|
}
|
|
|
|
void DynamicAssertionHelper::Fail(const char* format, ...) {
|
|
std::ostringstream stream;
|
|
stream << file_ << ":" << line_ << ": error: ";
|
|
|
|
va_list arguments;
|
|
va_start(arguments, format);
|
|
char buffer[2 * KB];
|
|
vsnprintf(buffer, sizeof(buffer), format, arguments);
|
|
va_end(arguments);
|
|
stream << buffer << std::endl;
|
|
|
|
// Get the message from the string stream and dump it on stderr.
|
|
std::string message = stream.str();
|
|
fprintf(stderr, "%s", message.c_str());
|
|
|
|
// In case of failed assertions, abort right away. Otherwise, wait
|
|
// until the program is exiting before producing a non-zero exit
|
|
// code through abort.
|
|
// TODO(5411324): replace std::abort with OS::Abort so that we can handle
|
|
// restoring of signal handlers before aborting.
|
|
if (kind_ == ASSERT) {
|
|
abort();
|
|
}
|
|
static bool failed = false;
|
|
if (!failed) {
|
|
atexit(&failed_exit);
|
|
}
|
|
failed = true;
|
|
}
|
|
|
|
} // namespace dart
|