From 3764f52a4ecafb2554afcdf9217f2d76221ed9a0 Mon Sep 17 00:00:00 2001 From: "christian.plesner.hansen@gmail.com" Date: Thu, 11 Sep 2008 15:03:22 +0000 Subject: [PATCH] Fixed build problem on mac, lint issues and a test failure on win32. Review URL: http://codereview.chromium.org/2601 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@285 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/platform-macos.cc | 39 ++++++++++++++++++++++++++++++++------- src/platform-win32.cc | 8 +++++--- src/utils.h | 6 +++--- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/platform-macos.cc b/src/platform-macos.cc index 7573125335..dc2e912da1 100644 --- a/src/platform-macos.cc +++ b/src/platform-macos.cc @@ -132,6 +132,11 @@ double OS::LocalTimeOffset() { } +FILE* OS::FOpen(const char* path, const char* mode) { + return fopen(path, mode); +} + + void OS::Print(const char* format, ...) { va_list args; va_start(args, format); @@ -158,19 +163,21 @@ void OS::VPrintError(const char* format, va_list args) { } -int OS::SNPrintF(char* str, size_t size, const char* format, ...) { +int OS::SNPrintF(Vector str, const char* format, ...) { va_list args; va_start(args, format); - int result = VSNPrintF(str, size, format, args); + int result = VSNPrintF(str, format, args); va_end(args); return result; } -int OS::VSNPrintF(char* str, size_t size, const char* format, va_list args) { - int n = vsnprintf(str, size, format, args); // forward to Mac OS X. - if (n < 0 || static_cast(n) >= size) { - str[size - 1] = '\0'; +int OS::VSNPrintF(Vector str, + const char* format, + va_list args) { + int n = vsnprintf(str.start(), str.length(), format, args); + if (n < 0 || n >= str.length()) { + str[str.length() - 1] = '\0'; return -1; } else { return n; @@ -178,6 +185,21 @@ int OS::VSNPrintF(char* str, size_t size, const char* format, va_list args) { } +void OS::StrNCpy(Vector dest, const char* src, size_t n) { + strncpy(dest.start(), src, n); +} + + +void OS::WcsCpy(Vector dest, const wchar_t* src) { + wcscpy(dest.start(), src); +} + + +char *OS::StrDup(const char* str) { + return strdup(str); +} + + // We keep the lowest and highest addresses mapped as a quick way of // determining that pointers are outside the heap (used mostly in assertions // and verification). The estimate is conservative, ie, not all addresses in @@ -299,7 +321,10 @@ int OS::StackWalk(StackFrame* frames, int frames_size) { frames[i].address = addresses[i]; // Format a text representation of the frame based on the information // available. - SNPrintF(frames[i].text, kStackWalkMaxTextLen, "%s", symbols[i]); + SNPrintF(MutableCStrVector(frames[i].text, + kStackWalkMaxTextLen), + "%s", + symbols[i]); // Make sure line termination is in place. frames[i].text[kStackWalkMaxTextLen - 1] = '\0'; } diff --git a/src/platform-win32.cc b/src/platform-win32.cc index d0d044fd6e..747f0a467f 100644 --- a/src/platform-win32.cc +++ b/src/platform-win32.cc @@ -668,7 +668,7 @@ int OS::SNPrintF(Vector str, const char* format, ...) { int OS::VSNPrintF(Vector str, const char* format, va_list args) { - int n = _vsnprintf_s(str.start(), str.length(), str.length(), format, args); + int n = _vsnprintf_s(str.start(), str.length(), _TRUNCATE, format, args); // Make sure to zero-terminate the string if the output was // truncated or if there was an error. if (n < 0 || n >= str.length()) { @@ -682,13 +682,15 @@ int OS::VSNPrintF(Vector str, const char* format, va_list args) { void OS::StrNCpy(Vector dest, const char* src, size_t n) { int result = strncpy_s(dest.start(), dest.length(), src, n); - USE(result); ASSERT(result == 0); + USE(result); + ASSERT(result == 0); } void OS::WcsCpy(Vector dest, const wchar_t* src) { int result = wcscpy_s(dest.start(), dest.length(), src); - USE(result); ASSERT(result == 0); + USE(result); + ASSERT(result == 0); } diff --git a/src/utils.h b/src/utils.h index 38bbd16416..1f385257a3 100644 --- a/src/utils.h +++ b/src/utils.h @@ -328,12 +328,12 @@ class Vector { }; -template +template class EmbeddedVector : public Vector { public: - EmbeddedVector() : Vector(buffer_, size) { } + EmbeddedVector() : Vector(buffer_, kSize) { } private: - T buffer_[size]; + T buffer_[kSize]; };