diff options
| author | ruki <[email protected]> | 2017-05-10 23:45:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-10 23:45:06 +0800 |
| commit | 7d461c4de3e3476366b53aa67dd17f4f1e785ee2 (patch) | |
| tree | 1f60f81d44d870d9aa5b97f243cc464ce11fb9cd /core/src | |
| parent | 966876f494902efecb1ea475bade16cd96fe160c (diff) | |
suppress clear_history crash on macos
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/readline/add_history.c | 9 | ||||
| -rw-r--r-- | core/src/xmake/readline/clear_history.c | 12 | ||||
| -rw-r--r-- | core/src/xmake/readline/history_list.c | 7 | ||||
| -rw-r--r-- | core/src/xmake/readline/readline.c | 12 |
4 files changed, 19 insertions, 21 deletions
diff --git a/core/src/xmake/readline/add_history.c b/core/src/xmake/readline/add_history.c index 57f947d0c..a0d660b7c 100644 --- a/core/src/xmake/readline/add_history.c +++ b/core/src/xmake/readline/add_history.c @@ -34,11 +34,10 @@ */ #include "prefix.h" -#ifdef XM_CONFIG_API_HAVE_READLINE - /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ +#ifdef XM_CONFIG_API_HAVE_READLINE // add_history wrapper tb_int_t xm_readline_add_history(lua_State* lua) @@ -53,11 +52,7 @@ tb_int_t xm_readline_add_history(lua_State* lua) // call add_history add_history(history); - // pushnil - lua_pushnil(lua); - // ok - return 1; + return 0; } - #endif diff --git a/core/src/xmake/readline/clear_history.c b/core/src/xmake/readline/clear_history.c index 7517e2e43..6b79bb8d0 100644 --- a/core/src/xmake/readline/clear_history.c +++ b/core/src/xmake/readline/clear_history.c @@ -34,11 +34,10 @@ */ #include "prefix.h" -#ifdef XM_CONFIG_API_HAVE_READLINE - /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ +#ifdef XM_CONFIG_API_HAVE_READLINE // clear_history wrapper tb_int_t xm_readline_clear_history(lua_State* lua) @@ -46,14 +45,13 @@ tb_int_t xm_readline_clear_history(lua_State* lua) // check tb_assert_and_check_return_val(lua, 0); - // call clear_history + // call clear_history (will crash on macOS) +#ifndef TB_CONFIG_OS_MACOSX clear_history(); - - // pushnil - lua_pushnil(lua); +#endif // ok - return 1; + return 0; } #endif diff --git a/core/src/xmake/readline/history_list.c b/core/src/xmake/readline/history_list.c index 3b0f8c0d3..d3145c4c7 100644 --- a/core/src/xmake/readline/history_list.c +++ b/core/src/xmake/readline/history_list.c @@ -48,13 +48,15 @@ tb_int_t xm_readline_history_list(lua_State* lua) // history list lua_newtable(lua); + #ifdef TB_CONFIG_OS_MACOSX for (tb_int_t i = 1; i <= history_length; ++i) { lua_newtable(lua); + // field line lua_pushstring(lua, "line"); - lua_pushstring(lua, history_get(i) -> line); + lua_pushstring(lua, history_get(i)->line); lua_settable(lua, -3); // set back @@ -65,9 +67,10 @@ tb_int_t xm_readline_history_list(lua_State* lua) for (HIST_ENTRY **p = history_list(); *p; ++p, ++i) { lua_newtable(lua); + // field line lua_pushstring(lua, "line"); - lua_pushstring(lua, (*p) -> line); + lua_pushstring(lua, (*p)->line); lua_settable(lua, -3); // set back diff --git a/core/src/xmake/readline/readline.c b/core/src/xmake/readline/readline.c index c52ff02aa..9684639be 100644 --- a/core/src/xmake/readline/readline.c +++ b/core/src/xmake/readline/readline.c @@ -52,14 +52,16 @@ tb_int_t xm_readline_readline(lua_State* lua) prompt = luaL_checkstring(lua, 1); // call readline - tb_char_t const* line = readline(prompt); + tb_char_t* line = readline(prompt); if (line) + { + // return line lua_pushstring(lua, line); - else - lua_pushnil(lua); - // free it - tb_free((void*)line); + // free it + tb_free(line); + } + else lua_pushnil(lua); // ok return 1; |
