[PATCH] D47170: [fuchsia] Add line buffering in RawWrite
Jake Ehrlich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 23 15:16:23 PDT 2018
jakehehrlich updated this revision to Diff 148300.
jakehehrlich added a comment.
Switched to use index. Fixed to print out full buffer in case no newline exists.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D47170
Files:
compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc
Index: compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc
+++ compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc
@@ -407,7 +407,31 @@
}
void RawWrite(const char *buffer) {
- __sanitizer_log_write(buffer, internal_strlen(buffer));
+ constexpr size_t size = 128;
+ static _Thread_local char line[size];
+ static _Thread_local size_t lastLineEnd = 0;
+ static _Thread_local size_t cur = 0;
+
+ while (*buffer) {
+ if (cur >= size) {
+ if (lastLineEnd == 0)
+ lastLineEnd = size;
+ __sanitizer_log_write(line, lastLineEnd);
+ internal_memmove(line, line + lastLineEnd, cur - lastLineEnd);
+ cur = cur - lastLineEnd;
+ lastLineEnd = 0;
+ }
+ if (*buffer == '\n')
+ lastLineEnd = cur + 1;
+ line[cur++] = *buffer++;
+ }
+ // Flush all complete lines before returning.
+ if (lastLineEnd != 0) {
+ __sanitizer_log_write(line, lastLineEnd);
+ internal_memmove(line, line + lastLineEnd, cur - lastLineEnd);
+ cur = cur - lastLineEnd;
+ lastLineEnd = 0;
+ }
}
void CatastrophicErrorWrite(const char *buffer, uptr length) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47170.148300.patch
Type: text/x-patch
Size: 1223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180523/75644b22/attachment.bin>
More information about the llvm-commits
mailing list