OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return; | 99 return; |
100 int offset = 0; | 100 int offset = 0; |
101 int elm = 0; | 101 int elm = 0; |
102 while (format[offset] != '\0') { | 102 while (format[offset] != '\0') { |
103 if (format[offset] != '%' || elm == elms.length()) { | 103 if (format[offset] != '%' || elm == elms.length()) { |
104 Put(format[offset]); | 104 Put(format[offset]); |
105 offset++; | 105 offset++; |
106 continue; | 106 continue; |
107 } | 107 } |
108 // Read this formatting directive into a temporary buffer | 108 // Read this formatting directive into a temporary buffer |
109 const int kTempSize = 24; | 109 EmbeddedVector<char, 24> temp; |
110 char temp_buffer[kTempSize]; | |
111 // Wrap temp buffer in a vector to get bounds checking in debug | |
112 // mode | |
113 Vector<char> temp(temp_buffer, kTempSize); | |
114 int format_length = 0; | 110 int format_length = 0; |
115 // Skip over the whole control character sequence until the | 111 // Skip over the whole control character sequence until the |
116 // format element type | 112 // format element type |
117 temp[format_length++] = format[offset++]; | 113 temp[format_length++] = format[offset++]; |
118 // '\0' is not a control character so we don't have to | 114 // '\0' is not a control character so we don't have to |
119 // explicitly check for the end of the string | 115 // explicitly check for the end of the string |
120 while (IsControlChar(format[offset])) | 116 while (IsControlChar(format[offset])) |
121 temp[format_length++] = format[offset++]; | 117 temp[format_length++] = format[offset++]; |
122 char type = format[offset]; | 118 char type = format[offset]; |
123 if (type == '\0') return; | 119 if (type == '\0') return; |
124 temp[format_length++] = type; | 120 temp[format_length++] = type; |
125 temp[format_length] = '\0'; | 121 temp[format_length] = '\0'; |
126 offset++; | 122 offset++; |
127 FmtElm current = elms[elm++]; | 123 FmtElm current = elms[elm++]; |
128 switch (type) { | 124 switch (type) { |
129 case 's': { | 125 case 's': { |
130 ASSERT_EQ(FmtElm::C_STR, current.type_); | 126 ASSERT_EQ(FmtElm::C_STR, current.type_); |
131 const char* value = current.data_.u_c_str_; | 127 const char* value = current.data_.u_c_str_; |
132 Add(value); | 128 Add(value); |
133 break; | 129 break; |
134 } | 130 } |
135 case 'o': { | 131 case 'o': { |
136 ASSERT_EQ(FmtElm::OBJ, current.type_); | 132 ASSERT_EQ(FmtElm::OBJ, current.type_); |
137 Object* obj = current.data_.u_obj_; | 133 Object* obj = current.data_.u_obj_; |
138 PrintObject(obj); | 134 PrintObject(obj); |
139 break; | 135 break; |
140 } | 136 } |
141 case 'i': case 'd': case 'u': case 'x': case 'c': case 'p': { | 137 case 'i': case 'd': case 'u': case 'x': case 'c': case 'p': { |
142 int value = current.data_.u_int_; | 138 int value = current.data_.u_int_; |
143 char formatted[kTempSize]; | 139 EmbeddedVector<char, 24> formatted; |
144 #ifdef WIN32 | 140 OS::SNPrintF(formatted, temp.start(), value); |
145 // This is not my idea of a good time. | 141 Add(formatted.start()); |
146 _snprintf(formatted, kTempSize, temp.start(), value); | |
147 #else | |
148 snprintf(formatted, kTempSize, temp.start(), value); | |
149 #endif | |
150 Add(formatted); | |
151 break; | 142 break; |
152 } | 143 } |
153 default: | 144 default: |
154 UNREACHABLE(); | 145 UNREACHABLE(); |
155 break; | 146 break; |
156 } | 147 } |
157 } | 148 } |
158 | 149 |
159 // Verify that the buffer is 0-terminated and doesn't contain any | 150 // Verify that the buffer is 0-terminated and doesn't contain any |
160 // other 0-characters. | 151 // other 0-characters. |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 unsigned new_bytes = *bytes * 2; | 541 unsigned new_bytes = *bytes * 2; |
551 if (new_bytes > size_) { | 542 if (new_bytes > size_) { |
552 new_bytes = size_; | 543 new_bytes = size_; |
553 } | 544 } |
554 *bytes = new_bytes; | 545 *bytes = new_bytes; |
555 return space_; | 546 return space_; |
556 } | 547 } |
557 | 548 |
558 | 549 |
559 } } // namespace v8::internal | 550 } } // namespace v8::internal |
OLD | NEW |