Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(761)

Unified Diff: runtime/platform/assert.cc

Issue 2085703002: Remove STL use from platform/assert.cc (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add parens Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/tests/vm/vm.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/assert.cc
diff --git a/runtime/platform/assert.cc b/runtime/platform/assert.cc
index e9d1c4fa301e66db915f676132275b292b21a5c6..c5b91e714f3bbb6c4a1ea6c73c56b562a38ffab4 100644
--- a/runtime/platform/assert.cc
+++ b/runtime/platform/assert.cc
@@ -4,9 +4,6 @@
#include "platform/assert.h"
-#include <sstream>
-#include <string>
-
#include "platform/globals.h"
#include "vm/os.h"
@@ -18,19 +15,27 @@ static void failed_exit(void) {
}
void DynamicAssertionHelper::Fail(const char* format, ...) {
- std::ostringstream stream;
- stream << file_ << ":" << line_ << ": error: ";
+ // Take only the last 1KB of the file name if it is longer.
+ const intptr_t file_len = strlen(file_);
+ const intptr_t file_offset = (file_len > (1 * KB)) ? file_len - (1 * KB) : 0;
+ const char* file = file_ + file_offset;
+
+ // Print the file and line number into the buffer.
+ char buffer[4 * KB];
+ intptr_t file_and_line_length =
+ snprintf(buffer, sizeof(buffer), "%s: %d: error: ", file, line_);
+ // Print the error message into the buffer.
va_list arguments;
va_start(arguments, format);
- char buffer[4 * KB];
- vsnprintf(buffer, sizeof(buffer), format, arguments);
+ vsnprintf(buffer + file_and_line_length,
+ sizeof(buffer) - file_and_line_length,
+ 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());
+ // Print the buffer on stderr.
+ fprintf(stderr, "%s\n", buffer);
fflush(stderr);
// In case of failed assertions, abort right away. Otherwise, wait
« no previous file with comments | « no previous file | runtime/tests/vm/vm.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698