aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/ex_getln.c98
-rw-r--r--src/nvim/ops.c1
-rw-r--r--src/nvim/os/pty_process.c5
-rw-r--r--third-party/cmake/BuildLuarocks.cmake109
4 files changed, 115 insertions, 98 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 6d5ebda256..6c6c72fc36 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -10,6 +10,7 @@
* ex_getln.c: Functions for entering and editing an Ex command line.
*/
+#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
@@ -4175,58 +4176,59 @@ static char_u *get_history_arg(expand_T *xp, int idx)
return NULL;
}
-/*
- * init_history() - Initialize the command line history.
- * Also used to re-allocate the history when the size changes.
- */
+/// Initialize command line history.
+/// Also used to re-allocate history tables when size changes.
void init_history(void)
{
- /*
- * If size of history table changed, reallocate it
- */
- ssize_t newlen = p_hi;
- if (newlen != hislen) {
- histentry_T *temp;
- ssize_t i;
- ssize_t j;
-
- // adjust the tables
- for (int type = 0; type < HIST_COUNT; ++type) {
- if (newlen) {
- temp = xmalloc(newlen * sizeof(*temp));
- } else
- temp = NULL;
- if (newlen == 0 || temp != NULL) {
- if (hisidx[type] < 0) { /* there are no entries yet */
- for (i = 0; i < newlen; ++i)
- clear_hist_entry(&temp[i]);
- } else if (newlen > hislen) { /* array becomes bigger */
- for (i = 0; i <= hisidx[type]; ++i)
- temp[i] = history[type][i];
- j = i;
- for (; i <= newlen - (hislen - hisidx[type]); ++i)
- clear_hist_entry(&temp[i]);
- for (; j < hislen; ++i, ++j)
- temp[i] = history[type][j];
- } else { /* array becomes smaller or 0 */
- j = hisidx[type];
- for (i = newlen - 1;; --i) {
- if (i >= 0) /* copy newest entries */
- temp[i] = history[type][j];
- else { /* remove older entries */
- xfree(history[type][j].hisstr);
- history[type][j].hisstr = NULL;
- }
- if (--j < 0)
- j = hislen - 1;
- if (j == hisidx[type])
- break;
- }
- hisidx[type] = newlen - 1;
+ assert(p_hi >= 0 && p_hi <= INT_MAX);
+ int newlen = (int)p_hi;
+ int oldlen = hislen;
+
+ // If history tables size changed, reallocate them.
+ // Tables are circular arrays (current position marked by hisidx[type]).
+ // On copying them to the new arrays, we take the chance to reorder them.
+ if (newlen != oldlen) {
+ for (int type = 0; type < HIST_COUNT; type++) {
+ histentry_T *temp = newlen ? xmalloc(newlen * sizeof(*temp)) : NULL;
+
+ int j = hisidx[type];
+ if (j >= 0) {
+ // old array gets partitioned this way:
+ // [0 , i1 ) --> newest entries to be deleted
+ // [i1 , i1 + l1) --> newest entries to be copied
+ // [i1 + l1 , i2 ) --> oldest entries to be deleted
+ // [i2 , i2 + l2) --> oldest entries to be copied
+ int l1 = MIN(j + 1, newlen); // how many newest to copy
+ int l2 = MIN(newlen, oldlen) - l1; // how many oldest to copy
+ int i1 = j + 1 - l1; // copy newest from here
+ int i2 = MAX(l1, oldlen - newlen + l1); // copy oldest from here
+
+ // copy as much entries as they fit to new table, reordering them
+ if (newlen) {
+ // copy oldest entries
+ memcpy(&temp[0], &history[type][i2], (size_t)l2 * sizeof(*temp));
+ // copy newest entries
+ memcpy(&temp[l2], &history[type][i1], (size_t)l1 * sizeof(*temp));
+ }
+
+ // delete entries that don't fit in newlen, if any
+ for (int i = 0; i < i1; i++) {
+ xfree(history[type][i].hisstr);
+ history[type][i].hisstr = NULL;
+ }
+ for (int i = i1 + l1; i < i2; i++) {
+ xfree(history[type][i].hisstr);
+ history[type][i].hisstr = NULL;
}
- xfree(history[type]);
- history[type] = temp;
}
+
+ // clear remaining space, if any
+ int l3 = j < 0 ? 0 : MIN(newlen, oldlen); // number of copied entries
+ memset(temp + l3, 0, (size_t)(newlen - l3) * sizeof(*temp));
+
+ hisidx[type] = l3 - 1;
+ xfree(history[type]);
+ history[type] = temp;
}
hislen = newlen;
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 595f025d63..66ba9943d3 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -2477,7 +2477,6 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append)
curr->y_array[j++] = reg->y_array[y_idx++];
curr->y_size = j;
xfree(reg->y_array);
- reg = curr;
}
if (curwin->w_p_rnu) {
redraw_later(SOME_VALID); // cursor moved to start
diff --git a/src/nvim/os/pty_process.c b/src/nvim/os/pty_process.c
index c64f3f9932..ff0bcfb6de 100644
--- a/src/nvim/os/pty_process.c
+++ b/src/nvim/os/pty_process.c
@@ -205,7 +205,10 @@ static void init_termios(struct termios *termios) FUNC_ATTR_NONNULL_ALL
memset(termios, 0, sizeof(struct termios));
// Taken from pangoterm
termios->c_iflag = ICRNL|IXON;
- termios->c_oflag = OPOST|ONLCR|TAB0;
+ termios->c_oflag = OPOST|ONLCR;
+#ifdef TAB0
+ termios->c_oflag |= TAB0;
+#endif
termios->c_cflag = CS8|CREAD;
termios->c_lflag = ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK;
diff --git a/third-party/cmake/BuildLuarocks.cmake b/third-party/cmake/BuildLuarocks.cmake
index 590c41c5d5..2f83cb8239 100644
--- a/third-party/cmake/BuildLuarocks.cmake
+++ b/third-party/cmake/BuildLuarocks.cmake
@@ -1,3 +1,5 @@
+option(USE_BUNDLED_BUSTED "Use the bundled version of busted to run tests." ON)
+
if(USE_BUNDLED_LUAJIT)
list(APPEND LUAROCKS_OPTS
--with-lua=${DEPS_INSTALL_DIR}
@@ -24,67 +26,78 @@ ExternalProject_Add(luarocks
list(APPEND THIRD_PARTY_DEPS luarocks)
+# The path to the luarocks executable
+set(LUAROCKS_BINARY ${DEPS_BIN_DIR}/luarocks)
+# Common build arguments for luarocks build
+set(LUAROCKS_BUILDARGS CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER})
+
if(USE_BUNDLED_LUAJIT)
add_dependencies(luarocks luajit)
endif()
-add_custom_command(OUTPUT ${DEPS_LIB_DIR}/luarocks/rocks/stable-busted-deps
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build lua_cliargs 2.3-3 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build luafilesystem 1.6.3-1 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build dkjson 2.5-1 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build say 1.3-0 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build luassert 1.7.4-0 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build lua-term 0.1-1 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build penlight 1.0.0-1 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build mediator_lua 1.1-3 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build luasocket 3.0rc1-2 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build xml 1.1.1-1 CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- COMMAND touch ${DEPS_LIB_DIR}/luarocks/rocks/stable-busted-deps
- DEPENDS luarocks)
-add_custom_target(stable-busted-deps
- DEPENDS ${DEPS_LIB_DIR}/luarocks/rocks/stable-busted-deps)
-
-add_custom_command(OUTPUT ${DEPS_BIN_DIR}/busted
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build https://raw.githubusercontent.com/Olivine-Labs/busted/master/busted-scm-0.rockspec CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- DEPENDS stable-busted-deps)
-add_custom_target(busted
- DEPENDS ${DEPS_BIN_DIR}/busted)
-
-# lua-messagepack doesn't depend on busted, but luarocks is unhappy to have
-# two instances running in parallel. So we depend on busted to force it to
-# be serialized.
+# Each target depends on the previous module, this serializes all calls to
+# luarocks since it is unhappy to be called in parallel.
add_custom_command(OUTPUT ${DEPS_LIB_DIR}/luarocks/rocks/lua-messagepack
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build lua-messagepack CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
- DEPENDS busted)
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build lua-messagepack ${LUAROCKS_BUILDARGS}
+ DEPENDS luarocks)
add_custom_target(lua-messagepack
DEPENDS ${DEPS_LIB_DIR}/luarocks/rocks/lua-messagepack)
# Like before, depend on lua-messagepack to ensure serialization of install
# commands
add_custom_command(OUTPUT ${DEPS_LIB_DIR}/luarocks/rocks/lpeg
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build lpeg CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build lpeg ${LUAROCKS_BUILDARGS}
DEPENDS lua-messagepack)
add_custom_target(lpeg
DEPENDS ${DEPS_LIB_DIR}/luarocks/rocks/lpeg)
-add_custom_command(OUTPUT ${DEPS_LIB_DIR}/luarocks/rocks/nvim-client
- COMMAND ${DEPS_BIN_DIR}/luarocks
- ARGS build https://raw.githubusercontent.com/neovim/lua-client/8cc5b6090ac61cd0bba53ba984f15792fbb64573/nvim-client-0.0.1-11.rockspec CC=${DEPS_C_COMPILER} LD=${DEPS_C_COMPILER} LIBUV_DIR=${DEPS_INSTALL_DIR}
- DEPENDS lpeg libuv)
-add_custom_target(nvim-client
- DEPENDS ${DEPS_LIB_DIR}/luarocks/rocks/nvim-client)
+list(APPEND THIRD_PARTY_DEPS lua-messagepack lpeg)
-list(APPEND THIRD_PARTY_DEPS stable-busted-deps busted lua-messagepack lpeg nvim-client)
+if(USE_BUNDLED_BUSTED)
+ # The following are only required if we want to run tests
+ # with busted
+
+ add_custom_command(OUTPUT ${DEPS_LIB_DIR}/luarocks/rocks/stable-busted-deps
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build lua_cliargs 2.3-3 ${LUAROCKS_BUILDARGS}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build luafilesystem 1.6.3-1 ${LUAROCKS_BUILDARGS}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build dkjson 2.5-1 ${LUAROCKS_BUILDARGS}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build say 1.3-0 ${LUAROCKS_BUILDARGS}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build luassert 1.7.4-0 ${LUAROCKS_BUILDARGS}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build lua-term 0.1-1 ${LUAROCKS_BUILDARGS}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build penlight 1.0.0-1 ${LUAROCKS_BUILDARGS}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build mediator_lua 1.1-3 ${LUAROCKS_BUILDARGS}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build luasocket 3.0rc1-2 ${LUAROCKS_BUILDARGS}
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build xml 1.1.1-1 ${LUAROCKS_BUILDARGS}
+ COMMAND touch ${DEPS_LIB_DIR}/luarocks/rocks/stable-busted-deps
+ DEPENDS lpeg)
+ add_custom_target(stable-busted-deps
+ DEPENDS ${DEPS_LIB_DIR}/luarocks/rocks/stable-busted-deps)
+
+ add_custom_command(OUTPUT ${DEPS_BIN_DIR}/busted
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build https://raw.githubusercontent.com/Olivine-Labs/busted/v2.0.rc8-0/busted-2.0.rc8-0.rockspec ${LUAROCKS_BUILDARGS}
+ DEPENDS stable-busted-deps)
+ add_custom_target(busted
+ DEPENDS ${DEPS_BIN_DIR}/busted)
+
+ add_custom_command(OUTPUT ${DEPS_LIB_DIR}/luarocks/rocks/nvim-client
+ COMMAND ${LUAROCKS_BINARY}
+ ARGS build https://raw.githubusercontent.com/neovim/lua-client/8cc5b6090ac61cd0bba53ba984f15792fbb64573/nvim-client-0.0.1-11.rockspec ${LUAROCKS_BUILDARGS} LIBUV_DIR=${DEPS_INSTALL_DIR}
+ DEPENDS busted libuv)
+ add_custom_target(nvim-client
+ DEPENDS ${DEPS_LIB_DIR}/luarocks/rocks/nvim-client)
+
+ list(APPEND THIRD_PARTY_DEPS stable-busted-deps busted nvim-client)
+endif()