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

Side by Side Diff: runtime/platform/text_buffer.cc

Issue 2204523002: Fuchsia: Use low-level prng call, add test, update test runner. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/sdk/@master
Patch Set: Fix bug Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « runtime/bin/run_vm_tests_fuchsia.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart 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 file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/text_buffer.h" 5 #include "platform/text_buffer.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/os.h" 10 #include "vm/os.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 51
52 void TextBuffer::AddRaw(const uint8_t* buffer, 52 void TextBuffer::AddRaw(const uint8_t* buffer,
53 intptr_t buffer_length) { 53 intptr_t buffer_length) {
54 EnsureCapacity(buffer_length); 54 EnsureCapacity(buffer_length);
55 memmove(&buf_[msg_len_], buffer, buffer_length); 55 memmove(&buf_[msg_len_], buffer, buffer_length);
56 msg_len_ += buffer_length; 56 msg_len_ += buffer_length;
57 buf_[msg_len_] = '\0'; 57 buf_[msg_len_] = '\0';
58 } 58 }
59 59
60
60 intptr_t TextBuffer::Printf(const char* format, ...) { 61 intptr_t TextBuffer::Printf(const char* format, ...) {
61 va_list args; 62 va_list args;
62 va_start(args, format); 63 va_start(args, format);
63 intptr_t remaining = buf_size_ - msg_len_; 64 intptr_t remaining = buf_size_ - msg_len_;
64 ASSERT(remaining >= 0); 65 ASSERT(remaining >= 0);
65 intptr_t len = OS::VSNPrint(buf_ + msg_len_, remaining, format, args); 66 intptr_t len = OS::VSNPrint(buf_ + msg_len_, remaining, format, args);
66 va_end(args); 67 va_end(args);
67 if (len >= remaining) { 68 if (len >= remaining) {
68 EnsureCapacity(len); 69 EnsureCapacity(len);
69 remaining = buf_size_ - msg_len_; 70 remaining = buf_size_ - msg_len_;
70 ASSERT(remaining > len); 71 ASSERT(remaining > len);
71 va_list args2; 72 va_list args2;
72 va_start(args2, format); 73 va_start(args2, format);
73 intptr_t len2 = OS::VSNPrint(buf_ + msg_len_, remaining, format, args2); 74 intptr_t len2 = OS::VSNPrint(buf_ + msg_len_, remaining, format, args2);
74 va_end(args2); 75 va_end(args2);
75 ASSERT(len == len2); 76 ASSERT(len == len2);
76 } 77 }
77 msg_len_ += len; 78 msg_len_ += len;
78 buf_[msg_len_] = '\0'; 79 buf_[msg_len_] = '\0';
79 return len; 80 return len;
80 } 81 }
81 82
83
82 // Write a UTF-32 code unit so it can be read by a JSON parser in a string 84 // Write a UTF-32 code unit so it can be read by a JSON parser in a string
83 // literal. Use official encoding from JSON specification. http://json.org/ 85 // literal. Use official encoding from JSON specification. http://json.org/
84 void TextBuffer::EscapeAndAddCodeUnit(uint32_t codeunit) { 86 void TextBuffer::EscapeAndAddCodeUnit(uint32_t codeunit) {
85 switch (codeunit) { 87 switch (codeunit) {
86 case '"': 88 case '"':
87 AddRaw(reinterpret_cast<uint8_t const*>("\\\""), 2); 89 AddRaw(reinterpret_cast<uint8_t const*>("\\\""), 2);
88 break; 90 break;
89 case '\\': 91 case '\\':
90 AddRaw(reinterpret_cast<uint8_t const*>("\\\\"), 2); 92 AddRaw(reinterpret_cast<uint8_t const*>("\\\\"), 2);
91 break; 93 break;
(...skipping 20 matching lines...) Expand all
112 EscapeAndAddUTF16CodeUnit(codeunit); 114 EscapeAndAddUTF16CodeUnit(codeunit);
113 } else { 115 } else {
114 char encoded[6]; 116 char encoded[6];
115 intptr_t length = Utf8::Length(codeunit); 117 intptr_t length = Utf8::Length(codeunit);
116 Utf8::Encode(codeunit, encoded); 118 Utf8::Encode(codeunit, encoded);
117 AddRaw(reinterpret_cast<uint8_t const*>(encoded), length); 119 AddRaw(reinterpret_cast<uint8_t const*>(encoded), length);
118 } 120 }
119 } 121 }
120 } 122 }
121 123
124
122 // Write an incomplete UTF-16 code unit so it can be read by a JSON parser in a 125 // Write an incomplete UTF-16 code unit so it can be read by a JSON parser in a
123 // string literal. 126 // string literal.
124 void TextBuffer::EscapeAndAddUTF16CodeUnit(uint16_t codeunit) { 127 void TextBuffer::EscapeAndAddUTF16CodeUnit(uint16_t codeunit) {
125 Printf("\\u%04X", codeunit); 128 Printf("\\u%04X", codeunit);
126 } 129 }
127 130
128 131
129 void TextBuffer::AddString(const char* s) { 132 void TextBuffer::AddString(const char* s) {
130 Printf("%s", s); 133 Printf("%s", s);
131 } 134 }
(...skipping 17 matching lines...) Expand all
149 // the debugger front-end. 152 // the debugger front-end.
150 intptr_t new_size = buf_size_ + len + kBufferSpareCapacity; 153 intptr_t new_size = buf_size_ + len + kBufferSpareCapacity;
151 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size)); 154 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size));
152 ASSERT(new_buf != NULL); 155 ASSERT(new_buf != NULL);
153 buf_ = new_buf; 156 buf_ = new_buf;
154 buf_size_ = new_size; 157 buf_size_ = new_size;
155 } 158 }
156 } 159 }
157 160
158 } // namespace dart 161 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/run_vm_tests_fuchsia.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698