mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
Eliminate need for va_copy in json.cc
The hacked version of va_copy did not work on Linux. Review URL: https://chromiumcodereview.appspot.com//10383122 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@7525 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
5d9dab620c
commit
dbd9fa4048
4 changed files with 10 additions and 30 deletions
|
@ -166,14 +166,9 @@ static bool IsValidJSON(const char* msg) {
|
|||
|
||||
|
||||
void DebuggerConnectionHandler::SendError(int msg_id,
|
||||
const char* format, ...) {
|
||||
const char* err_msg) {
|
||||
dart::TextBuffer msg(64);
|
||||
msg.Printf("{\"id\": %d, \"error\": \"", msg_id);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
msg.Printf(format, args);
|
||||
va_end(args);
|
||||
msg.Printf("\"}");
|
||||
msg.Printf("{\"id\": %d, \"error\": \"Error: %s\"}", msg_id, err_msg);
|
||||
Socket::Write(debugger_fd_, msg.buf(), msg.length());
|
||||
// TODO(hausner): Error checking. Probably just shut down the debugger
|
||||
// session if we there is an error while writing.
|
||||
|
@ -226,7 +221,7 @@ void DebuggerConnectionHandler::HandleGetScriptURLsCmd(const char* json_msg) {
|
|||
ASSERT_NOT_ERROR(lib_url);
|
||||
Dart_Handle urls = Dart_GetScriptURLs(lib_url);
|
||||
if (Dart_IsError(urls)) {
|
||||
SendError(msg_id, "Error: '%s'.", Dart_GetError(urls));
|
||||
SendError(msg_id, Dart_GetError(urls));
|
||||
return;
|
||||
}
|
||||
ASSERT(Dart_IsList(urls));
|
||||
|
|
|
@ -50,7 +50,7 @@ class DebuggerConnectionHandler {
|
|||
static void HandleGetLibraryURLsCmd(const char* json_msg);
|
||||
static void HandleGetScriptURLsCmd(const char* json_msg);
|
||||
|
||||
static void SendError(int msg_id, const char* format, ...);
|
||||
static void SendError(int msg_id, const char* err_msg);
|
||||
|
||||
static bool handler_started_;
|
||||
|
||||
|
|
|
@ -11,11 +11,6 @@
|
|||
|
||||
namespace dart {
|
||||
|
||||
#ifndef va_copy
|
||||
#define va_copy(dst, src) (memmove(&(dst), &(src), sizeof(dst)))
|
||||
#endif /* va_copy */
|
||||
|
||||
|
||||
JSONScanner::JSONScanner(const char* json_text) {
|
||||
SetText(json_text);
|
||||
}
|
||||
|
@ -354,20 +349,20 @@ void TextBuffer::Clear() {
|
|||
}
|
||||
|
||||
|
||||
intptr_t TextBuffer::Printf(const char* format, va_list args) {
|
||||
va_list args1;
|
||||
va_copy(args1, args);
|
||||
intptr_t TextBuffer::Printf(const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
intptr_t remaining = buf_size_ - msg_len_;
|
||||
ASSERT(remaining >= 0);
|
||||
intptr_t len = OS::VSNPrint(buf_ + msg_len_, remaining, format, args1);
|
||||
va_end(args1);
|
||||
intptr_t len = OS::VSNPrint(buf_ + msg_len_, remaining, format, args);
|
||||
va_end(args);
|
||||
if (len >= remaining) {
|
||||
const int kBufferSpareCapacity = 64; // Somewhat arbitrary.
|
||||
GrowBuffer(len + kBufferSpareCapacity);
|
||||
remaining = buf_size_ - msg_len_;
|
||||
ASSERT(remaining > len);
|
||||
va_list args2;
|
||||
va_copy(args2, args);
|
||||
va_start(args2, format);
|
||||
intptr_t len2 = OS::VSNPrint(buf_ + msg_len_, remaining, format, args2);
|
||||
va_end(args2);
|
||||
ASSERT(len == len2);
|
||||
|
@ -378,15 +373,6 @@ intptr_t TextBuffer::Printf(const char* format, va_list args) {
|
|||
}
|
||||
|
||||
|
||||
intptr_t TextBuffer::Printf(const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
intptr_t len = this->Printf(format, args);
|
||||
va_end(args);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
void TextBuffer::GrowBuffer(intptr_t len) {
|
||||
intptr_t new_size = buf_size_ + len;
|
||||
char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size));
|
||||
|
|
|
@ -117,7 +117,6 @@ class TextBuffer : ValueObject {
|
|||
~TextBuffer();
|
||||
|
||||
intptr_t Printf(const char* format, ...);
|
||||
intptr_t Printf(const char* format, va_list args);
|
||||
|
||||
void Clear();
|
||||
|
||||
|
|
Loading…
Reference in a new issue