diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 59 | ||||
-rw-r--r-- | src/nvim/globals.h | 12 | ||||
-rw-r--r-- | src/nvim/memory.c | 10 | ||||
-rw-r--r-- | src/nvim/testdir/test_expr.vim | 11 | ||||
-rw-r--r-- | src/nvim/version.c | 64 |
5 files changed, 95 insertions, 61 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index e5858b779a..2ca621ad22 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5162,12 +5162,18 @@ dict_equal ( dictitem_T *item2; int todo; - if (d1 == NULL || d2 == NULL) - return FALSE; - if (d1 == d2) - return TRUE; - if (dict_len(d1) != dict_len(d2)) - return FALSE; + if (d1 == NULL && d2 == NULL) { + return true; + } + if (d1 == NULL || d2 == NULL) { + return false; + } + if (d1 == d2) { + return true; + } + if (dict_len(d1) != dict_len(d2)) { + return false; + } todo = (int)d1->dv_hashtab.ht_used; for (hi = d1->dv_hashtab.ht_array; todo > 0; ++hi) { @@ -6669,9 +6675,12 @@ dictitem_T *dict_find(dict_T *d, char_u *key, int len) char_u *tofree = NULL; hashitem_T *hi; - if (len < 0) + if (d == NULL) { + return NULL; + } + if (len < 0) { akey = key; - else if (len >= AKEYLEN) { + } else if (len >= AKEYLEN) { tofree = akey = vim_strnsave(key, len); } else { /* Avoid a malloc/free by using buf[]. */ @@ -10067,7 +10076,7 @@ static void f_getbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) } else if (STRCMP(varname, "changedtick") == 0) { rettv->v_type = VAR_NUMBER; rettv->vval.v_number = curbuf->b_changedtick; - done = TRUE; + done = true; } else { /* Look up the variable. */ /* Let getbufvar({nr}, "") return the "b:" dictionary. */ @@ -15064,7 +15073,6 @@ static void f_serverstop(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_setbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) { buf_T *buf; - aco_save_T aco; char_u *varname, *bufvarname; typval_T *varp; char_u nbuf[NUMBUFLEN]; @@ -15077,29 +15085,34 @@ static void f_setbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) varp = &argvars[2]; if (buf != NULL && varname != NULL && varp != NULL) { - /* set curbuf to be our buf, temporarily */ - aucmd_prepbuf(&aco, buf); - if (*varname == '&') { long numval; char_u *strval; - int error = FALSE; + int error = false; + aco_save_T aco; + + // set curbuf to be our buf, temporarily + aucmd_prepbuf(&aco, buf); ++varname; numval = get_tv_number_chk(varp, &error); strval = get_tv_string_buf_chk(varp, nbuf); if (!error && strval != NULL) set_option_value(varname, numval, strval, OPT_LOCAL); + + // reset notion of buffer + aucmd_restbuf(&aco); } else { + buf_T *save_curbuf = curbuf; + bufvarname = xmalloc(STRLEN(varname) + 3); + curbuf = buf; STRCPY(bufvarname, "b:"); STRCPY(bufvarname + 2, varname); set_var(bufvarname, varp, TRUE); xfree(bufvarname); + curbuf = save_curbuf; } - - /* reset notion of buffer */ - aucmd_restbuf(&aco); } } @@ -15516,7 +15529,10 @@ static void f_setreg(typval_T *argvars, typval_T *rettv, FunPtr fptr) } if (argvars[1].v_type == VAR_LIST) { - int len = argvars[1].vval.v_list->lv_len; + list_T *ll = argvars[1].vval.v_list; + // If the list is NULL handle like an empty list. + int len = ll == NULL ? 0 : ll->lv_len; + // First half: use for pointers to result lines; second half: use for // pointers to allocated copies. char_u **lstval = xmalloc(sizeof(char_u *) * ((len + 1) * 2)); @@ -15525,7 +15541,7 @@ static void f_setreg(typval_T *argvars, typval_T *rettv, FunPtr fptr) char_u **curallocval = allocval; char_u buf[NUMBUFLEN]; - for (listitem_T *li = argvars[1].vval.v_list->lv_first; + for (listitem_T *li = ll == NULL ? NULL : ll->lv_first; li != NULL; li = li->li_next) { char_u *strval = get_tv_string_buf_chk(&li->li_tv, buf); @@ -21561,7 +21577,10 @@ void func_unref(char_u *name) if (name != NULL && isdigit(*name)) { fp = find_func(name); if (fp == NULL) { - EMSG2(_(e_intern2), "func_unref()"); +#ifdef EXITFREE + if (!entered_free_all_mem) // NOLINT(readability/braces) +#endif + EMSG2(_(e_intern2), "func_unref()"); } else { user_func_unref(fp); } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index fbffc2d44d..872ff8d5b8 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -636,10 +636,14 @@ EXTERN int exiting INIT(= FALSE); /* TRUE when planning to exit Vim. Might * still keep on running if there is a changed * buffer. */ -/* volatile because it is used in signal handler deathtrap(). */ -EXTERN volatile int full_screen INIT(= FALSE); -/* TRUE when doing full-screen output - * otherwise only writing some messages */ +#if defined(EXITFREE) +// true when in or after free_all_mem() +EXTERN bool entered_free_all_mem INIT(= false); +#endif +// volatile because it is used in signal handler deathtrap(). +EXTERN volatile int full_screen INIT(= false); +// TRUE when doing full-screen output +// otherwise only writing some messages EXTERN int restricted INIT(= FALSE); // TRUE when started in restricted mode (-Z) diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 071ef335cf..1884d55999 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -488,13 +488,13 @@ void time_to_bytes(time_t time_, uint8_t buf[8]) void free_all_mem(void) { buf_T *buf, *nextbuf; - static bool entered = false; - /* When we cause a crash here it is caught and Vim tries to exit cleanly. - * Don't try freeing everything again. */ - if (entered) + // When we cause a crash here it is caught and Vim tries to exit cleanly. + // Don't try freeing everything again. + if (entered_free_all_mem) { return; - entered = true; + } + entered_free_all_mem = true; // Don't want to trigger autocommands from here on. block_autocmds(); diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 571a37c62c..7483973fca 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -81,3 +81,14 @@ func Test_loop_over_null_list() call assert_true(0, 'should not get here') endfor endfunc + +func Test_compare_null_dict() + call assert_fails('let x = v:_null_dict[10]') + call assert_equal({}, {}) + call assert_equal(v:_null_dict, v:_null_dict) + call assert_notequal({}, v:_null_dict) +endfunc + +func Test_set_reg_null_list() + call setreg('x', v:_null_list) +endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index 06ddbd5306..6914cd9409 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -242,7 +242,7 @@ static int included_patches[] = { 2201, // 2200, // 2199 NA - // 2198, + // 2198 NA // 2197, // 2196, // 2195 NA @@ -308,7 +308,7 @@ static int included_patches[] = { // 2135, // 2134, // 2133 NA - // 2132, + // 2132 NA // 2131 NA // 2130 NA // 2129 NA @@ -346,8 +346,8 @@ static int included_patches[] = { // 2097, // 2096, // 2095, - // 2094, - // 2093, + // 2094 NA + // 2093 NA // 2092 NA // 2091 NA // 2090, @@ -367,7 +367,7 @@ static int included_patches[] = { // 2076, // 2075, // 2074, - // 2073, + // 2073 NA // 2072, 2071, // 2070 NA @@ -397,7 +397,7 @@ static int included_patches[] = { // 2046, // 2045 NA // 2044, - // 2043, + 2043, // 2042 NA // 2041 NA // 2040 NA @@ -435,16 +435,16 @@ static int included_patches[] = { // 2008, 2007, // 2006, - // 2005, + 2005, // 2004 NA // 2003 NA // 2002, // 2001 NA - // 2000, - // 1999, + 2000, + 1999, // 1998 NA 1997, - // 1996, + 1996, // 1995 NA // 1994, // 1993, @@ -468,7 +468,7 @@ static int included_patches[] = { // 1975, // 1974 NA 1973, - // 1972, + // 1972 NA 1971, 1970, // 1969 NA @@ -485,7 +485,7 @@ static int included_patches[] = { // 1958 NA // 1957 NA 1956, - // 1955, + // 1955 NA // 1954, 1953, 1952, @@ -504,7 +504,7 @@ static int included_patches[] = { // 1939 NA // 1938 NA 1937, - // 1936, + // 1936 NA // 1935 NA // 1934 NA // 1933 NA @@ -529,15 +529,15 @@ static int included_patches[] = { // 1914, 1913, 1912, - // 1911, + // 1911 NA // 1910, 1909, // 1908 NA - // 1907, + // 1907 NA // 1906 NA - // 1905, - // 1904, - // 1903, + // 1905 NA + // 1904 NA + // 1903 NA // 1902 NA // 1901 NA 1900, @@ -552,7 +552,7 @@ static int included_patches[] = { // 1891 NA // 1890 NA // 1889, - // 1888, + // 1888 NA // 1887 NA // 1886 NA // 1885 NA @@ -572,14 +572,14 @@ static int included_patches[] = { 1871, // 1870 NA // 1869 NA - // 1868, + 1868, 1867, - // 1866, + 1866, // 1865 NA // 1864 NA // 1863 NA // 1862 NA - // 1861, + 1861, 1860, // 1859 NA // 1858 NA @@ -593,15 +593,15 @@ static int included_patches[] = { // 1850 NA // 1849 NA // 1848 NA - // 1847, + 1847, // 1846 NA // 1845 NA - // 1844, + // 1844 NA // 1843 NA 1842, 1841, 1840, - // 1839, + 1839, 1838, 1837, 1836, @@ -628,7 +628,7 @@ static int included_patches[] = { 1815, // 1814 NA 1813, - // 1812, + // 1812 NA // 1811 NA // 1810 NA 1809, @@ -660,7 +660,7 @@ static int included_patches[] = { // 1784 NA 1783, 1782, - // 1781, + 1781, 1780, 1779, // 1778 NA @@ -672,15 +672,15 @@ static int included_patches[] = { // 1772 NA // 1771 NA // 1770 NA - // 1769, + // 1769 NA 1768, // 1767 NA // 1766 NA 1765, // 1764 NA 1763, - // 1762, - // 1761, + // 1762 NA + // 1761 NA // 1760 NA 1759, 1758, @@ -715,7 +715,7 @@ static int included_patches[] = { 1730, // 1729 NA 1728, - // 1727, + // 1727 NA // 1726 NA // 1725 NA // 1724 NA @@ -786,7 +786,7 @@ static int included_patches[] = { // 1659 NA 1658, // 1657 NA - // 1656, + 1656, // 1655 NA 1654, // 1653 NA |