OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #include <cstdlib> | |
6 #include <sstream> | |
7 #include <string> | |
8 | |
9 #include "vm/assert.h" | |
10 | |
11 namespace dart { | |
12 | |
13 // Exit with a failure code when we miss an EXPECT check. | |
14 static void failed_exit(void) { | |
15 exit(255); | |
16 } | |
17 | |
18 void DynamicAssertionHelper::Fail(const char* format, ...) { | |
19 std::stringstream stream; | |
20 stream << file_ << ":" << line_ << ": error: "; | |
21 | |
22 va_list arguments; | |
23 va_start(arguments, format); | |
24 char buffer[KB]; | |
25 vsnprintf(buffer, sizeof(buffer), format, arguments); | |
26 va_end(arguments); | |
27 stream << buffer << std::endl; | |
28 | |
29 // Get the message from the string stream and dump it on stderr. | |
30 std::string message = stream.str(); | |
31 fprintf(stderr, "%s", message.c_str()); | |
32 | |
33 // In case of failed assertions, abort right away. Otherwise, wait | |
34 // until the program is exiting before producing a non-zero exit | |
35 // code through abort. | |
36 // TODO(5411324): replace std::abort with OS::Abort so that we can handle | |
37 // restoring of signal handlers before aborting. | |
38 if (kind_ == ASSERT) { | |
39 std::abort(); | |
40 } | |
41 static bool failed = false; | |
42 if (!failed) { | |
43 std::atexit(&failed_exit); | |
44 } | |
45 failed = true; | |
46 } | |
47 | |
48 } // namespace dart | |
OLD | NEW |