Made d8 console=readline work on leopard.
authorchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 3 Dec 2008 15:51:16 +0000 (15:51 +0000)
committerchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 3 Dec 2008 15:51:16 +0000 (15:51 +0000)
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@910 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/d8-readline.cc
src/platform-freebsd.cc
src/platform-linux.cc
src/platform-macos.cc
src/platform-win32.cc
src/platform.h

index 4cfee8b..65aa8b7 100644 (file)
@@ -26,6 +26,7 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
+#include <cstdio>
 #include <readline/readline.h>
 #include <readline/history.h>
 
 #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<Array> current_completions;
   if (state == 0) {
-    i::SmartPointer<char> full_text(strndup(rl_line_buffer, rl_point));
+    i::SmartPointer<char> full_text(i::OS::StrNDup(rl_line_buffer, rl_point));
     HandleScope scope;
     Handle<Array> completions =
       Shell::GetCompletions(String::New(text), String::New(*full_text));
index 75140c9..d7b3223 100644 (file)
@@ -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;
 }
index 2bb9665..96ef899 100644 (file)
@@ -185,11 +185,16 @@ void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) {
 }
 
 
-char *OS::StrDup(const char* str) {
+charOS::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;
 }
index f08d64d..122e7fa 100644 (file)
@@ -190,11 +190,26 @@ void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) {
 }
 
 
-char *OS::StrDup(const char* str) {
+charOS::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
index bd65dde..ada090a 100644 (file)
@@ -695,11 +695,26 @@ void OS::StrNCpy(Vector<char> dest, const char* src, size_t n) {
 }
 
 
-char *OS::StrDup(const char* str) {
+charOS::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
index cc44718..8d62efd 100644 (file)
@@ -206,6 +206,7 @@ class OS {
 
   static void StrNCpy(Vector<char> 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