From: christian.plesner.hansen@gmail.com Date: Wed, 3 Dec 2008 15:51:16 +0000 (+0000) Subject: Made d8 console=readline work on leopard. X-Git-Tag: upstream/4.7.83~24914 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f56c10598b8afe04eccf93e8a441f7907b7c7da8;p=platform%2Fupstream%2Fv8.git Made d8 console=readline work on leopard. git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@910 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/d8-readline.cc b/src/d8-readline.cc index 4cfee8b..65aa8b7 100644 --- a/src/d8-readline.cc +++ b/src/d8-readline.cc @@ -26,6 +26,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include #include #include @@ -33,6 +34,13 @@ #include "d8.h" +// There are incompatibilities between different versions and different +// implementations of readline. This smoothes out one known incompatibility. +#if RL_READLINE_VERSION >= 0x0500 +#define completion_matches rl_completion_matches +#endif + + namespace v8 { @@ -85,7 +93,7 @@ void ReadLineEditor::AddHistory(const char* str) { char** ReadLineEditor::AttemptedCompletion(const char* text, int start, int end) { - char** result = rl_completion_matches(text, CompletionGenerator); + char** result = completion_matches(text, CompletionGenerator); rl_attempted_completion_over = true; return result; } @@ -95,7 +103,7 @@ char* ReadLineEditor::CompletionGenerator(const char* text, int state) { static unsigned current_index; static Persistent current_completions; if (state == 0) { - i::SmartPointer full_text(strndup(rl_line_buffer, rl_point)); + i::SmartPointer full_text(i::OS::StrNDup(rl_line_buffer, rl_point)); HandleScope scope; Handle completions = Shell::GetCompletions(String::New(text), String::New(*full_text)); diff --git a/src/platform-freebsd.cc b/src/platform-freebsd.cc index 75140c9..d7b3223 100644 --- a/src/platform-freebsd.cc +++ b/src/platform-freebsd.cc @@ -194,6 +194,11 @@ char *OS::StrDup(const char* str) { } +char* OS::StrNDup(const char* str, size_t n) { + return strndup(str, n); +} + + double OS::nan_value() { return NAN; } diff --git a/src/platform-linux.cc b/src/platform-linux.cc index 2bb9665..96ef899 100644 --- a/src/platform-linux.cc +++ b/src/platform-linux.cc @@ -185,11 +185,16 @@ void OS::StrNCpy(Vector dest, const char* src, size_t n) { } -char *OS::StrDup(const char* str) { +char* OS::StrDup(const char* str) { return strdup(str); } +char* OS::StrNDup(const char* str, size_t n) { + return strndup(str, n); +} + + double OS::nan_value() { return NAN; } diff --git a/src/platform-macos.cc b/src/platform-macos.cc index f08d64d..122e7fa 100644 --- a/src/platform-macos.cc +++ b/src/platform-macos.cc @@ -190,11 +190,26 @@ void OS::StrNCpy(Vector dest, const char* src, size_t n) { } -char *OS::StrDup(const char* str) { +char* OS::StrDup(const char* str) { return strdup(str); } +char* OS::StrNDup(const char* str, size_t n) { + // Stupid implementation of strndup since macos isn't born with + // one. + size_t len = strlen(str); + if (len <= n) + return StrDup(str); + char* result = new char[n+1]; + size_t i; + for (i = 0; i <= n; i++) + result[i] = str[i]; + result[i] = '\0'; + return result; +} + + // 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 diff --git a/src/platform-win32.cc b/src/platform-win32.cc index bd65dde..ada090a 100644 --- a/src/platform-win32.cc +++ b/src/platform-win32.cc @@ -695,11 +695,26 @@ void OS::StrNCpy(Vector dest, const char* src, size_t n) { } -char *OS::StrDup(const char* str) { +char* OS::StrDup(const char* str) { return _strdup(str); } +char* OS::StrNDup(const char* str, size_t n) { + // Stupid implementation of strndup since windows isn't born with + // one. + size_t len = strlen(str); + if (len <= n) + return StrDup(str); + char* result = new char[n+1]; + size_t i; + for (i = 0; i <= n; i++) + result[i] = str[i]; + result[i] = '\0'; + return result; +} + + // 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 diff --git a/src/platform.h b/src/platform.h index cc44718..8d62efd 100644 --- a/src/platform.h +++ b/src/platform.h @@ -206,6 +206,7 @@ class OS { static void StrNCpy(Vector dest, const char* src, size_t n); static char* StrDup(const char* str); + static char* StrNDup(const char* str, size_t n); // Support for profiler. Can do nothing, in which case ticks // occuring in shared libraries will not be properly accounted