summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mrbgems/mruby-bin-mirb/tools/mirb/mirb.c30
-rw-r--r--src/dump.c8
-rw-r--r--src/pool.c9
3 files changed, 31 insertions, 16 deletions
diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
index a42577a57..320bc30fb 100644
--- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
+++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c
@@ -15,15 +15,29 @@
#include "mruby/string.h"
#ifdef ENABLE_READLINE
-#include <limits.h>
#include <readline/readline.h>
#include <readline/history.h>
-
+#define MIRB_ADD_HISTORY(line) add_history(line)
+#define MIRB_READLINE(ch) readline(ch)
+#define MIRB_WRITE_HISTORY(path) write_history(path)
+#define MIRB_READ_HISTORY(path) read_history(path)
+#define MIRB_USING_HISTORY() using_history()
+#elif ENABLE_LINENOISE
+#define ENABLE_READLINE
+#include <linenoise.h>
+#define MIRB_ADD_HISTORY(line) linenoiseHistoryAdd(line)
+#define MIRB_READLINE(ch) linenoise(ch)
+#define MIRB_WRITE_HISTORY(path) linenoiseHistorySave(path)
+#define MIRB_READ_HISTORY(path) linenoiseHistoryLoad(history_path)
+#define MIRB_USING_HISTORY()
+#endif
+
+#ifdef ENABLE_READLINE
+#include <limits.h>
static const char *history_file_name = ".mirb_history";
char history_path[PATH_MAX];
#endif
-
static void
p(mrb_state *mrb, mrb_value obj, int prompt)
{
@@ -281,7 +295,7 @@ main(int argc, char **argv)
ai = mrb_gc_arena_save(mrb);
#ifdef ENABLE_READLINE
- using_history();
+ MIRB_USING_HISTORY();
home = getenv("HOME");
#ifdef _WIN32
if (!home)
@@ -291,7 +305,7 @@ main(int argc, char **argv)
strcpy(history_path, home);
strcat(history_path, "/");
strcat(history_path, history_file_name);
- read_history(history_path);
+ MIRB_READ_HISTORY(history_path);
}
#endif
@@ -312,13 +326,13 @@ main(int argc, char **argv)
last_code_line[char_index] = '\0';
#else
- char* line = readline(code_block_open ? "* " : "> ");
+ char* line = MIRB_READLINE(code_block_open ? "* " : "> ");
if (line == NULL) {
printf("\n");
break;
}
strncpy(last_code_line, line, sizeof(last_code_line)-1);
- add_history(line);
+ MIRB_ADD_HISTORY(line);
free(line);
#endif
@@ -387,7 +401,7 @@ main(int argc, char **argv)
mrb_close(mrb);
#ifdef ENABLE_READLINE
- write_history(history_path);
+ MIRB_WRITE_HISTORY(history_path);
#endif
return 0;
diff --git a/src/dump.c b/src/dump.c
index 4c843f8d7..72d1ffcbe 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -157,7 +157,7 @@ get_syms_block_size(mrb_state *mrb, mrb_irep *irep)
{
uint32_t size = 0;
uint32_t sym_no;
- uint32_t len;
+ size_t len;
size += sizeof(uint32_t); /* slen */
for (sym_no = 0; sym_no < irep->slen; sym_no++) {
@@ -182,7 +182,7 @@ write_syms_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf)
for (sym_no = 0; sym_no < irep->slen; sym_no++) {
if (irep->syms[sym_no] != 0) {
- uint32_t len;
+ size_t len;
name = mrb_sym2name_len(mrb, irep->syms[sym_no], &len);
if (len > UINT16_MAX) {
@@ -474,8 +474,8 @@ get_filename_table_size(mrb_state *mrb, mrb_irep *irep, mrb_sym **fp, uint32_t *
}
for (file_i = 0; file_i < di->flen; ++file_i) {
mrb_irep_debug_info_file *file;
- uint32_t filename_len;
- uint32_t i;
+ size_t filename_len;
+ size_t i;
file = di->files[file_i];
if (find_filename_index(filenames, *lp, file->filename_sym) == -1) {
diff --git a/src/pool.c b/src/pool.c
index f09df92c5..4d8c42dd1 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -5,6 +5,7 @@
*/
#include <stddef.h>
+#include <stdint.h>
#include <string.h>
#include "mruby.h"
@@ -36,12 +37,12 @@ struct mrb_pool {
#undef TEST_POOL
#ifdef TEST_POOL
-#define mrb_malloc(m,s) malloc(s)
+#define mrb_malloc_simple(m,s) malloc(s)
#define mrb_free(m,p) free(p)
#endif
#ifdef POOL_ALIGNMENT
-# define ALIGN_PADDING(x) ((-x) & (POOL_ALIGNMENT - 1))
+# define ALIGN_PADDING(x) ((SIZE_MAX - (x) + 1) & (POOL_ALIGNMENT - 1))
#else
# define ALIGN_PADDING(x) (0)
#endif
@@ -49,7 +50,7 @@ struct mrb_pool {
mrb_pool*
mrb_pool_open(mrb_state *mrb)
{
- mrb_pool *pool = (mrb_pool *)mrb_malloc(mrb, sizeof(mrb_pool));
+ mrb_pool *pool = (mrb_pool *)mrb_malloc_simple(mrb, sizeof(mrb_pool));
if (pool) {
pool->mrb = mrb;
@@ -81,7 +82,7 @@ page_alloc(mrb_pool *pool, size_t len)
if (len < POOL_PAGE_SIZE)
len = POOL_PAGE_SIZE;
- page = (struct mrb_pool_page *)mrb_malloc(pool->mrb, sizeof(struct mrb_pool_page)+len);
+ page = (struct mrb_pool_page *)mrb_malloc_simple(pool->mrb, sizeof(struct mrb_pool_page)+len);
if (page) {
page->offset = 0;
page->len = len;