// 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 {
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;
}
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));
}
+char* OS::StrNDup(const char* str, size_t n) {
+ return strndup(str, n);
+}
+
+
double OS::nan_value() {
return NAN;
}
}
-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;
}
}
-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
}
-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
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