OLD | NEW |
1 // Copyright (c) 2014, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #include "src/shared/assert.h" | 5 #include "src/shared/assert.h" |
6 | 6 |
7 #include <stdarg.h> | 7 #include <stdarg.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "src/shared/utils.h" | 10 #include "src/shared/utils.h" |
11 #include "src/shared/platform.h" | 11 #include "src/shared/platform.h" |
12 | 12 |
13 namespace fletch { | 13 namespace dartino { |
14 namespace DynamicAssertionHelper { | 14 namespace DynamicAssertionHelper { |
15 | 15 |
16 static void PrintError(const char* file, int line, const char* format, | 16 static void PrintError(const char* file, int line, const char* format, |
17 const va_list& arguments) { | 17 const va_list& arguments) { |
18 #ifdef FLETCH_ENABLE_PRINT_INTERCEPTORS | 18 #ifdef DARTINO_ENABLE_PRINT_INTERCEPTORS |
19 // Print out the error. | 19 // Print out the error. |
20 Print::Error("%s:%d: error: ", file, line); | 20 Print::Error("%s:%d: error: ", file, line); |
21 char buffer[KB]; | 21 char buffer[KB]; |
22 vsnprintf(buffer, sizeof(buffer), format, const_cast<va_list&>(arguments)); | 22 vsnprintf(buffer, sizeof(buffer), format, const_cast<va_list&>(arguments)); |
23 Print::Error("%s\n", buffer); | 23 Print::Error("%s\n", buffer); |
24 #else | 24 #else |
25 fprintf(stderr, "%s:%d: error: ", file, line); | 25 fprintf(stderr, "%s:%d: error: ", file, line); |
26 vfprintf(stderr, format, const_cast<va_list&>(arguments)); | 26 vfprintf(stderr, format, const_cast<va_list&>(arguments)); |
27 fprintf(stderr, "\n"); | 27 fprintf(stderr, "\n"); |
28 #endif // FLETCH_SUPPORT_PRINT_INTERCEPTORS | 28 #endif // DARTINO_SUPPORT_PRINT_INTERCEPTORS |
29 } | 29 } |
30 | 30 |
31 template <> | 31 template <> |
32 void Fail<ASSERT>(const char* file, int line, const char* format, ...) { | 32 void Fail<ASSERT>(const char* file, int line, const char* format, ...) { |
33 va_list arguments; | 33 va_list arguments; |
34 va_start(arguments, format); | 34 va_start(arguments, format); |
35 PrintError(file, line, format, arguments); | 35 PrintError(file, line, format, arguments); |
36 va_end(arguments); | 36 va_end(arguments); |
37 Platform::ImmediateAbort(); | 37 Platform::ImmediateAbort(); |
38 } | 38 } |
39 | 39 |
40 template <> | 40 template <> |
41 void Fail<EXPECT>(const char* file, int line, const char* format, ...) { | 41 void Fail<EXPECT>(const char* file, int line, const char* format, ...) { |
42 va_list arguments; | 42 va_list arguments; |
43 va_start(arguments, format); | 43 va_start(arguments, format); |
44 PrintError(file, line, format, arguments); | 44 PrintError(file, line, format, arguments); |
45 va_end(arguments); | 45 va_end(arguments); |
46 Platform::ScheduleAbort(); | 46 Platform::ScheduleAbort(); |
47 } | 47 } |
48 | 48 |
49 } // namespace DynamicAssertionHelper | 49 } // namespace DynamicAssertionHelper |
50 } // namespace fletch | 50 } // namespace dartino |
OLD | NEW |