diff options
Diffstat (limited to 'src')
130 files changed, 3217 insertions, 4235 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 47782e8b6b..dc44c9135d 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -1,11 +1,5 @@ include(CheckLibraryExists) -option(SANITIZE "Enable Clang sanitizers for nvim binary" OFF) -if(SANITIZE AND NOT CMAKE_C_COMPILER_ID MATCHES "Clang") - message(WARNING "SANITIZE is only supported for Clang ... disabling") - set(SANITIZE OFF) -endif() - set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto) set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/msgpack-gen.lua) file(GLOB API_HEADERS api/*.h) @@ -58,9 +52,7 @@ set(CONV_SOURCES ex_cmds.c ex_docmd.c ex_getln.c - farsi.c fileio.c - fold.c getchar.c if_cscope.c mbyte.c @@ -68,11 +60,9 @@ set(CONV_SOURCES menu.c message.c misc1.c - move.c normal.c ops.c path.c - popupmnu.c quickfix.c regexp.c screen.c @@ -180,9 +170,16 @@ list(APPEND NVIM_LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ) +set(NVIM_EXEC_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES}) + +if(USE_JEMALLOC) + # dont use jemalloc in the unit test library + list(APPEND NVIM_EXEC_LINK_LIBRARIES ${JEMALLOC_LIBRARIES}) +endif() + add_executable(nvim ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES} ${NEOVIM_HEADERS}) -target_link_libraries(nvim ${NVIM_LINK_LIBRARIES}) +target_link_libraries(nvim ${NVIM_EXEC_LINK_LIBRARIES}) install_helper(TARGETS nvim) if(SANITIZE) @@ -203,5 +200,6 @@ set_property(TARGET libnvim APPEND_STRING PROPERTY COMPILE_FLAGS " -DMAKE_LIB ") add_library(nvim-test MODULE EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES} ${NEOVIM_HEADERS}) target_link_libraries(nvim-test ${NVIM_LINK_LIBRARIES}) +set_target_properties(nvim-test PROPERTIES COMPILE_FLAGS -DUNIT_TESTING) add_subdirectory(po) diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 5bd48fc19f..c9ada8dfc0 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -58,7 +58,7 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err) rv = slice.items[0].data.string; } - free(slice.items); + xfree(slice.items); return rv; } @@ -144,10 +144,10 @@ ArrayOf(String) buffer_get_line_slice(Buffer buffer, end: if (err->set) { for (size_t i = 0; i < rv.size; i++) { - free(rv.items[i].data.string.data); + xfree(rv.items[i].data.string.data); } - free(rv.items); + xfree(rv.items); rv.items = NULL; } @@ -280,7 +280,7 @@ void buffer_set_line_slice(Buffer buffer, } // Same as with replacing, but we also need to free lines - free(lines[i]); + xfree(lines[i]); lines[i] = NULL; extra++; } @@ -301,10 +301,10 @@ void buffer_set_line_slice(Buffer buffer, end: for (size_t i = 0; i < new_len; i++) { - free(lines[i]); + xfree(lines[i]); } - free(lines); + xfree(lines); restore_win_for_buf(save_curwin, save_curtab, save_curbuf); try_end(err); } diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index 76ac23a521..6c8e324649 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -22,6 +22,15 @@ typedef enum { kErrorTypeValidation } ErrorType; +typedef enum { + kMessageTypeRequest, + kMessageTypeResponse, + kMessageTypeNotification +} MessageType; + +/// Used as the message ID of notifications. +#define NO_RESPONSE UINT64_MAX + typedef struct { ErrorType type; char msg[1024]; diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 39ca0756f3..67ff77ebac 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -61,7 +61,7 @@ bool try_end(Error *err) free_global_msglist(); if (should_free) { - free(msg); + xfree(msg); } } else if (did_throw) { api_set_error(err, Exception, "%s", current_exception->value); @@ -405,6 +405,9 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err) tv->vval.v_number = obj.data.boolean; break; + case kObjectTypeBuffer: + case kObjectTypeWindow: + case kObjectTypeTabpage: case kObjectTypeInteger: if (obj.data.integer > INT_MAX || obj.data.integer < INT_MIN) { api_set_error(err, Validation, _("Integer value outside range")); @@ -489,7 +492,7 @@ void api_free_string(String value) return; } - free(value.data); + xfree(value.data); } void api_free_object(Object value) @@ -527,7 +530,7 @@ void api_free_array(Array value) api_free_object(value.items[i]); } - free(value.items); + xfree(value.items); } void api_free_dictionary(Dictionary value) @@ -537,7 +540,7 @@ void api_free_dictionary(Dictionary value) api_free_object(value.items[i].value); } - free(value.items); + xfree(value.items); } Dictionary api_metadata(void) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 587e19fe35..1204c9e1d1 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -85,7 +85,7 @@ void vim_feedkeys(String keys, String mode, Boolean escape_csi) insert ? 0 : typebuf.tb_len, !typed, false); if (escape_csi) { - free(keys_esc); + xfree(keys_esc); } if (vgetc_busy) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 11cb7bdeac..4585278714 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -443,8 +443,8 @@ close_buffer ( * Remove the buffer from the list. */ if (wipe_buf) { - free(buf->b_ffname); - free(buf->b_sfname); + xfree(buf->b_ffname); + xfree(buf->b_sfname); if (buf->b_prev == NULL) firstbuf = buf->b_next; else @@ -563,7 +563,7 @@ static void free_buffer(buf_T *buf) buf->b_next = au_pending_free_buf; au_pending_free_buf = buf; } else { - free(buf); + xfree(buf); } } @@ -587,7 +587,7 @@ free_buffer_stuff ( buf_delete_signs(buf); /* delete any signs */ map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); /* clear local mappings */ map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); /* clear local abbrevs */ - free(buf->b_start_fenc); + xfree(buf->b_start_fenc); buf->b_start_fenc = NULL; } @@ -605,7 +605,7 @@ static void clear_wininfo(buf_T *buf) clear_winopt(&wip->wi_opt); deleteFoldRecurse(&wip->wi_folds); } - free(wip); + xfree(wip); } } @@ -1332,7 +1332,7 @@ buflist_new ( if (ffname != NULL && !(flags & BLN_DUMMY) && (buf = buflist_findname_file_id(ffname, &file_id, file_id_valid)) != NULL) { - free(ffname); + xfree(ffname); if (lnum != 0) buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE); /* copy the options now, if 'cpo' doesn't have 's' and not done @@ -1396,9 +1396,9 @@ buflist_new ( buf->b_wininfo = xcalloc(1, sizeof(wininfo_T)); if (ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) { - free(buf->b_ffname); + xfree(buf->b_ffname); buf->b_ffname = NULL; - free(buf->b_sfname); + xfree(buf->b_sfname); buf->b_sfname = NULL; if (buf != curbuf) free_buffer(buf); @@ -1672,7 +1672,7 @@ buf_T *buflist_findname_exp(char_u *fname) ); if (ffname != NULL) { buf = buflist_findname(ffname); - free(ffname); + xfree(ffname); } return buf; } @@ -1767,7 +1767,7 @@ buflist_findpat ( ++p; prog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); if (prog == NULL) { - free(pat); + xfree(pat); return -1; } @@ -1809,7 +1809,7 @@ buflist_findpat ( find_listed = FALSE; } - free(pat); + xfree(pat); } if (match == -2) @@ -1855,7 +1855,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) prog = vim_regcomp(patc + attempt * 11, RE_MAGIC); if (prog == NULL) { if (patc != pat) - free(patc); + xfree(patc); return FAIL; } @@ -1893,7 +1893,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) } if (patc != pat) - free(patc); + xfree(patc); *num_file = count; return count == 0 ? FAIL : OK; @@ -1938,7 +1938,7 @@ static char_u *fname_match(regprog_T *prog, char_u *name, bool ignore_case) p = home_replace_save(NULL, name); if (vim_regexec(®match, p, (colnr_T)0)) match = name; - free(p); + xfree(p); } } @@ -2223,8 +2223,8 @@ setfname ( if (ffname == NULL || *ffname == NUL) { /* Removing the name. */ - free(buf->b_ffname); - free(buf->b_sfname); + xfree(buf->b_ffname); + xfree(buf->b_sfname); buf->b_ffname = NULL; buf->b_sfname = NULL; } else { @@ -2245,7 +2245,7 @@ setfname ( if (obuf->b_ml.ml_mfp != NULL) { /* it's loaded, fail */ if (message) EMSG(_("E95: Buffer with this name already exists")); - free(ffname); + xfree(ffname); return FAIL; } /* delete from the list */ @@ -2255,8 +2255,8 @@ setfname ( #ifdef USE_FNAME_CASE path_fix_case(sfname); /* set correct case for short file name */ #endif - free(buf->b_ffname); - free(buf->b_sfname); + xfree(buf->b_ffname); + xfree(buf->b_sfname); buf->b_ffname = ffname; buf->b_sfname = sfname; } @@ -2282,8 +2282,8 @@ void buf_set_name(int fnum, char_u *name) buf = buflist_findnr(fnum); if (buf != NULL) { - free(buf->b_sfname); - free(buf->b_ffname); + xfree(buf->b_sfname); + xfree(buf->b_ffname); buf->b_ffname = vim_strsave(name); buf->b_sfname = NULL; /* Allocate ffname and expand into full path. Also resolves .lnk @@ -2561,7 +2561,7 @@ fileinfo ( set_keep_msg(p, 0); } - free(buffer); + xfree(buffer); } void col_print(char_u *buf, size_t buflen, int col, int vcol) @@ -2636,7 +2636,7 @@ void maketitle(void) else { p = transstr(path_tail(curbuf->b_fname)); STRLCPY(buf, p, SPACE_FOR_FNAME + 1); - free(p); + xfree(p); } switch (bufIsChanged(curbuf) @@ -2677,7 +2677,7 @@ void maketitle(void) if (off < SPACE_FOR_DIR) { p = transstr(buf + off); STRLCPY(buf + off, p, SPACE_FOR_DIR - off + 1); - free(p); + xfree(p); } else { STRLCPY(buf + off, "...", SPACE_FOR_ARGNR - off + 1); } @@ -2749,7 +2749,7 @@ static int ti_change(char_u *str, char_u **last) { if ((str == NULL) != (*last == NULL) || (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) { - free(*last); + xfree(*last); if (str == NULL) *last = NULL; else @@ -2771,8 +2771,8 @@ void resettitle(void) # if defined(EXITFREE) void free_titles(void) { - free(lasttitle); - free(lasticon); + xfree(lasttitle); + xfree(lasticon); } # endif @@ -3124,7 +3124,7 @@ build_stl_str_hl ( if (str != NULL && *str != 0) { if (*skipdigits(str) == NUL) { num = atoi((char *)str); - free(str); + xfree(str); str = NULL; itemisflag = FALSE; } @@ -3381,7 +3381,7 @@ build_stl_str_hl ( item[curitem].type = Empty; if (opt == STL_VIM_EXPR) - free(str); + xfree(str); if (num >= 0 || (!itemisflag && str && *str)) prevchar_isflag = FALSE; /* Item not NULL, but not a flag */ @@ -3391,7 +3391,7 @@ build_stl_str_hl ( itemcnt = curitem; if (usefmt != fmt) - free(usefmt); + xfree(usefmt); width = vim_strsize(out); if (maxwidth > 0 && width > maxwidth) { @@ -3585,7 +3585,7 @@ void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname) /* If the file name is a shortcut file, use the file it links to. */ rfname = mch_resolve_shortcut(*ffname); if (rfname != NULL) { - free(*ffname); + xfree(*ffname); *ffname = rfname; *sfname = rfname; } @@ -3844,7 +3844,7 @@ do_arg_all ( win_enter(new_curwin, false); --autocmd_no_leave; - free(opened); + xfree(opened); } /* @@ -4161,7 +4161,7 @@ chk_modeline ( sourcing_lnum = save_sourcing_lnum; sourcing_name = save_sourcing_name; - free(linecopy); + xfree(linecopy); return retval; } @@ -4208,7 +4208,7 @@ int read_viminfo_bufferlist(vir_T *virp, int writing) buflist_setfpos(buf, curwin, lnum, col, FALSE); } } - free(xline); + xfree(xline); return viminfo_readline(virp); } @@ -4249,7 +4249,7 @@ void write_viminfo_bufferlist(FILE *fp) buf->b_last_cursor.col); viminfo_writestring(fp, line); } - free(line); + xfree(line); } @@ -4426,7 +4426,7 @@ linenr_T buf_delsign( if (sign->id == id) { *lastp = next; lnum = sign->lnum; - free(sign); + xfree(sign); break; } else { lastp = &sign->next; @@ -4498,7 +4498,7 @@ void buf_delete_signs(buf_T *buf) while (buf->b_signlist != NULL) { next = buf->b_signlist->next; - free(buf->b_signlist); + xfree(buf->b_signlist); buf->b_signlist = next; } } @@ -4621,7 +4621,7 @@ int buf_contents_changed(buf_T *buf) } } } - free(ea.cmd); + xfree(ea.cmd); /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index 35fa3978b6..9c8cdd41ae 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -6,6 +6,8 @@ // for FILE #include <stdio.h> +typedef struct file_buffer buf_T; // Forward declaration + // for garray_T #include "nvim/garray.h" // for pos_T, lpos_T and linenr_T @@ -16,7 +18,7 @@ #include "nvim/iconv.h" // for jump list and tag stack sizes in a buffer and mark types #include "nvim/mark_defs.h" -// for u_header_T +// for u_header_T; needs buf_T. #include "nvim/undo_defs.h" // for hashtab_T #include "nvim/hashtab.h" @@ -80,7 +82,6 @@ typedef struct window_S win_T; typedef struct wininfo_S wininfo_T; typedef struct frame_S frame_T; typedef int scid_T; /* script ID */ -typedef struct file_buffer buf_T; /* forward declaration */ // for struct memline (it needs memfile_T) #include "nvim/memline_defs.h" diff --git a/src/nvim/diff.c b/src/nvim/diff.c index e50b096270..937baad648 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -393,7 +393,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, } } dprev->df_next = dp->df_next; - free(dp); + xfree(dp); dp = dprev->df_next; } else { // Advance to next entry. @@ -416,7 +416,7 @@ static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, if (i == DB_COUNT) { diff_T *dnext = dp->df_next; - free(dp); + xfree(dp); dp = dnext; if (dprev == NULL) { @@ -527,7 +527,7 @@ static void diff_check_unchanged(tabpage_T *tp, diff_T *dp) break; } } - free(line_org); + xfree(line_org); // Stop when a line isn't equal in all diff buffers. if (i_new != DB_COUNT) { @@ -786,9 +786,9 @@ void ex_diffupdate(exarg_T *eap) diff_redraw(TRUE); theend: - free(tmp_orig); - free(tmp_new); - free(tmp_diff); + xfree(tmp_orig); + xfree(tmp_new); + xfree(tmp_diff); } /// Make a diff between files "tmp_orig" and "tmp_new", results in "tmp_diff". @@ -828,7 +828,7 @@ static void diff_file(char_u *tmp_orig, char_u *tmp_new, char_u *tmp_diff) NULL ); unblock_autocmds(); - free(cmd); + xfree(cmd); } } @@ -989,16 +989,16 @@ theend: if (tmp_orig != NULL) { os_remove((char *)tmp_orig); } - free(tmp_orig); + xfree(tmp_orig); if (tmp_new != NULL) { os_remove((char *)tmp_new); } - free(tmp_new); - free(newname); - free(buf); + xfree(tmp_new); + xfree(newname); + xfree(buf); #ifdef UNIX - free(fullname); + xfree(fullname); #endif // ifdef UNIX } @@ -1340,7 +1340,7 @@ static void diff_read(int idx_orig, int idx_new, char_u *fname) while (dn != dp->df_next) { dpl = dn->df_next; - free(dn); + xfree(dn); dn = dpl; } } else { @@ -1407,7 +1407,7 @@ void diff_clear(tabpage_T *tp) diff_T *next_p; for (p = tp->tp_first_diff; p != NULL; p = next_p) { next_p = p->df_next; - free(p); + xfree(p); } tp->tp_first_diff = NULL; } @@ -1559,7 +1559,7 @@ static int diff_equal_entry(diff_T *dp, int idx1, int idx2) int cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], dp->df_lnum[idx2] + i, FALSE)); - free(line); + xfree(line); if (cmp != 0) { return FALSE; @@ -1863,7 +1863,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) int idx = diff_buf_idx(wp->w_buffer); if (idx == DB_COUNT) { // cannot happen - free(line_org); + xfree(line_org); return FALSE; } @@ -1876,7 +1876,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) } if ((dp == NULL) || (diff_check_sanity(curtab, dp) == FAIL)) { - free(line_org); + xfree(line_org); return FALSE; } @@ -1956,7 +1956,7 @@ int diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp) } } - free(line_org); + xfree(line_org); return added; } @@ -2262,7 +2262,7 @@ void ex_diffgetput(exarg_T *eap) } p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], nr, FALSE)); ml_append(lnum + i - 1, p, 0, FALSE); - free(p); + xfree(p); added++; if (buf_empty && (curbuf->b_ml.ml_line_count == 2)) { // Added the first line into an empty buffer, need to @@ -2317,7 +2317,7 @@ void ex_diffgetput(exarg_T *eap) if (dfree != NULL) { // Diff is deleted, update folds in other windows. diff_fold_update(dfree, idx_to); - free(dfree); + xfree(dfree); } else { // mark_adjust() may have changed the count in a wrong way dp->df_count[idx_to] = new_count; diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index cb6bfc9cc9..cf998c041d 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1538,7 +1538,7 @@ static int getexactdigraph(int char1, int char2, int meta_char) if (to != NULL) { retval = (*mb_ptr2char)(to); - free(to); + xfree(to); } (void)convert_setup(&vc, NULL, NULL); } @@ -1763,11 +1763,11 @@ char_u* keymap_init(void) curbuf->b_p_keymap); if (source_runtime((char_u *)buf, FALSE) == FAIL) { - free(buf); + xfree(buf); return (char_u *)N_("E544: Keymap file not found"); } } - free(buf); + xfree(buf); } return NULL; @@ -1824,12 +1824,12 @@ void ex_loadkeymap(exarg_T *eap) if (*kp->to == NUL) { EMSG(_("E791: Empty keymap entry")); } - free(kp->from); - free(kp->to); + xfree(kp->from); + xfree(kp->to); --curbuf->b_kmap_ga.ga_len; } } - free(line); + xfree(line); } // setup ":lnoremap" to map the keys @@ -1866,8 +1866,8 @@ static void keymap_unload(void) for (int i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from); (void)do_map(1, buf, LANGMAP, FALSE); - free(kp[i].from); - free(kp[i].to); + xfree(kp[i].from); + xfree(kp[i].to); } p_cpo = save_cpo; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 8b2ac1943f..26665aa84c 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -246,7 +246,7 @@ edit ( ) { if (curbuf->terminal) { - terminal_enter(curbuf->terminal, true); + terminal_enter(true); return false; } @@ -482,7 +482,7 @@ edit ( new_insert_skip = 0; else { new_insert_skip = (int)STRLEN(ptr); - free(ptr); + xfree(ptr); } old_indent = 0; @@ -652,7 +652,7 @@ edit ( if (str != NULL) { for (p = str; *p != NUL; mb_ptr_adv(p)) ins_compl_addleader(PTR2CHAR(p)); - free(str); + xfree(str); } else ins_compl_addleader(c); continue; @@ -1153,7 +1153,7 @@ normalchar: } AppendToRedobuffLit(str, -1); } - free(str); + xfree(str); c = NUL; } @@ -1569,7 +1569,7 @@ change_indent ( memset(ptr, ' ', i); new_cursor_col += i; ins_str(ptr); - free(ptr); + xfree(ptr); } /* @@ -1648,7 +1648,7 @@ change_indent ( /* Insert new stuff into line again */ ins_bytes(new_line); - free(new_line); + xfree(new_line); } } @@ -1970,7 +1970,7 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int *(p++) = wca[i++]; *p = NUL; - free(wca); + xfree(wca); return ins_compl_add(IObuff, len, icase, fname, NULL, dir, flags, FALSE); @@ -2273,7 +2273,7 @@ static void ins_compl_del_pum(void) { if (compl_match_array != NULL) { pum_undisplay(); - free(compl_match_array); + xfree(compl_match_array); compl_match_array = NULL; } } @@ -2490,8 +2490,8 @@ ins_compl_dictionaries ( ptr = xmalloc(len); vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc); regmatch.regprog = vim_regcomp(ptr, RE_MAGIC); - free(pat_esc); - free(ptr); + xfree(pat_esc); + xfree(ptr); } else { regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); if (regmatch.regprog == NULL) @@ -2539,7 +2539,7 @@ ins_compl_dictionaries ( theend: p_scs = save_p_scs; vim_regfree(regmatch.regprog); - free(buf); + xfree(buf); } static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir) @@ -2689,9 +2689,9 @@ static void ins_compl_free(void) compl_T *match; int i; - free(compl_pattern); + xfree(compl_pattern); compl_pattern = NULL; - free(compl_leader); + xfree(compl_leader); compl_leader = NULL; if (compl_first_match == NULL) @@ -2704,13 +2704,13 @@ static void ins_compl_free(void) do { match = compl_curr_match; compl_curr_match = compl_curr_match->cp_next; - free(match->cp_str); + xfree(match->cp_str); /* several entries may use the same fname, free it just once. */ if (match->cp_flags & FREE_FNAME) - free(match->cp_fname); + xfree(match->cp_fname); for (i = 0; i < CPT_COUNT; ++i) - free(match->cp_text[i]); - free(match); + xfree(match->cp_text[i]); + xfree(match); } while (compl_curr_match != NULL && compl_curr_match != compl_first_match); compl_first_match = compl_curr_match = NULL; compl_shown_match = NULL; @@ -2721,12 +2721,12 @@ static void ins_compl_clear(void) compl_cont_status = 0; compl_started = FALSE; compl_matches = 0; - free(compl_pattern); + xfree(compl_pattern); compl_pattern = NULL; - free(compl_leader); + xfree(compl_leader); compl_leader = NULL; edit_submode_extra = NULL; - free(compl_orig_text); + xfree(compl_orig_text); compl_orig_text = NULL; compl_enter_selects = FALSE; } @@ -2767,7 +2767,7 @@ static int ins_compl_bs(void) || ins_compl_need_restart()) ins_compl_restart(); - free(compl_leader); + xfree(compl_leader); compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col); ins_compl_new_leader(); if (compl_shown_match != NULL) @@ -2871,7 +2871,7 @@ static void ins_compl_addleader(int c) * cursor doesn't point original position, changing compl_leader would * break redo. */ if (!compl_opt_refresh_always) { - free(compl_leader); + xfree(compl_leader); compl_leader = vim_strnsave(get_cursor_line_ptr() + compl_col, (int)(curwin->w_cursor.col - compl_col)); ins_compl_new_leader(); @@ -2898,7 +2898,7 @@ static void ins_compl_set_original_text(char_u *str) { /* Replace the original text entry. */ if (compl_first_match->cp_flags & ORIGINAL_TEXT) { /* safety check */ - free(compl_first_match->cp_str); + xfree(compl_first_match->cp_str); compl_first_match->cp_str = vim_strsave(str); } } @@ -4449,13 +4449,13 @@ static int ins_complete(int c) ins_compl_fixRedoBufForLeader(NULL); /* Always add completion for the original text. */ - free(compl_orig_text); + xfree(compl_orig_text); compl_orig_text = vim_strnsave(line + compl_col, compl_length); if (ins_compl_add(compl_orig_text, -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK) { - free(compl_pattern); + xfree(compl_pattern); compl_pattern = NULL; - free(compl_orig_text); + xfree(compl_orig_text); compl_orig_text = NULL; return FAIL; } @@ -5326,7 +5326,7 @@ internal_format ( * moved, now we re-insert it into the new line. */ ins_bytes(saved_text); - free(saved_text); + xfree(saved_text); } else { /* * Check if cursor is not past the NUL off the line, cindent @@ -5661,11 +5661,11 @@ stop_insert ( ptr = get_inserted(); if (did_restart_edit == 0 || (ptr != NULL && (int)STRLEN(ptr) > new_insert_skip)) { - free(last_insert); + xfree(last_insert); last_insert = ptr; last_insert_skip = new_insert_skip; } else - free(ptr); + xfree(ptr); if (!arrow_used && end_insert_pos != NULL) { /* Auto-format now. It may seem strange to do this when stopping an @@ -5770,7 +5770,7 @@ void set_last_insert(int c) { char_u *s; - free(last_insert); + xfree(last_insert); last_insert = xmalloc(MB_MAXBYTES * 3 + 5); s = last_insert; /* Use the CTRL-V only when entering a special char */ @@ -5785,9 +5785,9 @@ void set_last_insert(int c) #if defined(EXITFREE) void free_last_insert(void) { - free(last_insert); + xfree(last_insert); last_insert = NULL; - free(compl_orig_text); + xfree(compl_orig_text); compl_orig_text = NULL; } @@ -6307,7 +6307,7 @@ static void mb_replace_pop_ins(int cc) */ static void replace_flush(void) { - free(replace_stack); + xfree(replace_stack); replace_stack = NULL; replace_stack_len = 0; replace_stack_nr = 0; @@ -7354,9 +7354,9 @@ static int ins_bs(int c, int mode, int *inserted_space_p) *inserted_space_p = FALSE; if (p_sta && in_indent) - ts = (int)get_sw_value(curbuf); + ts = get_sw_value(curbuf); else - ts = (int)get_sts_value(); + ts = get_sts_value(); /* Compute the virtual column where we want to be. Since * 'showbreak' may get in the way, need to get the last column of * the previous character. */ @@ -7826,9 +7826,9 @@ static int ins_tab(void) AppendToRedobuff((char_u *)"\t"); if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ - temp = (int)get_sw_value(curbuf); + temp = get_sw_value(curbuf); else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */ - temp = (int)get_sts_value(); + temp = get_sts_value(); else /* otherwise use 'tabstop' */ temp = (int)curbuf->b_p_ts; temp -= get_nolist_virtcol() % temp; @@ -7966,7 +7966,7 @@ static int ins_tab(void) } if (State & VREPLACE_FLAG) - free(saved_line); + xfree(saved_line); curwin->w_p_list = save_list; } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 4ab31985b5..1dab9df9cb 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -21,8 +21,6 @@ #include <math.h> #include <limits.h> -#include "nvim/lib/klist.h" - #include "nvim/assert.h" #include "nvim/vim.h" #include "nvim/ascii.h" @@ -89,6 +87,7 @@ #include "nvim/os/rstream_defs.h" #include "nvim/os/time.h" #include "nvim/msgpack_rpc/channel.h" +#include "nvim/msgpack_rpc/server.h" #include "nvim/api/private/helpers.h" #include "nvim/api/vim.h" #include "nvim/os/dl.h" @@ -469,10 +468,7 @@ typedef struct { list_T *received; int status; } JobEvent; -#define JobEventFreer(x) -KMEMPOOL_INIT(JobEventPool, JobEvent, JobEventFreer) -static kmempool_t(JobEventPool) *job_event_pool = NULL; -static bool defer_job_callbacks = true; +static int disable_job_defer = 0; /* * Initialize the global and v: variables. @@ -508,8 +504,6 @@ void eval_init(void) set_vim_var_nr(VV_SEARCHFORWARD, 1L); set_vim_var_nr(VV_HLSEARCH, 1L); set_reg_var(0); /* default for v:register is not 0 but '"' */ - - job_event_pool = kmp_init(JobEventPool); } #if defined(EXITFREE) @@ -520,7 +514,7 @@ void eval_clear(void) for (int i = 0; i < VV_LEN; ++i) { p = &vimvars[i]; if (p->vv_di.di_tv.v_type == VAR_STRING) { - free(p->vv_str); + xfree(p->vv_str); p->vv_str = NULL; } else if (p->vv_di.di_tv.v_type == VAR_LIST) { list_unref(p->vv_list); @@ -546,7 +540,7 @@ void eval_clear(void) for (int i = 1; i <= ga_scripts.ga_len; ++i) vars_clear(&SCRIPT_VARS(i)); for (int i = 1; i <= ga_scripts.ga_len; ++i) - free(SCRIPT_SV(i)); + xfree(SCRIPT_SV(i)); ga_clear(&ga_scripts); /* unreferenced lists and dicts */ @@ -742,13 +736,13 @@ void var_redir_stop(void) } /* free the collected output */ - free(redir_ga.ga_data); + xfree(redir_ga.ga_data); redir_ga.ga_data = NULL; - free(redir_lval); + xfree(redir_lval); redir_lval = NULL; } - free(redir_varname); + xfree(redir_varname); redir_varname = NULL; } @@ -1066,7 +1060,7 @@ typval_T *eval_expr(char_u *arg, char_u **nextcmd) typval_T *tv = xmalloc(sizeof(typval_T)); if (eval0(arg, tv, nextcmd, TRUE) == FAIL) { - free(tv); + xfree(tv); return NULL; } @@ -1133,7 +1127,7 @@ call_vim_function ( --sandbox; restore_funccal(save_funccalp); } - free(argvars); + xfree(argvars); if (ret == FAIL) clear_tv(rettv); @@ -1698,14 +1692,14 @@ static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first) s == NULL ? (char_u *)"" : s, first); *arg = c; - free(tf); + xfree(tf); } clear_tv(&tv); } } } - free(tofree); + xfree(tofree); } arg = skipwhite(arg); @@ -1763,7 +1757,7 @@ ex_let_one ( if (s != NULL) { p = tofree = concat_str(s, p); if (mustfree) - free(s); + xfree(s); } } if (p != NULL) { @@ -1778,7 +1772,7 @@ ex_let_one ( arg_end = arg; } name[len] = c1; - free(tofree); + xfree(tofree); } } } @@ -1819,7 +1813,7 @@ ex_let_one ( n = numval - n; } else if (opt_type == 0 && stringval != NULL) { /* string */ s = concat_str(stringval, s); - free(stringval); + xfree(stringval); stringval = s; } } @@ -1829,7 +1823,7 @@ ex_let_one ( arg_end = p; } *p = c1; - free(stringval); + xfree(stringval); } } /* @@ -1851,14 +1845,14 @@ ex_let_one ( s = get_reg_contents(*arg == '@' ? '"' : *arg, kGRegExprSrc); if (s != NULL) { p = ptofree = concat_str(s, p); - free(s); + xfree(s); } } if (p != NULL) { write_reg_contents(*arg == '@' ? '"' : *arg, p, -1, FALSE); arg_end = arg + 1; } - free(ptofree); + xfree(ptofree); } } /* @@ -2218,8 +2212,8 @@ get_lval ( */ static void clear_lval(lval_T *lp) { - free(lp->ll_exp_name); - free(lp->ll_newkey); + xfree(lp->ll_exp_name); + xfree(lp->ll_newkey); } /* @@ -2312,7 +2306,7 @@ static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, ch /* Need to add an item to the Dictionary. */ di = dictitem_alloc(lp->ll_newkey); if (dict_add(lp->ll_tv->vval.v_dict, di) == FAIL) { - free(di); + xfree(di); return; } lp->ll_tv = &di->di_tv; @@ -2547,7 +2541,7 @@ void free_for_info(void *fi_void) list_rem_watch(fi->fi_list, &fi->fi_lw); list_unref(fi->fi_list); } - free(fi); + xfree(fi); } @@ -2661,7 +2655,7 @@ void ex_call(exarg_T *eap) if (fudi.fd_newkey != NULL) { /* Still need to give an error message for missing key. */ EMSG2(_(e_dictkey), fudi.fd_newkey); - free(fudi.fd_newkey); + xfree(fudi.fd_newkey); } if (tofree == NULL) return; @@ -2741,7 +2735,7 @@ void ex_call(exarg_T *eap) end: dict_unref(fudi.fd_dict); - free(tofree); + xfree(tofree); } /* @@ -3062,7 +3056,7 @@ static char_u *cat_prefix_varname(int prefix, char_u *name) size_t len = STRLEN(name) + 3; if (len > varnamebuflen) { - free(varnamebuf); + xfree(varnamebuf); len += 10; /* some additional space */ varnamebuf = xmalloc(len); varnamebuflen = len; @@ -3149,7 +3143,7 @@ char_u *get_user_var_name(expand_T *xp, int idx) if (vidx < VV_LEN) return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name); - free(varnamebuf); + xfree(varnamebuf); varnamebuf = NULL; varnamebuflen = 0; return NULL; @@ -4157,7 +4151,7 @@ eval7 ( else ret = OK; } - free(alias); + xfree(alias); } *arg = skipwhite(*arg); @@ -4791,9 +4785,9 @@ list_free ( if (recurse || (item->li_tv.v_type != VAR_LIST && item->li_tv.v_type != VAR_DICT)) clear_tv(&item->li_tv); - free(item); + xfree(item); } - free(l); + xfree(l); } /* @@ -4810,7 +4804,7 @@ listitem_T *listitem_alloc(void) FUNC_ATTR_NONNULL_RET void listitem_free(listitem_T *item) { clear_tv(&item->li_tv); - free(item); + xfree(item); } /* @@ -5282,7 +5276,7 @@ static list_T *list_copy(list_T *orig, int deep, int copyID) ni = listitem_alloc(); if (deep) { if (item_copy(&item->li_tv, &ni->li_tv, deep, copyID) == FAIL) { - free(ni); + xfree(ni); break; } } else @@ -5337,7 +5331,7 @@ static char_u *list2string(typval_T *tv, int copyID) ga_init(&ga, (int)sizeof(char), 80); ga_append(&ga, '['); if (list_join(&ga, tv->vval.v_list, (char_u *)", ", FALSE, copyID) == FAIL) { - free(ga.ga_data); + xfree(ga.ga_data); return NULL; } ga_append(&ga, ']'); @@ -5430,7 +5424,7 @@ static int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int ga_init(&join_ga, (int)sizeof(join_T), l->lv_len); retval = list_join_inner(gap, l, sep, echo_style, copyID, &join_ga); -# define FREE_JOIN_TOFREE(join) free((join)->tofree) +# define FREE_JOIN_TOFREE(join) xfree((join)->tofree) GA_DEEP_CLEAR(&join_ga, join_T, FREE_JOIN_TOFREE); return retval; @@ -5736,12 +5730,12 @@ dict_free ( if (recurse || (di->di_tv.v_type != VAR_LIST && di->di_tv.v_type != VAR_DICT)) clear_tv(&di->di_tv); - free(di); + xfree(di); --todo; } } hash_clear(&d->dv_hashtab); - free(d); + xfree(d); } /* @@ -5794,7 +5788,7 @@ static void dictitem_remove(dict_T *dict, dictitem_T *item) void dictitem_free(dictitem_T *item) { clear_tv(&item->di_tv); - free(item); + xfree(item); } /* @@ -5827,7 +5821,7 @@ static dict_T *dict_copy(dict_T *orig, int deep, int copyID) if (deep) { if (item_copy(&HI2DI(hi)->di_tv, &di->di_tv, deep, copyID) == FAIL) { - free(di); + xfree(di); break; } } else @@ -5936,33 +5930,39 @@ dictitem_T *dict_find(dict_T *d, char_u *key, int len) } hi = hash_find(&d->dv_hashtab, akey); - free(tofree); + xfree(tofree); if (HASHITEM_EMPTY(hi)) return NULL; return HI2DI(hi); } -// Get a function from a dictionary -static ufunc_T *get_dict_callback(dict_T *d, char *key) +/// Get a function from a dictionary +/// @param[out] result The address where a pointer to the wanted callback +/// will be left. +/// @return true/false on success/failure. +static bool get_dict_callback(dict_T *d, char *key, ufunc_T **result) { dictitem_T *di = dict_find(d, (uint8_t *)key, -1); if (di == NULL) { - return NULL; + *result = NULL; + return true; } if (di->di_tv.v_type != VAR_FUNC && di->di_tv.v_type != VAR_STRING) { EMSG(_("Argument is not a function or function name")); - return NULL; + *result = NULL; + return false; } uint8_t *name = di->di_tv.vval.v_string; uint8_t *n = name; - ufunc_T *rv; + ufunc_T *rv = NULL; if (*n > '9' || *n < '0') { - n = trans_function_name(&n, false, TFN_INT|TFN_QUIET, NULL); - rv = find_func(n); - free(n); + if ((n = trans_function_name(&n, false, TFN_INT|TFN_QUIET, NULL))) { + rv = find_func(n); + xfree(n); + } } else { // dict function, name is already translated rv = find_func(n); @@ -5970,11 +5970,13 @@ static ufunc_T *get_dict_callback(dict_T *d, char *key) if (!rv) { EMSG2(_("Function %s doesn't exist"), name); - return NULL; + *result = NULL; + return false; } rv->uf_refcount++; - return rv; + *result = rv; + return true; } /* @@ -6044,20 +6046,20 @@ static char_u *dict2string(typval_T *tv, int copyID) tofree = string_quote(hi->hi_key, FALSE); if (tofree != NULL) { ga_concat(&ga, tofree); - free(tofree); + xfree(tofree); } ga_concat(&ga, (char_u *)": "); s = tv2string(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID); if (s != NULL) ga_concat(&ga, s); - free(tofree); + xfree(tofree); if (s == NULL || did_echo_string_emsg) { break; } line_breakcheck(); } if (todo > 0) { - free(ga.ga_data); + xfree(ga.ga_data); return NULL; } @@ -6373,13 +6375,13 @@ static int get_env_tv(char_u **arg, typval_T *rettv, int evaluate) } } else { if (mustfree) { - free(string); + xfree(string); } // Next try expanding things like $VIM and ${HOME}. string = expand_env_save(name - 1); if (string != NULL && *string == '$') { - free(string); + xfree(string); string = NULL; } } @@ -6604,6 +6606,9 @@ static struct fst { {"searchpair", 3, 7, f_searchpair}, {"searchpairpos", 3, 7, f_searchpairpos}, {"searchpos", 1, 4, f_searchpos}, + {"serverlist", 0, 0, f_serverlist}, + {"serverstart", 0, 1, f_serverstart}, + {"serverstop", 1, 1, f_serverstop}, {"setbufvar", 3, 3, f_setbufvar}, {"setcmdpos", 1, 1, f_setcmdpos}, {"setline", 2, 2, f_setline}, @@ -7029,8 +7034,8 @@ call_func ( } if (fname != name && fname != fname_buf) - free(fname); - free(name); + xfree(fname); + xfree(name); return ret; } @@ -7049,7 +7054,7 @@ static void emsg_funcname(char *ermsg, char_u *name) p = name; EMSG2(_(ermsg), p); if (p != name) - free(p); + xfree(p); } /* @@ -8199,7 +8204,7 @@ static void f_exists(typval_T *argvars, typval_T *rettv) p = expand_env_save(p); if (p != NULL && *p != '$') n = TRUE; - free(p); + xfree(p); } } else if (*p == '&' || *p == '+') { /* option */ n = (get_option_tv(&p, NULL, TRUE) == OK); @@ -8235,7 +8240,7 @@ static void f_exists(typval_T *argvars, typval_T *rettv) if (*p != NUL) n = FALSE; - free(tofree); + xfree(tofree); } rettv->vval.v_number = n; @@ -8528,7 +8533,7 @@ static void findfilendir(typval_T *argvars, typval_T *rettv, int find_what) if (*fname != NUL && !error) { do { if (rettv->v_type == VAR_STRING || rettv->v_type == VAR_LIST) - free(fresult); + xfree(fresult); fresult = find_file_in_path_option(first ? fname : NULL, first ? (int)STRLEN(fname) : 0, 0, first, path, @@ -8791,7 +8796,7 @@ static void f_fnamemodify(typval_T *argvars, typval_T *rettv) rettv->vval.v_string = NULL; else rettv->vval.v_string = vim_strnsave(fname, len); - free(fbuf); + xfree(fbuf); } @@ -9274,7 +9279,7 @@ static void f_getcwd(typval_T *argvars, typval_T *rettv) slash_adjust(rettv->vval.v_string); #endif } - free(cwd); + xfree(cwd); } /* @@ -10251,8 +10256,8 @@ static void f_iconv(typval_T *argvars, typval_T *rettv) rettv->vval.v_string = string_convert(&vimconv, str, NULL); convert_setup(&vimconv, NULL, NULL); - free(from); - free(to); + xfree(from); + xfree(to); } /* @@ -10390,7 +10395,7 @@ static void get_user_input(typval_T *argvars, typval_T *rettv, int inputdialog) rettv->vval.v_string = vim_strsave(get_tv_string_buf( &argvars[2], buf)); - free(xp_arg); + xfree(xp_arg); /* since the user typed this, no need to wait for return */ need_wait_return = FALSE; @@ -10741,7 +10746,7 @@ static void f_jobsend(typval_T *argvars, typval_T *rettv) return; } - WBuffer *buf = wstream_new_buffer(input, input_len, 1, free); + WBuffer *buf = wstream_new_buffer(input, input_len, 1, xfree); rettv->vval.v_number = job_write(job, buf); } @@ -10810,9 +10815,12 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv) return; } - if (!os_can_exe(args->lv_first->li_tv.vval.v_string, NULL)) { + assert(args->lv_first); + + const char_u *exe = get_tv_string(&args->lv_first->li_tv); + if (!os_can_exe(exe, NULL)) { // String is not executable - EMSG2(e_jobexe, args->lv_first->li_tv.vval.v_string); + EMSG2(e_jobexe, exe); return; } @@ -10820,8 +10828,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv) ufunc_T *on_stdout = NULL, *on_stderr = NULL, *on_exit = NULL; if (argvars[1].v_type == VAR_DICT) { job_opts = argvars[1].vval.v_dict; - common_job_callbacks(job_opts, &on_stdout, &on_stderr, &on_exit); - if (did_emsg) { + if (!common_job_callbacks(job_opts, &on_stdout, &on_stderr, &on_exit)) { return; } } @@ -10830,7 +10837,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv) int i = 0; char **argv = xcalloc(argc + 1, sizeof(char *)); for (listitem_T *arg = args->lv_first; arg != NULL; arg = arg->li_next) { - argv[i++] = xstrdup((char *)arg->li_tv.vval.v_string); + argv[i++] = xstrdup((char *) get_tv_string(&arg->li_tv)); } JobOptions opts = common_job_options(argv, on_stdout, on_stderr, on_exit, @@ -10912,9 +10919,16 @@ static void f_jobwait(typval_T *argvars, typval_T *rettv) list_T *args = argvars[0].vval.v_list; list_T *rv = list_alloc(); - // must temporarily disable job event deferring so the callbacks are - // processed while waiting. - defer_job_callbacks = false; + ui_busy_start(); + // disable breakchecks, which could result in job callbacks being executed + // at unexpected places + disable_breakcheck++; + // disable job event deferring so the callbacks are processed while waiting. + if (!disable_job_defer++) { + // process any pending job events in the deferred queue, but only do this if + // deferred is not disabled(at the top-level `jobwait()` call) + event_process(); + } // For each item in the input list append an integer to the output list. -3 // is used to represent an invalid job id, -2 is for a interrupted job and // -1 for jobs that were skipped or timed out. @@ -10987,8 +11001,9 @@ static void f_jobwait(typval_T *argvars, typval_T *rettv) // job exits data->status_ptr = NULL; } - // restore defer flag - defer_job_callbacks = true; + disable_job_defer--; + disable_breakcheck--; + ui_busy_stop(); rv->lv_refcount++; rettv->v_type = VAR_LIST; @@ -11228,7 +11243,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) keys = replace_termcodes(keys, &keys_buf, TRUE, TRUE, FALSE); rhs = check_map(keys, mode, exact, FALSE, abbr, &mp, &buffer_local); - free(keys_buf); + xfree(keys_buf); if (!get_dict) { /* Return a string. */ @@ -11253,8 +11268,8 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact) dict_add_nr_str(dict, "nowait", mp->m_nowait ? 1L : 0L, NULL); dict_add_nr_str(dict, "mode", 0L, mapmode); - free(lhs); - free(mapmode); + xfree(lhs); + xfree(mapmode); } } } @@ -11401,7 +11416,7 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type) match = FALSE; break; } - free(tofree); + xfree(tofree); str = echo_string(&li->li_tv, &tofree, strbuf, 0); if (str == NULL) break; @@ -11465,7 +11480,7 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type) } theend: - free(tofree); + xfree(tofree); p_cpo = save_cpo; } @@ -11699,7 +11714,7 @@ static int mkdir_recurse(char_u *dir, int prot) r = OK; else if (mkdir_recurse(updir, prot) == OK) r = vim_mkdir_emsg(updir, prot); - free(updir); + xfree(updir); return r; } @@ -12128,7 +12143,7 @@ static void f_readfile(typval_T *argvars, typval_T *rettv) --cnt; } - free(prev); + xfree(prev); fclose(fd); } @@ -12278,7 +12293,7 @@ static void f_remove(typval_T *argvars, typval_T *rettv) // Remove one item, return its value. vim_list_remove(l, item, item); *rettv = item->li_tv; - free(item); + xfree(item); } else { /* Remove range of items, return list with values. */ end = get_tv_number_chk(&argvars[2], &error); @@ -12421,8 +12436,8 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) buf[len] = NUL; if (limit-- == 0) { - free(p); - free(remain); + xfree(p); + xfree(remain); EMSG(_("E655: Too many symbolic links (cycle?)")); rettv->vval.v_string = NULL; goto fail; @@ -12440,7 +12455,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) cpy = remain; remain = remain ? concat_str(q - 1, remain) : (char_u *) xstrdup((char *)q - 1); - free(cpy); + xfree(cpy); q[-1] = NUL; } @@ -12455,10 +12470,10 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) cpy = xmalloc(STRLEN(p) + STRLEN(buf) + 1); STRCPY(cpy, p); STRCPY(path_tail(cpy), buf); - free(p); + xfree(p); p = cpy; } else { - free(p); + xfree(p); p = vim_strsave(buf); } } @@ -12471,14 +12486,14 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) len = q - remain - (*q != NUL); cpy = vim_strnsave(p, STRLEN(p) + len); STRNCAT(cpy, remain, len); - free(p); + xfree(p); p = cpy; /* Shorten "remain". */ if (*q != NUL) STRMOVE(remain, q - 1); else { - free(remain); + xfree(remain); remain = NULL; } } @@ -12496,7 +12511,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) || vim_ispathsep(p[2])))))) { /* Prepend "./". */ cpy = concat_str((char_u *)"./", p); - free(p); + xfree(p); p = cpy; } else if (!is_relative_to_current) { /* Strip leading "./". */ @@ -12527,7 +12542,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv) #ifdef HAVE_READLINK fail: - free(buf); + xfree(buf); #endif rettv->v_type = VAR_STRING; } @@ -12742,7 +12757,7 @@ static void f_rpcnotify(typval_T *argvars, typval_T *rettv) } if (!channel_send_event((uint64_t)argvars[0].vval.v_number, - (char *)argvars[1].vval.v_string, + (char *)get_tv_string(&argvars[1]), args)) { EMSG2(_(e_invarg2), "Channel doesn't exist"); return; @@ -12809,7 +12824,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv) Error err = ERROR_INIT; Object result = channel_send_call((uint64_t)argvars[0].vval.v_number, - (char *)argvars[1].vval.v_string, + (char *)get_tv_string(&argvars[1]), args, &err); @@ -12873,13 +12888,17 @@ static void f_rpcstart(typval_T *argvars, typval_T *rettv) char **argv = xmalloc(sizeof(char_u *) * argvl); // Copy program name + if (argvars[0].vval.v_string == NULL || argvars[0].vval.v_string[0] == NUL) { + EMSG(_(e_api_spawn_failed)); + return; + } argv[0] = xstrdup((char *)argvars[0].vval.v_string); int i = 1; // Copy arguments to the vector if (argsl > 0) { for (listitem_T *arg = args->lv_first; arg != NULL; arg = arg->li_next) { - argv[i++] = xstrdup((char *)arg->li_tv.vval.v_string); + argv[i++] = xstrdup((char *) get_tv_string(&arg->li_tv)); } } @@ -13241,8 +13260,8 @@ do_searchpair ( if ((flags & SP_NOMOVE) || retval == 0) curwin->w_cursor = save_cursor; - free(pat2); - free(pat3); + xfree(pat2); + xfree(pat3); if (p_cpo == empty_option) p_cpo = save_cpo; else @@ -13277,6 +13296,69 @@ static void f_searchpos(typval_T *argvars, typval_T *rettv) list_append_number(rettv->vval.v_list, (varnumber_T)n); } +/// "serverlist()" function +static void f_serverlist(typval_T *argvars, typval_T *rettv) +{ + size_t n; + char **addrs = server_address_list(&n); + + // Copy addrs into a linked list. + list_T *l = rettv_list_alloc(rettv); + for (size_t i = 0; i < n; i++) { + listitem_T *li = listitem_alloc(); + li->li_tv.v_type = VAR_STRING; + li->li_tv.v_lock = 0; + li->li_tv.vval.v_string = (char_u *) addrs[i]; + list_append(l, li); + } + xfree(addrs); +} + +/// "serverstart()" function +static void f_serverstart(typval_T *argvars, typval_T *rettv) +{ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = NULL; // Will hold the address of the new server. + + if (check_restricted() || check_secure()) { + return; + } + + // If the user supplied an address, use it, otherwise use a temp. + if (argvars[0].v_type != VAR_UNKNOWN) { + if (argvars[0].v_type != VAR_STRING) { + EMSG(_(e_invarg)); + return; + } else { + rettv->vval.v_string = vim_strsave(get_tv_string(argvars)); + } + } else { + rettv->vval.v_string = vim_tempname(); + } + + int result = server_start((char *) rettv->vval.v_string); + if (result != 0) { + EMSG2("Failed to start server: %s", uv_strerror(result)); + } +} + +/// "serverstop()" function +static void f_serverstop(typval_T *argvars, typval_T *rettv) +{ + if (check_restricted() || check_secure()) { + return; + } + + if (argvars[0].v_type == VAR_UNKNOWN || argvars[0].v_type != VAR_STRING) { + EMSG(_(e_invarg)); + return; + } + + if (argvars[0].vval.v_string) { + server_stop((char *) argvars[0].vval.v_string); + } +} + /* * "setbufvar()" function */ @@ -13314,7 +13396,7 @@ static void f_setbufvar(typval_T *argvars, typval_T *rettv) STRCPY(bufvarname, "b:"); STRCPY(bufvarname + 2, varname); set_var(bufvarname, varp, TRUE); - free(bufvarname); + xfree(bufvarname); } /* reset notion of buffer */ @@ -13617,8 +13699,8 @@ static void f_setreg(typval_T *argvars, typval_T *rettv) free_lstval: while (curallocval > allocval) - free(*--curallocval); - free(lstval); + xfree(*--curallocval); + xfree(lstval); } else { char_u *strval = get_tv_string_chk(&argvars[1]); if (strval == NULL) { @@ -13658,7 +13740,7 @@ static void f_settabvar(typval_T *argvars, typval_T *rettv) STRCPY(tabvarname, "t:"); STRCPY(tabvarname + 2, varname); set_var(tabvarname, varp, TRUE); - free(tabvarname); + xfree(tabvarname); /* Restore current tabpage */ if (valid_tabpage(save_curtab)) @@ -13724,7 +13806,7 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off) STRCPY(winvarname, "w:"); STRCPY(winvarname + 2, varname); set_var(winvarname, varp, TRUE); - free(winvarname); + xfree(winvarname); } restore_win(save_curwin, save_curtab, TRUE); } @@ -13873,8 +13955,8 @@ static int item_compare(const void *s1, const void *s2, bool keep_zero) res = si1->idx > si2->idx ? 1 : -1; } - free(tofree1); - free(tofree2); + xfree(tofree1); + xfree(tofree2); return res; } @@ -14080,7 +14162,7 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort) } } - free(ptrs); + xfree(ptrs); } } @@ -14350,7 +14432,7 @@ static void f_strftime(typval_T *argvars, typval_T *rettv) result_buf[0] = NUL; if (conv.vc_type != CONV_NONE) - free(p); + xfree(p); convert_setup(&conv, enc, p_enc); if (conv.vc_type != CONV_NONE) rettv->vval.v_string = string_convert(&conv, result_buf, NULL); @@ -14359,7 +14441,7 @@ static void f_strftime(typval_T *argvars, typval_T *rettv) /* Release conversion descriptors */ convert_setup(&conv, NULL, NULL); - free(enc); + xfree(enc); } } @@ -14847,7 +14929,7 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, char *res = NULL; int status = os_system(cmd, input, input_len, &res, &nread); - free(input); + xfree(input); set_vim_var_nr(VV_SHELL_ERROR, (long) status); @@ -14855,6 +14937,8 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, if (retlist) { // return an empty list when there's no output rettv_list_alloc(rettv); + } else { + rettv->vval.v_string = (char_u *) xstrdup(""); } return; } @@ -14868,7 +14952,7 @@ static void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, rettv->vval.v_list->lv_refcount++; rettv->v_type = VAR_LIST; - free(res); + xfree(res); } else { // res may contain several NULs before the final terminating one. // Replace them with SOH (1) like in get_cmd_output() to avoid truncation. @@ -15026,7 +15110,7 @@ static void f_tagfiles(typval_T *argvars, typval_T *rettv) } tagname_free(&tn); - free(fname); + xfree(fname); } /* @@ -15077,8 +15161,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv) dict_T *job_opts = NULL; if (argvars[1].v_type == VAR_DICT) { job_opts = argvars[1].vval.v_dict; - common_job_callbacks(job_opts, &on_stdout, &on_stderr, &on_exit); - if (did_emsg) { + if (!common_job_callbacks(job_opts, &on_stdout, &on_stderr, &on_exit)) { return; } } @@ -15356,7 +15439,7 @@ static void f_undofile(typval_T *argvars, typval_T *rettv) if (ffname != NULL) rettv->vval.v_string = u_get_undo_file_name(ffname, FALSE); - free(ffname); + xfree(ffname); } } } @@ -16099,7 +16182,7 @@ static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u * STRCAT(retval, temp_result); STRCAT(retval, expr_end + 1); } - free(temp_result); + xfree(temp_result); *in_end = c1; /* put char back for error messages */ *expr_start = '{'; @@ -16111,7 +16194,7 @@ static char_u *make_expanded_name(char_u *in_start, char_u *expr_start, char_u * /* Further expansion! */ temp_result = make_expanded_name(retval, expr_start, expr_end, temp_result); - free(retval); + xfree(retval); retval = temp_result; } } @@ -16212,7 +16295,7 @@ set_vim_var_string ( * Will always be invoked when "v:progname" is set. */ vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; - free(vimvars[idx].vv_str); + xfree(vimvars[idx].vv_str); if (val == NULL) vimvars[idx].vv_str = NULL; else if (len == -1) @@ -16291,7 +16374,7 @@ char_u *set_cmdarg(exarg_T *eap, char_u *oldarg) oldval = vimvars[VV_CMDARG].vv_str; if (eap == NULL) { - free(oldval); + xfree(oldval); vimvars[VV_CMDARG].vv_str = oldarg; return NULL; } @@ -16474,7 +16557,7 @@ void free_tv(typval_T *varp) func_unref(varp->vval.v_string); /*FALLTHROUGH*/ case VAR_STRING: - free(varp->vval.v_string); + xfree(varp->vval.v_string); break; case VAR_LIST: list_unref(varp->vval.v_list); @@ -16490,7 +16573,7 @@ void free_tv(typval_T *varp) EMSG2(_(e_intern2), "free_tv()"); break; } - free(varp); + xfree(varp); } } @@ -16504,12 +16587,12 @@ void clear_tv(typval_T *varp) case VAR_FUNC: func_unref(varp->vval.v_string); if (varp->vval.v_string != empty_string) { - free(varp->vval.v_string); + xfree(varp->vval.v_string); } varp->vval.v_string = NULL; break; case VAR_STRING: - free(varp->vval.v_string); + xfree(varp->vval.v_string); varp->vval.v_string = NULL; break; case VAR_LIST: @@ -16913,7 +16996,7 @@ static void vars_clear_ext(hashtab_T *ht, int free_val) if (free_val) clear_tv(&v->di_tv); if ((v->di_flags & DI_FLAGS_FIX) == 0) - free(v); + xfree(v); } } hash_clear(ht); @@ -16930,7 +17013,7 @@ static void delete_var(hashtab_T *ht, hashitem_T *hi) hash_remove(ht, hi); clear_tv(&di->di_tv); - free(di); + xfree(di); } /* @@ -16946,7 +17029,7 @@ static void list_one_var(dictitem_T *v, char_u *prefix, int *first) s = echo_string(&v->di_tv, &tofree, numbuf, current_copyID); list_one_var_a(prefix, v->di_key, v->di_tv.v_type, s == NULL ? (char_u *)"" : s, first); - free(tofree); + xfree(tofree); } static void @@ -17041,7 +17124,7 @@ set_var ( */ if (ht == &vimvarht) { if (v->di_tv.v_type == VAR_STRING) { - free(v->di_tv.vval.v_string); + xfree(v->di_tv.vval.v_string); if (copy || tv->v_type != VAR_STRING) v->di_tv.vval.v_string = vim_strsave(get_tv_string(tv)); else { @@ -17078,7 +17161,7 @@ set_var ( v = xmalloc(sizeof(dictitem_T) + STRLEN(varname)); STRCPY(v->di_key, varname); if (hash_add(ht, DI2HIKEY(v)) == FAIL) { - free(v); + xfree(v); return; } v->di_flags = 0; @@ -17369,7 +17452,7 @@ void ex_echo(exarg_T *eap) (void)msg_outtrans_len_attr(p, 1, echo_attr); } } - free(tofree); + xfree(tofree); } clear_tv(&rettv); arg = skipwhite(arg); @@ -17615,7 +17698,7 @@ void ex_function(exarg_T *eap) if (!aborting()) { if (!eap->skip && fudi.fd_newkey != NULL) EMSG2(_(e_dictkey), fudi.fd_newkey); - free(fudi.fd_newkey); + xfree(fudi.fd_newkey); return; } else eap->skip = TRUE; @@ -17731,7 +17814,7 @@ void ex_function(exarg_T *eap) for (int i = 0; i < newargs.ga_len; ++i) if (STRCMP(((char_u **)(newargs.ga_data))[i], arg) == 0) { EMSG2(_("E853: Duplicate argument name: %s"), arg); - free(arg); + xfree(arg); goto erret; } @@ -17837,7 +17920,7 @@ void ex_function(exarg_T *eap) /* between ":append" and "." and between ":python <<EOF" and "EOF" * don't check for ":endfunc". */ if (STRCMP(theline, skip_until) == 0) { - free(skip_until); + xfree(skip_until); skip_until = NULL; } } else { @@ -17848,7 +17931,7 @@ void ex_function(exarg_T *eap) /* Check for "endfunction". */ if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0) { if (line_arg == NULL) - free(theline); + xfree(theline); break; } @@ -17868,7 +17951,7 @@ void ex_function(exarg_T *eap) p = skipwhite(p + 1); } p += eval_fname_script(p); - free(trans_function_name(&p, TRUE, 0, NULL)); + xfree(trans_function_name(&p, TRUE, 0, NULL)); if (*skipwhite(p) == '(') { nesting++; indent += 2; @@ -17884,7 +17967,7 @@ void ex_function(exarg_T *eap) (p[2] == 's')))))) skip_until = vim_strsave((char_u *)"."); - /* Check for ":python <<EOF", ":tcl <<EOF", etc. */ + // Check for ":python <<EOF", ":lua <<EOF", etc. arg = skipwhite(skiptowhite(p)); if (arg[0] == '<' && arg[1] =='<' && ((p[0] == 'p' && p[1] == 'y' @@ -17917,7 +18000,7 @@ void ex_function(exarg_T *eap) * is an extra alloc/free. */ p = vim_strsave(theline); if (line_arg == NULL) - free(theline); + xfree(theline); theline = p; ((char_u **)(newlines.ga_data))[newlines.ga_len++] = theline; @@ -17962,7 +18045,7 @@ void ex_function(exarg_T *eap) /* redefine existing function */ ga_clear_strings(&(fp->uf_args)); ga_clear_strings(&(fp->uf_lines)); - free(name); + xfree(name); name = NULL; } } else { @@ -17984,7 +18067,7 @@ void ex_function(exarg_T *eap) /* Give the function a sequential number. Can only be used with a * Funcref! */ - free(name); + xfree(name); sprintf(numbuf, "%d", ++func_nr); name = vim_strsave((char_u *)numbuf); } @@ -18004,7 +18087,7 @@ void ex_function(exarg_T *eap) if (slen > plen && fnamecmp(p, sourcing_name + slen - plen) == 0) j = OK; - free(scriptname); + xfree(scriptname); } if (j == FAIL) { EMSG2(_( @@ -18021,8 +18104,8 @@ void ex_function(exarg_T *eap) /* add new dict entry */ fudi.fd_di = dictitem_alloc(fudi.fd_newkey); if (dict_add(fudi.fd_dict, fudi.fd_di) == FAIL) { - free(fudi.fd_di); - free(fp); + xfree(fudi.fd_di); + xfree(fp); goto erret; } } else @@ -18059,9 +18142,9 @@ erret: ga_clear_strings(&newargs); ga_clear_strings(&newlines); ret_free: - free(skip_until); - free(fudi.fd_newkey); - free(name); + xfree(skip_until); + xfree(fudi.fd_newkey); + xfree(name); did_emsg |= saved_did_emsg; need_wait_return |= saved_wait_return; } @@ -18373,7 +18456,7 @@ static int function_exists(char_u *name) * "funcname(...", not "funcname!...". */ if (p != NULL && (*nm == NUL || *nm == '(')) n = translated_function_exists(p); - free(p); + xfree(p); return n; } @@ -18480,7 +18563,7 @@ void func_dump_profile(FILE *fd) prof_sort_list(fd, sorttab, st_len, "SELF", TRUE); } - free(sorttab); + xfree(sorttab); } static void @@ -18596,7 +18679,7 @@ script_autoload ( ret = TRUE; } - free(tofree); + xfree(tofree); return ret; } @@ -18686,14 +18769,14 @@ void ex_delfunction(exarg_T *eap) p = eap->arg; name = trans_function_name(&p, eap->skip, 0, &fudi); - free(fudi.fd_newkey); + xfree(fudi.fd_newkey); if (name == NULL) { if (fudi.fd_dict != NULL && !eap->skip) EMSG(_(e_funcref)); return; } if (!ends_excmd(*skipwhite(p))) { - free(name); + xfree(name); EMSG(_(e_trailing)); return; } @@ -18703,7 +18786,7 @@ void ex_delfunction(exarg_T *eap) if (!eap->skip) fp = find_func(name); - free(name); + xfree(name); if (!eap->skip) { if (fp == NULL) { @@ -18739,9 +18822,9 @@ static void func_free(ufunc_T *fp) /* clear this function */ ga_clear_strings(&(fp->uf_args)); ga_clear_strings(&(fp->uf_lines)); - free(fp->uf_tml_count); - free(fp->uf_tml_total); - free(fp->uf_tml_self); + xfree(fp->uf_tml_count); + xfree(fp->uf_tml_total); + xfree(fp->uf_tml_self); /* remove the function from the function hashtable */ hi = hash_find(&func_hashtab, UF2HIKEY(fp)); @@ -18750,7 +18833,7 @@ static void func_free(ufunc_T *fp) else hash_remove(&func_hashtab, hi); - free(fp); + xfree(fp); } /* @@ -18987,7 +19070,7 @@ call_user_func ( s = buf; } msg_puts(s); - free(tofree); + xfree(tofree); } } } @@ -19074,7 +19157,7 @@ call_user_func ( s = buf; } smsg((char_u *)_("%s returning %s"), sourcing_name, s); - free(tofree); + xfree(tofree); } } msg_puts((char_u *)"\n"); /* don't overwrite this either */ @@ -19083,7 +19166,7 @@ call_user_func ( --no_wait_return; } - free(sourcing_name); + xfree(sourcing_name); sourcing_name = save_sourcing_name; sourcing_lnum = save_sourcing_lnum; current_SID = save_current_SID; @@ -19180,7 +19263,7 @@ free_funccal ( for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next) clear_tv(&li->li_tv); - free(fc); + xfree(fc); } /* @@ -19311,7 +19394,7 @@ int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv) clear_tv(current_funccal->rettv); *current_funccal->rettv = *(typval_T *)rettv; if (!is_cmd) - free(rettv); + xfree(rettv); } } @@ -19345,7 +19428,7 @@ char_u *get_return_cmd(void *rettv) STRNCPY(IObuff + 8, s, IOSIZE - 8); if (STRLEN(s) + 8 >= IOSIZE) STRCPY(IObuff + IOSIZE - 4, "..."); - free(tofree); + xfree(tofree); return vim_strsave(IObuff); } @@ -19533,16 +19616,16 @@ int read_viminfo_varlist(vir_T *virp, int writing) * string. */ tv.v_type = VAR_STRING; else { - free(tv.vval.v_string); + xfree(tv.vval.v_string); tv = *etv; - free(etv); + xfree(etv); } } set_var(virp->vir_line + 1, &tv, FALSE); if (tv.v_type == VAR_STRING) - free(tv.vval.v_string); + xfree(tv.vval.v_string); else if (tv.v_type == VAR_DICT || tv.v_type == VAR_LIST) clear_tv(&tv); } @@ -19588,7 +19671,7 @@ void write_viminfo_varlist(FILE *fp) p = echo_string(&this_var->di_tv, &tofree, numbuf, 0); if (p != NULL) viminfo_writestring(fp, p); - free(tofree); + xfree(tofree); } } } @@ -19626,10 +19709,10 @@ int store_session_globals(FILE *fd) (this_var->di_tv.v_type == VAR_STRING) ? '"' : ' ') < 0) || put_eol(fd) == FAIL) { - free(p); + xfree(p); return FAIL; } - free(p); + xfree(p); } else if (this_var->di_tv.v_type == VAR_FLOAT && var_flavour(this_var->di_key) == VAR_FLAVOUR_SESSION) { float_T f = this_var->di_tv.vval.v_float; @@ -19660,7 +19743,7 @@ void last_set_msg(scid_T scriptID) verbose_enter(); MSG_PUTS(_("\n\tLast set from ")); MSG_PUTS(p); - free(p); + xfree(p); verbose_leave(); } } @@ -19740,7 +19823,7 @@ repeat: #endif ) { *fnamep = expand_env_save(*fnamep); - free(*bufp); /* free any allocated file name */ + xfree(*bufp); /* free any allocated file name */ *bufp = *fnamep; if (*fnamep == NULL) return -1; @@ -19760,7 +19843,7 @@ repeat: /* FullName_save() is slow, don't use it when not needed. */ if (*p != NUL || !vim_isAbsName(*fnamep)) { *fnamep = FullName_save(*fnamep, *p != NUL); - free(*bufp); /* free any allocated file name */ + xfree(*bufp); /* free any allocated file name */ *bufp = *fnamep; if (*fnamep == NULL) return -1; @@ -19770,7 +19853,7 @@ repeat: if (os_isdir(*fnamep)) { /* Make room for one or two extra characters. */ *fnamep = vim_strnsave(*fnamep, (int)STRLEN(*fnamep) + 2); - free(*bufp); /* free any allocated file name */ + xfree(*bufp); /* free any allocated file name */ *bufp = *fnamep; if (*fnamep == NULL) return -1; @@ -19806,7 +19889,7 @@ repeat: if (s != NULL) { *fnamep = s; if (pbuf != NULL) { - free(*bufp); /* free any allocated file name */ + xfree(*bufp); /* free any allocated file name */ *bufp = pbuf; pbuf = NULL; } @@ -19817,11 +19900,11 @@ repeat: if (*dirname == '~') { s = vim_strsave(dirname); *fnamep = s; - free(*bufp); + xfree(*bufp); *bufp = s; } } - free(pbuf); + xfree(pbuf); } } @@ -19839,7 +19922,7 @@ repeat: *fnamelen = (int)(tail - *fnamep); if (*fnamelen == 0) { /* Result is empty. Turn it into "." to make ":cd %:h" work. */ - free(*bufp); + xfree(*bufp); *bufp = *fnamep = tail = vim_strsave((char_u *)"."); *fnamelen = 1; } else { @@ -19924,13 +20007,13 @@ repeat: s = do_string_sub(str, pat, sub, flags); *fnamep = s; *fnamelen = (int)STRLEN(s); - free(*bufp); + xfree(*bufp); *bufp = s; didit = TRUE; - free(sub); - free(str); + xfree(sub); + xfree(str); } - free(pat); + xfree(pat); } /* after using ":s", repeat all the modifiers */ if (didit) @@ -19940,7 +20023,7 @@ repeat: if (src[*usedlen] == ':' && src[*usedlen + 1] == 'S') { p = vim_strsave_shellescape(*fnamep, false, false); - free(*bufp); + xfree(*bufp); *bufp = *fnamep = p; *fnamelen = (int)STRLEN(p); *usedlen += 2; @@ -20051,27 +20134,27 @@ static inline JobOptions common_job_options(char **argv, ufunc_T *on_stdout, return opts; } -static inline void common_job_callbacks(dict_T *vopts, ufunc_T **on_stdout, - ufunc_T **on_stderr, ufunc_T **on_exit) +/// Return true/false on success/failure. +static inline bool common_job_callbacks(dict_T *vopts, ufunc_T **on_stdout, + ufunc_T **on_stderr, ufunc_T **on_exit) { - *on_stdout = get_dict_callback(vopts, "on_stdout"); - *on_stderr = get_dict_callback(vopts, "on_stderr"); - *on_exit = get_dict_callback(vopts, "on_exit"); - if (did_emsg) { - if (*on_stdout) { - user_func_unref(*on_stdout); - } - if (*on_stderr) { - user_func_unref(*on_stderr); - } - if (*on_exit) { - user_func_unref(*on_exit); - } - return; + if (get_dict_callback(vopts, "on_stdout", on_stdout) + && get_dict_callback(vopts, "on_stderr", on_stderr) + && get_dict_callback(vopts, "on_exit", on_exit)) { + vopts->internal_refcount++; + vopts->dv_refcount++; + return true; } - - vopts->internal_refcount++; - vopts->dv_refcount++; + if (*on_stdout) { + user_func_unref(*on_stdout); + } + if (*on_stderr) { + user_func_unref(*on_stderr); + } + if (*on_exit) { + user_func_unref(*on_exit); + } + return false; } static inline Job *common_job_start(JobOptions opts, typval_T *rettv) @@ -20083,7 +20166,7 @@ static inline Job *common_job_start(JobOptions opts, typval_T *rettv) if (rettv->vval.v_number <= 0) { if (rettv->vval.v_number == 0) { EMSG(_(e_jobtblfull)); - free(opts.term_name); + xfree(opts.term_name); free_term_job_data(data); } else { EMSG(_(e_jobexe)); @@ -20109,7 +20192,7 @@ static inline void free_term_job_data(TerminalJobData *data) { data->self->internal_refcount--; dict_unref(data->self); } - free(data); + xfree(data); } static inline bool is_user_job(Job *job) @@ -20126,7 +20209,7 @@ static inline bool is_user_job(Job *job) static inline void push_job_event(Job *job, ufunc_T *callback, const char *type, char *data, size_t count, int status) { - JobEvent *event_data = kmp_alloc(JobEventPool, job_event_pool); + JobEvent *event_data = xmalloc(sizeof(JobEvent)); event_data->received = NULL; if (data) { event_data->received = list_alloc(); @@ -20161,7 +20244,7 @@ static inline void push_job_event(Job *job, ufunc_T *callback, event_push((Event) { .handler = on_job_event, .data = event_data - }, defer_job_callbacks); + }, !disable_job_defer); } static void on_job_stdout(RStream *rstream, void *job, bool eof) @@ -20220,7 +20303,7 @@ static void on_job_exit(Job *job, int status, void *d) static void term_write(char *buf, size_t size, void *data) { Job *job = ((TerminalJobData *)data)->job; - WBuffer *wbuf = wstream_new_buffer(xmemdup(buf, size), size, 1, free); + WBuffer *wbuf = wstream_new_buffer(xmemdup(buf, size), size, 1, xfree); job_write(job, wbuf); } @@ -20290,11 +20373,11 @@ static void on_job_event(Event event) clear_tv(&rettv); end: - kmp_free(JobEventPool, job_event_pool, ev); if (!ev->received) { // exit event, safe to free job data now term_job_data_decref(ev->data); } + xfree(ev); } static void script_host_eval(char *name, typval_T *argvars, typval_T *rettv) diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c686c5effa..c57861282d 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -533,9 +533,9 @@ void ex_sort(exarg_T *eap) beginline(BL_WHITE | BL_FIX); sortend: - free(nrs); - free(sortbuf1); - free(sortbuf2); + xfree(nrs); + xfree(sortbuf1); + xfree(sortbuf2); vim_regfree(regmatch.regprog); if (got_int) EMSG(_(e_interr)); @@ -698,7 +698,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest) for (extra = 0, l = line1; l <= line2; l++) { str = vim_strsave(ml_get(l + extra)); ml_append(dest + l - line1, str, (colnr_T)0, FALSE); - free(str); + xfree(str); if (dest < line1) extra++; } @@ -804,7 +804,7 @@ void ex_copy(linenr_T line1, linenr_T line2, linenr_T n) * ml_append() */ p = vim_strsave(ml_get(line1)); ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); - free(p); + xfree(p); /* situation 2: skip already copied lines */ if (line1 == n) @@ -827,7 +827,7 @@ static char_u *prevcmd = NULL; /* the previous command */ #if defined(EXITFREE) void free_prev_shellcmd(void) { - free(prevcmd); + xfree(prevcmd); } #endif @@ -878,7 +878,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) if (ins_prevcmd) { if (prevcmd == NULL) { EMSG(_(e_noprev)); - free(newcmd); + xfree(newcmd); return; } len += (int)STRLEN(prevcmd); @@ -891,7 +891,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) STRCAT(t, prevcmd); p = t + STRLEN(t); STRCAT(t, trailarg); - free(newcmd); + xfree(newcmd); newcmd = t; /* @@ -914,7 +914,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) } } while (trailarg != NULL); - free(prevcmd); + xfree(prevcmd); prevcmd = newcmd; if (bangredo) { /* put cmd in redo buffer for ! command */ @@ -924,7 +924,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); AppendToRedobuffLit(cmd, -1); - free(cmd); + xfree(cmd); AppendToRedobuff((char_u *)"\n"); bangredo = FALSE; } @@ -955,7 +955,7 @@ void do_bang(int addr_count, exarg_T *eap, int forceit, int do_in, int do_out) apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf); } if (free_newcmd) - free(newcmd); + xfree(newcmd); } /* @@ -1076,7 +1076,7 @@ do_filter ( if (do_out) { if (u_save((linenr_T)(line2), (linenr_T)(line2 + 1)) == FAIL) { - free(cmd_buf); + xfree(cmd_buf); goto error; } redraw_curbuf_later(VALID); @@ -1100,7 +1100,7 @@ do_filter ( redraw_later_clear(); wait_return(FALSE); } - free(cmd_buf); + xfree(cmd_buf); did_check_timestamps = FALSE; need_check_timestamps = TRUE; @@ -1197,8 +1197,8 @@ filterend: os_remove((char *)itmp); if (otmp != NULL) os_remove((char *)otmp); - free(itmp); - free(otmp); + xfree(itmp); + xfree(otmp); } /* @@ -1448,7 +1448,7 @@ read_viminfo ( verbose_leave(); } - free(fname); + xfree(fname); if (fp == NULL) return FAIL; @@ -1550,7 +1550,7 @@ void write_viminfo(char_u *file, int forceit) * write the viminfo file then. */ if (*wp == 'a') { - free(tempname); + xfree(tempname); tempname = NULL; break; } @@ -1586,7 +1586,7 @@ void write_viminfo(char_u *file, int forceit) * "normal" temp file. */ if (fp_out == NULL) { - free(tempname); + xfree(tempname); if ((tempname = vim_tempname()) != NULL) fp_out = mch_fopen((char *)tempname, WRITEBIN); } @@ -1639,8 +1639,8 @@ void write_viminfo(char_u *file, int forceit) } end: - free(fname); - free(tempname); + xfree(fname); + xfree(tempname); } /* @@ -1721,7 +1721,7 @@ static void do_viminfo(FILE *fp_in, FILE *fp_out, int flags) && (flags & (VIF_WANT_MARKS | VIF_GET_OLDFILES | VIF_FORCEIT))) copy_viminfo_marks(&vir, fp_out, count, eof, flags); - free(vir.vir_line); + xfree(vir.vir_line); if (vir.vir_conv.vc_type != CONV_NONE) convert_setup(&vir.vir_conv, NULL, NULL); } @@ -1886,7 +1886,7 @@ viminfo_readstring ( if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) { d = string_convert(&virp->vir_conv, retval, NULL); if (d != NULL) { - free(retval); + xfree(retval); retval = d; } } @@ -2000,8 +2000,8 @@ int rename_buffer(char_u *new_fname) if (buf != NULL && !cmdmod.keepalt) curwin->w_alt_fnum = buf->b_fnum; } - free(fname); - free(sfname); + xfree(fname); + xfree(sfname); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); /* Change directories when the 'acd' option is set. */ do_autochdir(); @@ -2206,7 +2206,7 @@ int do_write(exarg_T *eap) } theend: - free(free_fname); + xfree(free_fname); return retval; } @@ -2279,7 +2279,7 @@ check_overwrite ( copy_option_part(&p, dir, MAXPATHL, ","); } swapname = makeswapname(fname, ffname, curbuf, dir); - free(dir); + xfree(dir); if (os_file_exists(swapname)) { if (p_confirm || cmdmod.confirm) { char_u buff[DIALOG_MSG_SIZE]; @@ -2289,18 +2289,18 @@ check_overwrite ( swapname); if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) { - free(swapname); + xfree(swapname); return FAIL; } eap->forceit = TRUE; } else { EMSG2(_("E768: Swap file exists: %s (:silent! overrides)"), swapname); - free(swapname); + xfree(swapname); return FAIL; } } - free(swapname); + xfree(swapname); } } return OK; @@ -2486,7 +2486,7 @@ int getfile(int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum, retval = 1; /* error encountered */ theend: - free(free_me); + xfree(free_me); return retval; } @@ -2623,7 +2623,7 @@ do_ecmd ( } set_vim_var_string(VV_SWAPCOMMAND, p, -1); did_set_swapcommand = TRUE; - free(p); + xfree(p); } /* @@ -2712,7 +2712,7 @@ do_ecmd ( goto theend; } if (aborting()) { /* autocmds may abort script processing */ - free(new_name); + xfree(new_name); goto theend; } if (buf == curbuf) /* already in new buffer */ @@ -2737,7 +2737,7 @@ do_ecmd ( } if (aborting()) { /* autocmds may abort script processing */ - free(new_name); + xfree(new_name); goto theend; } /* Be careful again, like above. */ @@ -2775,7 +2775,7 @@ do_ecmd ( did_get_winopts = TRUE; } - free(new_name); + xfree(new_name); au_new_curbuf = NULL; } else ++curbuf->b_nwindows; @@ -2849,7 +2849,7 @@ do_ecmd ( delbuf_msg(new_name); /* frees new_name */ goto theend; } - free(new_name); + xfree(new_name); /* If autocommands change buffers under our fingers, forget about * re-editing the file. Should do the buf_clear_file(), but perhaps @@ -3040,7 +3040,7 @@ do_ecmd ( theend: if (did_set_swapcommand) set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); - free(free_fname); + xfree(free_fname); return retval; } @@ -3048,7 +3048,7 @@ static void delbuf_msg(char_u *name) { EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"), name == NULL ? (char_u *)"" : name); - free(name); + xfree(name); au_new_curbuf = NULL; } @@ -3140,7 +3140,7 @@ void ex_append(exarg_T *eap) if ((p[0] == '.' && p[1] == NUL) || (!did_undo && u_save(lnum, lnum + 1 + (empty ? 1 : 0)) == FAIL)) { - free(theline); + xfree(theline); break; } @@ -3152,7 +3152,7 @@ void ex_append(exarg_T *eap) ml_append(lnum, theline, (colnr_T)0, FALSE); appended_lines_mark(lnum, 1L); - free(theline); + xfree(theline); ++lnum; if (empty) { @@ -3481,7 +3481,7 @@ void do_sub(exarg_T *eap) } sub = old_sub; } else { - free(old_sub); + xfree(old_sub); old_sub = vim_strsave(sub); } } @@ -3742,7 +3742,7 @@ void do_sub(exarg_T *eap) lnum += regmatch.startpos[0].lnum; sub_firstlnum += regmatch.startpos[0].lnum; nmatch -= regmatch.startpos[0].lnum; - free(sub_firstline); + xfree(sub_firstline); sub_firstline = NULL; } @@ -3846,7 +3846,7 @@ void do_sub(exarg_T *eap) resp = getexmodeline('?', NULL, 0); if (resp != NULL) { typed = *resp; - free(resp); + xfree(resp); } } else { char_u *orig_line = NULL; @@ -4061,7 +4061,7 @@ void do_sub(exarg_T *eap) * line and continue in that one. */ if (nmatch > 1) { sub_firstlnum += nmatch - 1; - free(sub_firstline); + xfree(sub_firstline); sub_firstline = vim_strsave(ml_get(sub_firstlnum)); /* When going beyond the last line, stop substituting. */ if (sub_firstlnum <= line2) @@ -4076,7 +4076,7 @@ void do_sub(exarg_T *eap) if (skip_match) { /* Already hit end of the buffer, sub_firstlnum is one * less than what it ought to be. */ - free(sub_firstline); + xfree(sub_firstline); sub_firstline = vim_strsave((char_u *)""); copycol = 0; } @@ -4204,7 +4204,7 @@ skip: } sub_firstlnum = lnum; - free(sub_firstline); /* free the temp buffer */ + xfree(sub_firstline); /* free the temp buffer */ sub_firstline = new_start; new_start = NULL; matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; @@ -4234,8 +4234,8 @@ skip: if (did_sub) ++sub_nlines; - free(new_start); /* for when substitute was cancelled */ - free(sub_firstline); /* free the copy of the original line */ + xfree(new_start); /* for when substitute was cancelled */ + xfree(sub_firstline); /* free the copy of the original line */ sub_firstline = NULL; } @@ -4250,7 +4250,7 @@ skip: changed_lines(first_line, 0, last_line - i, i); } - free(sub_firstline); /* may have to free allocated copy of the line */ + xfree(sub_firstline); /* may have to free allocated copy of the line */ /* ":s/pat//n" doesn't move the cursor */ if (do_count) @@ -4510,7 +4510,7 @@ void global_exe(char_u *cmd) int read_viminfo_sub_string(vir_T *virp, int force) { if (force) - free(old_sub); + xfree(old_sub); if (force || old_sub == NULL) old_sub = viminfo_readstring(virp, 1, TRUE); return viminfo_readline(virp); @@ -4527,7 +4527,7 @@ void write_viminfo_sub_string(FILE *fp) #if defined(EXITFREE) void free_old_sub(void) { - free(old_sub); + xfree(old_sub); } #endif @@ -4739,7 +4739,7 @@ void ex_help(exarg_T *eap) curwin->w_alt_fnum = alt_fnum; erret: - free(tag); + xfree(tag); } @@ -5003,7 +5003,7 @@ int find_help_tags(char_u *arg, int *num_matches, char_u ***matches, int keep_la sizeof(char_u *), help_compare); /* Delete more than TAG_MANY to reduce the size of the listing. */ while (*num_matches > TAG_MANY) - free((*matches)[--*num_matches]); + xfree((*matches)[--*num_matches]); } return OK; } @@ -5165,7 +5165,7 @@ void fix_help_buffer(void) if (fnamecmp(e1, ".txt") != 0 && fnamecmp(e1, fname + 4) != 0) { /* Not .txt and not .abx, remove it. */ - free(fnames[i1]); + xfree(fnames[i1]); fnames[i1] = NULL; continue; } @@ -5174,7 +5174,7 @@ void fix_help_buffer(void) if (fnamecmp(e1, ".txt") == 0 && fnamecmp(e2, fname + 4) == 0) { /* use .abx instead of .txt */ - free(fnames[i1]); + xfree(fnames[i1]); fnames[i1] = NULL; } } @@ -5234,7 +5234,7 @@ void fix_help_buffer(void) ml_append(lnum, cp, (colnr_T)0, FALSE); if (cp != IObuff) - free(cp); + xfree(cp); ++lnum; } fclose(fd); @@ -5243,7 +5243,7 @@ void fix_help_buffer(void) } } if (mustfree) - free(rt); + xfree(rt); } break; } @@ -5310,7 +5310,7 @@ void ex_helptags(exarg_T *eap) EW_FILE|EW_SILENT) == FAIL || filecount == 0) { EMSG2("E151: No match: %s", NameBuff); - free(dirname); + xfree(dirname); return; } @@ -5372,7 +5372,7 @@ void ex_helptags(exarg_T *eap) ga_clear(&ga); FreeWild(filecount, files); - free(dirname); + xfree(dirname); } static void @@ -5722,7 +5722,7 @@ void ex_sign(exarg_T *eap) next_sign_typenr = 1; if (next_sign_typenr == start) { - free(sp); + xfree(sp); EMSG(_("E612: Too many signs defined")); return; } @@ -5755,7 +5755,7 @@ void ex_sign(exarg_T *eap) if (STRNCMP(arg, "icon=", 5) == 0) { arg += 5; - free(sp->sn_icon); + xfree(sp->sn_icon); sp->sn_icon = vim_strnsave(arg, (int)(p - arg)); backslash_halve(sp->sn_icon); } @@ -5794,7 +5794,7 @@ void ex_sign(exarg_T *eap) return; } - free(sp->sn_text); + xfree(sp->sn_text); /* Allocate one byte more if we need to pad up * with a space. */ len = (int)(p - arg + ((cells == 1) ? 1 : 0)); @@ -5983,7 +5983,7 @@ void ex_sign(exarg_T *eap) sprintf((char *)cmd, "e +%" PRId64 " %s", (int64_t)lnum, buf->b_fname); do_cmdline_cmd(cmd); - free(cmd); + xfree(cmd); } foldOpenCursor(); @@ -6076,14 +6076,14 @@ static void sign_list_defined(sign_T *sp) */ static void sign_undefine(sign_T *sp, sign_T *sp_prev) { - free(sp->sn_name); - free(sp->sn_icon); - free(sp->sn_text); + xfree(sp->sn_name); + xfree(sp->sn_icon); + xfree(sp->sn_text); if (sp_prev == NULL) first_sign = sp->sn_next; else sp_prev->sn_next = sp->sn_next; - free(sp); + xfree(sp); } /* diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index cd1b066fdd..463cc794c7 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -278,11 +278,11 @@ void do_debug(char_u *cmd) DOCMD_VERBOSE|DOCMD_EXCRESET); debug_break_level = n; - free(cmdline); + xfree(cmdline); } lines_left = Rows - 1; } - free(cmdline); + xfree(cmdline); --RedrawingDisabled; --no_wait_return; @@ -491,12 +491,12 @@ dbg_parsearg ( if (q == NULL) return FAIL; p = expand_env_save(q); - free(q); + xfree(q); if (p == NULL) return FAIL; if (*p != '*') { bp->dbg_name = fix_fname(p); - free(p); + xfree(p); } else bp->dbg_name = p; } @@ -526,10 +526,10 @@ void ex_breakadd(exarg_T *eap) pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE); if (pat != NULL) { bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); - free(pat); + xfree(pat); } if (pat == NULL || bp->dbg_prog == NULL) - free(bp->dbg_name); + xfree(bp->dbg_name); else { if (bp->dbg_lnum == 0) /* default line number is 1 */ bp->dbg_lnum = 1; @@ -598,14 +598,14 @@ void ex_breakdel(exarg_T *eap) best_lnum = bpi->dbg_lnum; } } - free(bp->dbg_name); + xfree(bp->dbg_name); } if (todel < 0) EMSG2(_("E161: Breakpoint not found: %s"), eap->arg); else { while (!GA_EMPTY(gap)) { - free(DEBUGGY(gap, todel).dbg_name); + xfree(DEBUGGY(gap, todel).dbg_name); vim_regfree(DEBUGGY(gap, todel).dbg_prog); --gap->ga_len; if (todel < gap->ga_len) @@ -727,7 +727,7 @@ debuggy_find ( } } if (name != fname) - free(name); + xfree(name); return lnum; } @@ -759,8 +759,8 @@ void ex_profile(exarg_T *eap) e = skipwhite(e); if (len == 5 && STRNCMP(eap->arg, "start", 5) == 0 && *e != NUL) { - free(profile_fname); - profile_fname = vim_strsave(e); + xfree(profile_fname); + profile_fname = expand_env_save_opt(e, true); do_profiling = PROF_YES; profile_set_wait(profile_zero()); set_vim_var_nr(VV_PROFILING, 1L); @@ -1293,7 +1293,7 @@ buf_found: set_curbuf(buf, DOBUF_GOTO); theend: - free(bufnrs); + xfree(bufnrs); return ret; } @@ -1450,7 +1450,7 @@ do_arglist ( break; regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); if (regmatch.regprog == NULL) { - free(p); + xfree(p); break; } @@ -1459,7 +1459,7 @@ do_arglist ( if (vim_regexec(®match, alist_name(&ARGLIST[match]), (colnr_T)0)) { didone = TRUE; - free(ARGLIST[match].ae_fname); + xfree(ARGLIST[match].ae_fname); memmove(ARGLIST + match, ARGLIST + match + 1, (ARGCOUNT - match - 1) * sizeof(aentry_T)); --ALIST(curwin)->al_ga.ga_len; @@ -1469,7 +1469,7 @@ do_arglist ( } vim_regfree(regmatch.regprog); - free(p); + xfree(p); if (!didone) EMSG2(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]); } @@ -1487,7 +1487,7 @@ do_arglist ( if (what == AL_ADD) { (void)alist_add_list(exp_count, exp_files, after); - free(exp_files); + xfree(exp_files); } else /* what == AL_SET */ alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0); } @@ -1683,7 +1683,7 @@ void do_argfile(exarg_T *eap, int argn) if (P_HID(curbuf)) { p = fix_fname(alist_name(&ARGLIST[argn])); other = otherfile(p); - free(p); + xfree(p); } if ((!P_HID(curbuf) || !other) && check_changed(curbuf, CCGD_AW @@ -1793,7 +1793,7 @@ void ex_argdelete(exarg_T *eap) EMSG(_(e_invarg)); else { for (int i = eap->line1; i <= eap->line2; ++i) - free(ARGLIST[i - 1].ae_fname); + xfree(ARGLIST[i - 1].ae_fname); memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2, (size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T))); ALIST(curwin)->al_ga.ga_len -= n; @@ -1858,7 +1858,7 @@ void ex_listdo(exarg_T *eap) set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); do_argfile(eap, i); set_option_value((char_u *)"shm", 0L, p_shm_save, 0); - free(p_shm_save); + xfree(p_shm_save); } if (curwin->w_arg_idx != i) break; @@ -1915,7 +1915,7 @@ void ex_listdo(exarg_T *eap) set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); set_option_value((char_u *)"shm", 0L, p_shm_save, 0); - free(p_shm_save); + xfree(p_shm_save); /* If autocommands took us elsewhere, quit here */ if (curbuf->b_fnum != next_fnum) @@ -2011,7 +2011,7 @@ void ex_compiler(exarg_T *eap) sprintf((char *)buf, "compiler/%s.vim", eap->arg); if (source_runtime(buf, TRUE) == FAIL) EMSG2(_("E666: compiler not supported: %s"), eap->arg); - free(buf); + xfree(buf); do_cmdline_cmd((char_u *)":delcommand CompilerSet"); @@ -2025,7 +2025,7 @@ void ex_compiler(exarg_T *eap) if (old_cur_comp != NULL) { set_internal_string_var((char_u *)"g:current_compiler", old_cur_comp); - free(old_cur_comp); + xfree(old_cur_comp); } else do_unlet((char_u *)"g:current_compiler", TRUE); } @@ -2135,8 +2135,8 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback, } } } - free(buf); - free(rtp_copy); + xfree(buf); + xfree(rtp_copy); if (p_verbose > 0 && !did_one && name != NULL) { verbose_enter(); smsg((char_u *)_("not found in 'runtimepath': \"%s\""), name); @@ -2273,7 +2273,7 @@ do_source ( if (p == NULL) return retval; fname_exp = fix_fname(p); - free(p); + xfree(p); if (fname_exp == NULL) return retval; if (os_isdir(fname_exp)) { @@ -2391,7 +2391,7 @@ do_source ( p = string_convert(&cookie.conv, firstline + 3, NULL); if (p == NULL) p = vim_strsave(firstline + 3); - free(firstline); + xfree(firstline); firstline = p; } @@ -2518,12 +2518,12 @@ do_source ( if (l_do_profiling == PROF_YES) prof_child_exit(&wait_start); /* leaving a child now */ fclose(cookie.fp); - free(cookie.nextline); - free(firstline); + xfree(cookie.nextline); + xfree(firstline); convert_setup(&cookie.conv, NULL, NULL); theend: - free(fname_exp); + xfree(fname_exp); return retval; } @@ -2577,7 +2577,7 @@ char_u *get_scriptname(scid_T id) # if defined(EXITFREE) void free_scriptnames() { -# define FREE_SCRIPTNAME(item) free((item)->sn_name) +# define FREE_SCRIPTNAME(item) xfree((item)->sn_name) GA_DEEP_CLEAR(&script_items, scriptitem_T, FREE_SCRIPTNAME); } # endif @@ -2636,7 +2636,7 @@ char_u *getsourceline(int c, void *cookie, int indent) ga_concat(&ga, line); ga_concat(&ga, p + 1); for (;; ) { - free(sp->nextline); + xfree(sp->nextline); sp->nextline = get_one_sourceline(sp); if (sp->nextline == NULL) break; @@ -2651,7 +2651,7 @@ char_u *getsourceline(int c, void *cookie, int indent) ga_concat(&ga, p + 1); } ga_append(&ga, NUL); - free(line); + xfree(line); line = ga.ga_data; } } @@ -2662,7 +2662,7 @@ char_u *getsourceline(int c, void *cookie, int indent) /* Convert the encoding of the script line. */ s = string_convert(&sp->conv, line, NULL); if (s != NULL) { - free(line); + xfree(line); line = s; } } @@ -2771,7 +2771,7 @@ static char_u *get_one_sourceline(struct source_cookie *sp) if (have_read) return (char_u *)ga.ga_data; - free(ga.ga_data); + xfree(ga.ga_data); return NULL; } @@ -2874,7 +2874,7 @@ void ex_scriptencoding(exarg_T *eap) convert_setup(&sp->conv, name, p_enc); if (name != eap->arg) - free(name); + xfree(name); } /* @@ -3192,7 +3192,7 @@ static char_u **find_locales(void) GA_APPEND(char_u *, &locales_ga, loc); loc = (char_u *)strtok(NULL, "\n"); } - free(locale_a); + xfree(locale_a); // Guarantee that .ga_data is NULL terminated ga_grow(&locales_ga, 1); ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; @@ -3205,8 +3205,8 @@ void free_locales(void) int i; if (locales != NULL) { for (i = 0; locales[i] != NULL; i++) - free(locales[i]); - free(locales); + xfree(locales[i]); + xfree(locales); locales = NULL; } } @@ -3260,7 +3260,7 @@ static void script_host_execute(char *name, exarg_T *eap) (void)eval_call_provider(name, "execute", args); } - free(script); + xfree(script); } static void script_host_execute_file(char *name, exarg_T *eap) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index cf22477dc9..f7f6b84e6e 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -104,7 +104,7 @@ typedef struct { linenr_T lnum; /* sourcing_lnum of the line */ } wcmd_T; -#define FREE_WCMD(wcmd) free((wcmd)->line) +#define FREE_WCMD(wcmd) xfree((wcmd)->line) /* * Structure used to store info for line position in a while or for loop. @@ -458,7 +458,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) { /* Each '|' separated command is stored separately in lines_ga, to * be able to jump to it. Don't use next_cmdline now. */ - free(cmdline_copy); + xfree(cmdline_copy); cmdline_copy = NULL; /* Check if a function has returned or, unless it has an unclosed @@ -554,7 +554,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, * Keep the first typed line. Clear it when more lines are typed. */ if (flags & DOCMD_KEEPLINE) { - free(repeat_cmdline); + xfree(repeat_cmdline); if (count == 0) repeat_cmdline = vim_strsave(next_cmdline); else @@ -628,7 +628,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, current_line = cmd_loop_cookie.current_line; if (next_cmdline == NULL) { - free(cmdline_copy); + xfree(cmdline_copy); cmdline_copy = NULL; /* * If the command was typed, remember it for the ':' register. @@ -636,7 +636,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, */ if (getline_equal(fgetline, cookie, getexline) && new_last_cmdline != NULL) { - free(last_cmdline); + xfree(last_cmdline); last_cmdline = new_last_cmdline; new_last_cmdline = NULL; } @@ -777,7 +777,7 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, || cstack.cs_idx >= 0 || (flags & DOCMD_REPEAT))); - free(cmdline_copy); + xfree(cmdline_copy); did_emsg_syntax = FALSE; GA_DEEP_CLEAR(&lines_ga, wcmd_T, FREE_WCMD); @@ -875,15 +875,15 @@ int do_cmdline(char_u *cmdline, LineGetter fgetline, do { next = messages->next; emsg(messages->msg); - free(messages->msg); - free(messages); + xfree(messages->msg); + xfree(messages); messages = next; } while (messages != NULL); } else if (p != NULL) { emsg(p); - free(p); + xfree(p); } - free(sourcing_name); + xfree(sourcing_name); sourcing_name = saved_sourcing_name; sourcing_lnum = saved_sourcing_lnum; } @@ -1459,7 +1459,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, } p = vim_strnsave(ea.cmd, p - ea.cmd); int ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL); - free(p); + xfree(p); if (ret && !aborting()) { p = find_command(&ea, NULL); } @@ -3275,7 +3275,7 @@ void ex_ni(exarg_T *eap) { if (!eap->skip) eap->errmsg = (char_u *)N_( - "E319: Sorry, the command is not available in this version"); + "E319: The command is not available in this version"); } /// Stub function for script command which is Not Implemented. NI! @@ -3285,7 +3285,7 @@ static void ex_script_ni(exarg_T *eap) if (!eap->skip) ex_ni(eap); else - free(script_get(eap, eap->arg)); + xfree(script_get(eap, eap->arg)); } /* @@ -3400,7 +3400,7 @@ static char_u *replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep) msg_make(p); /* 'eap->cmd' is not set here, because it is not used at CMD_make */ - free(*cmdlinep); + xfree(*cmdlinep); *cmdlinep = new_cmdline; p = new_cmdline; } @@ -3464,7 +3464,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) char_u *l = repl; repl = expand_env_save(repl); - free(l); + xfree(l); } /* Need to escape white space et al. with a backslash. @@ -3500,7 +3500,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) for (l = repl; *l; ++l) if (vim_strchr(ESCAPE_CHARS, *l) != NULL) { l = vim_strsave_escaped(repl, ESCAPE_CHARS); - free(repl); + xfree(repl); repl = l; break; } @@ -3512,12 +3512,12 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) char_u *l; l = vim_strsave_escaped(repl, (char_u *)"!"); - free(repl); + xfree(repl); repl = l; } p = repl_cmdline(eap, p, srclen, repl, cmdlinep); - free(repl); + xfree(repl); } /* @@ -3595,7 +3595,7 @@ int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp) if (p != NULL) { (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), p, cmdlinep); - free(p); + xfree(p); } } } @@ -3649,7 +3649,7 @@ static char_u *repl_cmdline(exarg_T *eap, char_u *src, int srclen, char_u *repl, eap->arg = new_cmdline + (eap->arg - *cmdlinep); if (eap->do_ecmd_cmd != NULL && eap->do_ecmd_cmd != dollar_command) eap->do_ecmd_cmd = new_cmdline + (eap->do_ecmd_cmd - *cmdlinep); - free(*cmdlinep); + xfree(*cmdlinep); *cmdlinep = new_cmdline; return src; @@ -4141,9 +4141,9 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep, goto fail; } - free(cmd->uc_rep); + xfree(cmd->uc_rep); cmd->uc_rep = NULL; - free(cmd->uc_compl_arg); + xfree(cmd->uc_compl_arg); cmd->uc_compl_arg = NULL; break; } @@ -4177,8 +4177,8 @@ static int uc_add_command(char_u *name, size_t name_len, char_u *rep, return OK; fail: - free(rep_buf); - free(compl_arg); + xfree(rep_buf); + xfree(compl_arg); return FAIL; } @@ -4531,9 +4531,9 @@ void ex_comclear(exarg_T *eap) } static void free_ucmd(ucmd_T* cmd) { - free(cmd->uc_name); - free(cmd->uc_rep); - free(cmd->uc_compl_arg); + xfree(cmd->uc_name); + xfree(cmd->uc_rep); + xfree(cmd->uc_compl_arg); } /* @@ -4569,9 +4569,9 @@ static void ex_delcommand(exarg_T *eap) return; } - free(cmd->uc_name); - free(cmd->uc_rep); - free(cmd->uc_compl_arg); + xfree(cmd->uc_name); + xfree(cmd->uc_rep); + xfree(cmd->uc_compl_arg); --gap->ga_len; @@ -4937,8 +4937,8 @@ static void do_ucmd(exarg_T *eap) (void)do_cmdline(buf, eap->getline, eap->cookie, DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED); current_SID = save_current_SID; - free(buf); - free(split_buf); + xfree(buf); + xfree(split_buf); } static char_u *get_user_command_name(int idx) @@ -5064,11 +5064,11 @@ static void ex_colorscheme(exarg_T *eap) ++emsg_off; p = eval_to_string(expr, NULL, FALSE); --emsg_off; - free(expr); + xfree(expr); if (p != NULL) { MSG(p); - free(p); + xfree(p); } else MSG("default"); } else if (load_colors(eap->arg) == FAIL) @@ -5468,7 +5468,7 @@ static void ex_goto(exarg_T *eap) */ void alist_clear(alist_T *al) { -# define FREE_AENTRY_FNAME(arg) free(arg->ae_fname) +# define FREE_AENTRY_FNAME(arg) xfree(arg->ae_fname) GA_DEEP_CLEAR(&al->al_ga, aentry_T, FREE_AENTRY_FNAME); } @@ -5490,7 +5490,7 @@ void alist_unlink(alist_T *al) { if (al != &global_alist && --al->al_refcount <= 0) { alist_clear(al); - free(al); + xfree(al); } } @@ -5556,7 +5556,7 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum /* When adding many buffers this can take a long time. Allow * interrupting here. */ while (i < count) - free(files[i++]); + xfree(files[i++]); break; } @@ -5568,7 +5568,7 @@ void alist_set(alist_T *al, int count, char_u **files, int use_curbuf, int *fnum alist_add(al, files[i], use_curbuf ? 2 : 1); os_breakcheck(); } - free(files); + xfree(files); } if (al == &global_alist) @@ -5729,7 +5729,7 @@ void ex_splitview(exarg_T *eap) theend: - free(fname); + xfree(fname); } /* @@ -5908,7 +5908,7 @@ static void ex_find(exarg_T *eap) * appears several times in the path. */ count = eap->line2; while (fname != NULL && --count > 0) { - free(fname); + xfree(fname); fname = find_file_in_path(NULL, 0, FNAME_MESS, FALSE, curbuf->b_ffname); } @@ -5917,7 +5917,7 @@ static void ex_find(exarg_T *eap) if (fname != NULL) { eap->arg = fname; do_exedit(eap, NULL); - free(fname); + xfree(fname); } } @@ -6236,10 +6236,10 @@ static char_u *prev_dir = NULL; #if defined(EXITFREE) void free_cd_dir(void) { - free(prev_dir); + xfree(prev_dir); prev_dir = NULL; - free(globaldir); + xfree(globaldir); globaldir = NULL; } @@ -6251,7 +6251,7 @@ void free_cd_dir(void) */ void post_chdir(int local) { - free(curwin->w_localdir); + xfree(curwin->w_localdir); curwin->w_localdir = NULL; if (local) { /* If still in global directory, need to remember current @@ -6264,7 +6264,7 @@ void post_chdir(int local) } else { /* We are now in the global directory, no need to remember its * name. */ - free(globaldir); + xfree(globaldir); globaldir = NULL; } @@ -6330,7 +6330,7 @@ void ex_cd(exarg_T *eap) if (KeyTyped || p_verbose >= 5) ex_pwd(eap); } - free(tofree); + xfree(tofree); } } @@ -6733,7 +6733,7 @@ static void ex_redir(exarg_T *eap) return; redir_fd = open_exfile(fname, eap->forceit, mode); - free(fname); + xfree(fname); } else if (*arg == '@') { /* redirect to a register a-z (resp. A-Z for appending) */ close_redir(); @@ -6970,7 +6970,7 @@ static void ex_mkrc(exarg_T *eap) shorten_fnames(TRUE); } } - free(dirnow); + xfree(dirnow); } else { failed |= (put_view(fd, curwin, !using_vdir, flagp, -1) == FAIL); @@ -6999,14 +6999,14 @@ static void ex_mkrc(exarg_T *eap) tbuf = xmalloc(MAXPATHL); if (vim_FullName(fname, tbuf, MAXPATHL, FALSE) == OK) set_vim_var_string(VV_THIS_SESSION, tbuf, -1); - free(tbuf); + xfree(tbuf); } #ifdef MKSESSION_NL mksession_nl = FALSE; #endif } - free(viewFile); + xfree(viewFile); } int vim_mkdir_emsg(char_u *name, int prot) @@ -7189,7 +7189,7 @@ static void ex_normal(exarg_T *eap) State = save_State; setmouse(); ui_cursor_shape(); /* may show different cursor shape */ - free(arg); + xfree(arg); } /* @@ -7609,7 +7609,7 @@ eval_vars ( * postponed to avoid a delay when <afile> is not used. */ autocmd_fname_full = TRUE; result = FullName_save(autocmd_fname, FALSE); - free(autocmd_fname); + xfree(autocmd_fname); autocmd_fname = result; } if (result == NULL) { @@ -7686,7 +7686,7 @@ eval_vars ( result = NULL; } else result = vim_strnsave(result, resultlen); - free(resultbuf); + xfree(resultbuf); return result; } @@ -7772,7 +7772,7 @@ char_u *expand_sfile(char_u *arg) if (errormsg != NULL) { if (*errormsg) emsg(errormsg); - free(result); + xfree(result); return NULL; } if (repl == NULL) { /* no match (cannot happen) */ @@ -7785,8 +7785,8 @@ char_u *expand_sfile(char_u *arg) STRCPY(newres + (p - result), repl); len = (int)STRLEN(newres); STRCAT(newres, p + srclen); - free(repl); - free(result); + xfree(repl); + xfree(result); result = newres; p = newres + len; /* continue after the match */ } @@ -7850,10 +7850,10 @@ makeopens ( if (fputs("cd ", fd) < 0 || ses_put_fname(fd, sname, &ssop_flags) == FAIL || put_eol(fd) == FAIL) { - free(sname); + xfree(sname); return FAIL; } - free(sname); + xfree(sname); } /* @@ -8434,10 +8434,10 @@ ses_arglist ( } if (fputs("argadd ", fd) < 0 || ses_put_fname(fd, s, flagp) == FAIL || put_eol(fd) == FAIL) { - free(buf); + xfree(buf); return FAIL; } - free(buf); + xfree(buf); } } return OK; @@ -8491,11 +8491,11 @@ static int ses_put_fname(FILE *fd, char_u *name, unsigned *flagp) /* escape special characters */ p = vim_strsave_fnameescape(sname, FALSE); - free(sname); + xfree(sname); /* write the result */ bool retval = fputs((char *)p, fd) < 0 ? FAIL : OK; - free(p); + xfree(p); return retval; } @@ -8511,7 +8511,7 @@ static void ex_loadview(exarg_T *eap) if (do_source(fname, FALSE, DOSO_NONE) == FAIL) { EMSG2(_(e_notopen), fname); } - free(fname); + xfree(fname); } } @@ -8564,7 +8564,7 @@ static char_u *get_view_file(int c) *s++ = c; STRCPY(s, ".vim"); - free(sname); + xfree(sname); return retval; } @@ -8829,7 +8829,7 @@ static void ex_match(exarg_T *eap) c = *end; *end = NUL; match_add(curwin, g, p + 1, 10, id, NULL); - free(g); + xfree(g); *end = c; } } diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index d2774804f8..5ed7a35209 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -281,8 +281,8 @@ static void free_msglist(struct msglist *l) messages = l; while (messages != NULL) { next = messages->next; - free(messages->msg); - free(messages); + xfree(messages->msg); + xfree(messages); messages = next; } } @@ -505,7 +505,7 @@ static int throw_exception(void *value, int type, char_u *cmdname) return OK; nomem: - free(excp); + xfree(excp); suppress_errthrow = TRUE; EMSG(_(e_outofmem)); fail: @@ -550,14 +550,14 @@ static void discard_exception(except_T *excp, int was_finished) else verbose_leave(); STRCPY(IObuff, saved_IObuff); - free(saved_IObuff); + xfree(saved_IObuff); } if (excp->type != ET_INTERRUPT) - free(excp->value); + xfree(excp->value); if (excp->type == ET_ERROR) free_msglist(excp->messages); - free(excp->throw_name); - free(excp); + xfree(excp->throw_name); + xfree(excp); } /* @@ -727,9 +727,9 @@ static void report_pending(int action, int pending, void *value) msg_silent = save_msg_silent; if (pending == CSTP_RETURN) - free(s); + xfree(s); else if (pending & CSTP_THROW) - free(mesg); + xfree(mesg); } /* @@ -1165,7 +1165,7 @@ void ex_throw(exarg_T *eap) * not throw. */ if (!eap->skip && value != NULL) { if (throw_exception(value, ET_USER, NULL) == FAIL) - free(value); + xfree(value); else do_throw(eap->cstack); } @@ -1977,7 +1977,7 @@ int cleanup_conditionals(struct condstack *cstack, int searched_cond, int inclus elem = cstack->cs_emsg_silent_list; cstack->cs_emsg_silent_list = elem->next; emsg_silent = elem->saved_emsg_silent; - free(elem); + xfree(elem); cstack->cs_flags[idx] &= ~CSF_SILENT; } if (stop) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index f0beef87e7..7dac4a9565 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -354,7 +354,7 @@ getcmdline ( && c != K_KPAGEDOWN && c != K_KPAGEUP && c != K_LEFT && c != K_RIGHT && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N))) { - free(lookfor); + xfree(lookfor); lookfor = NULL; } @@ -593,7 +593,7 @@ getcmdline ( realloc_cmdbuff(len + 1); ccline.cmdlen = len; STRCPY(ccline.cmdbuff, p); - free(p); + xfree(p); /* Restore the cursor or use the position set with * set_cmdline_pos(). */ @@ -825,7 +825,7 @@ getcmdline ( ) goto cmdline_not_changed; - free(ccline.cmdbuff); /* no commandline to return */ + xfree(ccline.cmdbuff); /* no commandline to return */ ccline.cmdbuff = NULL; if (!cmd_silent) { if (cmdmsg_rl) @@ -1193,7 +1193,7 @@ getcmdline ( int len; int old_firstc; - free(ccline.cmdbuff); + xfree(ccline.cmdbuff); xpc.xp_context = EXPAND_NOTHING; if (hiscnt == hislen) p = lookfor; /* back to the old one */ @@ -1476,13 +1476,13 @@ returncmd: add_to_history(histype, ccline.cmdbuff, TRUE, histype == HIST_SEARCH ? firstc : NUL); if (firstc == ':') { - free(new_last_cmdline); + xfree(new_last_cmdline); new_last_cmdline = vim_strsave(ccline.cmdbuff); } } if (gotesc) { /* abandon command line */ - free(ccline.cmdbuff); + xfree(ccline.cmdbuff); ccline.cmdbuff = NULL; if (msg_scrolled == 0) compute_cmdrow(); @@ -1784,7 +1784,7 @@ getexmodeline ( } if (c1 == Ctrl_T) { - long sw = get_sw_value(curbuf); + int sw = get_sw_value(curbuf); p = (char_u *)line_ga.ga_data; p[line_ga.ga_len] = NUL; @@ -1958,7 +1958,7 @@ static void realloc_cmdbuff(int len) * there, thus copy up to the NUL and add a NUL. */ memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen); ccline.cmdbuff[ccline.cmdlen] = NUL; - free(p); + xfree(p); if (ccline.xpc != NULL && ccline.xpc->xp_pattern != NULL @@ -1978,7 +1978,7 @@ static char_u *arshape_buf = NULL; # if defined(EXITFREE) void free_cmdline_buf(void) { - free(arshape_buf); + xfree(arshape_buf); } # endif @@ -2017,7 +2017,7 @@ static void draw_cmdline(int start, int len) if (len * 2 + 2 > buflen) { /* Re-allocate the buffer. We keep it around to avoid a lot of * alloc()/free() calls. */ - free(arshape_buf); + xfree(arshape_buf); buflen = len * 2 + 2; arshape_buf = xmalloc(buflen); } @@ -2291,7 +2291,7 @@ char_u *save_cmdline_alloc(void) void restore_cmdline_alloc(char_u *p) { restore_cmdline((struct cmdline_info *)p); - free(p); + xfree(p); } /* @@ -2368,7 +2368,7 @@ cmdline_paste ( cmdline_paste_str(p, literally); if (allocated) - free(arg); + xfree(arg); return OK; } @@ -2616,7 +2616,7 @@ nextwild ( p2 = ExpandOne(xp, p1, vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len), use_options, type); - free(p1); + xfree(p1); /* longest match: make sure it is not shorter, happens with :help */ if (p2 != NULL && type == WILD_LONGEST) { for (j = 0; j < xp->xp_pattern_len; ++j) @@ -2624,7 +2624,7 @@ nextwild ( || ccline.cmdbuff[i + j] == '?') break; if ((int)STRLEN(p2) < j) { - free(p2); + xfree(p2); p2 = NULL; } } @@ -2644,7 +2644,7 @@ nextwild ( ccline.cmdlen += difflen; ccline.cmdpos += difflen; } - free(p2); + xfree(p2); redrawcmd(); cursorcmd(); @@ -2755,7 +2755,7 @@ ExpandOne ( if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) { FreeWild(xp->xp_numfiles, xp->xp_files); xp->xp_numfiles = -1; - free(orig_save); + xfree(orig_save); orig_save = NULL; } findex = 0; @@ -2764,7 +2764,7 @@ ExpandOne ( return NULL; if (xp->xp_numfiles == -1) { - free(orig_save); + xfree(orig_save); orig_save = orig; orig_saved = TRUE; @@ -2872,7 +2872,7 @@ ExpandOne ( /* Free "orig" if it wasn't stored in "orig_save". */ if (!orig_saved) - free(orig); + xfree(orig); return ss; } @@ -2930,11 +2930,11 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o /* for ":set path=" we need to escape spaces twice */ if (xp->xp_backslash == XP_BS_THREE) { p = vim_strsave_escaped(files[i], (char_u *)" "); - free(files[i]); + xfree(files[i]); files[i] = p; #if defined(BACKSLASH_IN_FILENAME) p = vim_strsave_escaped(files[i], (char_u *)" "); - free(files[i]); + xfree(files[i]); files[i] = p; #endif } @@ -2943,7 +2943,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o #else p = vim_strsave_fnameescape(files[i], xp->xp_shell); #endif - free(files[i]); + xfree(files[i]); files[i] = p; /* If 'str' starts with "\~", replace "~" at start of @@ -2964,7 +2964,7 @@ void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int o */ for (i = 0; i < numfiles; ++i) { p = vim_strsave_escaped(files[i], (char_u *)"\\|\""); - free(files[i]); + xfree(files[i]); files[i] = p; } } @@ -2998,7 +2998,7 @@ char_u *vim_strsave_fnameescape(char_u *fname, int shell) FUNC_ATTR_NONNULL_RET /* For csh and similar shells need to put two backslashes before '!'. * One is taken by Vim, one by the shell. */ char_u *s = vim_strsave_escaped(p, (char_u *)"!"); - free(p); + xfree(p); p = s; } #endif @@ -3020,7 +3020,7 @@ static void escape_fname(char_u **pp) char_u *p = xmalloc(STRLEN(*pp) + 2); p[0] = '\\'; STRCPY(p + 1, *pp); - free(*pp); + xfree(*pp); *pp = p; } @@ -3036,7 +3036,7 @@ void tilde_replace(char_u *orig_pat, int num_files, char_u **files) if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) { for (i = 0; i < num_files; ++i) { p = home_replace_save(NULL, files[i]); - free(files[i]); + xfree(files[i]); files[i] = p; } } @@ -3154,8 +3154,8 @@ static int showmatches(expand_T *xp, int wildmenu) halved_slash = backslash_halve_save( exp_path != NULL ? exp_path : files_found[k]); j = os_isdir(halved_slash); - free(exp_path); - free(halved_slash); + xfree(exp_path); + xfree(halved_slash); } else /* Expansion was done here, file names are literal. */ j = os_isdir(files_found[k]); @@ -3515,7 +3515,7 @@ expand_cmdline ( *matchcount = 0; *matches = NULL; } - free(file_str); + xfree(file_str); return EXPAND_OK; } @@ -3610,7 +3610,7 @@ ExpandFromContext ( /* Expand wildcards, supporting %:h and the like. */ ret = expand_wildcards_eval(&pat, num_file, file, flags); if (free_pat) - free(pat); + xfree(pat); return ret; } @@ -3887,9 +3887,9 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, STRMOVE(s, s + l); ((char_u **)ga.ga_data)[ga.ga_len++] = s; } else - free(s); + xfree(s); } - free(*file); + xfree(*file); } } if (*e != NUL) @@ -3898,10 +3898,10 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, *file = ga.ga_data; *num_file = ga.ga_len; - free(buf); - free(pat); + xfree(buf); + xfree(pat); if (mustfree) - free(path); + xfree(path); } /* @@ -3946,7 +3946,7 @@ static void * call_user_expand_func(user_expand_func_T user_expand_func, if (ccline.cmdbuff != NULL) ccline.cmdbuff[ccline.cmdlen] = keep; - free(args[0]); + xfree(args[0]); return ret; } @@ -3986,7 +3986,7 @@ static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, if (*e != NUL) ++e; } - free(retstr); + xfree(retstr); *file = ga.ga_data; *num_file = ga.ga_len; return OK; @@ -4039,7 +4039,7 @@ static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname char_u *s = xmalloc(size); snprintf((char *)s, size, "%s/%s*.vim", dirnames[i], pat); globpath(p_rtp, s, &ga, 0); - free(s); + xfree(s); } for (int i = 0; i < ga.ga_len; i++) { @@ -4108,7 +4108,7 @@ void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options) } } - free(buf); + xfree(buf); } @@ -4210,7 +4210,7 @@ void init_history(void) if (i >= 0) /* copy newest entries */ temp[i] = history[type][j]; else { /* remove older entries */ - free(history[type][j].hisstr); + xfree(history[type][j].hisstr); history[type][j].hisstr = NULL; } if (--j < 0) @@ -4220,7 +4220,7 @@ void init_history(void) } hisidx[type] = newlen - 1; } - free(history[type]); + xfree(history[type]); history[type] = temp; } } @@ -4347,7 +4347,7 @@ add_to_history ( if (maptick == last_maptick) { /* Current line is from the same mapping, remove it */ hisptr = &history[HIST_SEARCH][hisidx[HIST_SEARCH]]; - free(hisptr->hisstr); + xfree(hisptr->hisstr); clear_hist_entry(hisptr); --hisnum[histype]; if (--hisidx[HIST_SEARCH] < 0) @@ -4359,7 +4359,7 @@ add_to_history ( if (++hisidx[histype] == hislen) hisidx[histype] = 0; hisptr = &history[histype][hisidx[histype]]; - free(hisptr->hisstr); + xfree(hisptr->hisstr); /* Store the separator after the NUL of the string. */ len = (int)STRLEN(new_entry); @@ -4532,7 +4532,7 @@ int clr_history(int histype) if (hislen != 0 && histype >= 0 && histype < HIST_COUNT) { hisptr = history[histype]; for (i = hislen; i--; ) { - free(hisptr->hisstr); + xfree(hisptr->hisstr); clear_hist_entry(hisptr); } hisidx[histype] = -1; /* mark history as cleared */ @@ -4571,7 +4571,7 @@ int del_history_entry(int histype, char_u *str) break; if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) { found = TRUE; - free(hisptr->hisstr); + xfree(hisptr->hisstr); clear_hist_entry(hisptr); } else { if (i != last) { @@ -4603,7 +4603,7 @@ int del_history_idx(int histype, int idx) if (i < 0) return FALSE; idx = hisidx[histype]; - free(history[histype][i].hisstr); + xfree(history[histype][i].hisstr); /* When deleting the last added search string in a mapping, reset * last_maptick, so that the last added search string isn't deleted again. @@ -4837,7 +4837,7 @@ int read_viminfo_history(vir_T *virp, int writing) viminfo_history[type][viminfo_hisidx[type]++] = p; } } - free(val); + xfree(val); } return viminfo_readline(virp); } @@ -4875,7 +4875,7 @@ void finish_viminfo_history(void) idx = hislen - 1; } for (i = 0; i < viminfo_hisidx[type]; i++) { - free(history[type][idx].hisstr); + xfree(history[type][idx].hisstr); history[type][idx].hisstr = viminfo_history[type][i]; history[type][idx].viminfo = TRUE; if (--idx < 0) @@ -4887,7 +4887,7 @@ void finish_viminfo_history(void) history[type][idx++].hisnum = ++hisnum[type]; idx %= hislen; } - free(viminfo_history[type]); + xfree(viminfo_history[type]); viminfo_history[type] = NULL; viminfo_hisidx[type] = 0; } @@ -4974,8 +4974,8 @@ void write_viminfo_history(FILE *fp, int merge) } for (i = 0; i < viminfo_hisidx[type]; ++i) if (viminfo_history[type] != NULL) - free(viminfo_history[type][i]); - free(viminfo_history[type]); + xfree(viminfo_history[type][i]); + xfree(viminfo_history[type]); viminfo_history[type] = NULL; viminfo_hisidx[type] = 0; } @@ -5161,7 +5161,7 @@ static int ex_window(void) if (aborting() && cmdwin_result != K_IGNORE) cmdwin_result = Ctrl_C; /* Set the new command line from the cmdline buffer. */ - free(ccline.cmdbuff); + xfree(ccline.cmdbuff); if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) { /* :qa[!] typed */ char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; @@ -5257,13 +5257,13 @@ char_u *script_get(exarg_T *eap, char_u *cmd) NUL, eap->cookie, 0); if (theline == NULL || STRCMP(end_pattern, theline) == 0) { - free(theline); + xfree(theline); break; } ga_concat(&ga, theline); ga_append(&ga, '\n'); - free(theline); + xfree(theline); } ga_append(&ga, NUL); diff --git a/src/nvim/farsi.c b/src/nvim/farsi.c index 2ca581ebd3..f9d6b14edc 100644 --- a/src/nvim/farsi.c +++ b/src/nvim/farsi.c @@ -2,6 +2,7 @@ /// /// Functions for Farsi language +#include <assert.h> #include <stdbool.h> #include "nvim/cursor.h" @@ -29,26 +30,23 @@ // Special Farsi text messages const char_u farsi_text_1[] = { - YE_, _SIN, RE, ALEF_, _FE, ' ', 'V', 'I', 'M', - ' ', F_HE, _BE, ' ', SHIN, RE, _GAF, DAL, ' ', NOON, - ALEF_, _YE, ALEF_, _PE, '\0' + YE_, _SIN, RE, ALEF_, _FE, ' ', 'V', 'I', 'M', ' ', F_HE, _BE, ' ', SHIN, RE, + _GAF, DAL, ' ', NOON, ALEF_, _YE, ALEF_, _PE, '\0' }; const char_u farsi_text_2[] = { - YE_, _SIN, RE, ALEF_, _FE, ' ', FARSI_3, FARSI_3, - FARSI_4, FARSI_2, ' ', DAL, RE, ALEF, DAL, _NOON, - ALEF_, _TE, _SIN, ALEF, ' ', F_HE, _BE, ' ', SHIN, - RE, _GAF, DAL, ' ', NOON, ALEF_, _YE, ALEF_, _PE, '\0' + YE_, _SIN, RE, ALEF_, _FE, ' ', FARSI_3, FARSI_3, FARSI_4, FARSI_2, ' ', DAL, + RE, ALEF, DAL, _NOON, ALEF_, _TE, _SIN, ALEF, ' ', F_HE, _BE, ' ', SHIN, RE, + _GAF, DAL, ' ', NOON, ALEF_, _YE, ALEF_, _PE, '\0' }; const char_u farsi_text_3[] = { - DAL, WAW, _SHIN, _YE, _MIM, _NOON, ' ', YE_, _NOON, - ALEF_, _BE, _YE, _TE, _SHIN, _PE, ' ', 'R', 'E', 'P', 'L', - 'A', 'C', 'E', ' ', NOON, ALEF_, _MIM, RE, _FE, ZE, ALEF, - ' ', 'R', 'E', 'V', 'E', 'R', 'S', 'E', ' ', 'I', 'N', - 'S', 'E', 'R', 'T', ' ', SHIN, WAW, RE, ' ', ALEF_, _BE, - ' ', YE_, _SIN, RE, ALEF_, _FE, ' ', RE, DAL, ' ', RE, - ALEF_, _KAF, ' ', MIM, ALEF_, _GAF, _NOON, _HE, '\0' + DAL, WAW, _SHIN, _YE, _MIM, _NOON, ' ', YE_, _NOON, ALEF_, _BE, _YE, _TE, + _SHIN, _PE, ' ', 'R', 'E', 'P', 'L', 'A', 'C', 'E', ' ', NOON, ALEF_, _MIM, + RE, _FE, ZE, ALEF, ' ', 'R', 'E', 'V', 'E', 'R', 'S', 'E', ' ', 'I', 'N', 'S', + 'E', 'R', 'T', ' ', SHIN, WAW, RE, ' ', ALEF_, _BE, ' ', YE_, _SIN, RE, ALEF_, + _FE, ' ', RE, DAL, ' ', RE, ALEF_, _KAF, ' ', MIM, ALEF_, _GAF, _NOON, _HE, + '\0' }; const char_u farsi_text_5[] = { @@ -65,93 +63,41 @@ const char_u farsi_text_5[] = { /// @param c The character to convert. /// /// @return Farsi character converted to a _X or _X_ type. -static int toF_Xor_X_(int c) +static char_u toF_Xor_X_(int c) { - int tempc; + char_u tempc; switch (c) { - case BE: - return _BE; - - case PE: - return _PE; - - case TE: - return _TE; - - case SE: - return _SE; - - case JIM: - return _JIM; - - case CHE: - return _CHE; - - case HE_J: - return _HE_J; - - case XE: - return _XE; - - case SIN: - return _SIN; - - case SHIN: - return _SHIN; - - case SAD: - return _SAD; - - case ZAD: - return _ZAD; - - case AYN: - return _AYN; - - case AYN_: - return _AYN_; - - case GHAYN: - return _GHAYN; - - case GHAYN_: - return _GHAYN_; - - case FE: - return _FE; - - case GHAF: - return _GHAF; - - case KAF: - return _KAF; - - case GAF: - return _GAF; - - case LAM: - return _LAM; - - case MIM: - return _MIM; - - case NOON: - return _NOON; - - case YE: - case YE_: - return _YE; - - case YEE: - case YEE_: - return _YEE; - - case IE: - case IE_: - return _IE; - - case F_HE: + case BE : tempc = _BE ; break; + case PE : tempc = _PE ; break; + case TE : tempc = _TE ; break; + case SE : tempc = _SE ; break; + case JIM : tempc = _JIM ; break; + case CHE : tempc = _CHE ; break; + case HE_J : tempc = _HE_J ; break; + case XE : tempc = _XE ; break; + case SIN : tempc = _SIN ; break; + case SHIN : tempc = _SHIN ; break; + case SAD : tempc = _SAD ; break; + case ZAD : tempc = _ZAD ; break; + case AYN : tempc = _AYN ; break; + case AYN_ : tempc = _AYN_ ; break; + case GHAYN : tempc = _GHAYN ; break; + case GHAYN_ : tempc = _GHAYN_ ; break; + case FE : tempc = _FE ; break; + case GHAF : tempc = _GHAF ; break; + case KAF : tempc = _KAF ; break; + case GAF : tempc = _GAF ; break; + case LAM : tempc = _LAM ; break; + case MIM : tempc = _MIM ; break; + case NOON : tempc = _NOON ; break; + case YE : + case YE_ : tempc = _YE ; break; + case YEE : + case YEE_ : tempc = _YEE ; break; + case IE : + case IE_ : tempc = _IE ; break; + case F_HE : tempc = _HE; if (p_ri && @@ -171,9 +117,13 @@ static int toF_Xor_X_(int c) inc_cursor(); } - return tempc; + break; + + default: + tempc = 0; } - return 0; + + return tempc; } /// Convert the given Farsi character into Farsi capital character. @@ -181,104 +131,51 @@ static int toF_Xor_X_(int c) /// @param c The character to convert. /// /// @return Character converted to the Farsi capital leter. -int toF_TyA(int c) +char_u toF_TyA(char_u c) { - switch (c) { - case ALEF_: - return ALEF; - - case ALEF_U_H_: - return ALEF_U_H; - - case _BE: - return BE; - - case _PE: - return PE; - - case _TE: - return TE; - - case _SE: - return SE; - - case _JIM: - return JIM; - - case _CHE: - return CHE; - - case _HE_J: - return HE_J; - - case _XE: - return XE; - - case _SIN: - return SIN; - - case _SHIN: - return SHIN; - - case _SAD: - return SAD; - - case _ZAD: - return ZAD; - - case _AYN: - case AYN_: - case _AYN_: - return AYN; - - case _GHAYN: - case GHAYN_: - case _GHAYN_: - return GHAYN; - - case _FE: - return FE; + char_u tempc; - case _GHAF: - return GHAF; - - // I am not sure what it is !!! - // case _KAF_H: - case _KAF: - return KAF; - - case _GAF: - return GAF; - - case _LAM: - return LAM; - - case _MIM: - return MIM; - - case _NOON: - return NOON; - - case _YE: - case YE_: - return YE; - - case _YEE: - case YEE_: - return YEE; - - case TEE_: - return TEE; - - case _IE: - case IE_: - return IE; - - case _HE: - case _HE_: - return F_HE; + switch (c) { + case ALEF_ : tempc = ALEF ; break; + case ALEF_U_H_ : tempc = ALEF_U_H ; break; + case _BE : tempc = BE ; break; + case _PE : tempc = PE ; break; + case _TE : tempc = TE ; break; + case _SE : tempc = SE ; break; + case _JIM : tempc = JIM ; break; + case _CHE : tempc = CHE ; break; + case _HE_J : tempc = HE_J ; break; + case _XE : tempc = XE ; break; + case _SIN : tempc = SIN ; break; + case _SHIN : tempc = SHIN ; break; + case _SAD : tempc = SAD ; break; + case _ZAD : tempc = ZAD ; break; + case _AYN : + case AYN_ : + case _AYN_ : tempc = AYN ; break; + case _GHAYN : + case GHAYN_ : + case _GHAYN_ : tempc = GHAYN ; break; + case _FE : tempc = FE ; break; + case _GHAF : tempc = GHAF ; break; + case _KAF : tempc = KAF ; break; + case _GAF : tempc = GAF ; break; + case _LAM : tempc = LAM ; break; + case _MIM : tempc = MIM ; break; + case _NOON : tempc = NOON ; break; + case _YE : + case YE_ : tempc = YE ; break; + case _YEE : + case YEE_ : tempc = YEE ; break; + case TEE_ : tempc = TEE ; break; + case _IE : + case IE_ : tempc = IE ; break; + case _HE : + case _HE_ : tempc = F_HE ; break; + default : tempc = c ; } - return c; + + return tempc; } /// Is the character under the cursor+offset in the given buffer a join type. @@ -388,51 +285,34 @@ static bool F_is_TyC_TyD(int c) /// @param c The character to convert. /// /// @return The character converted into a leading type. -static int toF_TyB(int c) +static char_u toF_TyB(int c) { - switch (c) { - case ALEF_: - return ALEF; - - case ALEF_U_H_: - return ALEF_U_H; - - case _AYN_: - return _AYN; - - case AYN_: - // exception - there are many of them - return AYN; - - case _GHAYN_: - return _GHAYN; - - case GHAYN_: - // exception - there are many of them - return GHAYN; - - case _HE_: - return _HE; - - case YE_: - return YE; - - case IE_: - return IE; - - case TEE_: - return TEE; + char_u tempc; - case YEE_: - return YEE; + switch (c) { + case ALEF_ : tempc = ALEF ; break; + case ALEF_U_H_ : tempc = ALEF_U_H ; break; + case _AYN_ : tempc = _AYN ; break; + case AYN_ : tempc = AYN ; break; // exception - there are many + case _GHAYN_ : tempc = _GHAYN ; break; + case GHAYN_ : tempc = GHAYN ; break; // exception - there are many + case _HE_ : tempc = _HE ; break; + case YE_ : tempc = YE ; break; + case IE_ : tempc = IE ; break; + case TEE_ : tempc = TEE ; break; + case YEE_ : tempc = YEE ; break; + default: + assert(c >= 0 && c <= UCHAR_MAX); + tempc = (char_u)c; } - return c; + + return tempc; } /// Overwrite the current redo and cursor characters + left adjust /// /// @param c -static void put_curr_and_l_to_X(int c) +static void put_curr_and_l_to_X(char_u c) { int tempc; @@ -465,7 +345,7 @@ static void put_curr_and_l_to_X(int c) put_and_redo(c); } -static void put_and_redo(int c) +static void put_and_redo(char_u c) { pchar_cursor(c); AppendCharToRedobuff(K_BS); @@ -475,110 +355,39 @@ static void put_and_redo(int c) /// Change the char. under the cursor to a X_ or X type static void chg_c_toX_orX(void) { - int tempc, curc; + int curc; + char_u tempc; switch ((curc = gchar_cursor())) { - case _BE: - tempc = BE; - break; - - case _PE: - tempc = PE; - break; - - case _TE: - tempc = TE; - break; - - case _SE: - tempc = SE; - break; - - case _JIM: - tempc = JIM; - break; - - case _CHE: - tempc = CHE; - break; - - case _HE_J: - tempc = HE_J; - break; - - case _XE: - tempc = XE; - break; - - case _SIN: - tempc = SIN; - break; - - case _SHIN: - tempc = SHIN; - break; - - case _SAD: - tempc = SAD; - break; - - case _ZAD: - tempc = ZAD; - break; - - case _FE: - tempc = FE; - break; - - case _GHAF: - tempc = GHAF; - break; - - case _KAF_H: - case _KAF: - tempc = KAF; - break; - - case _GAF: - tempc = GAF; - break; - - case _AYN: - tempc = AYN; - break; - - case _AYN_: - tempc = AYN_; - break; - - case _GHAYN: - tempc = GHAYN; - break; - - case _GHAYN_: - tempc = GHAYN_; - break; - - case _LAM: - tempc = LAM; - break; - - case _MIM: - tempc = MIM; - break; - - case _NOON: - tempc = NOON; - break; - - case _HE: - case _HE_: - tempc = F_HE; - break; - - case _YE: - case _IE: - case _YEE: + case _BE : tempc = BE ; break ; + case _PE : tempc = PE ; break ; + case _TE : tempc = TE ; break ; + case _SE : tempc = SE ; break ; + case _JIM : tempc = JIM ; break ; + case _CHE : tempc = CHE ; break ; + case _HE_J : tempc = HE_J ; break ; + case _XE : tempc = XE ; break ; + case _SIN : tempc = SIN ; break ; + case _SHIN : tempc = SHIN ; break ; + case _SAD : tempc = SAD ; break ; + case _ZAD : tempc = ZAD ; break ; + case _FE : tempc = FE ; break ; + case _GHAF : tempc = GHAF ; break ; + case _KAF_H : + case _KAF : tempc = KAF ; break ; + case _GAF : tempc = GAF ; break ; + case _AYN : tempc = AYN ; break ; + case _AYN_ : tempc = AYN_ ; break ; + case _GHAYN : tempc = GHAYN ; break ; + case _GHAYN_ : tempc = GHAYN_ ; break ; + case _LAM : tempc = LAM ; break ; + case _MIM : tempc = MIM ; break ; + case _NOON : tempc = NOON ; break ; + case _HE : + case _HE_ : tempc = F_HE ; break; + case _YE : + case _IE : + case _YEE : if (p_ri) { inc_cursor(); @@ -621,55 +430,21 @@ static void chg_c_toX_orX(void) /// Change the char. under the cursor to a _X_ or X_ type static void chg_c_to_X_orX_(void) { - int tempc; + char_u tempc; switch (gchar_cursor()) { - case ALEF: - tempc = ALEF_; - break; - - case ALEF_U_H: - tempc = ALEF_U_H_; - break; - - case _AYN: - tempc = _AYN_; - break; - - case AYN: - tempc = AYN_; - break; - - case _GHAYN: - tempc = _GHAYN_; - break; - - case GHAYN: - tempc = GHAYN_; - break; - - case _HE: - tempc = _HE_; - break; - - case YE: - tempc = YE_; - break; - - case IE: - tempc = IE_; - break; - - case TEE: - tempc = TEE_; - break; - - case YEE: - tempc = YEE_; - break; - - default: - tempc = 0; + case ALEF : tempc = ALEF_ ; break; + case ALEF_U_H : tempc = ALEF_U_H_ ; break; + case _AYN : tempc = _AYN_ ; break; + case AYN : tempc = AYN_ ; break; + case _GHAYN : tempc = _GHAYN_ ; break; + case GHAYN : tempc = GHAYN_ ; break; + case _HE : tempc = _HE_ ; break; + case YE : tempc = YE_ ; break; + case IE : tempc = IE_ ; break; + case TEE : tempc = TEE_ ; break; + case YEE : tempc = YEE_ ; break; + default : tempc = 0 ; } if (tempc) { @@ -689,15 +464,14 @@ static void chg_c_to_X_or_X(void) if ((tempc == F_HE) && (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))) { tempc = _HE_; dec_cursor(); - put_and_redo(tempc); + put_and_redo((char_u)tempc); return; } - dec_cursor(); } if ((tempc = toF_Xor_X_(tempc)) != 0) { - put_and_redo(tempc); + put_and_redo((char_u)tempc); } } @@ -722,56 +496,22 @@ static void chg_l_to_X_orX_(void) } switch (gchar_cursor()) { - case ALEF: - tempc = ALEF_; - break; - - case ALEF_U_H: - tempc = ALEF_U_H_; - break; - - case _AYN: - tempc = _AYN_; - break; - - case AYN: - tempc = AYN_; - break; - - case _GHAYN: - tempc = _GHAYN_; - break; - - case GHAYN: - tempc = GHAYN_; - break; - - case _HE: - tempc = _HE_; - break; - - case YE: - tempc = YE_; - break; - - case IE: - tempc = IE_; - break; - - case TEE: - tempc = TEE_; - break; - - case YEE: - tempc = YEE_; - break; - - default: - tempc = 0; + case ALEF : tempc = ALEF_ ; break; + case ALEF_U_H : tempc = ALEF_U_H_ ; break; + case _AYN : tempc = _AYN_ ; break; + case AYN : tempc = AYN_ ; break; + case _GHAYN : tempc = _GHAYN_ ; break; + case GHAYN : tempc = GHAYN_ ; break; + case _HE : tempc = _HE_ ; break; + case YE : tempc = YE_ ; break; + case IE : tempc = IE_ ; break; + case TEE : tempc = TEE_ ; break; + case YEE : tempc = YEE_ ; break; + default : tempc = 0 ; } if (tempc) { - put_and_redo(tempc); + put_and_redo((char_u)tempc); } if (p_ri) { @@ -784,7 +524,7 @@ static void chg_l_to_X_orX_(void) /// Change the character left to the cursor to a X or _X type static void chg_l_toXor_X(void) { - int tempc; + char_u tempc; if ((curwin->w_cursor.col != 0) && (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(get_cursor_line_ptr()))) { @@ -802,52 +542,18 @@ static void chg_l_toXor_X(void) } switch (gchar_cursor()) { - case ALEF_: - tempc = ALEF; - break; - - case ALEF_U_H_: - tempc = ALEF_U_H; - break; - - case _AYN_: - tempc = _AYN; - break; - - case AYN_: - tempc = AYN; - break; - - case _GHAYN_: - tempc = _GHAYN; - break; - - case GHAYN_: - tempc = GHAYN; - break; - - case _HE_: - tempc = _HE; - break; - - case YE_: - tempc = YE; - break; - - case IE_: - tempc = IE; - break; - - case TEE_: - tempc = TEE; - break; - - case YEE_: - tempc = YEE; - break; - - default: - tempc = 0; + case ALEF_ : tempc = ALEF ; break; + case ALEF_U_H_ : tempc = ALEF_U_H ; break; + case _AYN_ : tempc = _AYN ; break; + case AYN_ : tempc = AYN ; break; + case _GHAYN_ : tempc = _GHAYN ; break; + case GHAYN_ : tempc = GHAYN ; break; + case _HE_ : tempc = _HE ; break; + case YE_ : tempc = YE ; break; + case IE_ : tempc = IE ; break; + case TEE_ : tempc = TEE ; break; + case YEE_ : tempc = YEE ; break; + default : tempc = 0 ; } if (tempc) { @@ -864,7 +570,8 @@ static void chg_l_toXor_X(void) /// Change the character right to the cursor to a _X or _X_ type static void chg_r_to_Xor_X_(void) { - int tempc, c; + int tempc; + char_u c; if (curwin->w_cursor.col) { if (!p_ri) { @@ -893,13 +600,13 @@ int fkmap(int c) } if (VIM_ISDIGIT(c) - || (((c == '.') - || (c == '+') - || (c == '-') - || (c == '^') - || (c == '%') - || (c == '#') - || (c == '=')) + || ((c == '.' + || c == '+' + || c == '-' + || c == '^' + || c == '%' + || c == '#' + || c == '=') && revins)) { if (!revins) { if (curwin->w_cursor.col) { @@ -1060,158 +767,57 @@ int fkmap(int c) if (!p_ri) { if (!curwin->w_cursor.col) { switch (c) { - case '0': - return FARSI_0; - - case '1': - return FARSI_1; - - case '2': - return FARSI_2; - - case '3': - return FARSI_3; - - case '4': - return FARSI_4; - - case '5': - return FARSI_5; - - case '6': - return FARSI_6; - - case '7': - return FARSI_7; - - case '8': - return FARSI_8; - - case '9': - return FARSI_9; - - case 'B': - return F_PSP; - - case 'E': - return JAZR_N; - - case 'F': - return ALEF_D_H; - - case 'H': - return ALEF_A; - - case 'I': - return TASH; - - case 'K': - return F_LQUOT; - - case 'L': - return F_RQUOT; - - case 'M': - return HAMZE; - - case 'O': - return '['; - - case 'P': - return ']'; - - case 'Q': - return OO; - - case 'R': - return MAD_N; - - case 'T': - return OW; - - case 'U': - return MAD; - - case 'W': - return OW_OW; - - case 'Y': - return JAZR; - - case '`': - return F_PCN; - - case '!': - return F_EXCL; - - case '@': - return F_COMMA; - - case '#': - return F_DIVIDE; - - case '$': - return F_CURRENCY; - - case '%': - return F_PERCENT; - - case '^': - return F_MUL; - - case '&': - return F_BCOMMA; - - case '*': - return F_STAR; - - case '(': - return F_LPARENT; - - case ')': - return F_RPARENT; - - case '-': - return F_MINUS; - - case '_': - return F_UNDERLINE; - - case '=': - return F_EQUALS; - - case '+': - return F_PLUS; - - case '\\': - return F_BSLASH; - - case '|': - return F_PIPE; - - case ':': - return F_DCOLON; - - case '"': - return F_SEMICOLON; - - case '.': - return F_PERIOD; - - case '/': - return F_SLASH; - - case '<': - return F_LESS; - - case '>': - return F_GREATER; - - case '?': - return F_QUESTION; - - case ' ': - return F_BLANK; + case '0' : return FARSI_0 ; + case '1' : return FARSI_1 ; + case '2' : return FARSI_2 ; + case '3' : return FARSI_3 ; + case '4' : return FARSI_4 ; + case '5' : return FARSI_5 ; + case '6' : return FARSI_6 ; + case '7' : return FARSI_7 ; + case '8' : return FARSI_8 ; + case '9' : return FARSI_9 ; + case 'B' : return F_PSP ; + case 'E' : return JAZR_N ; + case 'F' : return ALEF_D_H ; + case 'H' : return ALEF_A ; + case 'I' : return TASH ; + case 'K' : return F_LQUOT ; + case 'L' : return F_RQUOT ; + case 'M' : return HAMZE ; + case 'O' : return '[' ; + case 'P' : return ']' ; + case 'Q' : return OO ; + case 'R' : return MAD_N ; + case 'T' : return OW ; + case 'U' : return MAD ; + case 'W' : return OW_OW ; + case 'Y' : return JAZR ; + case '`' : return F_PCN ; + case '!' : return F_EXCL ; + case '@' : return F_COMMA ; + case '#' : return F_DIVIDE ; + case '$' : return F_CURRENCY ; + case '%' : return F_PERCENT ; + case '^' : return F_MUL ; + case '&' : return F_BCOMMA ; + case '*' : return F_STAR ; + case '(' : return F_LPARENT ; + case ')' : return F_RPARENT ; + case '-' : return F_MINUS ; + case '_' : return F_UNDERLINE ; + case '=' : return F_EQUALS ; + case '+' : return F_PLUS ; + case '\\' : return F_BSLASH ; + case '|' : return F_PIPE ; + case ':' : return F_DCOLON ; + case '"' : return F_SEMICOLON ; + case '.' : return F_PERIOD ; + case '/' : return F_SLASH ; + case '<' : return F_LESS ; + case '>' : return F_GREATER ; + case '?' : return F_QUESTION ; + case ' ' : return F_BLANK ; } break; } @@ -1246,7 +852,7 @@ int fkmap(int c) case _HE_: case _TA: case _ZA: - put_curr_and_l_to_X(toF_TyA(tempc)); + put_curr_and_l_to_X(toF_TyA((char_u)tempc)); break; case _AYN: @@ -1276,7 +882,7 @@ int fkmap(int c) inc_cursor(); } - put_curr_and_l_to_X(tempc); + put_curr_and_l_to_X((char_u)tempc); break; case _GHAYN: @@ -1307,7 +913,7 @@ int fkmap(int c) inc_cursor(); } - put_curr_and_l_to_X(tempc); + put_curr_and_l_to_X((char_u)tempc); break; case _YE: @@ -1316,8 +922,8 @@ int fkmap(int c) if (!p_ri) { if (!curwin->w_cursor.col) { - put_curr_and_l_to_X((tempc == _YE ? YE : - (tempc == _IE ? IE : YEE))); + put_curr_and_l_to_X( + (tempc == _YE ? YE : tempc == _IE ? IE : YEE)); break; } } @@ -1329,11 +935,9 @@ int fkmap(int c) } if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { - tempc = (tempc == _YE ? YE_ : - (tempc == _IE ? IE_ : YEE_)); + tempc = (tempc == _YE ? YE_ : tempc == _IE ? IE_ : YEE_); } else { - tempc = (tempc == _YE ? YE : - (tempc == _IE ? IE : YEE)); + tempc = (tempc == _YE ? YE : tempc == _IE ? IE : YEE); } if (p_ri) { @@ -1342,7 +946,7 @@ int fkmap(int c) inc_cursor(); } - put_curr_and_l_to_X(tempc); + put_curr_and_l_to_X((char_u)tempc); break; } @@ -1353,200 +957,70 @@ int fkmap(int c) tempc = 0; switch (c) { - case '0': - return FARSI_0; - - case '1': - return FARSI_1; - - case '2': - return FARSI_2; - - case '3': - return FARSI_3; - - case '4': - return FARSI_4; - - case '5': - return FARSI_5; - - case '6': - return FARSI_6; - - case '7': - return FARSI_7; - - case '8': - return FARSI_8; - - case '9': - return FARSI_9; - - case 'B': - return F_PSP; - - case 'E': - return JAZR_N; - - case 'F': - return ALEF_D_H; - - case 'H': - return ALEF_A; - - case 'I': - return TASH; - - case 'K': - return F_LQUOT; - - case 'L': - return F_RQUOT; - - case 'M': - return HAMZE; - - case 'O': - return '['; - - case 'P': - return ']'; - - case 'Q': - return OO; - - case 'R': - return MAD_N; - - case 'T': - return OW; - - case 'U': - return MAD; - - case 'W': - return OW_OW; - - case 'Y': - return JAZR; - - case '`': - return F_PCN; - - case '!': - return F_EXCL; - - case '@': - return F_COMMA; - - case '#': - return F_DIVIDE; - - case '$': - return F_CURRENCY; - - case '%': - return F_PERCENT; - - case '^': - return F_MUL; - - case '&': - return F_BCOMMA; - - case '*': - return F_STAR; - - case '(': - return F_LPARENT; - - case ')': - return F_RPARENT; - - case '-': - return F_MINUS; - - case '_': - return F_UNDERLINE; - - case '=': - return F_EQUALS; - - case '+': - return F_PLUS; - - case '\\': - return F_BSLASH; - - case '|': - return F_PIPE; - - case ':': - return F_DCOLON; - - case '"': - return F_SEMICOLON; - - case '.': - return F_PERIOD; - - case '/': - return F_SLASH; - - case '<': - return F_LESS; - - case '>': - return F_GREATER; - - case '?': - return F_QUESTION; - - case ' ': - return F_BLANK; + case '0' : return FARSI_0 ; + case '1' : return FARSI_1 ; + case '2' : return FARSI_2 ; + case '3' : return FARSI_3 ; + case '4' : return FARSI_4 ; + case '5' : return FARSI_5 ; + case '6' : return FARSI_6 ; + case '7' : return FARSI_7 ; + case '8' : return FARSI_8 ; + case '9' : return FARSI_9 ; + case 'B' : return F_PSP ; + case 'E' : return JAZR_N ; + case 'F' : return ALEF_D_H ; + case 'H' : return ALEF_A ; + case 'I' : return TASH ; + case 'K' : return F_LQUOT ; + case 'L' : return F_RQUOT ; + case 'M' : return HAMZE ; + case 'O' : return '[' ; + case 'P' : return ']' ; + case 'Q' : return OO ; + case 'R' : return MAD_N ; + case 'T' : return OW ; + case 'U' : return MAD ; + case 'W' : return OW_OW ; + case 'Y' : return JAZR ; + case '`' : return F_PCN ; + case '!' : return F_EXCL ; + case '@' : return F_COMMA ; + case '#' : return F_DIVIDE ; + case '$' : return F_CURRENCY ; + case '%' : return F_PERCENT ; + case '^' : return F_MUL ; + case '&' : return F_BCOMMA ; + case '*' : return F_STAR ; + case '(' : return F_LPARENT ; + case ')' : return F_RPARENT ; + case '-' : return F_MINUS ; + case '_' : return F_UNDERLINE ; + case '=' : return F_EQUALS ; + case '+' : return F_PLUS ; + case '\\' : return F_BSLASH ; + case '|' : return F_PIPE ; + case ':' : return F_DCOLON ; + case '"' : return F_SEMICOLON ; + case '.' : return F_PERIOD ; + case '/' : return F_SLASH ; + case '<' : return F_LESS ; + case '>' : return F_GREATER ; + case '?' : return F_QUESTION ; + case ' ' : return F_BLANK ; } break; - case 'a': - tempc = _SHIN; - break; - - case 'A': - tempc = WAW_H; - break; - - case 'b': - tempc = ZAL; - break; - - case 'c': - tempc = ZE; - break; - - case 'C': - tempc = JE; - break; - - case 'd': - tempc = _YE; - break; - - case 'D': - tempc = _YEE; - break; - - case 'e': - tempc = _SE; - break; - - case 'f': - tempc = _BE; - break; - - case 'g': - tempc = _LAM; - break; + case 'a' : tempc = _SHIN ; break; + case 'A' : tempc = WAW_H ; break; + case 'b' : tempc = ZAL ; break; + case 'c' : tempc = ZE ; break; + case 'C' : tempc = JE ; break; + case 'd' : tempc = _YE ; break; + case 'D' : tempc = _YEE ; break; + case 'e' : tempc = _SE ; break; + case 'f' : tempc = _BE ; break; + case 'g' : tempc = _LAM ; break; case 'G': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { @@ -1621,7 +1095,6 @@ int fkmap(int c) return tempc; case 'i': - if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (!p_ri && !F_is_TyE(tempc)) { chg_c_to_X_orX_(); @@ -1656,7 +1129,6 @@ int fkmap(int c) break; case 'J': - if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (p_ri) { chg_c_to_X_or_X(); @@ -1683,50 +1155,18 @@ int fkmap(int c) return tempc; - case 'k': - tempc = _NOON; - break; - - case 'l': - tempc = _MIM; - break; - - case 'm': - tempc = _PE; - break; - - case 'n': - case 'N': - tempc = DAL; - break; - - case 'o': - tempc = _XE; - break; - - case 'p': - tempc = _HE_J; - break; - - case 'q': - tempc = _ZAD; - break; - - case 'r': - tempc = _GHAF; - break; - - case 's': - tempc = _SIN; - break; - - case 'S': - tempc = _IE; - break; - - case 't': - tempc = _FE; - break; + case 'k' : tempc = _NOON ; break; + case 'l' : tempc = _MIM ; break; + case 'm' : tempc = _PE ; break; + case 'n' : + case 'N' : tempc = DAL ; break; + case 'o' : tempc = _XE ; break; + case 'p' : tempc = _HE_J ; break; + case 'q' : tempc = _ZAD ; break; + case 'r' : tempc = _GHAF ; break; + case 's' : tempc = _SIN ; break; + case 'S' : tempc = _IE ; break; + case 't' : tempc = _FE ; break; case 'u': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { @@ -1758,19 +1198,11 @@ int fkmap(int c) } break; - case 'v': - case 'V': - tempc = RE; - break; - - case 'w': - tempc = _SAD; - break; - - case 'x': - case 'X': - tempc = _TA; - break; + case 'v' : + case 'V' : tempc = RE ; break; + case 'w' : tempc = _SAD ; break; + case 'x' : + case 'X' : tempc = _TA ; break; case 'y': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { @@ -1803,33 +1235,13 @@ int fkmap(int c) break; - case 'z': - tempc = _ZA; - break; - - case 'Z': - tempc = _KAF_H; - break; - - case ';': - tempc = _KAF; - break; - - case '\'': - tempc = _GAF; - break; - - case ',': - tempc = WAW; - break; - - case '[': - tempc = _JIM; - break; - - case ']': - tempc = _CHE; - break; + case 'z' : tempc = _ZA ; break; + case 'Z' : tempc = _KAF_H ; break; + case ';' : tempc = _KAF ; break; + case '\'' : tempc = _GAF ; break; + case ',' : tempc = WAW ; break; + case '[' : tempc = _JIM ; break; + case ']' : tempc = _CHE ; break; } if ((F_isalpha(tempc) || F_isdigit(tempc))) { @@ -1871,99 +1283,50 @@ int fkmap(int c) /// @param c The character to convert. /// /// @return The non-leading Farsi character converted to a leading type. -static int toF_leading(int c) +static char_u toF_leading(char_u c) { - switch (c) { - case ALEF_: - return ALEF; - - case ALEF_U_H_: - return ALEF_U_H; - - case BE: - return _BE; - - case PE: - return _PE; + char_u tempc; - case TE: - return _TE; - - case SE: - return _SE; - - case JIM: - return _JIM; - - case CHE: - return _CHE; - - case HE_J: - return _HE_J; - - case XE: - return _XE; - - case SIN: - return _SIN; - - case SHIN: - return _SHIN; - - case SAD: - return _SAD; - - case ZAD: - return _ZAD; - - case AYN: - case AYN_: - case _AYN_: - return _AYN; - - case GHAYN: - case GHAYN_: - case _GHAYN_: - return _GHAYN; - - case FE: - return _FE; - - case GHAF: - return _GHAF; - - case KAF: - return _KAF; - - case GAF: - return _GAF; - - case LAM: - return _LAM; - - case MIM: - return _MIM; - - case NOON: - return _NOON; - - case _HE_: - case F_HE: - return _HE; - - case YE: - case YE_: - return _YE; - - case IE_: - case IE: - return _IE; - - case YEE: - case YEE_: - return _YEE; + switch (c) { + case ALEF_ : tempc = ALEF ; break; + case ALEF_U_H_ : tempc = ALEF_U_H ; break; + case BE : tempc = _BE ; break; + case PE : tempc = _PE ; break; + case TE : tempc = _TE ; break; + case SE : tempc = _SE ; break; + case JIM : tempc = _JIM ; break; + case CHE : tempc = _CHE ; break; + case HE_J : tempc = _HE_J ; break; + case XE : tempc = _XE ; break; + case SIN : tempc = _SIN ; break; + case SHIN : tempc = _SHIN ; break; + case SAD : tempc = _SAD ; break; + case ZAD : tempc = _ZAD ; break; + case AYN : + case AYN_ : + case _AYN_ : tempc = _AYN ; break; + case GHAYN : + case GHAYN_ : + case _GHAYN_ : tempc = _GHAYN ; break; + case FE : tempc = _FE ; break; + case GHAF : tempc = _GHAF ; break; + case KAF : tempc = _KAF ; break; + case GAF : tempc = _GAF ; break; + case LAM : tempc = _LAM ; break; + case MIM : tempc = _MIM ; break; + case NOON : tempc = _NOON ; break; + case _HE_ : + case F_HE : tempc = _HE ; break; + case YE : + case YE_ : tempc = _YE ; break; + case IE_ : + case IE : tempc = _IE ; break; + case YEE : + case YEE_ : tempc = _YEE ; break; + default : tempc = c; } - return c; + + return tempc; } /// Convert a given Farsi char into right joining type. @@ -1971,102 +1334,51 @@ static int toF_leading(int c) /// @param c The character to convert. /// /// @return The Farsi character converted into a right joining type -static int toF_Rjoin(int c) +static char_u toF_Rjoin(char_u c) { - switch (c) { - case ALEF: - return ALEF_; - - case ALEF_U_H: - return ALEF_U_H_; - - case BE: - return _BE; - - case PE: - return _PE; - - case TE: - return _TE; - - case SE: - return _SE; - - case JIM: - return _JIM; + char_u tempc; - case CHE: - return _CHE; - - case HE_J: - return _HE_J; - - case XE: - return _XE; - - case SIN: - return _SIN; - - case SHIN: - return _SHIN; - - case SAD: - return _SAD; - - case ZAD: - return _ZAD; - - case AYN: - case AYN_: - case _AYN: - return _AYN_; - - case GHAYN: - case GHAYN_: - case _GHAYN_: - return _GHAYN_; - - case FE: - return _FE; - - case GHAF: - return _GHAF; - - case KAF: - return _KAF; - - case GAF: - return _GAF; - - case LAM: - return _LAM; - - case MIM: - return _MIM; - - case NOON: - return _NOON; - - case _HE: - case F_HE: - return _HE_; - - case YE: - case YE_: - return _YE; - - case IE_: - case IE: - return _IE; - - case TEE: - return TEE_; - - case YEE: - case YEE_: - return _YEE; + switch (c) { + case ALEF : tempc = ALEF_ ; break; + case ALEF_U_H : tempc = ALEF_U_H_ ; break; + case BE : tempc = _BE ; break; + case PE : tempc = _PE ; break; + case TE : tempc = _TE ; break; + case SE : tempc = _SE ; break; + case JIM : tempc = _JIM ; break; + case CHE : tempc = _CHE ; break; + case HE_J : tempc = _HE_J ; break; + case XE : tempc = _XE ; break; + case SIN : tempc = _SIN ; break; + case SHIN : tempc = _SHIN ; break; + case SAD : tempc = _SAD ; break; + case ZAD : tempc = _ZAD ; break; + case AYN : + case AYN_ : + case _AYN : tempc = _AYN_ ; break; + case GHAYN : + case GHAYN_ : + case _GHAYN_ : tempc = _GHAYN_ ; break; + case FE : tempc = _FE ; break; + case GHAF : tempc = _GHAF ; break; + case KAF : tempc = _KAF ; break; + case GAF : tempc = _GAF ; break; + case LAM : tempc = _LAM ; break; + case MIM : tempc = _MIM ; break; + case NOON : tempc = _NOON ; break; + case _HE : + case F_HE : tempc = _HE_ ; break; + case YE : + case YE_ : tempc = _YE ; break; + case IE_ : + case IE : tempc = _IE ; break; + case TEE : tempc = TEE_ ; break; + case YEE : + case YEE_ : tempc = _YEE ; break; + default : tempc = c ; } - return c; + + return tempc; } /// Can a given Farsi character join via its left edj. @@ -2074,7 +1386,7 @@ static int toF_Rjoin(int c) /// @param c The character to check. /// /// @return true if the character can join via its left edj. -static bool canF_Ljoin(int c) +static bool canF_Ljoin(char_u c) { switch (c) { case _BE: @@ -2148,7 +1460,7 @@ static bool canF_Ljoin(int c) /// @param c /// /// @return true if the character can join via its right edj. -static bool canF_Rjoin(int c) +static bool canF_Rjoin(char_u c) { switch (c) { case ALEF: @@ -2174,7 +1486,7 @@ static bool canF_Rjoin(int c) /// @param c /// /// @return true if the character is a terminating type. -static bool F_isterm(int c) +static bool F_isterm(char_u c) { switch (c) { case ALEF: @@ -2200,105 +1512,48 @@ static bool F_isterm(int c) /// @param c The character to convert. /// /// @return The character converted into an ending type. -static int toF_ending(int c) +static char_u toF_ending(char_u c) { - switch (c) { - case _BE: - return BE; - - case _PE: - return PE; - - case _TE: - return TE; - - case _SE: - return SE; - - case _JIM: - return JIM; - - case _CHE: - return CHE; - - case _HE_J: - return HE_J; - - case _XE: - return XE; - - case _SIN: - return SIN; - - case _SHIN: - return SHIN; - - case _SAD: - return SAD; + char_u tempc; - case _ZAD: - return ZAD; - - case _AYN: - return AYN; - - case _AYN_: - return AYN_; - - case _GHAYN: - return GHAYN; - - case _GHAYN_: - return GHAYN_; - - case _FE: - return FE; - - case _GHAF: - return GHAF; - - case _KAF_H: - case _KAF: - return KAF; - - case _GAF: - return GAF; - - case _LAM: - return LAM; - - case _MIM: - return MIM; - - case _NOON: - return NOON; - - case _YE: - return YE_; - - case YE_: - return YE; - - case _YEE: - return YEE_; - - case YEE_: - return YEE; - - case TEE: - return TEE_; - - case _IE: - return IE_; - - case IE_: - return IE; - - case _HE: - case _HE_: - return F_HE; + switch (c) { + case _BE : tempc = BE ; break; + case _PE : tempc = PE ; break; + case _TE : tempc = TE ; break; + case _SE : tempc = SE ; break; + case _JIM : tempc = JIM ; break; + case _CHE : tempc = CHE ; break; + case _HE_J : tempc = HE_J ; break; + case _XE : tempc = XE ; break; + case _SIN : tempc = SIN ; break; + case _SHIN : tempc = SHIN ; break; + case _SAD : tempc = SAD ; break; + case _ZAD : tempc = ZAD ; break; + case _AYN : tempc = AYN ; break; + case _AYN_ : tempc = AYN_ ; break; + case _GHAYN : tempc = GHAYN ; break; + case _GHAYN_ : tempc = GHAYN_ ; break; + case _FE : tempc = FE ; break; + case _GHAF : tempc = GHAF ; break; + case _KAF_H : + case _KAF : tempc = KAF ; break; + case _GAF : tempc = GAF ; break; + case _LAM : tempc = LAM ; break; + case _MIM : tempc = MIM ; break; + case _NOON : tempc = NOON ; break; + case _YE : tempc = YE_ ; break; + case YE_ : tempc = YE ; break; + case _YEE : tempc = YEE_ ; break; + case YEE_ : tempc = YEE ; break; + case TEE : tempc = TEE_ ; break; + case _IE : tempc = IE_ ; break; + case IE_ : tempc = IE ; break; + case _HE : + case _HE_ : tempc = F_HE ; break; + default : tempc = c ; } - return c; + + return tempc; } /// Convert the Farsi 3342 standard into Farsi VIM. @@ -2369,7 +1624,7 @@ void conv_to_pstd(void) static void lrswapbuf(char_u *buf, int len) { char_u *s, *e; - int c; + char_u c; s = buf; e = buf + len - 1; @@ -2442,6 +1697,7 @@ char_u* lrF_sub(char_u *ibuf) // Find the boundary of the search path while (((p = vim_strchr(p + 1, '/')) != NULL) && p[-1] == '\\') { + // empty } if (p == NULL) { @@ -2560,15 +1816,15 @@ int cmdl_fkmap(int c) case _NOON: case _HE: case _HE_: - cmd_pchar(toF_TyA(tempc), AT_CURSOR); + cmd_pchar(toF_TyA((char_u)tempc), AT_CURSOR); break; case _AYN_: - cmd_pchar(AYN_, AT_CURSOR); + cmd_pchar(AYN_, AT_CURSOR); break; case _GHAYN_: - cmd_pchar(GHAYN_, AT_CURSOR); + cmd_pchar(GHAYN_, AT_CURSOR); break; case _IE: @@ -2596,190 +1852,70 @@ int cmdl_fkmap(int c) } switch (c) { - case '0': - return FARSI_0; - - case '1': - return FARSI_1; - - case '2': - return FARSI_2; - - case '3': - return FARSI_3; - - case '4': - return FARSI_4; - - case '5': - return FARSI_5; - - case '6': - return FARSI_6; - - case '7': - return FARSI_7; - - case '8': - return FARSI_8; - - case '9': - return FARSI_9; - - case 'B': - return F_PSP; - - case 'E': - return JAZR_N; - - case 'F': - return ALEF_D_H; - - case 'H': - return ALEF_A; - - case 'I': - return TASH; - - case 'K': - return F_LQUOT; - - case 'L': - return F_RQUOT; - - case 'M': - return HAMZE; - - case 'O': - return '['; - - case 'P': - return ']'; - - case 'Q': - return OO; - - case 'R': - return MAD_N; - - case 'T': - return OW; - - case 'U': - return MAD; - - case 'W': - return OW_OW; - - case 'Y': - return JAZR; - - case '`': - return F_PCN; - - case '!': - return F_EXCL; - - case '@': - return F_COMMA; - - case '#': - return F_DIVIDE; - - case '$': - return F_CURRENCY; - - case '%': - return F_PERCENT; - - case '^': - return F_MUL; - - case '&': - return F_BCOMMA; - - case '*': - return F_STAR; - - case '(': - return F_LPARENT; - - case ')': - return F_RPARENT; - - case '-': - return F_MINUS; - - case '_': - return F_UNDERLINE; - - case '=': - return F_EQUALS; - - case '+': - return F_PLUS; - - case '\\': - return F_BSLASH; - - case '|': - return F_PIPE; - - case ':': - return F_DCOLON; - - case '"': - return F_SEMICOLON; - - case '.': - return F_PERIOD; - - case '/': - return F_SLASH; - - case '<': - return F_LESS; - - case '>': - return F_GREATER; - - case '?': - return F_QUESTION; - - case ' ': - return F_BLANK; + case '0' : return FARSI_0 ; + case '1' : return FARSI_1 ; + case '2' : return FARSI_2 ; + case '3' : return FARSI_3 ; + case '4' : return FARSI_4 ; + case '5' : return FARSI_5 ; + case '6' : return FARSI_6 ; + case '7' : return FARSI_7 ; + case '8' : return FARSI_8 ; + case '9' : return FARSI_9 ; + case 'B' : return F_PSP ; + case 'E' : return JAZR_N ; + case 'F' : return ALEF_D_H ; + case 'H' : return ALEF_A ; + case 'I' : return TASH ; + case 'K' : return F_LQUOT ; + case 'L' : return F_RQUOT ; + case 'M' : return HAMZE ; + case 'O' : return '[' ; + case 'P' : return ']' ; + case 'Q' : return OO ; + case 'R' : return MAD_N ; + case 'T' : return OW ; + case 'U' : return MAD ; + case 'W' : return OW_OW ; + case 'Y' : return JAZR ; + case '`' : return F_PCN ; + case '!' : return F_EXCL ; + case '@' : return F_COMMA ; + case '#' : return F_DIVIDE ; + case '$' : return F_CURRENCY ; + case '%' : return F_PERCENT ; + case '^' : return F_MUL ; + case '&' : return F_BCOMMA ; + case '*' : return F_STAR ; + case '(' : return F_LPARENT ; + case ')' : return F_RPARENT ; + case '-' : return F_MINUS ; + case '_' : return F_UNDERLINE ; + case '=' : return F_EQUALS ; + case '+' : return F_PLUS ; + case '\\' : return F_BSLASH ; + case '|' : return F_PIPE ; + case ':' : return F_DCOLON ; + case '"' : return F_SEMICOLON ; + case '.' : return F_PERIOD ; + case '/' : return F_SLASH ; + case '<' : return F_LESS ; + case '>' : return F_GREATER ; + case '?' : return F_QUESTION ; + case ' ' : return F_BLANK ; } break; - case 'a': - return _SHIN; - - case 'A': - return WAW_H; - - case 'b': - return ZAL; - - case 'c': - return ZE; - - case 'C': - return JE; - - case 'd': - return _YE; - - case 'D': - return _YEE; - - case 'e': - return _SE; - - case 'f': - return _BE; - - case 'g': - return _LAM; + case 'a' : return _SHIN ; + case 'A' : return WAW_H ; + case 'b' : return ZAL ; + case 'c' : return ZE ; + case 'C' : return JE ; + case 'd' : return _YE ; + case 'D' : return _YEE ; + case 'e' : return _SE ; + case 'f' : return _BE ; + case 'g' : return _LAM ; case 'G': if (cmd_gchar(AT_CURSOR) == _LAM) { @@ -2823,39 +1959,18 @@ int cmdl_fkmap(int c) return TEE; } - case 'k': - return _NOON; - - case 'l': - return _MIM; - - case 'm': - return _PE; - - case 'n': - case 'N': - return DAL; - - case 'o': - return _XE; - - case 'p': - return _HE_J; - - case 'q': - return _ZAD; - - case 'r': - return _GHAF; - - case 's': - return _SIN; - - case 'S': - return _IE; - - case 't': - return _FE; + case 'k' : return _NOON ; + case 'l' : return _MIM ; + case 'm' : return _PE ; + case 'n' : + case 'N' : return DAL ; + case 'o' : return _XE ; + case 'p' : return _HE_J ; + case 'q' : return _ZAD ; + case 'r' : return _GHAF ; + case 's' : return _SIN ; + case 'S' : return _IE ; + case 't' : return _FE ; case 'u': if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR)) { @@ -2864,16 +1979,11 @@ int cmdl_fkmap(int c) return _AYN; } - case 'v': - case 'V': - return RE; - - case 'w': - return _SAD; - - case 'x': - case 'X': - return _TA; + case 'v' : + case 'V' : return RE ; + case 'w' : return _SAD ; + case 'x' : + case 'X' : return _TA ; case 'y': if (F_is_TyB_TyC_TyD(SRC_CMD, AT_CURSOR)) { @@ -2882,24 +1992,13 @@ int cmdl_fkmap(int c) return _GHAYN; } - case 'z': - case 'Z': - return _ZA; - - case ';': - return _KAF; - - case '\'': - return _GAF; - - case ',': - return WAW; - - case '[': - return _JIM; - - case ']': - return _CHE; + case 'z' : + case 'Z' : return _ZA ; + case ';' : return _KAF ; + case '\'' : return _GAF ; + case ',' : return WAW ; + case '[' : return _JIM ; + case ']' : return _CHE ; } return c; diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 9267e7991c..42779d6b71 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -496,19 +496,19 @@ vim_findfile_init ( } if (temp == NULL || wc_path == NULL) { - free(buf); - free(temp); - free(wc_path); + xfree(buf); + xfree(temp); + xfree(wc_path); goto error_return; } STRCPY(temp, search_ctx->ffsc_fix_path + len); STRCAT(temp, search_ctx->ffsc_wc_path); - free(search_ctx->ffsc_wc_path); - free(wc_path); + xfree(search_ctx->ffsc_wc_path); + xfree(wc_path); search_ctx->ffsc_wc_path = temp; } - free(buf); + xfree(buf); } sptr = ff_create_stack_element(ff_expand_buffer, @@ -563,7 +563,7 @@ void vim_findfile_cleanup(void *ctx) vim_findfile_free_visited(ctx); ff_clear(ctx); - free(ctx); + xfree(ctx); } /* @@ -947,7 +947,7 @@ char_u *vim_findfile(void *search_ctx_arg) break; } - free(file_path); + xfree(file_path); return NULL; } @@ -975,8 +975,8 @@ static void vim_findfile_free_visited_list(ff_visited_list_hdr_T **list_headp) vp = (*list_headp)->ffvl_next; ff_free_visited_list((*list_headp)->ffvl_visited_list); - free((*list_headp)->ffvl_filename); - free(*list_headp); + xfree((*list_headp)->ffvl_filename); + xfree(*list_headp); *list_headp = vp; } *list_headp = NULL; @@ -988,8 +988,8 @@ static void ff_free_visited_list(ff_visited_T *vl) while (vl != NULL) { vp = vl->ffv_next; - free(vl->ffv_wc_path); - free(vl); + xfree(vl->ffv_wc_path); + xfree(vl); vl = vp; } vl = NULL; @@ -1205,13 +1205,13 @@ static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx) static void ff_free_stack_element(ff_stack_T *stack_ptr) { /* free handles possible NULL pointers */ - free(stack_ptr->ffs_fix_path); - free(stack_ptr->ffs_wc_path); + xfree(stack_ptr->ffs_fix_path); + xfree(stack_ptr->ffs_wc_path); if (stack_ptr->ffs_filearray != NULL) FreeWild(stack_ptr->ffs_filearray_size, stack_ptr->ffs_filearray); - free(stack_ptr); + xfree(stack_ptr); } /* @@ -1225,19 +1225,19 @@ static void ff_clear(ff_search_ctx_T *search_ctx) while ((sptr = ff_pop(search_ctx)) != NULL) ff_free_stack_element(sptr); - free(search_ctx->ffsc_file_to_search); - free(search_ctx->ffsc_start_dir); - free(search_ctx->ffsc_fix_path); - free(search_ctx->ffsc_wc_path); + xfree(search_ctx->ffsc_file_to_search); + xfree(search_ctx->ffsc_start_dir); + xfree(search_ctx->ffsc_fix_path); + xfree(search_ctx->ffsc_wc_path); if (search_ctx->ffsc_stopdirs_v != NULL) { int i = 0; while (search_ctx->ffsc_stopdirs_v[i] != NULL) { - free(search_ctx->ffsc_stopdirs_v[i]); + xfree(search_ctx->ffsc_stopdirs_v[i]); i++; } - free(search_ctx->ffsc_stopdirs_v); + xfree(search_ctx->ffsc_stopdirs_v); } search_ctx->ffsc_stopdirs_v = NULL; @@ -1327,9 +1327,9 @@ static void *fdip_search_ctx = NULL; #if defined(EXITFREE) void free_findfile(void) { - free(ff_file_to_find); + xfree(ff_file_to_find); vim_findfile_cleanup(fdip_search_ctx); - free(ff_expand_buffer); + xfree(ff_expand_buffer); } #endif @@ -1382,7 +1382,7 @@ find_file_in_path_option ( expand_env(ptr, NameBuff, MAXPATHL); ptr[len] = save_char; - free(ff_file_to_find); + xfree(ff_file_to_find); ff_file_to_find = vim_strsave(NameBuff); } @@ -1487,7 +1487,7 @@ find_file_in_path_option ( fdip_search_ctx, FALSE, rel_fname); if (fdip_search_ctx != NULL) did_findfile_init = TRUE; - free(buf); + xfree(buf); } } } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 80f843048a..def1cc1d1a 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -724,7 +724,7 @@ readfile ( * always using the GUI. */ if (read_stdin) { - mch_msg(_("Vim: Reading from stdin...\n")); + mch_msg(_("Nvim: Reading from stdin...\n")); } else if (!read_buffer) filemess(curbuf, sfname, (char_u *)"", 0); } @@ -881,12 +881,12 @@ retry: notconverted = TRUE; conv_error = 0; if (fenc_alloced) - free(fenc); + xfree(fenc); fenc = (char_u *)""; fenc_alloced = FALSE; } else { if (fenc_alloced) - free(fenc); + xfree(fenc); if (fenc_next != NULL) { fenc = next_fenc(&fenc_next); fenc_alloced = (fenc_next != NULL); @@ -897,7 +897,7 @@ retry: } if (tmpname != NULL) { os_remove((char *)tmpname); // delete converted file - free(tmpname); + xfree(tmpname); tmpname = NULL; } } @@ -1026,7 +1026,7 @@ retry: } if (linerest) /* copy characters from the previous buffer */ memmove(new_buffer, ptr - linerest, (size_t)linerest); - free(buffer); + xfree(buffer); buffer = new_buffer; ptr = buffer + linerest; line_start = buffer; @@ -1215,7 +1215,7 @@ retry: } else { /* BOM detected: set "fenc" and jump back */ if (fenc_alloced) - free(fenc); + xfree(fenc); fenc = ccname; fenc_alloced = FALSE; } @@ -1738,7 +1738,7 @@ failed: OPT_FREE | OPT_LOCAL, 0); } if (fenc_alloced) - free(fenc); + xfree(fenc); # ifdef USE_ICONV if (iconv_fd != (iconv_t)-1) { iconv_close(iconv_fd); @@ -1757,7 +1757,7 @@ failed: fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC); } #endif - free(buffer); + xfree(buffer); #ifdef HAVE_DUP if (read_stdin) { @@ -1769,7 +1769,7 @@ failed: if (tmpname != NULL) { os_remove((char *)tmpname); // delete converted file - free(tmpname); + xfree(tmpname); } --no_wait_return; /* may wait for return now */ @@ -1886,7 +1886,7 @@ failed: c = TRUE; msg_add_lines(c, (long)linecnt, filesize); - free(keep_msg); + xfree(keep_msg); keep_msg = NULL; msg_scrolled_ign = TRUE; p = msg_trunc_attr(IObuff, FALSE, 0); @@ -2084,7 +2084,7 @@ void set_forced_fenc(exarg_T *eap) if (eap->force_enc != 0) { char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); set_string_option_direct((char_u *)"fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); - free(fenc); + xfree(fenc); } } @@ -2113,7 +2113,7 @@ static char_u *next_fenc(char_u **pp) r = vim_strnsave(*pp, (int)(p - *pp)); *pp = p + 1; p = enc_canonize(r); - free(r); + xfree(r); r = p; } return r; @@ -2157,7 +2157,7 @@ readfile_charconvert ( MSG(errmsg); if (tmpname != NULL) { os_remove((char *)tmpname); // delete converted file - free(tmpname); + xfree(tmpname); tmpname = NULL; } } @@ -2816,7 +2816,7 @@ buf_write ( */ backup = modname(rootname, backup_ext, FALSE); if (backup == NULL) { - free(rootname); + xfree(rootname); some_error = TRUE; /* out of memory */ goto nobackup; } @@ -2832,7 +2832,7 @@ buf_write ( * link). If we don't check here, we either ruin the file when * copying or erase it after writing. */ - free(backup); + xfree(backup); backup = NULL; /* no backup file to delete */ } else if (!p_bk) { /* @@ -2851,13 +2851,13 @@ buf_write ( } /* They all exist??? Must be something wrong. */ if (*wp == 'a') { - free(backup); + xfree(backup); backup = NULL; } } } } - free(rootname); + xfree(rootname); /* * Try to create the backup file @@ -2871,7 +2871,7 @@ buf_write ( O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW, perm & 0777); if (bfd < 0) { - free(backup); + xfree(backup); backup = NULL; } else { /* set file protection same as original file, but @@ -2939,7 +2939,7 @@ buf_write ( } nobackup: close(fd); /* ignore errors for closing read file */ - free(copybuf); + xfree(copybuf); if (backup == NULL && errmsg == NULL) errmsg = (char_u *)_( @@ -2986,7 +2986,7 @@ nobackup: backup = NULL; else { backup = modname(rootname, backup_ext, FALSE); - free(rootname); + xfree(rootname); } if (backup != NULL) { @@ -3004,7 +3004,7 @@ nobackup: --*p; /* They all exist??? Must be something wrong! */ if (*p == 'a') { - free(backup); + xfree(backup); backup = NULL; } } @@ -3023,7 +3023,7 @@ nobackup: if (vim_rename(fname, backup) == 0) break; - free(backup); /* don't do the rename below */ + xfree(backup); /* don't do the rename below */ backup = NULL; } } @@ -3250,7 +3250,7 @@ restore_backup: } if (wfname != fname) - free(wfname); + xfree(wfname); goto fail; } errmsg = NULL; @@ -3446,7 +3446,7 @@ restore_backup: } } os_remove((char *)wfname); - free(wfname); + xfree(wfname); } if (end == 0) { @@ -3606,7 +3606,7 @@ restore_backup: EMSG(_("E205: Patchmode: can't save original file")); else if (!os_file_exists((char_u *)org)) { vim_rename(backup, (char_u *)org); - free(backup); /* don't delete the file */ + xfree(backup); /* don't delete the file */ backup = NULL; #ifdef UNIX set_file_time((char_u *)org, @@ -3632,7 +3632,7 @@ restore_backup: } if (org != NULL) { os_setperm((char_u *)org, os_getperm(fname) & 0777); - free(org); + xfree(org); } } @@ -3655,11 +3655,11 @@ nofail: /* Done saving, we accept changed buffer warnings again */ buf->b_saving = false; - free(backup); + xfree(backup); if (buffer != smallbuf) - free(buffer); - free(fenc_tofree); - free(write_info.bw_conv_buf); + xfree(buffer); + xfree(fenc_tofree); + xfree(write_info.bw_conv_buf); # ifdef USE_ICONV if (write_info.bw_iconv_fd != (iconv_t)-1) { iconv_close(write_info.bw_iconv_fd); @@ -3692,7 +3692,7 @@ nofail: STRCAT(IObuff, errmsg); emsg(IObuff); if (errmsg_allocated) - free(errmsg); + xfree(errmsg); retval = FAIL; if (end == 0) { @@ -4314,7 +4314,7 @@ void shorten_fnames(int force) && (force || buf->b_sfname == NULL || path_is_absolute_path(buf->b_sfname))) { - free(buf->b_sfname); + xfree(buf->b_sfname); buf->b_sfname = NULL; p = path_shorten_fname(buf->b_ffname, dirname); if (p != NULL) { @@ -4366,7 +4366,7 @@ modname ( retval = xmalloc(MAXPATHL + extlen + 3); if (os_dirname(retval, MAXPATHL) == FAIL || (fnamelen = (int)STRLEN(retval)) == 0) { - free(retval); + xfree(retval); return NULL; } if (!after_pathsep(retval, retval + fnamelen)) { @@ -4596,7 +4596,7 @@ int vim_rename(char_u *from, char_u *to) break; } - free(buffer); + xfree(buffer); close(fd_in); if (close(fd_out) < 0) errmsg = _("E209: Error closing \"%s\""); @@ -4705,11 +4705,11 @@ static int move_lines(buf_T *frombuf, buf_T *tobuf) for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) { p = vim_strsave(ml_get_buf(frombuf, lnum, FALSE)); if (ml_append(lnum - 1, p, 0, FALSE) == FAIL) { - free(p); + xfree(p); retval = FAIL; break; } - free(p); + xfree(p); } /* Delete all the lines in "frombuf". */ @@ -4922,8 +4922,8 @@ buf_check_timestamp ( already_warned = TRUE; } - free(path); - free(tbuf); + xfree(path); + xfree(tbuf); } if (reload) { @@ -5041,7 +5041,7 @@ void buf_reload(buf_T *buf, int orig_mode) } } } - free(ea.cmd); + xfree(ea.cmd); if (savebuf != NULL && buf_valid(savebuf)) wipe_buffer(savebuf, FALSE); @@ -5315,7 +5315,7 @@ static void show_autocmd(AutoPat *ap, event_T event) */ static void au_remove_pat(AutoPat *ap) { - free(ap->pat); + xfree(ap->pat); ap->pat = NULL; ap->buflocal_nr = -1; au_need_clean = TRUE; @@ -5329,7 +5329,7 @@ static void au_remove_cmds(AutoPat *ap) AutoCmd *ac; for (ac = ap->cmds; ac != NULL; ac = ac->next) { - free(ac->cmd); + xfree(ac->cmd); ac->cmd = NULL; } au_need_clean = TRUE; @@ -5361,8 +5361,8 @@ static void au_cleanup(void) * the command has been marked for deletion */ if (ap->pat == NULL || ac->cmd == NULL) { *prev_ac = ac->next; - free(ac->cmd); - free(ac); + xfree(ac->cmd); + xfree(ac); } else prev_ac = &(ac->next); } @@ -5371,7 +5371,7 @@ static void au_cleanup(void) if (ap->pat == NULL) { *prev_ap = ap->next; vim_regfree(ap->reg_prog); - free(ap); + xfree(ap); } else prev_ap = &(ap->next); } @@ -5445,7 +5445,7 @@ static void au_del_group(char_u *name) if (i == AUGROUP_ERROR) /* the group doesn't exist */ EMSG2(_("E367: No such group: \"%s\""), name); else { - free(AUGROUP_NAME(i)); + xfree(AUGROUP_NAME(i)); AUGROUP_NAME(i) = NULL; } } @@ -5637,7 +5637,7 @@ char_u *au_event_disable(char *what) else STRCAT(new_ei, what); set_string_option_direct((char_u *)"ei", -1, new_ei, OPT_FREE, SID_NONE); - free(new_ei); + xfree(new_ei); return save_ei; } @@ -5647,7 +5647,7 @@ void au_event_restore(char_u *old_ei) if (old_ei != NULL) { set_string_option_direct((char_u *)"ei", -1, old_ei, OPT_FREE, SID_NONE); - free(old_ei); + xfree(old_ei); } } @@ -5782,8 +5782,8 @@ void do_autocmd(char_u *arg, int forceit) } if (need_free) - free(cmd); - free(envpat); + xfree(cmd); + xfree(envpat); } /* @@ -5807,7 +5807,7 @@ static int au_get_grouparg(char_u **argp) group = AUGROUP_ALL; /* no match, use all groups */ else *argp = skipwhite(p); /* match, skip over group name */ - free(group_name); + xfree(group_name); } return group; } @@ -5984,10 +5984,10 @@ static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd, &ap->allow_dirs, TRUE); if (reg_pat != NULL) ap->reg_prog = vim_regcomp(reg_pat, RE_MAGIC); - free(reg_pat); + xfree(reg_pat); if (reg_pat == NULL || ap->reg_prog == NULL) { - free(ap->pat); - free(ap); + xfree(ap->pat); + xfree(ap); return FAIL; } } @@ -6186,7 +6186,7 @@ aucmd_prepbuf ( /* Make sure w_localdir and globaldir are NULL to avoid a chdir() in * win_enter_ext(). */ - free(aucmd_win->w_localdir); + xfree(aucmd_win->w_localdir); aucmd_win->w_localdir = NULL; aco->globaldir = globaldir; globaldir = NULL; @@ -6262,7 +6262,7 @@ win_found: hash_init(&aucmd_win->w_vars->dv_hashtab); /* re-use the hashtab */ curbuf = curwin->w_buffer; - free(globaldir); + xfree(globaldir); globaldir = aco->globaldir; /* the buffer contents may have changed */ @@ -6584,23 +6584,22 @@ apply_autocmds_group ( fname = vim_strsave(fname); /* make a copy, so we can change it */ } else { sfname = vim_strsave(fname); - /* Don't try expanding FileType, Syntax, FuncUndefined, WindowID, - * ColorScheme, QuickFixCmd or JobActivity */ - if (event == EVENT_FILETYPE - || event == EVENT_SYNTAX + // don't try expanding the following events + if (event == EVENT_COLORSCHEME + || event == EVENT_FILETYPE || event == EVENT_FUNCUNDEFINED + || event == EVENT_QUICKFIXCMDPOST + || event == EVENT_QUICKFIXCMDPRE || event == EVENT_REMOTEREPLY || event == EVENT_SPELLFILEMISSING - || event == EVENT_QUICKFIXCMDPRE - || event == EVENT_COLORSCHEME - || event == EVENT_QUICKFIXCMDPOST + || event == EVENT_SYNTAX || event == EVENT_TABCLOSED) fname = vim_strsave(fname); else fname = FullName_save(fname, FALSE); } if (fname == NULL) { /* out of memory */ - free(sfname); + xfree(sfname); retval = FALSE; goto BYPASS_AU; } @@ -6706,10 +6705,10 @@ apply_autocmds_group ( autocmd_busy = save_autocmd_busy; filechangeshell_busy = FALSE; autocmd_nested = save_autocmd_nested; - free(sourcing_name); + xfree(sourcing_name); sourcing_name = save_sourcing_name; sourcing_lnum = save_sourcing_lnum; - free(autocmd_fname); + xfree(autocmd_fname); autocmd_fname = save_autocmd_fname; autocmd_fname_full = save_autocmd_fname_full; autocmd_bufnr = save_autocmd_bufnr; @@ -6718,8 +6717,8 @@ apply_autocmds_group ( restore_funccal(save_funccalp); if (do_profiling == PROF_YES) prof_child_exit(&wait_time); - free(fname); - free(sfname); + xfree(fname); + xfree(sfname); --nesting; /* see matching increment above */ // When stopping to execute autocommands, restore the search patterns and @@ -6731,12 +6730,12 @@ apply_autocmds_group ( did_filetype = FALSE; while (au_pending_free_buf != NULL) { buf_T *b = au_pending_free_buf->b_next; - free(au_pending_free_buf); + xfree(au_pending_free_buf); au_pending_free_buf = b; } while (au_pending_free_win != NULL) { win_T *w = au_pending_free_win->w_next; - free(au_pending_free_win); + xfree(au_pending_free_win); au_pending_free_win = w; } } @@ -6807,7 +6806,7 @@ auto_next_pat ( char_u *name; char *s; - free(sourcing_name); + xfree(sourcing_name); sourcing_name = NULL; for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next) { @@ -6943,9 +6942,9 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf) break; } - free(fname); + xfree(fname); #ifdef BACKSLASH_IN_FILENAME - free(sfname); + xfree(sfname); #endif return retval; @@ -7125,7 +7124,7 @@ int au_exists(char_u *arg) } theend: - free(arg_save); + xfree(arg_save); return retval; } @@ -7204,7 +7203,7 @@ int match_file_list(char_u *list, char_u *sfname, char_u *ffname) break; match = match_file_pat(regpat, NULL, ffname, sfname, tail, (int)allow_dirs); - free(regpat); + xfree(regpat); if (match) return TRUE; } @@ -7400,7 +7399,7 @@ file_pat_to_reg_pat ( EMSG(_("E219: Missing {.")); else EMSG(_("E220: Missing }.")); - free(reg_pat); + xfree(reg_pat); reg_pat = NULL; } return reg_pat; diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 267c586543..8e6c2a598e 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -114,9 +114,9 @@ static int prev_lnum_lvl = -1; #define DONE_ACTION 1 /* did close or open a fold */ #define DONE_FOLD 2 /* did find a fold */ -static int foldstartmarkerlen; +static size_t foldstartmarkerlen; static char_u *foldendmarker; -static int foldendmarkerlen; +static size_t foldendmarkerlen; /* Exported folding functions. {{{1 */ /* copyFoldingState() {{{2 */ @@ -622,7 +622,7 @@ void foldCreate(linenr_T start, linenr_T end) if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; /* Move contained folds to inside new fold. */ - memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont); + memmove(fold_ga.ga_data, fp, sizeof(fold_T) * (size_t)cont); fold_ga.ga_len += cont; i += cont; @@ -634,7 +634,7 @@ void foldCreate(linenr_T start, linenr_T end) /* Move remaining entries to after the new fold. */ if (i < gap->ga_len) memmove(fp + 1, (fold_T *)gap->ga_data + i, - sizeof(fold_T) * (gap->ga_len - i)); + sizeof(fold_T) * (size_t)(gap->ga_len - i)); gap->ga_len = gap->ga_len + 1 - cont; /* insert new fold */ @@ -1051,7 +1051,7 @@ static int foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp) low = 0; high = gap->ga_len - 1; while (low <= high) { - int i = (low + high) / 2; + linenr_T i = (low + high) / 2; if (fp[i].fd_top > lnum) /* fold below lnum, adjust high */ high = i - 1; @@ -1292,7 +1292,6 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive) { fold_T *fp; int i; - long moved; fold_T *nfp; fp = (fold_T *)gap->ga_data + idx; @@ -1301,12 +1300,12 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive) deleteFoldRecurse(&fp->fd_nested); --gap->ga_len; if (idx < gap->ga_len) - memmove(fp, fp + 1, sizeof(fold_T) * (gap->ga_len - idx)); + memmove(fp, fp + 1, sizeof(fold_T) * (size_t)(gap->ga_len - idx)); } else { /* Move nested folds one level up, to overwrite the fold that is * deleted. */ - moved = fp->fd_nested.ga_len; - ga_grow(gap, (int)(moved - 1)); + int moved = fp->fd_nested.ga_len; + ga_grow(gap, moved - 1); { /* Get "fp" again, the array may have been reallocated. */ fp = (fold_T *)gap->ga_data + idx; @@ -1324,10 +1323,10 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive) /* move the existing folds down to make room */ if (idx + 1 < gap->ga_len) memmove(fp + moved, fp + 1, - sizeof(fold_T) * (gap->ga_len - (idx + 1))); + sizeof(fold_T) * (size_t)(gap->ga_len - (idx + 1))); /* move the contained folds one level up */ - memmove(fp, nfp, (size_t)(sizeof(fold_T) * moved)); - free(nfp); + memmove(fp, nfp, sizeof(fold_T) * (size_t)moved); + xfree(nfp); gap->ga_len += moved - 1; } } @@ -1584,17 +1583,16 @@ static void foldCreateMarkers(linenr_T start, linenr_T end) /* * Add "marker[markerlen]" in 'commentstring' to line "lnum". */ -static void foldAddMarker(linenr_T lnum, char_u *marker, int markerlen) +static void foldAddMarker(linenr_T lnum, char_u *marker, size_t markerlen) { char_u *cms = curbuf->b_p_cms; char_u *line; - int line_len; char_u *newline; char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s"); /* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */ line = ml_get(lnum); - line_len = (int)STRLEN(line); + size_t line_len = STRLEN(line); if (u_save(lnum - 1, lnum + 1) == OK) { newline = xmalloc(line_len + markerlen + STRLEN(cms) + 1); @@ -1629,8 +1627,8 @@ deleteFoldMarkers ( } } foldDelMarker(fp->fd_top + lnum_off, curwin->w_p_fmr, foldstartmarkerlen); - foldDelMarker(fp->fd_top + lnum_off + fp->fd_len - 1, - foldendmarker, foldendmarkerlen); + foldDelMarker(fp->fd_top + lnum_off + fp->fd_len - 1, foldendmarker, + foldendmarkerlen); } /* foldDelMarker() {{{2 */ @@ -1640,7 +1638,7 @@ deleteFoldMarkers ( * If the marker is not found, there is no error message. Could a missing * close-marker. */ -static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) +static void foldDelMarker(linenr_T lnum, char_u *marker, size_t markerlen) { char_u *newline; char_u *cms = curbuf->b_p_cms; @@ -1652,7 +1650,7 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) continue; } /* Found the marker, include a digit if it's there. */ - int len = markerlen; + size_t len = markerlen; if (VIM_ISDIGIT(p[len])) ++len; if (*cms != NUL) { @@ -1662,7 +1660,7 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) && STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0 && STRNCMP(p + len, cms2 + 2, STRLEN(cms2 + 2)) == 0) { p -= cms2 - cms; - len += (int)STRLEN(cms) - 2; + len += STRLEN(cms) - 2; } } if (u_save(lnum - 1, lnum + 1) == OK) { @@ -1762,7 +1760,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, } if (*p != NUL) { p = transstr(text); - free(text); + xfree(text); text = p; } } @@ -1781,27 +1779,23 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, */ void foldtext_cleanup(char_u *str) { - char_u *cms_start; /* first part or the whole comment */ - int cms_slen = 0; /* length of cms_start */ - char_u *cms_end; /* last part of the comment or NULL */ - int cms_elen = 0; /* length of cms_end */ char_u *s; char_u *p; - int len; int did1 = FALSE; int did2 = FALSE; /* Ignore leading and trailing white space in 'commentstring'. */ - cms_start = skipwhite(curbuf->b_p_cms); - cms_slen = (int)STRLEN(cms_start); + char_u *cms_start = skipwhite(curbuf->b_p_cms); + size_t cms_slen = STRLEN(cms_start); while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1])) --cms_slen; /* locate "%s" in 'commentstring', use the part before and after it. */ - cms_end = (char_u *)strstr((char *)cms_start, "%s"); + char_u *cms_end = (char_u *)strstr((char *)cms_start, "%s"); + size_t cms_elen = 0; if (cms_end != NULL) { - cms_elen = cms_slen - (int)(cms_end - cms_start); - cms_slen = (int)(cms_end - cms_start); + cms_elen = cms_slen - (size_t)(cms_end - cms_start); + cms_slen = (size_t)(cms_end - cms_start); /* exclude white space before "%s" */ while (cms_slen > 0 && vim_iswhite(cms_start[cms_slen - 1])) @@ -1809,13 +1803,13 @@ void foldtext_cleanup(char_u *str) /* skip "%s" and white space after it */ s = skipwhite(cms_end + 2); - cms_elen -= (int)(s - cms_end); + cms_elen -= (size_t)(s - cms_end); cms_end = s; } parseMarker(curwin); for (s = str; *s != NUL; ) { - len = 0; + size_t len = 0; if (STRNCMP(s, curwin->w_p_fmr, foldstartmarkerlen) == 0) len = foldstartmarkerlen; else if (STRNCMP(s, foldendmarker, foldendmarkerlen) == 0) @@ -1830,7 +1824,7 @@ void foldtext_cleanup(char_u *str) ; if (p >= str + cms_slen && STRNCMP(p - cms_slen, cms_start, cms_slen) == 0) { - len += (int)(s - p) + cms_slen; + len += (size_t)(s - p) + cms_slen; s = p - cms_slen; } } else if (cms_end != NULL) { @@ -2035,8 +2029,8 @@ static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot) if (fline.lvl > 0) { invalid_top = fline.lnum; invalid_bot = end; - end = foldUpdateIEMSRecurse(&wp->w_folds, - 1, start, &fline, getlevel, end, FD_LEVEL); + end = foldUpdateIEMSRecurse(&wp->w_folds, 1, start, &fline, getlevel, end, + FD_LEVEL); start = fline.lnum; } else { if (fline.lnum == wp->w_buffer->b_ml.ml_line_count) @@ -2095,7 +2089,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level, linenr_T startlnum, fline_T *flp, LevelGetter getlevel, linenr_T bot, - int topflags /* flags used by containing fold */ + char topflags /* containing fold flags */ ) { linenr_T ll; @@ -2333,8 +2327,8 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level, flp->off += fp->fd_top; i = (int)(fp - (fold_T *)gap->ga_data); bot = foldUpdateIEMSRecurse(&fp->fd_nested, level + 1, - startlnum2 - fp->fd_top, flp, getlevel, - bot - fp->fd_top, fp->fd_flags); + startlnum2 - fp->fd_top, flp, getlevel, + bot - fp->fd_top, fp->fd_flags); fp = (fold_T *)gap->ga_data + i; flp->lnum += fp->fd_top; flp->lnum_save += fp->fd_top; @@ -2468,7 +2462,7 @@ static void foldInsert(garray_T *gap, int i) fp = (fold_T *)gap->ga_data + i; if (i < gap->ga_len) - memmove(fp + 1, fp, sizeof(fold_T) * (gap->ga_len - i)); + memmove(fp + 1, fp, sizeof(fold_T) * (size_t)(gap->ga_len - i)); ++gap->ga_len; ga_init(&fp->fd_nested, (int)sizeof(fold_T), 10); } @@ -2649,9 +2643,7 @@ static void foldlevelIndent(fline_T *flp) } else flp->lvl = get_indent_buf(buf, lnum) / get_sw_value(curbuf); if (flp->lvl > flp->wp->w_p_fdn) { - flp->lvl = flp->wp->w_p_fdn; - if (flp->lvl < 0) - flp->lvl = 0; + flp->lvl = (int) MAX(0, flp->wp->w_p_fdn); } } @@ -2768,8 +2760,8 @@ static void foldlevelExpr(fline_T *flp) static void parseMarker(win_T *wp) { foldendmarker = vim_strchr(wp->w_p_fmr, ','); - foldstartmarkerlen = (int)(foldendmarker++ - wp->w_p_fmr); - foldendmarkerlen = (int)STRLEN(foldendmarker); + foldstartmarkerlen = (size_t)(foldendmarker++ - wp->w_p_fmr); + foldendmarkerlen = STRLEN(foldendmarker); } /* foldlevelMarker() {{{2 */ @@ -2822,9 +2814,8 @@ static void foldlevelMarker(fline_T *flp) ++flp->lvl_next; ++flp->start; } - } else if (*s == cend - && STRNCMP(s + 1, foldendmarker + 1, - foldendmarkerlen - 1) == 0) { + } else if (*s == cend && STRNCMP(s + 1, foldendmarker + 1, + foldendmarkerlen - 1) == 0) { /* found endmarker: set flp->lvl_next */ s += foldendmarkerlen; if (VIM_ISDIGIT(*s)) { diff --git a/src/nvim/fold.h b/src/nvim/fold.h index 1cbd7af5da..2ff10c0e91 100644 --- a/src/nvim/fold.h +++ b/src/nvim/fold.h @@ -1,14 +1,16 @@ #ifndef NVIM_FOLD_H #define NVIM_FOLD_H +#include "nvim/pos.h" + /* * Info used to pass info about a fold from the fold-detection code to the * code that displays the foldcolumn. */ typedef struct foldinfo { + linenr_T fi_lnum; /* line number where fold starts */ int fi_level; /* level of the fold; when this is zero the other fields are invalid */ - int fi_lnum; /* line number where fold starts */ int fi_low_level; /* lowest fold level that starts in the same line */ } foldinfo_T; diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 31a79db209..953eb58841 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -24,7 +24,7 @@ /// Clear an allocated growing array. void ga_clear(garray_T *gap) { - free(gap->ga_data); + xfree(gap->ga_data); // Initialize growing array without resetting itemsize or growsize gap->ga_data = NULL; @@ -114,7 +114,7 @@ void ga_remove_duplicate_strings(garray_T *gap) // loop over the growing array in reverse for (int i = gap->ga_len - 1; i > 0; i--) { if (fnamecmp(fnames[i - 1], fnames[i]) == 0) { - free(fnames[i]); + xfree(fnames[i]); // close the gap (move all strings one slot lower) for (int j = i + 1; j < gap->ga_len; j++) { diff --git a/src/nvim/garray.h b/src/nvim/garray.h index b758fce5da..642eaf54f0 100644 --- a/src/nvim/garray.h +++ b/src/nvim/garray.h @@ -61,7 +61,7 @@ static inline void *ga_append_via_ptr(garray_T *gap, size_t item_size) ga_clear(_gap); \ } while (false) -#define FREE_PTR_PTR(ptr) free(*(ptr)) +#define FREE_PTR_PTR(ptr) xfree(*(ptr)) /// Call `free` for every pointer stored in the garray and then frees the /// garray. diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index d901e99a2d..f45ee609bd 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -167,7 +167,7 @@ void free_buff(buffheader_T *buf) for (p = buf->bh_first.b_next; p != NULL; p = np) { np = p->b_next; - free(p); + xfree(p); } buf->bh_first.b_next = NULL; } @@ -365,7 +365,7 @@ static int read_readbuf(buffheader_T *buf, int advance) if (advance) { if (curr->b_str[++buf->bh_index] == NUL) { buf->bh_first.b_next = curr->b_next; - free(curr); + xfree(curr); buf->bh_index = 0; } } @@ -495,7 +495,7 @@ void saveRedobuff(void) s = get_buffcont(&save_redobuff, FALSE); if (s != NULL) { add_buff(&redobuff, s, -1L); - free(s); + xfree(s); } } } @@ -904,7 +904,7 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int silent) typebuf.tb_buf + typebuf.tb_off + offset, (size_t)(typebuf.tb_len - offset + 1)); if (typebuf.tb_buf != typebuf_init) - free(typebuf.tb_buf); + xfree(typebuf.tb_buf); typebuf.tb_buf = s1; memmove(s2 + newoff, typebuf.tb_noremap + typebuf.tb_off, @@ -913,7 +913,7 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, int silent) typebuf.tb_noremap + typebuf.tb_off + offset, (size_t)(typebuf.tb_len - offset)); if (typebuf.tb_noremap != noremapbuf_init) - free(typebuf.tb_noremap); + xfree(typebuf.tb_noremap); typebuf.tb_noremap = s2; typebuf.tb_off = newoff; @@ -1162,11 +1162,11 @@ void free_typebuf(void) if (typebuf.tb_buf == typebuf_init) EMSG2(_(e_intern2), "Free typebuf 1"); else - free(typebuf.tb_buf); + xfree(typebuf.tb_buf); if (typebuf.tb_noremap == noremapbuf_init) EMSG2(_(e_intern2), "Free typebuf 2"); else - free(typebuf.tb_noremap); + xfree(typebuf.tb_noremap); } /* @@ -2068,10 +2068,10 @@ static int vgetorpeek(int advance) i = ins_typebuf(s, noremap, 0, TRUE, cmd_silent || save_m_silent); if (save_m_expr) - free(s); + xfree(s); } - free(save_m_keys); - free(save_m_str); + xfree(save_m_keys); + xfree(save_m_str); if (i == FAIL) { c = -1; break; @@ -2906,9 +2906,9 @@ do_map ( } else { /* new rhs for existing entry */ mp->m_mode &= ~mode; /* remove mode bits */ if (mp->m_mode == 0 && !did_it) { /* reuse entry */ - free(mp->m_str); + xfree(mp->m_str); mp->m_str = vim_strsave(rhs); - free(mp->m_orig_str); + xfree(mp->m_orig_str); mp->m_orig_str = vim_strsave(orig_rhs); mp->m_noremap = noremap; mp->m_nowait = nowait; @@ -2998,8 +2998,8 @@ do_map ( } theend: - free(keys_buf); - free(arg_buf); + xfree(keys_buf); + xfree(arg_buf); return retval; } @@ -3012,11 +3012,11 @@ static void map_free(mapblock_T **mpp) mapblock_T *mp; mp = *mpp; - free(mp->m_keys); - free(mp->m_str); - free(mp->m_orig_str); + xfree(mp->m_keys); + xfree(mp->m_str); + xfree(mp->m_orig_str); *mpp = mp->m_next; - free(mp); + xfree(mp); } /* @@ -3211,7 +3211,7 @@ showmap ( if (mapchars != NULL) { msg_puts(mapchars); len = (int)STRLEN(mapchars); - free(mapchars); + xfree(mapchars); } while (++len <= 3) @@ -3246,7 +3246,7 @@ showmap ( char_u *s = vim_strsave(mp->m_str); vim_unescape_csi(s); msg_outtrans_special(s, FALSE); - free(s); + xfree(s); } if (p_verbose > 0) last_set_msg(mp->m_script_ID); @@ -3285,7 +3285,7 @@ int map_to_exists(char_u *str, char_u *modechars, int abbr) mode |= CMDLINE; retval = map_to_exists_mode(rhs, mode, abbr); - free(buf); + xfree(buf); return retval; } @@ -3469,7 +3469,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) p = NULL; } } - free(p); + xfree(p); } } /* for (mp) */ } /* for (hash) */ @@ -3499,7 +3499,7 @@ int ExpandMappings(regmatch_T *regmatch, int *num_file, char_u ***file) if (STRCMP(*ptr1, *ptr2)) *++ptr1 = *ptr2++; else { - free(*ptr2++); + xfree(*ptr2++); count--; } } @@ -3617,7 +3617,7 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) && qlen == len && !STRNCMP(q, ptr, (size_t)len); if (q != mp->m_keys) { - free(q); + xfree(q); } if (match) { break; @@ -3669,7 +3669,7 @@ int check_abbr(int c, char_u *ptr, int col, int mincol) /* no abbrev. for these chars */ typebuf.tb_no_abbr_cnt += (int)STRLEN(s) + j + 1; if (mp->m_expr) - free(s); + xfree(s); } tb[0] = Ctrl_H; @@ -3725,13 +3725,13 @@ eval_map_expr ( msg_row = save_msg_row; restore_cmdline_alloc(save_cmd); - free(expr); + xfree(expr); if (p == NULL) return NULL; /* Escape CSI in the result to be able to use the string as typeahead. */ res = vim_strsave_escape_csi(p); - free(p); + xfree(p); return res; } @@ -4171,7 +4171,7 @@ void add_map(char_u *map, int mode) p_cpo = (char_u *)""; /* Allow <> notation */ s = vim_strsave(map); (void)do_map(0, s, mode, FALSE); - free(s); + xfree(s); p_cpo = cpo_save; } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index d7087ee928..a8c97c800d 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -404,7 +404,9 @@ EXTERN int no_check_timestamps INIT(= 0); /* Don't check timestamps */ typedef enum { HLF_8 = 0 /* Meta & special keys listed with ":map", text that is displayed different from what it is */ - , HLF_EOB // after the last line in the buffer + , HLF_EOB //< after the last line in the buffer + , HLF_TERM //< terminal cursor focused + , HLF_TERMNC //< terminal cursor unfocused , HLF_AT /* @ characters at end of screen, characters that don't really exist in the text */ , HLF_D /* directories in CTRL-D listing */ @@ -451,10 +453,10 @@ typedef enum { /* The HL_FLAGS must be in the same order as the HLF_ enums! * When changing this also adjust the default for 'highlight'. */ -#define HL_FLAGS {'8', '~', '@', 'd', 'e', 'i', 'l', 'm', 'M', 'n', 'N', 'r', \ - 's', 'S', 'c', 't', 'v', 'V', 'w', 'W', 'f', 'F', 'A', 'C', \ - 'D', 'T', '-', '>', 'B', 'P', 'R', 'L', '+', '=', 'x', 'X', \ - '*', '#', '_', '!', '.', 'o'} +#define HL_FLAGS {'8', '~', 'z', 'Z', '@', 'd', 'e', 'i', 'l', 'm', 'M', 'n', \ + 'N', 'r', 's', 'S', 'c', 't', 'v', 'V', 'w', 'W', 'f', 'F', \ + 'A', 'C', 'D', 'T', '-', '>', 'B', 'P', 'R', 'L', '+', '=', \ + 'x', 'X', '*', '#', '_', '!', '.', 'o'} EXTERN int highlight_attr[HLF_COUNT]; /* Highl. attr for each context. */ EXTERN int highlight_user[9]; /* User[1-9] attributes */ @@ -896,6 +898,14 @@ EXTERN FILE *scriptout INIT(= NULL); /* stream to write script to */ /* volatile because it is used in signal handler catch_sigint(). */ EXTERN volatile int got_int INIT(= FALSE); /* set to TRUE when interrupt signal occurred */ +EXTERN int disable_breakcheck INIT(= 0); // > 0 if breakchecks should be + // ignored. FIXME(tarruda): Hacky + // way to run functions that would + // result in *_breakcheck calls + // while events that would normally + // be deferred are being processed + // immediately. Ref: + // neovim/neovim#2371 EXTERN int bangredo INIT(= FALSE); /* set to TRUE with ! command */ EXTERN int searchcmdlen; /* length of previous search cmd */ EXTERN int reg_do_extmatch INIT(= 0); /* Used when compiling regexp: @@ -972,8 +982,8 @@ EXTERN char breakat_flags[256]; /* which characters are in 'breakat' */ * Makefile to make their value depend on the Makefile. */ #ifdef HAVE_PATHDEF -extern char_u *default_vim_dir; -extern char_u *default_vimruntime_dir; +extern char *default_vim_dir; +extern char *default_vimruntime_dir; extern char_u *compiled_user; extern char_u *compiled_sys; #endif @@ -1122,8 +1132,7 @@ EXTERN char_u e_nesting[] INIT(= N_("E22: Scripts nested too deep")); EXTERN char_u e_noalt[] INIT(= N_("E23: No alternate file")); EXTERN char_u e_noabbr[] INIT(= N_("E24: No such abbreviation")); EXTERN char_u e_nobang[] INIT(= N_("E477: No ! allowed")); -EXTERN char_u e_nogvim[] INIT(= N_( - "E25: GUI cannot be used: Not enabled at compile time")); +EXTERN char_u e_nogvim[] INIT(= N_("E25: Nvim does not have a built-in GUI")); EXTERN char_u e_nogroup[] INIT(= N_("E28: No such highlight group name: %s")); EXTERN char_u e_noinstext[] INIT(= N_("E29: No inserted text yet")); EXTERN char_u e_nolastcmd[] INIT(= N_("E30: No previous command line")); diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index b5e7ec414c..6e9ad02b3a 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -551,7 +551,7 @@ static void prt_header(prt_settings_T *psettings, int pagenum, linenr_T lnum) p += l; } - free(tbuf); + xfree(tbuf); if (psettings->do_syntax) /* Set colors for next character. */ @@ -1539,7 +1539,7 @@ static int prt_find_resource(char *name, struct prt_ps_resource_S *resource) retval = (do_in_runtimepath(buffer, FALSE, prt_resource_name, resource->filename) && resource->filename[0] != NUL); - free(buffer); + xfree(buffer); return retval; } @@ -1921,7 +1921,7 @@ void mch_print_cleanup(void) */ for (i = PRT_PS_FONT_ROMAN; i <= PRT_PS_FONT_BOLDOBLIQUE; i++) { if (prt_ps_mb_font.ps_fontname[i] != NULL) - free(prt_ps_mb_font.ps_fontname[i]); + xfree(prt_ps_mb_font.ps_fontname[i]); prt_ps_mb_font.ps_fontname[i] = NULL; } } @@ -1936,7 +1936,7 @@ void mch_print_cleanup(void) prt_file_error = FALSE; } if (prt_ps_file_name != NULL) { - free(prt_ps_file_name); + xfree(prt_ps_file_name); prt_ps_file_name = NULL; } } @@ -2342,7 +2342,7 @@ int mch_print_init(prt_settings_T *psettings, char_u *jobname, int forceit) p = expand_env_save(psettings->outfile); if (p != NULL) { prt_ps_fd = mch_fopen((char *)p, WRITEBIN); - free(p); + xfree(p); } } if (prt_ps_fd == NULL) { @@ -3032,7 +3032,7 @@ int mch_print_text_out(char_u *p, size_t len) /* Need to free any translated characters */ if (prt_do_conv) - free(p); + xfree(p); prt_text_run += char_width; prt_pos_x += char_width; diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 6b90c4fee4..2da937633e 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -53,7 +53,7 @@ void hash_init(hashtab_T *ht) void hash_clear(hashtab_T *ht) { if (ht->ht_array != ht->ht_smallarray) { - free(ht->ht_array); + xfree(ht->ht_array); } } @@ -65,7 +65,7 @@ void hash_clear_all(hashtab_T *ht, unsigned int off) size_t todo = ht->ht_used; for (hashitem_T *hi = ht->ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { - free(hi->hi_key - off); + xfree(hi->hi_key - off); todo--; } } @@ -351,7 +351,7 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems) } if (ht->ht_array != ht->ht_smallarray) { - free(ht->ht_array); + xfree(ht->ht_array); } ht->ht_array = newarray; ht->ht_mask = newmask; diff --git a/src/nvim/if_cscope.c b/src/nvim/if_cscope.c index bd9e005676..48d8522865 100644 --- a/src/nvim/if_cscope.c +++ b/src/nvim/if_cscope.c @@ -433,7 +433,7 @@ static void cs_stat_emsg(char *fname) (void)sprintf(buf, stat_emsg, fname, errno); (void)EMSG(buf); - free(buf); + xfree(buf); } @@ -470,7 +470,7 @@ cs_add_common ( if (fname == NULL) goto add_err; fname = (char *)vim_strnsave((char_u *)fname, len); - free(fbuf); + xfree(fbuf); FileInfo file_info; bool file_info_ok = os_fileinfo(fname, &file_info); if (!file_info_ok) { @@ -538,15 +538,15 @@ staterr: } } - free(fname); - free(fname2); - free(ppath); + xfree(fname); + xfree(fname2); + xfree(ppath); return CSCOPE_SUCCESS; add_err: - free(fname2); - free(fname); - free(ppath); + xfree(fname2); + xfree(fname); + xfree(ppath); return CSCOPE_FAILURE; } /* cs_add_common */ @@ -605,7 +605,7 @@ static int cs_cnt_matches(int idx) cs_reading_emsg(idx); - free(buf); + xfree(buf); return -1; } @@ -636,7 +636,7 @@ static int cs_cnt_matches(int idx) break; } - free(buf); + xfree(buf); return nlines; } /* cs_cnt_matches */ @@ -805,9 +805,9 @@ err_closing: } # ifdef UNIX /* on Win32 we still need prog */ - free(prog); + xfree(prog); # endif - free(ppath); + xfree(ppath); #if defined(UNIX) # if defined(HAVE_SETSID) || defined(HAVE_SETPGID) @@ -852,8 +852,8 @@ err_closing: si.hStdInput = stdin_rd; created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); - free(prog); - free(cmd); + xfree(prog); + xfree(cmd); if (!created) { PERROR(_("cs_create_connection exec failed")); @@ -982,7 +982,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us sprintf(buf, nf, *qfpos, *(qfpos-1)); (void)EMSG(buf); - free(buf); + xfree(buf); return FALSE; } @@ -1022,22 +1022,22 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us if (nummatches[i] == 0) (void)cs_read_prompt(i); } - free(cmd); + xfree(cmd); if (totmatches == 0) { char *nf = _("E259: no matches found for cscope query %s of %s"); char *buf; if (!verbose) { - free(nummatches); + xfree(nummatches); return FALSE; } buf = xmalloc(strlen(opt) + strlen(pat) + strlen(nf)); sprintf(buf, nf, opt, pat); (void)EMSG(buf); - free(buf); - free(nummatches); + xfree(buf); + xfree(nummatches); return FALSE; } @@ -1079,8 +1079,8 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us } } os_remove((char *)tmp); - free(tmp); - free(nummatches); + xfree(tmp); + xfree(nummatches); return TRUE; } else { char **matches = NULL, **contexts = NULL; @@ -1089,7 +1089,7 @@ static int cs_find_common(char *opt, char *pat, int forceit, int verbose, int us /* read output */ cs_fill_results((char *)pat, totmatches, nummatches, &matches, &contexts, &matched); - free(nummatches); + xfree(nummatches); if (matches == NULL) return FALSE; @@ -1424,12 +1424,12 @@ static char *cs_manage_matches(char **matches, char **contexts, int totmatches, if (mp != NULL) { if (cnt > 0) while (cnt--) { - free(mp[cnt]); + xfree(mp[cnt]); if (cp != NULL) - free(cp[cnt]); + xfree(cp[cnt]); } - free(mp); - free(cp); + xfree(mp); + xfree(cp); } mp = NULL; cp = NULL; @@ -1537,14 +1537,14 @@ static void cs_file_results(FILE *f, int *nummatches_a) else fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search); - free(context); - free(fullname); + xfree(context); + xfree(fullname); } /* for all matches */ (void)cs_read_prompt(i); } /* for all cscope connections */ - free(buf); + xfree(buf); } /* @@ -1583,7 +1583,7 @@ static void cs_fill_results(char *tagstr, int totmatches, int *nummatches_a, cha matches[totsofar] = cs_make_vim_style_matches(fullname, slno, search, tagstr); - free(fullname); + xfree(fullname); if (strcmp(cntx, "<global>") == 0) cntxts[totsofar] = NULL; @@ -1601,16 +1601,16 @@ static void cs_fill_results(char *tagstr, int totmatches, int *nummatches_a, cha if (totsofar == 0) { /* No matches, free the arrays and return NULL in "*matches_p". */ - free(matches); + xfree(matches); matches = NULL; - free(cntxts); + xfree(cntxts); cntxts = NULL; } *matched = totsofar; *matches_p = matches; *cntxts_p = cntxts; - free(buf); + xfree(buf); } /* cs_fill_results */ @@ -1661,7 +1661,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches) (void)sprintf(buf, cstag_msg, ptag); MSG_PUTS_ATTR(buf, hl_attr(HLF_T)); - free(tbuf); + xfree(tbuf); MSG_PUTS_ATTR(_("\n # line"), hl_attr(HLF_T)); /* strlen is 7 */ msg_advance(msg_col + 2); @@ -1727,7 +1727,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches) MSG_PUTS_LONG(extra); } - free(tbuf); /* only after printing extra due to strtok use */ + xfree(tbuf); /* only after printing extra due to strtok use */ if (msg_col) msg_putchar('\n'); @@ -1741,7 +1741,7 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches) num++; } /* for all matches */ - free(buf); + xfree(buf); } /* cs_print_tags_priv */ @@ -1806,7 +1806,7 @@ static int cs_read_prompt(int i) else if (p_csverbose) cs_reading_emsg(i); /* don't have additional information */ cs_release_csp(i, TRUE); - free(buf); + xfree(buf); return CSCOPE_FAILURE; } @@ -1821,7 +1821,7 @@ static int cs_read_prompt(int i) break; /* did find the prompt */ } - free(buf); + xfree(buf); return CSCOPE_SUCCESS; } @@ -1947,9 +1947,9 @@ static void cs_release_csp(int i, int freefnpp) (void)fclose(csinfo[i].to_fp); if (freefnpp) { - free(csinfo[i].fname); - free(csinfo[i].ppath); - free(csinfo[i].flags); + xfree(csinfo[i].fname); + xfree(csinfo[i].ppath); + xfree(csinfo[i].flags); } clear_csinfo(i); @@ -1996,13 +1996,13 @@ static int cs_reset(exarg_T *eap) MSG_PUTS_ATTR(buf, hl_attr(HLF_R)); } } - free(dblist[i]); - free(pplist[i]); - free(fllist[i]); + xfree(dblist[i]); + xfree(pplist[i]); + xfree(fllist[i]); } - free(dblist); - free(pplist); - free(fllist); + xfree(dblist); + xfree(pplist); + xfree(fllist); if (p_csverbose) MSG_ATTR(_("All cscope databases reset"), hl_attr(HLF_R) | MSG_HIST); @@ -2061,7 +2061,7 @@ static char *cs_resolve_file(int i, char *name) fullname = xstrdup(name); } - free(csdir); + xfree(csdir); return fullname; } @@ -2109,7 +2109,7 @@ void cs_end(void) for (i = 0; i < csinfo_size; i++) cs_release_csp(i, TRUE); - free(csinfo); + xfree(csinfo); csinfo_size = 0; } diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 5711207933..183456d3f7 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -297,7 +297,7 @@ int set_indent(int size, int flags) } retval = true; } else { - free(newline); + xfree(newline); } curwin->w_cursor.col = ind_len; return retval; diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index 8310f635c9..c0613331cf 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -136,7 +136,7 @@ bool cin_is_cinword(char_u *line) } } - free(cinw_buf); + xfree(cinw_buf); return retval; } @@ -1332,7 +1332,7 @@ void parse_cino(buf_T *buf) char_u *l; int divider; int fraction = 0; - int sw = (int)get_sw_value(buf); + int sw = get_sw_value(buf); /* * Set the default values. @@ -3280,7 +3280,7 @@ theend: /* put the cursor back where it belongs */ curwin->w_cursor = cur_curpos; - free(linecopy); + xfree(linecopy); if (amount < 0) return 0; diff --git a/src/nvim/lib/khash.h b/src/nvim/lib/khash.h index c9198e048c..96e7ea6df0 100644 --- a/src/nvim/lib/khash.h +++ b/src/nvim/lib/khash.h @@ -181,7 +181,7 @@ typedef khint_t khiter_t; #define krealloc(P,Z) xrealloc(P,Z) #endif #ifndef kfree -#define kfree(P) free(P) +#define kfree(P) xfree(P) #endif static const double __ac_HASH_UPPER = 0.77; diff --git a/src/nvim/lib/klist.h b/src/nvim/lib/klist.h index f8dc7d4c43..7df809f07b 100644 --- a/src/nvim/lib/klist.h +++ b/src/nvim/lib/klist.h @@ -44,9 +44,9 @@ static inline void kmp_destroy_##name(kmp_##name##_t *mp) { \ size_t k; \ for (k = 0; k < mp->n; ++k) { \ - kmpfree_f(mp->buf[k]); free(mp->buf[k]); \ + kmpfree_f(mp->buf[k]); xfree(mp->buf[k]); \ } \ - free(mp->buf); free(mp); \ + xfree(mp->buf); xfree(mp); \ } \ static inline kmptype_t *kmp_alloc_##name(kmp_##name##_t *mp) { \ ++mp->cnt; \ @@ -95,7 +95,7 @@ kmp_free(name, kl->mp, p); \ kmp_free(name, kl->mp, p); \ kmp_destroy(name, kl->mp); \ - free(kl); \ + xfree(kl); \ } \ static inline kltype_t *kl_pushp_##name(kl_##name##_t *kl) { \ kl1_##name *q, *p = kmp_alloc(name, kl->mp); \ diff --git a/src/nvim/lib/kvec.h b/src/nvim/lib/kvec.h index 982b5d6f1c..0466cb229c 100644 --- a/src/nvim/lib/kvec.h +++ b/src/nvim/lib/kvec.h @@ -55,7 +55,7 @@ int main() { #define kvec_t(type) struct { size_t size, capacity; type *items; } #define kv_init(v) ((v).size = (v).capacity = 0, (v).items = 0) -#define kv_destroy(v) free((v).items) +#define kv_destroy(v) xfree((v).items) #define kv_A(v, i) ((v).items[(i)]) #define kv_pop(v) ((v).items[--(v).size]) #define kv_size(v) ((v).size) diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 93812683d6..e14e998e7a 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -59,12 +59,12 @@ /* Use our own isdigit() replacement, because on MS-Windows isdigit() returns * non-zero for superscript 1. Also avoids that isdigit() crashes for numbers * below 0 and above 255. */ -#define VIM_ISDIGIT(c) ((unsigned)(c) - '0' < 10) +#define VIM_ISDIGIT(c) ((unsigned)(c) >= '0' && (unsigned)(c) <= '9') /* Like isalpha() but reject non-ASCII characters. Can't be used with a * special key (negative value). */ -# define ASCII_ISLOWER(c) ((unsigned)(c) - 'a' < 26) -# define ASCII_ISUPPER(c) ((unsigned)(c) - 'A' < 26) +# define ASCII_ISLOWER(c) ((unsigned)(c) >= 'a' && (unsigned)(c) <= 'z') +# define ASCII_ISUPPER(c) ((unsigned)(c) >= 'A' && (unsigned)(c) <= 'Z') # define ASCII_ISALPHA(c) (ASCII_ISUPPER(c) || ASCII_ISLOWER(c)) # define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || VIM_ISDIGIT(c)) diff --git a/src/nvim/main.c b/src/nvim/main.c index a03fd2e8a9..4753dc31c3 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -644,7 +644,7 @@ main_loop ( // duplicates. p = keep_msg; msg_attr(p, keep_msg_attr); - free(p); + xfree(p); } if (need_fileinfo) { /* show file info after redraw */ fileinfo(FALSE, TRUE, FALSE); @@ -840,7 +840,7 @@ static void init_locale(void) bindtextdomain(VIMPACKAGE, (char *)NameBuff); } if (mustfree) - free(p); + xfree(p); textdomain(VIMPACKAGE); } TIME_MSG("locale set"); @@ -1285,7 +1285,7 @@ scripterror: char_u *r; r = concat_fnames(p, path_tail(alist_name(&GARGLIST[0])), TRUE); - free(p); + xfree(p); p = r; } @@ -1322,7 +1322,7 @@ scripterror: p = xmalloc(STRLEN(parmp->commands[0]) + 3); sprintf((char *)p, ":%s\r", parmp->commands[0]); set_vim_var_string(VV_SWAPCOMMAND, p, -1); - free(p); + xfree(p); } TIME_MSG("parsing arguments"); } @@ -1753,7 +1753,7 @@ static void exe_commands(mparm_T *parmp) for (i = 0; i < parmp->n_commands; ++i) { do_cmdline_cmd(parmp->commands[i]); if (parmp->cmds_tofree[i]) - free(parmp->commands[i]); + xfree(parmp->commands[i]); } sourcing_name = NULL; current_SID = 0; diff --git a/src/nvim/map.c b/src/nvim/map.c index 06ae19f5bc..5d83020619 100644 --- a/src/nvim/map.c +++ b/src/nvim/map.c @@ -45,7 +45,7 @@ void map_##T##_##U##_free(Map(T, U) *map) \ { \ kh_destroy(T##_##U##_map, map->table); \ - free(map); \ + xfree(map); \ } \ \ U map_##T##_##U##_get(Map(T, U) *map, T key) \ diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 2737380a8e..a142d12c13 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -131,7 +131,7 @@ int setmark_pos(int c, pos_T *pos, int fnum) i = c - 'A'; namedfm[i].fmark.mark = *pos; namedfm[i].fmark.fnum = fnum; - free(namedfm[i].fname); + xfree(namedfm[i].fname); namedfm[i].fname = NULL; return OK; } @@ -146,9 +146,6 @@ void setpcmark(void) { int i; xfmark_T *fm; -#ifdef JUMPLIST_ROTATE - xfmark_T tempmark; -#endif /* for :global the mark is set only once */ if (global_busy || listcmd_busy || cmdmod.keepjumps) @@ -157,27 +154,10 @@ void setpcmark(void) curwin->w_prev_pcmark = curwin->w_pcmark; curwin->w_pcmark = curwin->w_cursor; -# ifdef JUMPLIST_ROTATE - /* - * If last used entry is not at the top, put it at the top by rotating - * the stack until it is (the newer entries will be at the bottom). - * Keep one entry (the last used one) at the top. - */ - if (curwin->w_jumplistidx < curwin->w_jumplistlen) - ++curwin->w_jumplistidx; - while (curwin->w_jumplistidx < curwin->w_jumplistlen) { - tempmark = curwin->w_jumplist[curwin->w_jumplistlen - 1]; - for (i = curwin->w_jumplistlen - 1; i > 0; --i) - curwin->w_jumplist[i] = curwin->w_jumplist[i - 1]; - curwin->w_jumplist[0] = tempmark; - ++curwin->w_jumplistidx; - } -# endif - /* If jumplist is full: remove oldest entry */ if (++curwin->w_jumplistlen > JUMPLISTSIZE) { curwin->w_jumplistlen = JUMPLISTSIZE; - free(curwin->w_jumplist[0].fname); + xfree(curwin->w_jumplist[0].fname); for (i = 1; i < JUMPLISTSIZE; ++i) curwin->w_jumplist[i - 1] = curwin->w_jumplist[i]; } @@ -516,7 +496,7 @@ void fmarks_check_names(buf_T *buf) } } - free(name); + xfree(name); } static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) @@ -525,7 +505,7 @@ static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) && fm->fname != NULL && fnamecmp(name, fm->fname) == 0) { fm->fmark.fnum = buf->b_fnum; - free(fm->fname); + xfree(fm->fname); fm->fname = NULL; } } @@ -643,7 +623,7 @@ void do_marks(exarg_T *eap) arg, &namedfm[i].fmark.mark, name, namedfm[i].fmark.fnum == curbuf->b_fnum); if (namedfm[i].fmark.fnum != 0) - free(name); + xfree(name); } } show_one_mark('"', arg, &curbuf->b_last_cursor, NULL, TRUE); @@ -698,7 +678,7 @@ show_one_mark ( if (name != NULL) { msg_outtrans_attr(name, current ? hl_attr(HLF_D) : 0); if (mustfree) - free(name); + xfree(name); } } ui_flush(); /* show one line at a time */ @@ -755,7 +735,7 @@ void ex_delmarks(exarg_T *eap) else n = i - 'A'; namedfm[n].fmark.mark.lnum = 0; - free(namedfm[n].fname); + xfree(namedfm[n].fname); namedfm[n].fname = NULL; } } @@ -797,7 +777,7 @@ void ex_jumps(exarg_T *eap) msg_putchar('\n'); if (got_int) { - free(name); + xfree(name); break; } sprintf((char *)IObuff, "%c %2d %5ld %4d ", @@ -810,7 +790,7 @@ void ex_jumps(exarg_T *eap) msg_outtrans_attr(name, curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum ? hl_attr(HLF_D) : 0); - free(name); + xfree(name); os_breakcheck(); } ui_flush(); @@ -844,7 +824,7 @@ void ex_changes(exarg_T *eap) msg_outtrans(IObuff); name = mark_line(&curbuf->b_changelist[i], 17); msg_outtrans_attr(name, hl_attr(HLF_D)); - free(name); + xfree(name); os_breakcheck(); } ui_flush(); @@ -1140,7 +1120,7 @@ static void cleanup_jumplist(void) if (i >= curwin->w_jumplistlen) /* no duplicate */ curwin->w_jumplist[to++] = curwin->w_jumplist[from]; else - free(curwin->w_jumplist[from].fname); + xfree(curwin->w_jumplist[from].fname); } if (curwin->w_jumplistidx == curwin->w_jumplistlen) curwin->w_jumplistidx = to; @@ -1171,7 +1151,7 @@ void free_jumplist(win_T *wp) int i; for (i = 0; i < wp->w_jumplistlen; ++i) - free(wp->w_jumplist[i].fname); + xfree(wp->w_jumplist[i].fname); } void set_last_cursor(win_T *win) @@ -1187,7 +1167,7 @@ void free_all_marks(void) for (i = 0; i < NMARKS + EXTRA_MARKS; i++) if (namedfm[i].fmark.mark.lnum != 0) - free(namedfm[i].fname); + xfree(namedfm[i].fname); } #endif @@ -1232,7 +1212,7 @@ int read_viminfo_filemark(vir_T *virp, int force) fm->fmark.mark.coladd = 0; fm->fmark.fnum = 0; str = skipwhite(str); - free(fm->fname); + xfree(fm->fname); fm->fname = viminfo_readstring(virp, (int)(str - virp->vir_line), FALSE); } @@ -1267,9 +1247,9 @@ void write_viminfo_filemarks(FILE *fp) : (name != NULL && STRCMP(name, namedfm[i].fname) == 0))) break; - free(name); + xfree(name); - free(namedfm[i].fname); + xfree(namedfm[i].fname); for (; i > NMARKS; --i) namedfm[i] = namedfm[i - 1]; namedfm[NMARKS].fmark.mark = curwin->w_cursor; @@ -1313,7 +1293,7 @@ static void write_one_filemark(FILE *fp, xfmark_T *fm, int c1, int c2) } if (fm->fmark.fnum != 0) - free(name); + xfree(name); } /* @@ -1337,7 +1317,7 @@ int removable(char_u *name) } } } - free(name); + xfree(name); return retval; } @@ -1494,7 +1474,7 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags count++; } } - free(str); + xfree(str); pos.coladd = 0; while (!(eof = viminfo_readline(virp)) && line[0] == TAB) { @@ -1540,5 +1520,5 @@ void copy_viminfo_marks(vir_T *virp, FILE *fp_out, int count, int eof, int flags break; } } - free(name_buf); + xfree(name_buf); } diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index fd6050f2d6..e45d43270a 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -523,7 +523,7 @@ char_u * mb_init(void) convert_setup(&vimconv, p_enc, (char_u *)"utf-8"); vimconv.vc_fail = true; } - free(p); + xfree(p); } #endif @@ -549,7 +549,7 @@ char_u * mb_init(void) */ p = string_convert(&vimconv, (char_u *)buf, NULL); if (p != NULL) { - free(p); + xfree(p); n = 1; } else n = 2; @@ -3103,7 +3103,7 @@ void utf_find_illegal(void) for (;; ) { p = get_cursor_pos_ptr(); if (vimconv.vc_type != CONV_NONE) { - free(tofree); + xfree(tofree); tofree = string_convert(&vimconv, p, NULL); if (tofree == NULL) break; @@ -3142,7 +3142,7 @@ void utf_find_illegal(void) beep_flush(); theend: - free(tofree); + xfree(tofree); convert_setup(&vimconv, NULL, NULL); } @@ -3375,7 +3375,7 @@ char_u *enc_canonize(char_u *enc) FUNC_ATTR_NONNULL_RET STRMOVE(r, p); } else if ((i = enc_alias_search(p)) >= 0) { /* alias recognized, get canonical name */ - free(r); + xfree(r); r = vim_strsave((char_u *)enc_canon_table[i].name); } return r; @@ -3537,7 +3537,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, size_t slen, p = xmalloc(len); if (done > 0) memmove(p, result, done); - free(result); + xfree(result); result = p; } @@ -3582,7 +3582,7 @@ static char_u * iconv_string(vimconv_T *vcp, char_u *str, size_t slen, fromlen -= l; } else if (ICONV_ERRNO != ICONV_E2BIG) { /* conversion failed */ - free(result); + xfree(result); result = NULL; break; } @@ -3891,7 +3891,7 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, if (l_w == 0) { /* Illegal utf-8 byte cannot be converted */ - free(retval); + xfree(retval); return NULL; } if (unconvlenp != NULL && l_w > len - i) { @@ -3925,7 +3925,7 @@ char_u * string_convert_ext(vimconv_T *vcp, char_u *ptr, if (c < 0x100) *d++ = c; else if (vcp->vc_fail) { - free(retval); + xfree(retval); return NULL; } else { *d++ = 0xbf; diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 26542759be..bbe2e62021 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -99,7 +99,7 @@ memfile_T *mf_open(char_u *fname, int flags) mf_do_open(mfp, fname, flags); if (mfp->mf_fd < 0) { // fail if file could not be opened - free(mfp); + xfree(mfp); return NULL; } } @@ -210,12 +210,12 @@ void mf_close(memfile_T *mfp, bool del_file) mf_free_bhdr(hp); } while (mfp->mf_free_first != NULL) // free entries in free list - free(mf_rem_free(mfp)); + xfree(mf_rem_free(mfp)); mf_hash_free(&mfp->mf_hash); mf_hash_free_all(&mfp->mf_trans); // free hashtable and its items - free(mfp->mf_fname); - free(mfp->mf_ffname); - free(mfp); + xfree(mfp->mf_fname); + xfree(mfp->mf_ffname); + xfree(mfp); } /// Close the swap file for a memfile. Used when 'swapfile' is reset. @@ -242,8 +242,8 @@ void mf_close_file(buf_T *buf, bool getlines) if (mfp->mf_fname != NULL) { os_remove((char *)mfp->mf_fname); // delete the swap file - free(mfp->mf_fname); - free(mfp->mf_ffname); + xfree(mfp->mf_fname); + xfree(mfp->mf_ffname); mfp->mf_fname = NULL; mfp->mf_ffname = NULL; } @@ -302,7 +302,7 @@ bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count) } else { // use the number, remove entry from free list freep = mf_rem_free(mfp); hp->bh_bnum = freep->bh_bnum; - free(freep); + xfree(freep); } } else { // get a new number if (hp == NULL) { @@ -398,11 +398,11 @@ void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile) /// Signal block as no longer used (may put it in the free list). void mf_free(memfile_T *mfp, bhdr_T *hp) { - free(hp->bh_data); // free data + xfree(hp->bh_data); // free data mf_rem_hash(mfp, hp); // get *hp out of the hash list mf_rem_used(mfp, hp); // get *hp out of the used list if (hp->bh_bnum < 0) { - free(hp); // don't want negative numbers in free list + xfree(hp); // don't want negative numbers in free list mfp->mf_neg_count--; } else { mf_ins_free(mfp, hp); // put *hp in the free list @@ -627,7 +627,7 @@ static bhdr_T *mf_release(memfile_T *mfp, unsigned page_count) /// Make sure page_count of bh_data is right. if (hp->bh_page_count != page_count) { - free(hp->bh_data); + xfree(hp->bh_data); hp->bh_data = xmalloc(mfp->mf_page_size * page_count); hp->bh_page_count = page_count; } @@ -682,8 +682,8 @@ static bhdr_T *mf_alloc_bhdr(memfile_T *mfp, unsigned page_count) /// Free a block header and its block memory. static void mf_free_bhdr(bhdr_T *hp) { - free(hp->bh_data); - free(hp); + xfree(hp->bh_data); + xfree(hp); } /// Insert a block in the free list. @@ -843,7 +843,7 @@ static int mf_trans_add(memfile_T *mfp, bhdr_T *hp) freep->bh_page_count -= page_count; } else { freep = mf_rem_free(mfp); - free(freep); + xfree(freep); } } else { new_bnum = mfp->mf_blocknr_max; @@ -881,7 +881,7 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr) // remove entry from the trans list mf_hash_rem_item(&mfp->mf_trans, (mf_hashitem_T *)np); - free(np); + xfree(np); return new_bnum; } @@ -902,7 +902,7 @@ void mf_set_ffname(memfile_T *mfp) void mf_fullname(memfile_T *mfp) { if (mfp != NULL && mfp->mf_fname != NULL && mfp->mf_ffname != NULL) { - free(mfp->mf_fname); + xfree(mfp->mf_fname); mfp->mf_fname = mfp->mf_ffname; mfp->mf_ffname = NULL; } @@ -940,8 +940,8 @@ static void mf_do_open(memfile_T *mfp, char_u *fname, int flags) // If the file cannot be opened, use memory only if (mfp->mf_fd < 0) { - free(mfp->mf_fname); - free(mfp->mf_ffname); + xfree(mfp->mf_fname); + xfree(mfp->mf_ffname); mfp->mf_fname = NULL; mfp->mf_ffname = NULL; } else { @@ -979,7 +979,7 @@ static void mf_hash_init(mf_hashtab_T *mht) static void mf_hash_free(mf_hashtab_T *mht) { if (mht->mht_buckets != mht->mht_small_buckets) - free(mht->mht_buckets); + xfree(mht->mht_buckets); } /// Free the array of a hash table and all the items it contains. @@ -990,7 +990,7 @@ static void mf_hash_free_all(mf_hashtab_T *mht) for (size_t idx = 0; idx <= mht->mht_mask; idx++) for (mf_hashitem_T *mhi = mht->mht_buckets[idx]; mhi != NULL; mhi = next) { next = mhi->mhi_next; - free(mhi); + xfree(mhi); } mf_hash_free(mht); @@ -1088,7 +1088,7 @@ static void mf_hash_grow(mf_hashtab_T *mht) } if (mht->mht_buckets != mht->mht_small_buckets) - free(mht->mht_buckets); + xfree(mht->mht_buckets); mht->mht_buckets = buckets; mht->mht_mask = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR - 1; diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 8b2ebfe554..a72dc43eb4 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -91,8 +91,6 @@ typedef struct pointer_entry PTR_EN; /* block/line-count pair */ #define PTR_ID (('p' << 8) + 't') /* pointer block id */ #define BLOCK0_ID0 'b' /* block 0 id 0 */ #define BLOCK0_ID1 '0' /* block 0 id 1 */ -#define BLOCK0_ID1_C0 'c' /* block 0 id 1 'cm' 0 */ -#define BLOCK0_ID1_C1 'C' /* block 0 id 1 'cm' 1 */ /* * pointer to a block, used in a pointer block @@ -176,8 +174,7 @@ struct data_block { * variables, because the rest of the swap file is not portable. */ struct block0 { - char_u b0_id[2]; /* id for block 0: BLOCK0_ID0 and BLOCK0_ID1, - * BLOCK0_ID1_C0, BLOCK0_ID1_C1 */ + char_u b0_id[2]; ///< ID for block 0: BLOCK0_ID0 and BLOCK0_ID1. char_u b0_version[10]; /* Vim version string */ char_u b0_page_size[4]; /* number of bytes per page */ char_u b0_mtime[4]; /* last modification time of file */ @@ -376,7 +373,7 @@ error: if (mfp != NULL) { if (hp) mf_put(mfp, hp, false, false); - mf_close(mfp, true); /* will also free(mfp->mf_fname) */ + mf_close(mfp, true); /* will also xfree(mfp->mf_fname) */ } buf->b_ml.ml_mfp = NULL; return FAIL; @@ -421,7 +418,7 @@ void ml_setname(buf_T *buf) /* if the file name is the same we don't have to do anything */ if (fnamecmp(fname, mfp->mf_fname) == 0) { - free(fname); + xfree(fname); success = TRUE; break; } @@ -434,14 +431,14 @@ void ml_setname(buf_T *buf) /* try to rename the swap file */ if (vim_rename(mfp->mf_fname, fname) == 0) { success = TRUE; - free(mfp->mf_fname); + xfree(mfp->mf_fname); mfp->mf_fname = fname; - free(mfp->mf_ffname); + xfree(mfp->mf_ffname); mf_set_ffname(mfp); ml_upd_block0(buf, UB_SAME_DIR); break; } - free(fname); /* this fname didn't work, try another */ + xfree(fname); /* this fname didn't work, try another */ } if (mfp->mf_fd == -1) { /* need to (re)open the swap file */ @@ -570,9 +567,9 @@ void ml_close(buf_T *buf, int del_file) return; mf_close(buf->b_ml.ml_mfp, del_file); /* close the .swp file */ if (buf->b_ml.ml_line_lnum != 0 && (buf->b_ml.ml_flags & ML_LINE_DIRTY)) - free(buf->b_ml.ml_line_ptr); - free(buf->b_ml.ml_stack); - free(buf->b_ml.ml_chunksize); + xfree(buf->b_ml.ml_line_ptr); + xfree(buf->b_ml.ml_stack); + xfree(buf->b_ml.ml_chunksize); buf->b_ml.ml_chunksize = NULL; buf->b_ml.ml_mfp = NULL; @@ -619,22 +616,16 @@ void ml_timestamp(buf_T *buf) ml_upd_block0(buf, UB_FNAME); } -/* - * Return FAIL when the ID of "b0p" is wrong. - */ -static int ml_check_b0_id(ZERO_BL *b0p) +/// Checks whether the IDs in b0 are valid. +static bool ml_check_b0_id(ZERO_BL *b0p) + FUNC_ATTR_NONNULL_ALL { - if (b0p->b0_id[0] != BLOCK0_ID0 - || (b0p->b0_id[1] != BLOCK0_ID1 - && b0p->b0_id[1] != BLOCK0_ID1_C0 - && b0p->b0_id[1] != BLOCK0_ID1_C1) - ) - return FAIL; - return OK; + return b0p->b0_id[0] == BLOCK0_ID0 && b0p->b0_id[1] == BLOCK0_ID1; } -/// Return true if all strings in b0 are correct (nul-terminated). -static bool ml_check_b0_strings(ZERO_BL *b0p) FUNC_ATTR_NONNULL_ALL +/// Checks whether all strings in b0 are valid (i.e. nul-terminated). +static bool ml_check_b0_strings(ZERO_BL *b0p) + FUNC_ATTR_NONNULL_ALL { return (memchr(b0p->b0_version, NUL, 10) && memchr(b0p->b0_uname, NUL, B0_UNAME_SIZE) @@ -833,7 +824,7 @@ void ml_recover(void) (void)recover_names(fname, FALSE, i, &fname_used); } if (fname_used == NULL) - goto theend; /* out of memory */ + goto theend; // user chose invalid number. /* When called from main() still need to initialize storage structure */ if (called_from_main && ml_open(curbuf) == FAIL) @@ -944,7 +935,7 @@ void ml_recover(void) /* need to reallocate the memory used to store the data */ p = xmalloc(mfp->mf_page_size); memmove(p, hp->bh_data, previous_page_size); - free(hp->bh_data); + xfree(hp->bh_data); hp->bh_data = p; b0p = hp->bh_data; } @@ -1017,7 +1008,7 @@ void ml_recover(void) set_fileformat(b0_ff - 1, OPT_LOCAL); if (b0_fenc != NULL) { set_option_value((char_u *)"fenc", 0L, b0_fenc, OPT_LOCAL); - free(b0_fenc); + xfree(b0_fenc); } unchanged(curbuf, TRUE); @@ -1203,7 +1194,7 @@ void ml_recover(void) /* Need to copy one line, fetching the other one may flush it. */ p = vim_strsave(ml_get(idx)); i = STRCMP(p, ml_get(idx + lnum)); - free(p); + xfree(p); if (i != 0) { changed_int(); ++curbuf->b_changedtick; @@ -1246,15 +1237,17 @@ void ml_recover(void) redraw_curbuf_later(NOT_VALID); theend: - free(fname_used); + xfree(fname_used); recoverymode = FALSE; if (mfp != NULL) { if (hp != NULL) mf_put(mfp, hp, false, false); - mf_close(mfp, false); /* will also free(mfp->mf_fname) */ + mf_close(mfp, false); /* will also xfree(mfp->mf_fname) */ + } + if (buf != NULL) { //may be NULL if swap file not found. + xfree(buf->b_ml.ml_stack); + xfree(buf); } - free(buf->b_ml.ml_stack); - free(buf); if (serious_error && called_from_main) ml_close(curbuf, TRUE); else { @@ -1330,53 +1323,35 @@ recover_names ( if (dir_name[0] == '.' && dir_name[1] == NUL) { /* check current dir */ if (fname == NULL) { names[0] = vim_strsave((char_u *)"*.sw?"); -#if defined(UNIX) || defined(WIN3264) /* For Unix names starting with a dot are special. MS-Windows * supports this too, on some file systems. */ names[1] = vim_strsave((char_u *)".*.sw?"); names[2] = vim_strsave((char_u *)".sw?"); num_names = 3; -#else - num_names = 1; -#endif } else num_names = recov_file_names(names, fname_res, TRUE); } else { /* check directory dir_name */ if (fname == NULL) { names[0] = concat_fnames(dir_name, (char_u *)"*.sw?", TRUE); -#if defined(UNIX) || defined(WIN3264) /* For Unix names starting with a dot are special. MS-Windows * supports this too, on some file systems. */ names[1] = concat_fnames(dir_name, (char_u *)".*.sw?", TRUE); names[2] = concat_fnames(dir_name, (char_u *)".sw?", TRUE); num_names = 3; -#else - num_names = 1; -#endif } else { -#if defined(UNIX) || defined(WIN3264) p = dir_name + STRLEN(dir_name); if (after_pathsep(dir_name, p) && p[-1] == p[-2]) { /* Ends with '//', Use Full path for swap name */ tail = make_percent_swname(dir_name, fname_res); - } else -#endif - tail = path_tail(fname_res); - tail = concat_fnames(dir_name, tail, TRUE); + } else { + tail = path_tail(fname_res); + tail = concat_fnames(dir_name, tail, TRUE); + } num_names = recov_file_names(names, tail, FALSE); - free(tail); + xfree(tail); } } - // check for out-of-memory - for (int i = 0; i < num_names; ++i) { - if (names[i] == NULL) { - for (int j = 0; j < num_names; ++j) - free(names[j]); - num_names = 0; - break; - } - } if (num_names == 0) num_files = 0; else if (expand_wildcards(num_names, names, &num_files, &files, @@ -1397,7 +1372,7 @@ recover_names ( swapname = NULL; num_files = 1; } - free(swapname); + xfree(swapname); } } @@ -1411,9 +1386,9 @@ recover_names ( /* Remove the name from files[i]. Move further entries * down. When the array becomes empty free it here, since * FreeWild() won't be called below. */ - free(files[i]); + xfree(files[i]); if (--num_files == 0) - free(files); + xfree(files); else for (; i < num_files; ++i) files[i] = files[i + 1]; @@ -1454,15 +1429,14 @@ recover_names ( file_count += num_files; for (int i = 0; i < num_names; ++i) - free(names[i]); + xfree(names[i]); if (num_files > 0) FreeWild(num_files, files); } - free(dir_name); + xfree(dir_name); return file_count; } -#if defined(UNIX) || defined(WIN3264) /* Need _very_ long file names */ /* * Append the full path to name with path separators made into percent * signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"") @@ -1479,12 +1453,11 @@ static char_u *make_percent_swname(char_u *dir, char_u *name) if (vim_ispathsep(*d)) *d = '%'; d = concat_fnames(dir, s, TRUE); - free(s); - free(f); + xfree(s); + xfree(f); } return d; } -#endif #ifdef UNIX static int process_still_running; @@ -1585,17 +1558,12 @@ static time_t swapfile_info(char_u *fname) } static int recov_file_names(char_u **names, char_u *path, int prepend_dot) + FUNC_ATTR_NONNULL_ALL { - int num_names; - char_u *p; - int i; - - num_names = 0; + int num_names = 0; - /* - * May also add the file name with a dot prepended, for swap file in same - * dir as original file. - */ + // May also add the file name with a dot prepended, for swap file in same + // dir as original file. if (prepend_dot) { names[num_names] = modname(path, (char_u *)".sw?", TRUE); if (names[num_names] == NULL) @@ -1606,15 +1574,15 @@ static int recov_file_names(char_u **names, char_u *path, int prepend_dot) // Form the normal swap file name pattern by appending ".sw?". names[num_names] = concat_fnames(path, (char_u *)".sw?", FALSE); if (num_names >= 1) { /* check if we have the same name twice */ - p = names[num_names - 1]; - i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]); + char_u *p = names[num_names - 1]; + int i = (int)STRLEN(names[num_names - 1]) - (int)STRLEN(names[num_names]); if (i > 0) p += i; /* file name has been expanded to full path */ if (STRCMP(p, names[num_names]) != 0) ++num_names; else - free(names[num_names]); + xfree(names[num_names]); } else ++num_names; @@ -2371,7 +2339,7 @@ int ml_replace(linenr_T lnum, char_u *line, int copy) if (curbuf->b_ml.ml_line_lnum != lnum) /* other line buffered */ ml_flush_line(curbuf); /* flush it */ else if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) /* same line allocated */ - free(curbuf->b_ml.ml_line_ptr); /* free it */ + xfree(curbuf->b_ml.ml_line_ptr); /* free it */ curbuf->b_ml.ml_line_ptr = line; curbuf->b_ml.ml_line_lnum = lnum; curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY; @@ -2726,7 +2694,7 @@ static void ml_flush_line(buf_T *buf) (void)ml_delete_int(buf, lnum, FALSE); } } - free(new_line); + xfree(new_line); entered = FALSE; } @@ -2970,7 +2938,7 @@ static int ml_add_stack(buf_T *buf) infoptr_T *newstack = xmalloc(sizeof(infoptr_T) * (buf->b_ml.ml_stack_size + STACK_INCR)); memmove(newstack, buf->b_ml.ml_stack, (size_t)top * sizeof(infoptr_T)); - free(buf->b_ml.ml_stack); + xfree(buf->b_ml.ml_stack); buf->b_ml.ml_stack = newstack; buf->b_ml.ml_stack_size += STACK_INCR; } @@ -3097,17 +3065,15 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name char_u fname_buf[MAXPATHL]; #endif -#if defined(UNIX) || defined(WIN3264) /* Need _very_ long file names */ s = dir_name + STRLEN(dir_name); if (after_pathsep(dir_name, s) && s[-1] == s[-2]) { /* Ends with '//', Use Full path */ r = NULL; if ((s = make_percent_swname(dir_name, fname)) != NULL) { r = modname(s, (char_u *)".swp", FALSE); - free(s); + xfree(s); } return r; } -#endif #ifdef HAVE_READLINK /* Expand symlink in the file name, so that we put the swap file with the @@ -3123,7 +3089,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name return NULL; s = get_file_in_dir(r, dir_name); - free(r); + xfree(r); return s; } @@ -3163,7 +3129,7 @@ get_file_in_dir ( t = concat_fnames(fname, dname + 2, TRUE); *tail = save_char; retval = concat_fnames(t, tail, TRUE); - free(t); + xfree(t); } } else { retval = concat_fnames(dname, tail, TRUE); @@ -3298,7 +3264,7 @@ findswapname ( if (fname == NULL) /* must be out of memory */ break; if ((n = (int)STRLEN(fname)) == 0) { /* safety check */ - free(fname); + xfree(fname); fname = NULL; break; } @@ -3428,7 +3394,7 @@ findswapname ( if (process_still_running && choice >= 4) choice++; /* Skip missing "Delete it" button */ # endif - free(name); + xfree(name); /* pretend screen didn't scroll, need redraw anyway */ msg_scrolled = 0; @@ -3481,7 +3447,7 @@ findswapname ( if (fname[n - 1] == 'a') { /* ".s?a" */ if (fname[n - 2] == 'a') { /* ".saa": tried enough, give up */ EMSG(_("E326: Too many swap files found")); - free(fname); + xfree(fname); fname = NULL; break; } @@ -3491,7 +3457,7 @@ findswapname ( --fname[n - 1]; /* ".swo", ".swn", etc. */ } - free(dir_name); + xfree(dir_name); return fname; } diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 2223b65a93..2d4259a238 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -18,6 +18,14 @@ # include "memory.c.generated.h" #endif +#if defined(USE_JEMALLOC) && !defined(UNIT_TESTING) +#include "jemalloc/jemalloc.h" +#define malloc(size) je_malloc(size) +#define calloc(count, size) je_calloc(count, size) +#define realloc(ptr, size) je_realloc(ptr, size) +#define free(ptr) je_free(ptr) +#endif + /// Try to free memory. Used when trying to recover from out of memory errors. /// @see {xmalloc} static void try_to_free_memory(void) @@ -92,6 +100,12 @@ void *xmalloc(size_t size) return ret; } +/// free wrapper that returns delegates to the backing memory manager +void xfree(void *ptr) +{ + free(ptr); +} + /// calloc() wrapper /// /// @see {xmalloc} @@ -362,19 +376,7 @@ size_t xstrlcpy(char *restrict dst, const char *restrict src, size_t size) char *xstrdup(const char *str) FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET { - char *ret = strdup(str); - - if (!ret) { - try_to_free_memory(); - ret = strdup(str); - if (!ret) { - mch_errmsg(e_outofmem); - mch_errmsg("\n"); - preserve_exit(); - } - } - - return ret; + return xmemdupz(str, strlen(str)); } /// A version of memchr that starts the search at `src + len`. @@ -541,8 +543,8 @@ void free_all_mem(void) clear_sb_text(); /* free any scrollback text */ /* Free some global vars. */ - free(last_cmdline); - free(new_last_cmdline); + xfree(last_cmdline); + xfree(new_last_cmdline); set_keep_msg(NULL, 0); /* Clear cmdline history. */ diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 8d9b5045b9..1689e7419e 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -188,7 +188,7 @@ ex_menu ( if (modes & (1 << i)) { p = popup_mode_name(menu_path, i); menu_nable_recurse(root_menu, p, MENU_ALL_MODES, enable); - free(p); + xfree(p); } } menu_nable_recurse(root_menu, menu_path, modes, enable); @@ -207,7 +207,7 @@ ex_menu ( if (modes & (1 << i)) { p = popup_mode_name(menu_path, i); remove_menu(&root_menu, p, MENU_ALL_MODES, TRUE); - free(p); + xfree(p); } } @@ -241,11 +241,11 @@ ex_menu ( // Include all modes, to make ":amenu" work menuarg.modes = modes; add_menu_path(p, &menuarg, pri_tab, map_to); - free(p); + xfree(p); } } - free(map_buf); + xfree(map_buf); } @@ -391,12 +391,12 @@ add_menu_path ( menup = &menu->children; parent = menu; name = next_name; - free(dname); + xfree(dname); dname = NULL; if (pri_tab[pri_idx + 1] != -1) ++pri_idx; } - free(path_name); + xfree(path_name); /* * Only add system menu items which have not been defined yet. @@ -470,8 +470,8 @@ add_menu_path ( return OK; erret: - free(path_name); - free(dname); + xfree(path_name); + xfree(dname); /* Delete any empty submenu we added before discovering the error. Repeat * for higher levels. */ @@ -663,14 +663,14 @@ static void free_menu(vimmenu_T **menup) /* Don't change *menup until after calling gui_mch_destroy_menu(). The * MacOS code needs the original structure to properly delete the menu. */ *menup = menu->next; - free(menu->name); - free(menu->dname); - free(menu->en_name); - free(menu->en_dname); - free(menu->actext); + xfree(menu->name); + xfree(menu->dname); + xfree(menu->en_name); + xfree(menu->en_dname); + xfree(menu->actext); for (i = 0; i < MENU_MODES; i++) free_menu_string(menu, i); - free(menu); + xfree(menu); } @@ -686,7 +686,7 @@ static void free_menu_string(vimmenu_T *menu, int idx) if (menu->strings[i] == menu->strings[idx]) count++; if (count == 1) - free(menu->strings[idx]); + xfree(menu->strings[idx]); menu->strings[idx] = NULL; } @@ -711,11 +711,11 @@ static int show_menus(char_u *path_name, int modes) /* Found menu */ if (*p != NUL && menu->children == NULL) { EMSG(_(e_notsubmenu)); - free(path_name); + xfree(path_name); return FAIL; } else if ((menu->modes & modes) == 0x0) { EMSG(_(e_othermode)); - free(path_name); + xfree(path_name); return FAIL; } break; @@ -724,14 +724,14 @@ static int show_menus(char_u *path_name, int modes) } if (menu == NULL) { EMSG2(_(e_nomenu), name); - free(path_name); + xfree(path_name); return FAIL; } name = p; parent = menu; menu = menu->children; } - free(path_name); + xfree(path_name); /* Now we have found the matching menu, and we list the mappings */ /* Highlight title */ @@ -893,7 +893,7 @@ char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forc * Menu path continues, but we have reached a leaf. * Or menu exists only in another mode. */ - free(path_name); + xfree(path_name); return NULL; } break; @@ -902,13 +902,13 @@ char_u *set_context_in_menu_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forc } if (menu == NULL) { /* No menu found with the name we were looking for */ - free(path_name); + xfree(path_name); return NULL; } name = p; menu = menu->children; } - free(path_name); + xfree(path_name); xp->xp_context = expand_menus ? EXPAND_MENUNAMES : EXPAND_MENUS; xp->xp_pattern = after_dot; @@ -1289,7 +1289,7 @@ void ex_emenu(exarg_T *eap) menu = menu->children; name = p; } - free(saved_name); + xfree(saved_name); if (menu == NULL) { EMSG2(_("E334: Menu not found: %s"), eap->arg); return; @@ -1410,7 +1410,7 @@ vimmenu_T *gui_find_menu(char_u *path_name) if (menu == NULL) EMSG(_("E337: Menu not found - check menu names")); theend: - free(saved_name); + xfree(saved_name); return menu; } #endif @@ -1429,9 +1429,9 @@ static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE; #define FREE_MENUTRANS(mt) \ menutrans_T* _mt = (mt); \ - free(_mt->from); \ - free(_mt->from_noamp); \ - free(_mt->to) + xfree(_mt->from); \ + xfree(_mt->from_noamp); \ + xfree(_mt->to) /* * ":menutrans". @@ -1514,11 +1514,11 @@ static char_u *menutrans_lookup(char_u *name, int len) name[len] = c; for (int i = 0; i < menutrans_ga.ga_len; i++) { if (STRCMP(dname, tp[i].from_noamp) == 0) { - free(dname); + xfree(dname); return tp[i].to; } } - free(dname); + xfree(dname); return NULL; } diff --git a/src/nvim/message.c b/src/nvim/message.c index b2e9488388..ae4d0ec230 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -200,7 +200,7 @@ msg_attr_keep ( * Columns + sc_col) set_keep_msg(s, 0); - free(buf); + xfree(buf); --entered; return retval; } @@ -362,7 +362,7 @@ static char_u *last_sourcing_name = NULL; */ void reset_last_sourcing(void) { - free(last_sourcing_name); + xfree(last_sourcing_name); last_sourcing_name = NULL; last_sourcing_lnum = 0; } @@ -433,18 +433,18 @@ void msg_source(int attr) p = get_emsg_source(); if (p != NULL) { msg_attr(p, attr); - free(p); + xfree(p); } p = get_emsg_lnum(); if (p != NULL) { msg_attr(p, hl_attr(HLF_N)); - free(p); + xfree(p); last_sourcing_lnum = sourcing_lnum; /* only once for each line */ } /* remember the last sourcing name printed, also when it's empty */ if (sourcing_name == NULL || other_sourcing_name()) { - free(last_sourcing_name); + xfree(last_sourcing_name); if (sourcing_name == NULL) last_sourcing_name = NULL; else @@ -525,13 +525,13 @@ int emsg(char_u *s) if (p != NULL) { STRCAT(p, "\n"); redir_write(p, -1); - free(p); + xfree(p); } p = get_emsg_lnum(); if (p != NULL) { STRCAT(p, "\n"); redir_write(p, -1); - free(p); + xfree(p); } redir_write(s, -1); return TRUE; @@ -726,8 +726,8 @@ int delete_first_msg(void) assert(msg_hist_len == 1); last_msg_hist = NULL; } - free(p->msg); - free(p); + xfree(p->msg); + xfree(p); --msg_hist_len; return OK; } @@ -949,7 +949,7 @@ void wait_return(int redraw) reset_last_sourcing(); if (keep_msg != NULL && vim_strsize(keep_msg) >= (Rows - cmdline_row - 1) * Columns + sc_col) { - free(keep_msg); + xfree(keep_msg); keep_msg = NULL; /* don't redisplay message, it's too long */ } @@ -985,7 +985,7 @@ static void hit_return_msg(void) */ void set_keep_msg(char_u *s, int attr) { - free(keep_msg); + xfree(keep_msg); if (s != NULL && msg_silent == 0) keep_msg = vim_strsave(s); else @@ -1002,7 +1002,7 @@ void msg_start(void) int did_return = FALSE; if (!msg_silent) { - free(keep_msg); + xfree(keep_msg); keep_msg = NULL; /* don't display old message now */ } @@ -1088,7 +1088,7 @@ static void msg_home_replace_attr(char_u *fname, int attr) name = home_replace_save(NULL, fname); msg_outtrans_attr(name, attr); - free(name); + xfree(name); } /* @@ -1808,7 +1808,7 @@ static void inc_msg_scrolled(void) p = tofree; } set_vim_var_string(VV_SCROLLSTART, p, -1); - free(tofree); + xfree(tofree); } ++msg_scrolled; } @@ -1879,7 +1879,7 @@ void clear_sb_text(void) while (last_msgchunk != NULL) { mp = last_msgchunk->sb_prev; - free(last_msgchunk); + xfree(last_msgchunk); last_msgchunk = mp; } } @@ -2586,7 +2586,7 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1) ++no_wait_return; set_vim_var_string(VV_WARNINGMSG, message, -1); - free(keep_msg); + xfree(keep_msg); keep_msg = NULL; if (hl) keep_msg_attr = hl_attr(HLF_W); @@ -2715,7 +2715,7 @@ do_dialog ( break; } - free(hotkeys); + xfree(hotkeys); State = oldState; setmouse(); @@ -2816,7 +2816,7 @@ static char_u * console_dialog_alloc(const char_u *message, // Now allocate space for the strings - free(confirm_msg); + xfree(confirm_msg); confirm_msg = xmalloc(len); *confirm_msg = NUL; diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 5d8b88601e..d8b84293c3 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -796,7 +796,7 @@ open_line ( ) { ++curwin->w_cursor.lnum; if (did_si) { - int sw = (int)get_sw_value(curbuf); + int sw = get_sw_value(curbuf); if (p_sr) newindent -= newindent % sw; @@ -929,16 +929,16 @@ open_line ( curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; ins_bytes(p_extra); /* will call changed_bytes() */ - free(p_extra); + xfree(p_extra); next_line = NULL; } retval = TRUE; /* success! */ theend: curbuf->b_p_pi = saved_pi; - free(saved_line); - free(next_line); - free(allocated); + xfree(saved_line); + xfree(next_line); + xfree(allocated); return retval; } @@ -2432,7 +2432,7 @@ int get_keystroke(void) #endif break; } - free(buf); + xfree(buf); mapped_ctrl_c = save_mapped_ctrl_c; return n; @@ -2784,7 +2784,7 @@ get_cmd_output ( call_shell(command, kShellOptDoOut | kShellOptExpand | flags, NULL); --no_check_timestamps; - free(command); + xfree(command); /* * read the names from the file into memory @@ -2806,7 +2806,7 @@ get_cmd_output ( os_remove((char *)tempname); if (i != len) { EMSG2(_(e_notread), tempname); - free(buffer); + xfree(buffer); buffer = NULL; } else if (ret_len == NULL) { /* Change NUL into SOH, otherwise the string is truncated. */ @@ -2820,7 +2820,7 @@ get_cmd_output ( } done: - free(tempname); + xfree(tempname); return buffer; } @@ -2833,8 +2833,8 @@ void FreeWild(int count, char_u **files) if (count <= 0 || files == NULL) return; while (count--) - free(files[count]); - free(files); + xfree(files[count]); + xfree(files); } /* diff --git a/src/nvim/misc2.c b/src/nvim/misc2.c index fafce66c5f..7a584d4ea1 100644 --- a/src/nvim/misc2.c +++ b/src/nvim/misc2.c @@ -9,6 +9,7 @@ /* * misc2.c: Various functions. */ +#include <assert.h> #include <errno.h> #include <inttypes.h> #include <string.h> @@ -29,6 +30,7 @@ #include "nvim/fileio.h" #include "nvim/fold.h" #include "nvim/getchar.h" +#include "nvim/macros.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memfile.h" @@ -327,10 +329,10 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg) : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\"" : p_sxq); retval = os_call_shell(ncmd, opts, extra_shell_arg); - free(ncmd); + xfree(ncmd); if (ecmd != cmd) - free(ecmd); + xfree(ecmd); } } @@ -385,7 +387,7 @@ int vim_chdir(char_u *new_dir) if (dir_name == NULL) return -1; r = os_chdir((char *)dir_name); - free(dir_name); + xfree(dir_name); return r; } @@ -451,7 +453,7 @@ char *read_string(FILE *fd, size_t cnt) for (size_t i = 0; i < cnt; i++) { int c = getc(fd); if (c == EOF) { - free(str); + xfree(str); return NULL; } str[i] = (uint8_t)c; @@ -459,22 +461,33 @@ char *read_string(FILE *fd, size_t cnt) return (char *)str; } -/// Write a number to file "fd", MSB first, in "len" bytes. -/// @return OK/FAIL. -int put_bytes(FILE *fd, uintmax_t number, unsigned int len) +/// Writes a number to file "fd", most significant bit first, in "len" bytes. +/// @returns false in case of an error. +bool put_bytes(FILE *fd, uintmax_t number, size_t len) { - for (unsigned int i = len - 1; i < len; --i) - if (putc((int)(number >> (i * 8)), fd) == EOF) - return FAIL; - return OK; + assert(len > 0); + for (size_t i = len - 1; i < len; i--) { + if (putc((int)(number >> (i * 8)), fd) == EOF) { + return false; + } + } + return true; } -/// Write time_t to file "fd" in 8 bytes. +/// Writes time_t to file "fd" in 8 bytes. void put_time(FILE *fd, time_t time_) { + uint8_t buf[8]; + time_to_bytes(time_, buf); + fwrite(buf, sizeof(uint8_t), ARRAY_SIZE(buf), fd); +} + +/// Writes time_t to "buf[8]". +void time_to_bytes(time_t time_, uint8_t buf[8]) +{ // time_t can be up to 8 bytes in size, more than uintmax_t in 32 bits // systems, thus we can't use put_bytes() here. - for (unsigned int i = 7; i < 8; --i) { - putc((int)((uint64_t)time_ >> (i * 8)), fd); + for (size_t i = 7, bufi = 0; bufi < 8; i--, bufi++) { + buf[bufi] = (uint8_t)((uint64_t)time_ >> (i * 8)); } } diff --git a/src/nvim/move.c b/src/nvim/move.c index 1ba064c65f..65f2853073 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -16,6 +16,7 @@ * The 'scrolloff' option makes this a bit complicated. */ +#include <assert.h> #include <inttypes.h> #include <stdbool.h> @@ -135,13 +136,13 @@ void update_topline(void) { long line_count; int halfheight; - int n; + long n; linenr_T old_topline; int old_topfill; linenr_T lnum; int check_topline = FALSE; int check_botline = FALSE; - int save_so = p_so; + long save_so = p_so; if (!screen_valid(TRUE)) return; @@ -342,9 +343,9 @@ void update_topline_win(win_T* win) */ static int scrolljump_value(void) { - if (p_sj >= 0) - return (int)p_sj; - return (curwin->w_height * -p_sj) / 100; + long result = p_sj >= 0 ? p_sj : (curwin->w_height * -p_sj) / 100; + assert(result <= INT_MAX); + return (int)result; } /* @@ -711,7 +712,7 @@ int win_col_off(win_T *wp) { return ((wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) + 1 : 0) + (cmdwin_type == 0 || wp != curwin ? 0 : 1) - + wp->w_p_fdc + + (int)wp->w_p_fdc + (wp->w_buffer->b_signlist != NULL ? 2 : 0) ; } @@ -831,9 +832,9 @@ curs_columns ( * If we get closer to the edge than 'sidescrolloff', scroll a little * extra */ - off_left = (int)startcol - (int)curwin->w_leftcol - p_siso; - off_right = (int)endcol - (int)(curwin->w_leftcol + curwin->w_width - - p_siso) + 1; + assert(p_siso <= INT_MAX); + off_left = startcol - curwin->w_leftcol - (int)p_siso; + off_right = endcol - curwin->w_leftcol - curwin->w_width + (int)p_siso + 1; if (off_left < 0 || off_right > 0) { if (off_left < 0) diff = -off_left; @@ -845,8 +846,10 @@ curs_columns ( if (p_ss == 0 || diff >= textwidth / 2 || off_right >= off_left) new_leftcol = curwin->w_wcol - extra - textwidth / 2; else { - if (diff < p_ss) - diff = p_ss; + if (diff < p_ss) { + assert(p_ss <= INT_MAX); + diff = (int)p_ss; + } if (off_left < 0) new_leftcol = curwin->w_leftcol - diff; else @@ -902,8 +905,10 @@ curs_columns ( if (p_lines == 0) p_lines = plines_win(curwin, curwin->w_cursor.lnum, FALSE); --p_lines; - if (p_lines > curwin->w_wrow + p_so) - n = curwin->w_wrow + p_so; + if (p_lines > curwin->w_wrow + p_so) { + assert(p_so <= INT_MAX); + n = curwin->w_wrow + (int)p_so; + } else n = p_lines; if ((colnr_T)n >= curwin->w_height + curwin->w_skipcol / width) @@ -922,7 +927,8 @@ curs_columns ( curwin->w_skipcol = n * width; } else if (extra == 1) { /* less then 'scrolloff' lines above, decrease skipcol */ - extra = (curwin->w_skipcol + p_so * width - curwin->w_virtcol + assert(p_so <= INT_MAX); + extra = (curwin->w_skipcol + (int)p_so * width - curwin->w_virtcol + width - 1) / width; if (extra > 0) { if ((colnr_T)(extra * width) > curwin->w_skipcol) @@ -974,7 +980,7 @@ scrolldown ( int byfold /* TRUE: count a closed fold as one line */ ) { - long done = 0; /* total # of physical lines done */ + int done = 0; /* total # of physical lines done */ int wrow; int moved = FALSE; @@ -1331,7 +1337,8 @@ void scroll_cursor_top(int min_scroll, int always) linenr_T old_topline = curwin->w_topline; linenr_T old_topfill = curwin->w_topfill; linenr_T new_topline; - int off = p_so; + assert(p_so <= INT_MAX); + int off = (int)p_so; if (mouse_dragging > 0) off = mouse_dragging - 1; @@ -1472,7 +1479,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot) int old_topfill = curwin->w_topfill; int fill_below_window; linenr_T old_botline = curwin->w_botline; - linenr_T old_valid = curwin->w_valid; + int old_valid = curwin->w_valid; int old_empty_rows = curwin->w_empty_rows; linenr_T cln; /* Cursor Line Number */ @@ -1708,8 +1715,9 @@ void cursor_correct(void) * How many lines we would like to have above/below the cursor depends on * whether the first/last line of the file is on screen. */ - above_wanted = p_so; - below_wanted = p_so; + assert(p_so <= INT_MAX); + above_wanted = (int)p_so; + below_wanted = (int)p_so; if (mouse_dragging > 0) { above_wanted = mouse_dragging - 1; below_wanted = mouse_dragging - 1; @@ -2040,14 +2048,14 @@ void halfpage(bool flag, linenr_T Prenum) { long scrolled = 0; int i; - int n; int room; if (Prenum) curwin->w_p_scr = (Prenum > curwin->w_height) ? curwin->w_height : Prenum; - n = (curwin->w_p_scr <= curwin->w_height) ? - curwin->w_p_scr : curwin->w_height; + assert(curwin->w_p_scr <= INT_MAX); + int n = curwin->w_p_scr <= curwin->w_height ? (int)curwin->w_p_scr + : curwin->w_height; validate_botline(); room = curwin->w_empty_rows; diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 35549ce042..b671b8b545 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -5,8 +5,6 @@ #include <uv.h> #include <msgpack.h> -#include "nvim/lib/klist.h" - #include "nvim/api/private/helpers.h" #include "nvim/api/vim.h" #include "nvim/msgpack_rpc/channel.h" @@ -69,10 +67,6 @@ typedef struct { uint64_t request_id; } RequestEvent; -#define _noop(x) -KMEMPOOL_INIT(RequestEventPool, RequestEvent, _noop) -static kmempool_t(RequestEventPool) *request_event_pool = NULL; - static uint64_t next_id = 1; static PMap(uint64_t) *channels = NULL; static PMap(cstr_t) *event_strings = NULL; @@ -85,7 +79,6 @@ static msgpack_sbuffer out_buffer; /// Initializes the module void channel_init(void) { - request_event_pool = kmp_init(RequestEventPool); channels = pmap_new(uint64_t)(); event_strings = pmap_new(cstr_t)(); msgpack_sbuffer_init(&out_buffer); @@ -232,7 +225,25 @@ Object channel_send_call(uint64_t id, channel->pending_requests--; if (frame.errored) { - api_set_error(err, Exception, "%s", frame.result.data.string.data); + if (frame.result.type == kObjectTypeString) { + api_set_error(err, Exception, "%s", frame.result.data.string.data); + } else if (frame.result.type == kObjectTypeArray) { + // Should be an error in the form [type, message] + Array array = frame.result.data.array; + if (array.size == 2 && array.items[0].type == kObjectTypeInteger + && (array.items[0].data.integer == kErrorTypeException + || array.items[0].data.integer == kErrorTypeValidation) + && array.items[1].type == kObjectTypeString) { + err->type = (ErrorType) array.items[0].data.integer; + xstrlcpy(err->msg, array.items[1].data.string.data, sizeof(err->msg)); + err->set = true; + } else { + api_set_error(err, Exception, "%s", "unknown error"); + } + } else { + api_set_error(err, Exception, "%s", "unknown error"); + } + api_free_object(frame.result); } @@ -442,20 +453,20 @@ static void handle_request(Channel *channel, msgpack_object *request) // Retrieve the request handler MsgpackRpcRequestHandler handler; - msgpack_object method = request->via.array.ptr[2]; + msgpack_object *method = msgpack_rpc_method(request); - if (method.type == MSGPACK_OBJECT_BIN || method.type == MSGPACK_OBJECT_STR) { - handler = msgpack_rpc_get_handler_for(method.via.bin.ptr, - method.via.bin.size); + if (method) { + handler = msgpack_rpc_get_handler_for(method->via.bin.ptr, + method->via.bin.size); } else { handler.fn = msgpack_rpc_handle_missing_method; handler.defer = false; } Array args = ARRAY_DICT_INIT; - msgpack_rpc_to_array(request->via.array.ptr + 3, &args); + msgpack_rpc_to_array(msgpack_rpc_args(request), &args); bool defer = (!kv_size(channel->call_stack) && handler.defer); - RequestEvent *event_data = kmp_alloc(RequestEventPool, request_event_pool); + RequestEvent *event_data = xmalloc(sizeof(RequestEvent)); event_data->channel = channel; event_data->handler = handler; event_data->args = args; @@ -476,18 +487,22 @@ static void on_request_event(Event event) uint64_t request_id = e->request_id; Error error = ERROR_INIT; Object result = handler.fn(channel->id, request_id, args, &error); - // send the response - msgpack_packer response; - msgpack_packer_init(&response, &out_buffer, msgpack_sbuffer_write); - channel_write(channel, serialize_response(channel->id, - request_id, - &error, - result, - &out_buffer)); + if (request_id != NO_RESPONSE) { + // send the response + msgpack_packer response; + msgpack_packer_init(&response, &out_buffer, msgpack_sbuffer_write); + channel_write(channel, serialize_response(channel->id, + request_id, + &error, + result, + &out_buffer)); + } else { + api_free_object(result); + } // All arguments were freed already, but we still need to free the array - free(args.items); + xfree(args.items); decref(channel); - kmp_free(RequestEventPool, request_event_pool, e); + xfree(e); } static bool channel_write(Channel *channel, WBuffer *buffer) @@ -608,7 +623,7 @@ static void unsubscribe(Channel *channel, char *event) // Since the string is no longer used by other channels, release it's memory pmap_del(cstr_t)(event_strings, event_string); - free(event_string); + xfree(event_string); } /// Close the channel streams/job and free the channel resources. @@ -662,13 +677,13 @@ static void free_channel(Channel *channel) pmap_free(cstr_t)(channel->subscribed_events); kv_destroy(channel->call_stack); kv_destroy(channel->delayed_notifications); - free(channel); + xfree(channel); } static void close_cb(uv_handle_t *handle) { - free(handle->data); - free(handle); + xfree(handle->data); + xfree(handle); } static Channel *register_channel(void) @@ -745,7 +760,7 @@ static WBuffer *serialize_request(uint64_t channel_id, WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size), sbuffer->size, refcount, - free); + xfree); msgpack_sbuffer_clear(sbuffer); api_free_array(args); return rv; @@ -764,7 +779,7 @@ static WBuffer *serialize_response(uint64_t channel_id, WBuffer *rv = wstream_new_buffer(xmemdup(sbuffer->data, sbuffer->size), sbuffer->size, 1, // responses only go though 1 channel - free); + xfree); msgpack_sbuffer_clear(sbuffer); api_free_object(arg); return rv; diff --git a/src/nvim/msgpack_rpc/helpers.c b/src/nvim/msgpack_rpc/helpers.c index 355176aa5f..7d0db9a9b8 100644 --- a/src/nvim/msgpack_rpc/helpers.c +++ b/src/nvim/msgpack_rpc/helpers.c @@ -351,49 +351,86 @@ void msgpack_rpc_serialize_response(uint64_t response_id, } } +static bool msgpack_rpc_is_notification(msgpack_object *req) +{ + return req->via.array.ptr[0].via.u64 == 2; +} + +msgpack_object *msgpack_rpc_method(msgpack_object *req) +{ + msgpack_object *obj = req->via.array.ptr + + (msgpack_rpc_is_notification(req) ? 1 : 2); + return obj->type == MSGPACK_OBJECT_STR || obj->type == MSGPACK_OBJECT_BIN ? + obj : NULL; +} + +msgpack_object *msgpack_rpc_args(msgpack_object *req) +{ + msgpack_object *obj = req->via.array.ptr + + (msgpack_rpc_is_notification(req) ? 2 : 3); + return obj->type == MSGPACK_OBJECT_ARRAY ? obj : NULL; +} + +static msgpack_object *msgpack_rpc_msg_id(msgpack_object *req) +{ + if (msgpack_rpc_is_notification(req)) { + return NULL; + } + msgpack_object *obj = &req->via.array.ptr[1]; + return obj->type == MSGPACK_OBJECT_POSITIVE_INTEGER ? obj : NULL; +} + void msgpack_rpc_validate(uint64_t *response_id, msgpack_object *req, Error *err) { // response id not known yet - *response_id = 0; + *response_id = NO_RESPONSE; // Validate the basic structure of the msgpack-rpc payload if (req->type != MSGPACK_OBJECT_ARRAY) { - api_set_error(err, Validation, _("Request is not an array")); + api_set_error(err, Validation, _("Message is not an array")); return; } - if (req->via.array.size != 4) { - api_set_error(err, Validation, _("Request array size should be 4")); + if (req->via.array.size == 0) { + api_set_error(err, Validation, _("Message is empty")); return; } - if (req->via.array.ptr[1].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { - api_set_error(err, Validation, _("Id must be a positive integer")); + if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { + api_set_error(err, Validation, _("Message type must be an integer")); return; } - // Set the response id, which is the same as the request - *response_id = req->via.array.ptr[1].via.u64; - - if (req->via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { - api_set_error(err, Validation, _("Message type must be an integer")); + uint64_t type = req->via.array.ptr[0].via.u64; + if (type != kMessageTypeRequest && type != kMessageTypeNotification) { + api_set_error(err, Validation, _("Unknown message type")); return; } - if (req->via.array.ptr[0].via.u64 != 0) { - api_set_error(err, Validation, _("Message type must be 0")); + if ((type == kMessageTypeRequest && req->via.array.size != 4) || + (type == kMessageTypeNotification && req->via.array.size != 3)) { + api_set_error(err, Validation, _("Request array size should be 4 (request) " + "or 3 (notification)")); return; } - if (req->via.array.ptr[2].type != MSGPACK_OBJECT_BIN - && req->via.array.ptr[2].type != MSGPACK_OBJECT_STR) { + if (type == kMessageTypeRequest) { + msgpack_object *id_obj = msgpack_rpc_msg_id(req); + if (!id_obj) { + api_set_error(err, Validation, _("ID must be a positive integer")); + return; + } + *response_id = id_obj->via.u64; + } + + if (!msgpack_rpc_method(req)) { api_set_error(err, Validation, _("Method must be a string")); return; } - if (req->via.array.ptr[3].type != MSGPACK_OBJECT_ARRAY) { + if (!msgpack_rpc_args(req)) { api_set_error(err, Validation, _("Parameters must be an array")); return; } diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index b554d76bed..07d78dd9d7 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -48,9 +48,9 @@ void remote_ui_disconnect(uint64_t channel_id) // destroy pending screen updates api_free_array(data->buffer); pmap_del(uint64_t)(connected_uis, channel_id); - free(ui->data); + xfree(ui->data); ui_detach(ui); - free(ui); + xfree(ui); } static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, diff --git a/src/nvim/msgpack_rpc/server.c b/src/nvim/msgpack_rpc/server.c index 91aca0c37a..8fb2902b0b 100644 --- a/src/nvim/msgpack_rpc/server.c +++ b/src/nvim/msgpack_rpc/server.c @@ -9,11 +9,11 @@ #include "nvim/msgpack_rpc/server.h" #include "nvim/os/os.h" #include "nvim/ascii.h" +#include "nvim/garray.h" #include "nvim/vim.h" #include "nvim/memory.h" #include "nvim/log.h" #include "nvim/tempfile.h" -#include "nvim/map.h" #include "nvim/path.h" #define MAX_CONNECTIONS 32 @@ -27,6 +27,9 @@ typedef enum { } ServerType; typedef struct { + // The address of a pipe, or string value of a tcp address. + char addr[ADDRESS_MAX_SIZE]; + // Type of the union below ServerType type; @@ -38,12 +41,11 @@ typedef struct { } tcp; struct { uv_pipe_t handle; - char addr[ADDRESS_MAX_SIZE]; } pipe; } socket; } Server; -static PMap(cstr_t) *servers = NULL; +static garray_T servers = GA_EMPTY_INIT_VALUE; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "msgpack_rpc/server.c.generated.h" @@ -52,33 +54,40 @@ static PMap(cstr_t) *servers = NULL; /// Initializes the module bool server_init(void) { - servers = pmap_new(cstr_t)(); + ga_init(&servers, sizeof(Server *), 1); - if (!os_getenv(LISTEN_ADDRESS_ENV_VAR)) { - char *listen_address = (char *)vim_tempname(); - os_setenv(LISTEN_ADDRESS_ENV_VAR, listen_address, 1); - free(listen_address); + bool must_free = false; + const char *listen_address = os_getenv(LISTEN_ADDRESS_ENV_VAR); + if (listen_address == NULL || *listen_address == NUL) { + must_free = true; + listen_address = (char *)vim_tempname(); } - return server_start((char *)os_getenv(LISTEN_ADDRESS_ENV_VAR)) == 0; + bool ok = (server_start(listen_address) == 0); + if (must_free) { + xfree((char *) listen_address); + } + return ok; } -/// Teardown the server module -void server_teardown(void) +/// Retrieve the file handle from a server. +static uv_handle_t *server_handle(Server *server) { - if (!servers) { - return; - } + return server->type == kServerTypeTcp + ? (uv_handle_t *)&server->socket.tcp.handle + : (uv_handle_t *) &server->socket.pipe.handle; +} - Server *server; +/// Teardown a single server +static void server_close_cb(Server **server) +{ + uv_close(server_handle(*server), free_server); +} - map_foreach_value(servers, server, { - if (server->type == kServerTypeTcp) { - uv_close((uv_handle_t *)&server->socket.tcp.handle, free_server); - } else { - uv_close((uv_handle_t *)&server->socket.pipe.handle, free_server); - } - }); +/// Teardown the server module +void server_teardown(void) +{ + GA_DEEP_CLEAR(&servers, Server *, server_close_cb); } /// Starts listening on arbitrary tcp/unix addresses specified by @@ -106,9 +115,11 @@ int server_start(const char *endpoint) } // Check if the server already exists - if (pmap_has(cstr_t)(servers, addr)) { - ELOG("Already listening on %s", addr); - return 1; + for (int i = 0; i < servers.ga_len; i++) { + if (strcmp(addr, ((Server **)servers.ga_data)[i]->addr) == 0) { + ELOG("Already listening on %s", addr); + return 1; + } } ServerType server_type = kServerTypeTcp; @@ -154,6 +165,8 @@ int server_start(const char *endpoint) int result; uv_stream_t *stream = NULL; + xstrlcpy(server->addr, addr, sizeof(server->addr)); + if (server_type == kServerTypeTcp) { // Listen on tcp address/port uv_tcp_init(uv_default_loop(), &server->socket.tcp.handle); @@ -163,10 +176,8 @@ int server_start(const char *endpoint) stream = (uv_stream_t *)&server->socket.tcp.handle; } else { // Listen on named pipe or unix socket - xstrlcpy(server->socket.pipe.addr, addr, sizeof(server->socket.pipe.addr)); uv_pipe_init(uv_default_loop(), &server->socket.pipe.handle, 0); - result = uv_pipe_bind(&server->socket.pipe.handle, - server->socket.pipe.addr); + result = uv_pipe_bind(&server->socket.pipe.handle, server->addr); stream = (uv_stream_t *)&server->socket.pipe.handle; } @@ -193,9 +204,17 @@ int server_start(const char *endpoint) return result; } + // Update $NVIM_LISTEN_ADDRESS, if not set. + const char *listen_address = os_getenv(LISTEN_ADDRESS_ENV_VAR); + if (listen_address == NULL || *listen_address == NUL) { + os_setenv(LISTEN_ADDRESS_ENV_VAR, addr, 1); + } + server->type = server_type; - // Add the server to the hash table - pmap_put(cstr_t)(servers, addr, server); + + // Add the server to the list. + ga_grow(&servers, 1); + ((Server **)servers.ga_data)[servers.ga_len++] = server; return 0; } @@ -211,18 +230,49 @@ void server_stop(char *endpoint) // Trim to `ADDRESS_MAX_SIZE` xstrlcpy(addr, endpoint, sizeof(addr)); - if ((server = pmap_get(cstr_t)(servers, addr)) == NULL) { + int i = 0; // The index of the server whose address equals addr. + for (; i < servers.ga_len; i++) { + server = ((Server **)servers.ga_data)[i]; + if (strcmp(addr, server->addr) == 0) { + break; + } + } + + if (i == servers.ga_len) { ELOG("Not listening on %s", addr); return; } - if (server->type == kServerTypeTcp) { - uv_close((uv_handle_t *)&server->socket.tcp.handle, free_server); - } else { - uv_close((uv_handle_t *)&server->socket.pipe.handle, free_server); + // If we are invalidating the listen address, unset it. + const char *listen_address = os_getenv(LISTEN_ADDRESS_ENV_VAR); + if (listen_address && strcmp(addr, listen_address) == 0) { + os_unsetenv(LISTEN_ADDRESS_ENV_VAR); } - pmap_del(cstr_t)(servers, addr); + uv_close(server_handle(server), free_server); + + // Remove this server from the list by swapping it with the last item. + if (i != servers.ga_len - 1) { + ((Server **)servers.ga_data)[i] = + ((Server **)servers.ga_data)[servers.ga_len - 1]; + } + servers.ga_len--; +} + +/// Returns an allocated array of server addresses. +/// @param[out] size The size of the returned array. +char **server_address_list(size_t *size) + FUNC_ATTR_NONNULL_ALL +{ + if ((*size = (size_t) servers.ga_len) == 0) { + return NULL; + } + + char **addrs = xcalloc((size_t) servers.ga_len, sizeof(const char **)); + for (int i = 0; i < servers.ga_len; i++) { + addrs[i] = xstrdup(((Server **)servers.ga_data)[i]->addr); + } + return addrs; } static void connection_cb(uv_stream_t *server, int status) @@ -256,10 +306,10 @@ static void connection_cb(uv_stream_t *server, int status) static void free_client(uv_handle_t *handle) { - free(handle); + xfree(handle); } static void free_server(uv_handle_t *handle) { - free(handle->data); + xfree(handle->data); } diff --git a/src/nvim/normal.c b/src/nvim/normal.c index c210c8fe8f..0dbaf52b7e 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -914,7 +914,7 @@ getcount: && !oap->op_type && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) { clearop(oap); - set_reg_var(0); + set_reg_var(get_default_register_name()); } /* Get the length of mapped chars again after typing a count, second @@ -980,7 +980,7 @@ getcount: /* now reset it, otherwise it's put in the history again */ keep_msg = kmsg; msg_attr(kmsg, keep_msg_attr); - free(kmsg); + xfree(kmsg); } setcursor(); ui_flush(); @@ -1015,7 +1015,7 @@ normal_end: clear_showcmd(); checkpcmark(); /* check if we moved since setting pcmark */ - free(ca.searchbuf); + xfree(ca.searchbuf); if (has_mbyte) mb_adjust_cursor(); @@ -1160,7 +1160,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) else { AppendToRedobuffLit(repeat_cmdline, -1); AppendToRedobuff(NL_STR); - free(repeat_cmdline); + xfree(repeat_cmdline); repeat_cmdline = NULL; } } @@ -3342,7 +3342,7 @@ find_decl ( reset_search_dir(); } - free(pat); + xfree(pat); p_ws = save_p_ws; p_scs = save_p_scs; @@ -4261,7 +4261,7 @@ static void nv_ident(cmdarg_T *cap) } if (n == 0) { EMSG(_(e_noident)); /* found dashes only */ - free(buf); + xfree(buf); return; } @@ -4312,11 +4312,11 @@ static void nv_ident(cmdarg_T *cap) /* Escape the argument properly for a shell command */ ptr = vim_strnsave(ptr, n); p = vim_strsave_shellescape(ptr, true, true); - free(ptr); + xfree(ptr); newbuf = (char_u *)xrealloc(buf, STRLEN(buf) + STRLEN(p) + 1); buf = newbuf; STRCAT(buf, p); - free(p); + xfree(p); } else { if (cmdchar == '*') aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\"); @@ -4365,7 +4365,7 @@ static void nv_ident(cmdarg_T *cap) } else do_cmdline_cmd(buf); - free(buf); + xfree(buf); } /* @@ -4724,7 +4724,7 @@ static void nv_gotofile(cmdarg_T *cap) check_cursor_lnum(); beginline(BL_SOL | BL_FIX); } - free(ptr); + xfree(ptr); } else clearop(cap->oap); } @@ -6934,7 +6934,7 @@ static void nv_esc(cmdarg_T *cap) && cmdwin_type == 0 && !VIsual_active && no_reason) - MSG(_("Type :quit<Enter> to exit Vim")); + MSG(_("Type :quit<Enter> to exit Nvim")); /* Don't reset "restart_edit" when 'insertmode' is set, it won't be * set again below when halfway through a mapping. */ diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 5921e27282..85b1244fa3 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -79,7 +79,7 @@ static struct yankreg { } y_regs[NUM_REGISTERS]; static struct yankreg *y_current; /* ptr to current yankreg */ -static int y_append; /* TRUE when appending */ +static bool y_append; /* true when appending */ static struct yankreg *y_previous = NULL; /* ptr to last written yankreg */ static bool clipboard_didwarn_unnamed = false; @@ -278,7 +278,7 @@ shift_line ( { int count; int i, j; - int p_sw = (int)get_sw_value(curbuf); + int p_sw = get_sw_value(curbuf); count = get_indent(); /* get current indent */ @@ -321,7 +321,7 @@ static void shift_block(oparg_T *oap, int amount) int total; char_u *newp, *oldp; int oldcol = curwin->w_cursor.col; - int p_sw = (int)get_sw_value(curbuf); + int p_sw = get_sw_value(curbuf); int p_ts = (int)curbuf->b_p_ts; struct block_def bd; int incr; @@ -668,7 +668,7 @@ int get_expr_register(void) if (new_line == NULL) return NUL; if (*new_line == NUL) /* use previous line */ - free(new_line); + xfree(new_line); else set_expr_line(new_line); return '='; @@ -680,7 +680,7 @@ int get_expr_register(void) */ void set_expr_line(char_u *new_line) { - free(expr_line); + xfree(expr_line); expr_line = new_line; } @@ -709,7 +709,7 @@ char_u *get_expr_line(void) ++nested; rv = eval_to_string(expr_copy, NULL, TRUE); --nested; - free(expr_copy); + xfree(expr_copy); return rv; } @@ -773,36 +773,35 @@ typedef enum { /// Obtain the location that would be read when pasting `regname`. void get_yank_register(int regname, int mode) { - int i; + y_append = false; - y_append = FALSE; - int unnamedclip = cb_flags & CB_UNNAMEDMASK; - if ((regname == 0 || regname == '"') && !unnamedclip && mode != YREG_YANK && y_previous != NULL) { + if (mode == YREG_PASTE && get_clipboard(regname, &y_current, false)) { + // y_current is set to clipboard contents. + return; + } else if (mode != YREG_YANK && (regname == 0 || regname == '"') && y_previous != NULL) { y_current = y_previous; return; } - i = regname; - if (VIM_ISDIGIT(i)) - i -= '0'; - else if (ASCII_ISLOWER(i)) - i = CharOrdLow(i) + 10; - else if (ASCII_ISUPPER(i)) { - i = CharOrdUp(i) + 10; - y_append = TRUE; + + int i = 0; // when not 0-9, a-z, A-Z or '-'/'+'/'*': use register 0 + if (VIM_ISDIGIT(regname)) + i = regname - '0'; + else if (ASCII_ISLOWER(regname)) + i = CharOrdLow(regname) + 10; + else if (ASCII_ISUPPER(regname)) { + i = CharOrdUp(regname) + 10; + y_append = true; } else if (regname == '-') i = DELETION_REGISTER; else if (regname == '*') i = STAR_REGISTER; else if (regname == '+') i = PLUS_REGISTER; - else /* not 0-9, a-z, A-Z or '-': use register 0 */ - i = 0; y_current = &(y_regs[i]); + if (mode == YREG_YANK) { // remember the written register for unnamed paste y_previous = y_current; - } else if (mode == YREG_PASTE) { - get_clipboard(regname, &y_current, false); } } @@ -844,7 +843,7 @@ void put_register(int name, void *reg) get_yank_register(name, YREG_PUT); free_yank_all(); *y_current = *(struct yankreg *)reg; - free(reg); + xfree(reg); set_clipboard(name); } @@ -924,11 +923,11 @@ static int stuff_yank(int regname, char_u *p) { /* check for read-only register */ if (regname != 0 && !valid_yank_reg(regname, TRUE)) { - free(p); + xfree(p); return FAIL; } if (regname == '_') { /* black hole: don't do anything */ - free(p); + xfree(p); return OK; } get_yank_register(regname, YREG_YANK); @@ -938,8 +937,8 @@ static int stuff_yank(int regname, char_u *p) STRCPY(lp, *pp); // TODO(philix): use xstpcpy() in stuff_yank() STRCAT(lp, p); - free(p); - free(*pp); + xfree(p); + xfree(*pp); *pp = lp; } else { free_yank_all(); @@ -993,7 +992,7 @@ do_execreg ( EMSG(_(e_nolastcmd)); return FAIL; } - free(new_last_cmdline); /* don't keep the cmdline containing @: */ + xfree(new_last_cmdline); /* don't keep the cmdline containing @: */ new_last_cmdline = NULL; /* Escape all control characters with a CTRL-V */ p = vim_strsave_escaped_ext( @@ -1007,13 +1006,13 @@ do_execreg ( retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); else retval = put_in_typebuf(p, TRUE, TRUE, silent); - free(p); + xfree(p); } else if (regname == '=') { p = get_expr_line(); if (p == NULL) return FAIL; retval = put_in_typebuf(p, TRUE, colon, silent); - free(p); + xfree(p); } else if (regname == '.') { /* use last inserted text */ p = get_last_insert_save(); if (p == NULL) { @@ -1021,7 +1020,7 @@ do_execreg ( return FAIL; } retval = put_in_typebuf(p, FALSE, colon, silent); - free(p); + xfree(p); } else { get_yank_register(regname, YREG_PASTE); if (y_current->y_array == NULL) @@ -1045,7 +1044,7 @@ do_execreg ( } escaped = vim_strsave_escape_csi(y_current->y_array[i]); retval = ins_typebuf(escaped, remap, 0, TRUE, silent); - free(escaped); + xfree(escaped); if (retval == FAIL) return FAIL; if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) @@ -1111,7 +1110,7 @@ put_in_typebuf ( retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, 0, TRUE, silent); if (esc) - free(p); + xfree(p); } if (colon && retval == OK) retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); @@ -1155,7 +1154,7 @@ insert_reg ( return FAIL; stuffescaped(arg, literally); if (allocated) - free(arg); + xfree(arg); } else { /* name or number register */ get_yank_register(regname, YREG_PASTE); if (y_current->y_array == NULL) @@ -1805,7 +1804,7 @@ int op_replace(oparg_T *oap, int c) ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); appended_lines_mark(curwin->w_cursor.lnum, 1L); oap->end.lnum++; - free(after_p); + xfree(after_p); } } } else { @@ -2187,7 +2186,7 @@ void op_insert(oparg_T *oap, long count1) curwin->w_cursor.col = oap->start.col; check_cursor(); - free(ins_text); + xfree(ins_text); } } } @@ -2300,7 +2299,7 @@ int op_change(oparg_T *oap) } check_cursor(); changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); - free(ins_text); + xfree(ins_text); } } @@ -2342,9 +2341,9 @@ static void free_yank(long n) long i; for (i = n; --i >= 0; ) { - free(y_current->y_array[i]); + xfree(y_current->y_array[i]); } - free(y_current->y_array); + xfree(y_current->y_array); y_current->y_array = NULL; } } @@ -2508,7 +2507,7 @@ int op_yank(oparg_T *oap, int deleting, int mess) new_ptr = xmalloc(sizeof(char_u *) * (curr->y_size + y_current->y_size)); for (j = 0; j < curr->y_size; ++j) new_ptr[j] = curr->y_array[j]; - free(curr->y_array); + xfree(curr->y_array); curr->y_array = new_ptr; if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ @@ -2521,8 +2520,8 @@ int op_yank(oparg_T *oap, int deleting, int mess) + STRLEN(y_current->y_array[0]) + 1); STRCPY(pnew, curr->y_array[--j]); STRCAT(pnew, y_current->y_array[0]); - free(curr->y_array[j]); - free(y_current->y_array[0]); + xfree(curr->y_array[j]); + xfree(y_current->y_array[0]); curr->y_array[j++] = pnew; y_idx = 1; } else @@ -2530,7 +2529,7 @@ int op_yank(oparg_T *oap, int deleting, int mess) while (y_idx < y_current->y_size) curr->y_array[j++] = y_current->y_array[y_idx++]; curr->y_size = j; - free(y_current->y_array); + xfree(y_current->y_array); y_current = curr; } if (curwin->w_p_rnu) { @@ -2736,7 +2735,7 @@ do_put ( goto end; ptr = vim_strsave(get_cursor_pos_ptr()); ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); - free(ptr); + xfree(ptr); ptr = vim_strnsave(get_cursor_line_ptr(), curwin->w_cursor.col); ml_replace(curwin->w_cursor.lnum, ptr, FALSE); @@ -3050,7 +3049,7 @@ do_put ( STRCAT(newp, ptr); /* insert second line */ ml_append(lnum, newp, (colnr_T)0, FALSE); - free(newp); + xfree(newp); oldp = ml_get(lnum); newp = (char_u *) xmalloc((size_t)(col + yanklen + 1)); @@ -3155,9 +3154,9 @@ error: end: if (allocated) - free(insert_string); + xfree(insert_string); if (regname == '=') - free(y_array); + xfree(y_array); VIsual_active = FALSE; @@ -3619,9 +3618,9 @@ int do_join(long count, curwin->w_set_curswant = TRUE; theend: - free(spaces); + xfree(spaces); if (remove_comments) - free(comments); + xfree(comments); return ret; } @@ -3682,7 +3681,7 @@ static int same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, in while (vim_iswhite(line1[idx1])) ++idx1; } - free(line1); + xfree(line1); return idx2 == leader2_len && idx1 == leader1_len; } @@ -4480,7 +4479,7 @@ int do_addsub(int command, linenr_T Prenum1) *ptr = NUL; STRCAT(buf1, buf2); ins_str(buf1); /* insert the new number */ - free(buf1); + xfree(buf1); } --curwin->w_cursor.col; curwin->w_set_curswant = TRUE; @@ -4557,7 +4556,7 @@ int read_viminfo_register(vir_T *virp, int force) if (do_it) { if (size == 0) { - free(array); + xfree(array); } else if (size < limit) { y_current->y_array = xrealloc(array, size * sizeof(char_u *)); } else { @@ -5019,7 +5018,7 @@ static void str_to_reg(struct yankreg *y_ptr, int yank_type, const char_u *str, ssize_t s_len = extra + line_len; if (append) { - free(pp[lnum]); + xfree(pp[lnum]); append = false; // only first line is appended } pp[lnum] = s; @@ -5310,7 +5309,28 @@ static void free_register(struct yankreg *reg) y_current = curr; } -// return target register +/// Check if the default register (used in an unnamed paste) should be a +/// clipboard register. This happens when `clipboard=unnamed[plus]` is set +/// and a provider is available. +/// +/// @returns the name of of a clipboard register that should be used, or `NUL` if none. +int get_default_register_name(void) +{ + int name = NUL; + adjust_clipboard_name(&name, true, false); + return name; +} + +/// Determine if register `*name` should be used as a clipboard. +/// In an unnammed operation, `*name` is `NUL` and will be adjusted to `'*'/'+'` if +/// `clipboard=unnamed[plus]` is set. +/// +/// @param name The name of register, or `NUL` if unnamed. +/// @param quiet Suppress error messages +/// @param writing if we're setting the contents of the clipboard +/// +/// @returns the yankreg that should be used, or `NULL` +/// if the register isn't a clipboard or provider isn't available. static struct yankreg* adjust_clipboard_name(int *name, bool quiet, bool writing) { if (*name == '*' || *name == '+') { if(!eval_has_provider("clipboard")) { @@ -5345,11 +5365,11 @@ static struct yankreg* adjust_clipboard_name(int *name, bool quiet, bool writing return NULL; } -static void get_clipboard(int name, struct yankreg** target, bool quiet) +static bool get_clipboard(int name, struct yankreg** target, bool quiet) { struct yankreg* reg = adjust_clipboard_name(&name, quiet, false); if (reg == NULL) { - return; + return false; } free_register(reg); @@ -5410,7 +5430,7 @@ static void get_clipboard(int name, struct yankreg** target, bool quiet) // a known-to-be charwise yank might have a final linebreak // but otherwise there is no line after the final newline if (reg->y_type != MCHAR) { - free(reg->y_array[reg->y_size-1]); + xfree(reg->y_array[reg->y_size-1]); reg->y_size--; if (reg->y_type == MAUTO) { reg->y_type = MLINE; @@ -5434,18 +5454,20 @@ static void get_clipboard(int name, struct yankreg** target, bool quiet) } *target = reg; - return; + return true; err: if (reg->y_array) { for (int i = 0; i < reg->y_size; i++) { - free(reg->y_array[i]); + xfree(reg->y_array[i]); } - free(reg->y_array); + xfree(reg->y_array); } reg->y_array = NULL; reg->y_size = 0; EMSG("clipboard: provider returned invalid data"); + *target = reg; + return false; } static void set_clipboard(int name) diff --git a/src/nvim/option.c b/src/nvim/option.c index 2d016d8350..23a23a0814 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -363,13 +363,14 @@ typedef struct vimoption { # define ISP_LATIN1 (char_u *)"@,161-255" #define HIGHLIGHT_INIT \ - "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch," \ - "l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine," \ - "S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg," \ - "W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete," \ - "T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare," \ - "L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine," \ - "#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn" + "8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \ + "d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr," \ + "N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title," \ + "v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn," \ + "A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal," \ + "B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel," \ + "x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill," \ + "!:CursorColumn,.:CursorLine,o:ColorColumn" /* * options[] is initialized here. @@ -1826,11 +1827,11 @@ void set_init_1(void) ga.ga_len += len; } if (mustfree) - free(p); + xfree(p); } if (ga.ga_data != NULL) { set_string_default("bsk", ga.ga_data); - free(ga.ga_data); + xfree(ga.ga_data); } } @@ -1884,10 +1885,10 @@ void set_init_1(void) options[opt_idx].def_val[VI_DEFAULT] = buf; options[opt_idx].flags |= P_DEF_ALLOCED; } else - free(buf); /* cannot happen */ + xfree(buf); /* cannot happen */ } if (mustfree) - free(cdpath); + xfree(cdpath); } } @@ -1957,7 +1958,7 @@ void set_init_1(void) * split P_DEF_ALLOCED in two. */ if (options[opt_idx].flags & P_DEF_ALLOCED) - free(options[opt_idx].def_val[VI_DEFAULT]); + xfree(options[opt_idx].def_val[VI_DEFAULT]); options[opt_idx].def_val[VI_DEFAULT] = p; options[opt_idx].flags |= P_DEF_ALLOCED; } @@ -1997,7 +1998,7 @@ void set_init_1(void) * for practical purposes, thus use that. It's not an alias to * still support conversion between gb18030 and utf-8. */ p_enc = vim_strsave((char_u *)"cp936"); - free(p); + xfree(p); } if (mb_init() == NULL) { opt_idx = findoption((char_u *)"encoding"); @@ -2027,7 +2028,7 @@ void set_init_1(void) #endif } else { - free(p_enc); + xfree(p_enc); // mb_init() failed; fallback to utf8 and try again. p_enc = save_enc; mb_init(); @@ -2135,7 +2136,7 @@ void set_string_default(const char *name, const char_u *val) int opt_idx = findoption((char_u *)name); if (opt_idx >= 0) { if (options[opt_idx].flags & P_DEF_ALLOCED) { - free(options[opt_idx].def_val[VI_DEFAULT]); + xfree(options[opt_idx].def_val[VI_DEFAULT]); } options[opt_idx].def_val[VI_DEFAULT] = (char_u *) xstrdup((char *) val); @@ -2275,7 +2276,7 @@ void set_init_3(void) options[idx_srr].def_val[VI_DEFAULT] = p_srr; } } - free(p); + xfree(p); } #endif @@ -2781,7 +2782,7 @@ do_set ( (char_u *)"indent,eol,start"); break; } - free(oldval); + xfree(oldval); oldval = *(char_u **)varp; } /* @@ -2878,7 +2879,7 @@ do_set ( || (flags & P_COMMA)) { s = option_expand(opt_idx, newval); if (s != NULL) { - free(newval); + xfree(newval); newlen = (unsigned)STRLEN(s) + 1; if (adding || prepending || removing) newlen += (unsigned)STRLEN(origval) + 1; @@ -3372,13 +3373,13 @@ void check_buf_options(buf_T *buf) void free_string_option(char_u *p) { if (p != empty_option) - free(p); + xfree(p); } void clear_string_option(char_u **pp) { if (*pp != empty_option) - free(*pp); + xfree(*pp); *pp = empty_option; } @@ -3767,7 +3768,7 @@ did_set_string_option ( if (errmsg == NULL) { /* canonize the value, so that STRCMP() can be used on it */ p = enc_canonize(*varp); - free(*varp); + xfree(*varp); *varp = p; if (varp == &p_enc) { errmsg = mb_init(); @@ -3794,7 +3795,7 @@ did_set_string_option ( } else if (varp == &p_penc) { /* Canonize printencoding if VIM standard one */ p = enc_canonize(p_penc); - free(p_penc); + xfree(p_penc); p_penc = p; } else if (varp == &curbuf->b_p_keymap) { /* load or unload key mapping tables */ @@ -4455,7 +4456,7 @@ skip: return e_invarg; /* illegal trailing comma as in "set cc=80," */ } - free(wp->w_p_cc_cols); + xfree(wp->w_p_cc_cols); if (count == 0) wp->w_p_cc_cols = NULL; else { @@ -4648,7 +4649,7 @@ static char_u *compile_cap_prog(synblock_T *synblock) /* Prepend a ^ so that we only match at one column */ re = concat_str((char_u *)"^", synblock->b_p_spc); synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC); - free(re); + xfree(re); if (synblock->b_cap_prog == NULL) { synblock->b_cap_prog = rp; /* restore the previous program */ return e_invarg; @@ -5929,7 +5930,7 @@ showoptions ( os_breakcheck(); } } - free(items); + xfree(items); } /* @@ -6156,10 +6157,10 @@ static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int e buf = xmalloc(MAXPATHL); home_replace(NULL, *valuep, buf, MAXPATHL, FALSE); if (put_escstr(fd, buf, 2) == FAIL) { - free(buf); + xfree(buf); return FAIL; } - free(buf); + xfree(buf); } else if (put_escstr(fd, *valuep, 2) == FAIL) return FAIL; } @@ -7437,10 +7438,10 @@ void vimrc_found(char_u *fname, char_u *envname) p = FullName_save(fname, FALSE); if (p != NULL) { vim_setenv(envname, p); - free(p); + xfree(p); } } else if (dofree) - free(p); + xfree(p); } } @@ -7607,7 +7608,7 @@ void save_file_ff(buf_T *buf) /* Only use free/alloc when necessary, they take time. */ if (buf->b_start_fenc == NULL || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { - free(buf->b_start_fenc); + xfree(buf->b_start_fenc); buf->b_start_fenc = vim_strsave(buf->b_p_fenc); } } @@ -7653,18 +7654,22 @@ int check_ff_value(char_u *p) * Return the effective shiftwidth value for current buffer, using the * 'tabstop' value when 'shiftwidth' is zero. */ -long get_sw_value(buf_T *buf) +int get_sw_value(buf_T *buf) { - return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts; + long result = buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts; + assert(result >= 0 && result <= INT_MAX); + return (int)result; } /* * Return the effective softtabstop value for the current buffer, using the * 'tabstop' value when 'softtabstop' is negative. */ -long get_sts_value(void) +int get_sts_value(void) { - return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts; + long result = curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts; + assert(result >= 0 && result <= INT_MAX); + return (int)result; } /* diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 30e44341a9..be4b22de3a 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -37,6 +37,19 @@ int os_setenv(const char *name, const char *value, int overwrite) return setenv(name, value, overwrite); } +/// Unset environment variable +/// +/// For systems where unsetenv() is not available the value will be set as an +/// empty string +int os_unsetenv(const char *name) +{ +#ifdef HAVE_UNSETENV + return unsetenv(name); +#else + return os_setenv(name, "", 1); +#endif +} + char *os_getenvname_at_index(size_t index) { # if defined(HAVE__NSGETENVIRON) @@ -113,7 +126,7 @@ void init_homedir(void) char_u *var; /* In case we are called a second time (when 'encoding' changes). */ - free(homedir); + xfree(homedir); homedir = NULL; var = (char_u *)os_getenv("HOME"); @@ -144,7 +157,7 @@ void init_homedir(void) void free_homedir(void) { - free(homedir); + xfree(homedir); } #endif @@ -304,7 +317,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, char_u *p = vim_strsave(var); if (mustfree) { - free(var); + xfree(var); } var = p; mustfree = true; @@ -318,7 +331,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, char_u *p = vim_strsave_escaped(var, (char_u *)" \t"); if (mustfree) - free(var); + xfree(var); var = p; mustfree = true; } @@ -341,7 +354,7 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, copy_char = false; } if (mustfree) - free(var); + xfree(var); } if (copy_char) { /* copy at least one char */ @@ -371,33 +384,33 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, /// Check if the directory "vimdir/<version>" or "vimdir/runtime" exists. /// Return NULL if not, return its name in allocated memory otherwise. /// @param vimdir directory to test -static char_u *vim_version_dir(char_u *vimdir) +static char *vim_version_dir(char *vimdir) { char_u *p; if (vimdir == NULL || *vimdir == NUL) return NULL; - p = concat_fnames(vimdir, (char_u *)VIM_VERSION_NODOT, true); + p = concat_fnames((char_u *)vimdir, (char_u *)VIM_VERSION_NODOT, true); if (os_isdir(p)) - return p; - free(p); - p = concat_fnames(vimdir, (char_u *)RUNTIME_DIRNAME, true); + return (char *)p; + xfree(p); + p = concat_fnames((char_u *)vimdir, (char_u *)RUNTIME_DIRNAME, true); if (os_isdir(p)) - return p; - free(p); + return (char *)p; + xfree(p); return NULL; } /// If the string between "p" and "pend" ends in "name/", return "pend" minus /// the length of "name/". Otherwise return "pend". -static char_u *remove_tail(char_u *p, char_u *pend, char_u *name) +static char *remove_tail(char *p, char *pend, char *name) { - int len = (int)STRLEN(name) + 1; - char_u *newend = pend - len; + size_t len = STRLEN(name) + 1; + char *newend = pend - len; if (newend >= p - && fnamencmp(newend, name, len - 1) == 0 - && (newend == p || after_pathsep(p, newend))) + && fnamencmp((char_u *)newend, (char_u *)name, len - 1) == 0 + && (newend == p || after_pathsep((char_u *)p, (char_u *)newend))) return newend; return pend; } @@ -442,7 +455,7 @@ char_u *vim_getenv(char_u *name, bool *mustfree) if (p != NULL && *p == NUL) /* empty is the same as not set */ p = NULL; if (p != NULL) { - p = vim_version_dir(p); + p = (char_u *)vim_version_dir((char *)p); if (p != NULL) *mustfree = true; else @@ -464,12 +477,14 @@ char_u *vim_getenv(char_u *name, bool *mustfree) /* remove "doc/" from 'helpfile', if present */ if (p == p_hf) - pend = remove_tail(p, pend, (char_u *)"doc"); + pend = (char_u *)remove_tail((char *)p, (char *)pend, "doc"); /* for $VIM, remove "runtime/" or "vim54/", if present */ if (!vimruntime) { - pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME); - pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT); + pend = (char_u *)remove_tail((char *)p, (char *)pend, + RUNTIME_DIRNAME); + pend = (char_u *)remove_tail((char *)p, (char *)pend, + VIM_VERSION_NODOT); } /* remove trailing path separator */ @@ -481,7 +496,7 @@ char_u *vim_getenv(char_u *name, bool *mustfree) p = vim_strnsave(p, (size_t)(pend - p)); if (!os_isdir(p)) { - free(p); + xfree(p); p = NULL; } else { *mustfree = true; @@ -495,13 +510,14 @@ char_u *vim_getenv(char_u *name, bool *mustfree) if (p == NULL) { /* Only use default_vimruntime_dir when it is not empty */ if (vimruntime && *default_vimruntime_dir != NUL) { - p = default_vimruntime_dir; + p = (char_u *)default_vimruntime_dir; *mustfree = false; } else if (*default_vim_dir != NUL) { - if (vimruntime && (p = vim_version_dir(default_vim_dir)) != NULL) { + if (vimruntime + && (p = (char_u *)vim_version_dir(default_vim_dir)) != NULL) { *mustfree = true; } else { - p = default_vim_dir; + p = (char_u *)default_vim_dir; *mustfree = false; } } @@ -631,7 +647,7 @@ void home_replace(buf_T *buf, char_u *src, char_u *dst, int dstlen, bool one) *dst = NUL; if (homedir_env != homedir_env_orig) - free(homedir_env); + xfree(homedir_env); } /// Like home_replace, store the replaced string in allocated memory. @@ -660,7 +676,7 @@ void vim_setenv(char_u *name, char_u *val) if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0) { char_u *buf = concat_str(val, (char_u *)"/lang"); bindtextdomain(VIMPACKAGE, (char *)buf); - free(buf); + xfree(buf); } } @@ -675,7 +691,7 @@ char_u *get_env_name(expand_T *xp, int idx) char *envname = os_getenvname_at_index((size_t)idx); if (envname) { STRLCPY(name, envname, ENVNAMELEN); - free(envname); + xfree(envname); return name; } else { return NULL; diff --git a/src/nvim/os/event.c b/src/nvim/os/event.c index fd9ff5b230..0560da1e2e 100644 --- a/src/nvim/os/event.c +++ b/src/nvim/os/event.c @@ -28,12 +28,6 @@ #define _destroy_event(x) // do nothing KLIST_INIT(Event, Event, _destroy_event) -typedef struct { - bool timed_out; - int ms; - uv_timer_t *timer; -} TimerData; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/event.c.generated.h" #endif @@ -52,7 +46,6 @@ void event_init(void) // early msgpack-rpc initialization msgpack_rpc_init_method_table(); msgpack_rpc_helpers_init(); - wstream_init(); // Initialize input events input_init(); // Timer to wake the event loop if a timeout argument is passed to @@ -107,19 +100,12 @@ void event_poll(int ms) uv_run_mode run_mode = UV_RUN_ONCE; uv_timer_t timer; - uv_prepare_t timer_prepare; - TimerData timer_data = {.ms = ms, .timed_out = false, .timer = &timer}; if (ms > 0) { uv_timer_init(uv_default_loop(), &timer); - // This prepare handle that actually starts the timer - uv_prepare_init(uv_default_loop(), &timer_prepare); - // Timeout passed as argument to the timer - timer.data = &timer_data; - // We only start the timer after the loop is running, for that we - // use a prepare handle(pass the interval as data to it) - timer_prepare.data = &timer_data; - uv_prepare_start(&timer_prepare, timer_prepare_cb); + // Use a repeating timeout of ms milliseconds to make sure + // we do not block indefinitely for I/O. + uv_timer_start(&timer, timer_cb, (uint64_t)ms, (uint64_t)ms); } else if (ms == 0) { // For ms == 0, we need to do a non-blocking event poll by // setting the run mode to UV_RUN_NOWAIT. @@ -129,17 +115,19 @@ void event_poll(int ms) loop(run_mode); if (ms > 0) { - // Ensure the timer-related handles are closed and run the event loop + // Ensure the timer handle is closed and run the event loop // once more to let libuv perform it's cleanup uv_timer_stop(&timer); - uv_prepare_stop(&timer_prepare); uv_close((uv_handle_t *)&timer, NULL); - uv_close((uv_handle_t *)&timer_prepare, NULL); loop(UV_RUN_NOWAIT); } recursive--; // Can re-enter uv_run now - process_events_from(immediate_events); + + // In case this is run before event_init, don't process any events. + if (immediate_events) { + process_events_from(immediate_events); + } } bool event_has_deferred(void) @@ -183,19 +171,8 @@ static void process_events_from(klist_t(Event) *queue) } } -// Set a flag in the `event_poll` loop for signaling of a timeout static void timer_cb(uv_timer_t *handle) { - TimerData *data = handle->data; - data->timed_out = true; -} - -static void timer_prepare_cb(uv_prepare_t *handle) -{ - TimerData *data = handle->data; - assert(data->ms > 0); - uv_timer_start(data->timer, timer_cb, (uint32_t)data->ms, 0); - uv_prepare_stop(handle); } static void loop(uv_run_mode run_mode) diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d583323b1f..2a41001cde 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -152,14 +152,14 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath) *abspath = save_absolute_path(buf); } - free(buf); + xfree(buf); return true; } if (*e != ':') { // End of $PATH without finding any executable called name. - free(buf); + xfree(buf); return false; } diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index a409a9ed13..8002d528ed 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -128,7 +128,9 @@ bool os_char_avail(void) // Check for CTRL-C typed by reading all available characters. void os_breakcheck(void) { - event_poll(0); + if (!disable_breakcheck && !got_int) { + event_poll(0); + } } /// Test whether a file descriptor refers to a terminal. diff --git a/src/nvim/os/job_private.h b/src/nvim/os/job_private.h index af13d2e636..983106d918 100644 --- a/src/nvim/os/job_private.h +++ b/src/nvim/os/job_private.h @@ -11,6 +11,7 @@ #include "nvim/os/pty_process.h" #include "nvim/os/shell.h" #include "nvim/log.h" +#include "nvim/memory.h" struct job { // Job id the index in the job table plus one. @@ -104,12 +105,12 @@ static inline void job_decref(Job *job) // Invoke the exit_cb job_exit_callback(job); // Free all memory allocated for the job - free(job->proc_stdin->data); - free(job->proc_stdout->data); - free(job->proc_stderr->data); + xfree(job->proc_stdin->data); + xfree(job->proc_stdout->data); + xfree(job->proc_stderr->data); shell_free_argv(job->opts.argv); process_destroy(job); - free(job); + xfree(job); } } diff --git a/src/nvim/os/pipe_process.c b/src/nvim/os/pipe_process.c index 5535c3fe93..2ac305e967 100644 --- a/src/nvim/os/pipe_process.c +++ b/src/nvim/os/pipe_process.c @@ -72,8 +72,8 @@ void pipe_process_init(Job *job) void pipe_process_destroy(Job *job) { UvProcess *pipeproc = job->process; - free(pipeproc->proc.data); - free(pipeproc); + xfree(pipeproc->proc.data); + xfree(pipeproc); job->process = NULL; } diff --git a/src/nvim/os/pty_process.c b/src/nvim/os/pty_process.c index 9a2721f769..c64f3f9932 100644 --- a/src/nvim/os/pty_process.c +++ b/src/nvim/os/pty_process.c @@ -65,8 +65,8 @@ void pty_process_init(Job *job) FUNC_ATTR_NONNULL_ALL void pty_process_destroy(Job *job) FUNC_ATTR_NONNULL_ALL { - free(job->opts.term_name); - free(job->process); + xfree(job->opts.term_name); + xfree(job->process); job->process = NULL; } diff --git a/src/nvim/os/rstream.c b/src/nvim/os/rstream.c index 29b8a5a9e1..702f282d53 100644 --- a/src/nvim/os/rstream.c +++ b/src/nvim/os/rstream.c @@ -162,8 +162,8 @@ size_t rbuffer_available(RBuffer *rbuffer) void rbuffer_free(RBuffer *rbuffer) { - free(rbuffer->data); - free(rbuffer); + xfree(rbuffer->data); + xfree(rbuffer); } /// Creates a new RStream instance. A RStream encapsulates all the boilerplate @@ -216,7 +216,7 @@ void rstream_free(RStream *rstream) } rbuffer_free(rstream->buffer); - free(rstream); + xfree(rstream); } /// Sets the underlying `uv_stream_t` instance @@ -401,8 +401,8 @@ static void fread_idle_cb(uv_idle_t *handle) static void close_cb(uv_handle_t *handle) { - free(handle->data); - free(handle); + xfree(handle->data); + xfree(handle); } static void rbuffer_relocate(RBuffer *rbuffer) diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 6fcb62a5f3..4f5928ba8a 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -80,11 +80,11 @@ void shell_free_argv(char **argv) while (*p != NULL) { // Free each argument - free(*p); + xfree(*p); p++; } - free(argv); + xfree(argv); } /// Calls the user-configured 'shell' (p_sh) for running a command or wildcard @@ -128,11 +128,11 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_args) emsg_silent, forward_output); - free(input.data); + xfree(input.data); if (output) { (void)write_output(output, nread, true, true); - free(output); + xfree(output); } if (!emsg_silent && status != 0 && !(opts & kShellOptSilent)) { @@ -250,7 +250,7 @@ static int shell(const char *cmd, if (buf.len == 0) { // no data received from the process, return NULL *output = NULL; - free(buf.data); + xfree(buf.data); } else { // NUL-terminate to make the output directly usable as a C string buf.data[buf.len] = NUL; diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index a332ad2314..f824543003 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -1,9 +1,8 @@ +#include <assert.h> #include <stdbool.h> #include <uv.h> -#include "nvim/lib/klist.h" - #include "nvim/ascii.h" #include "nvim/vim.h" #include "nvim/globals.h" @@ -15,10 +14,6 @@ #include "nvim/os/signal.h" #include "nvim/os/event.h" -#define SignalEventFreer(x) -KMEMPOOL_INIT(SignalEventPool, int, SignalEventFreer) -kmempool_t(SignalEventPool) *signal_event_pool = NULL; - static uv_signal_t spipe, shup, squit, sterm; #ifdef SIGPWR static uv_signal_t spwr; @@ -32,7 +27,6 @@ static bool rejecting_deadly; void signal_init(void) { - signal_event_pool = kmp_init(SignalEventPool); uv_signal_init(uv_default_loop(), &spipe); uv_signal_init(uv_default_loop(), &shup); uv_signal_init(uv_default_loop(), &squit); @@ -119,18 +113,16 @@ static void deadly_signal(int signum) static void signal_cb(uv_signal_t *handle, int signum) { - int *n = kmp_alloc(SignalEventPool, signal_event_pool); - *n = signum; + assert(signum >= 0); event_push((Event) { .handler = on_signal_event, - .data = n + .data = (void *)(uintptr_t)signum }, false); } static void on_signal_event(Event event) { - int signum = *((int *)event.data); - kmp_free(SignalEventPool, signal_event_pool, event.data); + int signum = (int)(uintptr_t)event.data; switch (signum) { #ifdef SIGPWR diff --git a/src/nvim/os/wstream.c b/src/nvim/os/wstream.c index 13c6c0429f..73896c381d 100644 --- a/src/nvim/os/wstream.c +++ b/src/nvim/os/wstream.c @@ -5,8 +5,6 @@ #include <uv.h> -#include "nvim/lib/klist.h" - #include "nvim/os/uv_helpers.h" #include "nvim/os/wstream.h" #include "nvim/os/wstream_defs.h" @@ -41,24 +39,10 @@ typedef struct { uv_write_t uv_req; } WRequest; -#define WRequestFreer(x) -KMEMPOOL_INIT(WRequestPool, WRequest, WRequestFreer) -kmempool_t(WRequestPool) *wrequest_pool = NULL; -#define WBufferFreer(x) -KMEMPOOL_INIT(WBufferPool, WBuffer, WBufferFreer) -kmempool_t(WBufferPool) *wbuffer_pool = NULL; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/wstream.c.generated.h" #endif -/// Initialize pools for reusing commonly created objects -void wstream_init(void) -{ - wrequest_pool = kmp_init(WRequestPool); - wbuffer_pool = kmp_init(WBufferPool); -} - /// Creates a new WStream instance. A WStream encapsulates all the boilerplate /// necessary for writing to a libuv stream. /// @@ -92,7 +76,7 @@ void wstream_free(WStream *wstream) { uv_close((uv_handle_t *)wstream->stream, close_cb); } else { handle_set_wstream((uv_handle_t *)wstream->stream, NULL); - free(wstream); + xfree(wstream); } } else { wstream->freed = true; @@ -163,7 +147,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer) wstream->curmem += buffer->size; - WRequest *data = kmp_alloc(WRequestPool, wrequest_pool); + WRequest *data = xmalloc(sizeof(WRequest)); data->wstream = wstream; data->buffer = buffer; data->uv_req.data = data; @@ -173,7 +157,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer) uvbuf.len = buffer->size; if (uv_write(&data->uv_req, wstream->stream, &uvbuf, 1, write_cb)) { - kmp_free(WRequestPool, wrequest_pool, data); + xfree(data); goto err; } @@ -202,7 +186,7 @@ WBuffer *wstream_new_buffer(char *data, size_t refcount, wbuffer_data_finalizer cb) { - WBuffer *rv = kmp_alloc(WBufferPool, wbuffer_pool); + WBuffer *rv = xmalloc(sizeof(WBuffer)); rv->size = size; rv->refcount = refcount; rv->cb = cb; @@ -232,11 +216,11 @@ static void write_cb(uv_write_t *req, int status) if (data->wstream->free_handle) { uv_close((uv_handle_t *)data->wstream->stream, close_cb); } else { - free(data->wstream); + xfree(data->wstream); } } - kmp_free(WRequestPool, wrequest_pool, data); + xfree(data); } void wstream_release_wbuffer(WBuffer *buffer) @@ -246,14 +230,14 @@ void wstream_release_wbuffer(WBuffer *buffer) buffer->cb(buffer->data); } - kmp_free(WBufferPool, wbuffer_pool, buffer); + xfree(buffer); } } static void close_cb(uv_handle_t *handle) { - free(handle_get_wstream(handle)); - free(handle->data); - free(handle); + xfree(handle_get_wstream(handle)); + xfree(handle->data); + xfree(handle); } diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index 26a4cdb083..e69b5ccc27 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -435,11 +435,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, if (ampersent) os_delay(10L, true); - free(command); + xfree(command); if (i) { /* os_call_shell() failed */ os_remove((char *)tempname); - free(tempname); + xfree(tempname); /* * With interactive completion, the error message is not printed. */ @@ -472,18 +472,18 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, MSG(_(e_wildexpand)); msg_start(); /* don't overwrite this message */ } - free(tempname); + xfree(tempname); goto notfound; } int fseek_res = fseek(fd, 0L, SEEK_END); if (fseek_res < 0) { - free(tempname); + xfree(tempname); fclose(fd); return FAIL; } long long templen = ftell(fd); /* get size of temp file */ if (templen < 0) { - free(tempname); + xfree(tempname); fclose(fd); return FAIL; } @@ -501,11 +501,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, if (readlen != len) { /* unexpected read error */ EMSG2(_(e_notread), tempname); - free(tempname); - free(buffer); + xfree(tempname); + xfree(buffer); return FAIL; } - free(tempname); + xfree(tempname); /* file names are separated with Space */ if (shell_style == STYLE_ECHO) { @@ -574,7 +574,7 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, * /bin/sh will happily expand it to nothing rather than returning an * error; and hey, it's good to check anyway -- webb. */ - free(buffer); + xfree(buffer); goto notfound; } *num_file = i; @@ -628,11 +628,11 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file, add_pathsep(p); /* add '/' to a directory name */ (*file)[j++] = p; } - free(buffer); + xfree(buffer); *num_file = j; if (*num_file == 0) { /* rejected all entries */ - free(*file); + xfree(*file); *file = NULL; goto notfound; } diff --git a/src/nvim/path.c b/src/nvim/path.c index 9515205643..36d550b764 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -83,15 +83,12 @@ FileComparison path_full_compare(char_u *s1, char_u *s2, int checkname) return kDifferentFiles; } -/// Get the tail of a path: the file name. +/// Gets the tail (i.e., the filename segment) of a path `fname`. /// -/// @param fname A file path. -/// @return -/// - Empty string, if fname is NULL. -/// - The position of the last path separator + 1. (i.e. empty string, if -/// fname ends in a slash). -/// - Never NULL. +/// @return pointer just past the last path separator (empty string, if fname +/// ends in a slash), or empty string if fname is NULL. char_u *path_tail(char_u *fname) + FUNC_ATTR_NONNULL_RET { if (fname == NULL) { return (char_u *)""; @@ -383,7 +380,7 @@ FullName_save ( } else { new_fname = vim_strsave(fname); } - free(buf); + xfree(buf); return new_fname; } @@ -560,7 +557,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, starts_with_dot = (*s == '.'); pat = file_pat_to_reg_pat(s, e, NULL, FALSE); if (pat == NULL) { - free(buf); + xfree(buf); return 0; } @@ -577,10 +574,10 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, regmatch.regprog = vim_regcomp(pat, RE_MAGIC); if (flags & (EW_NOERROR | EW_NOTWILD)) --emsg_silent; - free(pat); + xfree(pat); if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0) { - free(buf); + xfree(buf); return 0; } @@ -637,7 +634,7 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, os_closedir(&dir); } - free(buf); + xfree(buf); vim_regfree(regmatch.regprog); matches = gap->ga_len - start_len; @@ -753,7 +750,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap) GA_APPEND(char_u *, gap, vim_strsave(buf)); } - free(buf); + xfree(buf); } /* @@ -822,13 +819,13 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) file_pattern[1] = NUL; STRCAT(file_pattern, pattern); pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, TRUE); - free(file_pattern); + xfree(file_pattern); if (pat == NULL) return; regmatch.rm_ic = TRUE; /* always ignore case */ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); - free(pat); + xfree(pat); if (regmatch.regprog == NULL) return; @@ -913,16 +910,16 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern) add_pathsep(rel_path); STRCAT(rel_path, short_name); - free(fnames[i]); + xfree(fnames[i]); fnames[i] = rel_path; sort_again = TRUE; os_breakcheck(); } - free(curdir); + xfree(curdir); for (int i = 0; i < gap->ga_len; i++) - free(in_curdir[i]); - free(in_curdir); + xfree(in_curdir[i]); + xfree(in_curdir); ga_clear_strings(&path_ga); vim_regfree(regmatch.regprog); @@ -981,7 +978,7 @@ expand_in_path ( ga_init(&path_ga, (int)sizeof(char_u *), 1); expand_path_option(curdir, &path_ga); - free(curdir); + xfree(curdir); if (GA_EMPTY(&path_ga)) return 0; @@ -989,7 +986,7 @@ expand_in_path ( ga_clear_strings(&path_ga); globpath(paths, pattern, gap, (flags & EW_ICASE) ? WILD_ICASE : 0); - free(paths); + xfree(paths); return gap->ga_len; } @@ -1113,7 +1110,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, * found file names and start all over again. */ else if (has_env_var(p) || *p == '~') { - free(p); + xfree(p); ga_clear_strings(&ga); i = mch_expand_wildcards(num_pat, pat, num_file, file, flags | EW_KEEPDOLLAR); @@ -1157,13 +1154,13 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, addfile(&ga, t, flags | EW_DIR | EW_FILE); else if (os_file_exists(t)) addfile(&ga, t, flags); - free(t); + xfree(t); } if (did_expand_in_path && !GA_EMPTY(&ga) && (flags & EW_PATH)) uniquefy_paths(&ga, p); if (p != pat[i]) - free(p); + xfree(p); } *num_file = ga.ga_len; @@ -1209,7 +1206,7 @@ expand_backtick ( else buffer = get_cmd_output(cmd, NULL, (flags & EW_SILENT) ? kShellOptSilent : 0, NULL); - free(cmd); + xfree(cmd); if (buffer == NULL) return 0; @@ -1232,7 +1229,7 @@ expand_backtick ( ++cmd; } - free(buffer); + xfree(buffer); return cnt; } @@ -1512,13 +1509,13 @@ find_file_name_in_path ( /* Repeat finding the file "count" times. This matters when it * appears several times in the path. */ while (file_name != NULL && --count > 0) { - free(file_name); + xfree(file_name); file_name = find_file_in_path(ptr, len, options, FALSE, rel_fname); } } else file_name = vim_strnsave(ptr, len); - free(tofree); + xfree(tofree); return file_name; } @@ -1796,7 +1793,7 @@ char_u *path_shorten_fname_if_possible(char_u *full_path) p = full_path; } } - free(dirname); + xfree(dirname); return p; } @@ -1857,8 +1854,8 @@ int expand_wildcards_eval(char_u **pat, int *num_file, char_u ***file, ret = expand_wildcards(1, &exp_pat, num_file, file, flags); if (eval_pat != NULL) { - free(exp_pat); - free(eval_pat); + xfree(exp_pat); + xfree(eval_pat); } return ret; @@ -1906,13 +1903,13 @@ int expand_wildcards(int num_pat, char_u **pat, int *num_file, char_u ***file, break; if (match_file_list(p_wig, (*file)[i], ffname)) { /* remove this matching file from the list */ - free((*file)[i]); + xfree((*file)[i]); for (j = i; j + 1 < *num_file; ++j) (*file)[j] = (*file)[j + 1]; --*num_file; --i; } - free(ffname); + xfree(ffname); } } diff --git a/src/nvim/po/af.po b/src/nvim/po/af.po index b0bd5356d5..6bb93b9e02 100644 --- a/src/nvim/po/af.po +++ b/src/nvim/po/af.po @@ -1625,7 +1625,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Gebruik w of w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Jammer, die bevel is nie geïmplementeer nie" #: ../ex_docmd.c:3752 @@ -2114,7 +2114,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: '*ReadPre' outobevele mag nie die huidige buffer verander nie" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Lees nou vanaf 'stdin'...\n" #. Re-opening the original file failed! @@ -2761,7 +2761,7 @@ msgid "E477: No ! allowed" msgstr "E477: Geen ! toegelaat nie" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI kan nie gebruik word nie: Nie tydens kompilering gekies nie" #: ../globals.h:1036 @@ -4458,7 +4458,7 @@ msgid "E663: At end of changelist" msgstr "E663: By die einde van die veranderingslys" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Tik :quit<Enter> om Vim te verlaat" # Het te doen met < en > diff --git a/src/nvim/po/ca.po b/src/nvim/po/ca.po index 8d0a11ad41..79434cfdcd 100644 --- a/src/nvim/po/ca.po +++ b/src/nvim/po/ca.po @@ -1612,7 +1612,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Useu w o bé w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Aquesta ordre no està disponible en aquesta versió" #: ../ex_docmd.c:3752 @@ -2101,7 +2101,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Les auto-ordres *ReadPre no poden canviar el buffer actual" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Llegint l'entrada estàndard...\n" #. Re-opening the original file failed! @@ -2756,7 +2756,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! no permès" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: No es pot usar la GUI: No ha estat compilada" #: ../globals.h:1036 @@ -4447,7 +4447,7 @@ msgstr "E663: A l'inici de la llista de canvis" # amplada 53 caràcters #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Feu :quit<Entrar> per sortir" #: ../ops.c:248 diff --git a/src/nvim/po/cs.cp1250.po b/src/nvim/po/cs.cp1250.po index 4826303f14..1e62034317 100644 --- a/src/nvim/po/cs.cp1250.po +++ b/src/nvim/po/cs.cp1250.po @@ -1633,7 +1633,7 @@ msgid "E494: Use w or w>>" msgstr "Použijte w èi w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Pøíkaz není této verzi bohužel implementován" #: ../ex_docmd.c:3752 @@ -2137,7 +2137,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre automatické pøíkazy nesmí mìnit aktuální buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Ètu ze standardního vstupu...\n" #. Re-opening the original file failed! @@ -2803,7 +2803,7 @@ msgid "E477: No ! allowed" msgstr "! není povoleno" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Nelze použít GUI: nebylo zapnuto pøi pøekladu programu" #: ../globals.h:1036 @@ -4533,7 +4533,7 @@ msgstr "" #: ../normal.c:7053 #, fuzzy -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "zadejte :q<Enter> pro ukonèení programu" #: ../ops.c:248 diff --git a/src/nvim/po/cs.po b/src/nvim/po/cs.po index 93ec04e6b8..dd7016fedb 100644 --- a/src/nvim/po/cs.po +++ b/src/nvim/po/cs.po @@ -1633,7 +1633,7 @@ msgid "E494: Use w or w>>" msgstr "Pou¾ijte w èi w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Pøíkaz není této verzi bohu¾el implementován" #: ../ex_docmd.c:3752 @@ -2137,7 +2137,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre automatické pøíkazy nesmí mìnit aktuální buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Ètu ze standardního vstupu...\n" #. Re-opening the original file failed! @@ -2803,7 +2803,7 @@ msgid "E477: No ! allowed" msgstr "! není povoleno" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Nelze pou¾ít GUI: nebylo zapnuto pøi pøekladu programu" #: ../globals.h:1036 @@ -4533,7 +4533,7 @@ msgstr "" #: ../normal.c:7053 #, fuzzy -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "zadejte :q<Enter> pro ukonèení programu" #: ../ops.c:248 diff --git a/src/nvim/po/de.po b/src/nvim/po/de.po index ed696eeb13..4950533a21 100644 --- a/src/nvim/po/de.po +++ b/src/nvim/po/de.po @@ -1040,7 +1040,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Verwenden Sie w oder w>>" #: ../ex_docmd.c:3319 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Der Befehl ist in dieser Version nicht implementiert" #: ../ex_docmd.c:3612 @@ -1523,7 +1523,7 @@ msgstr "" "E201: *ReadPre-Autokommandos dürfen den aktuellen Puffer nicht wechseln" #: ../fileio.c:720 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Lese von stdin...\n" #. Re-opening the original file failed! @@ -2176,7 +2176,7 @@ msgid "E477: No ! allowed" msgstr "E477: Kein ! erlaubt" #: ../globals.h:1034 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: GUI kann nicht benutzt werden: wurde zum Zeitpunkt des Übersetzens " "nicht eingeschaltet." @@ -3899,7 +3899,7 @@ msgid "E663: At end of changelist" msgstr "E663: Am Ende der Liste der Änderungen" #: ../normal.c:6950 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Bitte :quit<Enter> eingeben um Vim zu verlassen" #: ../ops.c:229 diff --git a/src/nvim/po/en_GB.po b/src/nvim/po/en_GB.po index a246029bf0..b4b38e11e3 100644 --- a/src/nvim/po/en_GB.po +++ b/src/nvim/po/en_GB.po @@ -1562,7 +1562,7 @@ msgid "E494: Use w or w>>" msgstr "" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "" #: ../ex_docmd.c:3752 @@ -2030,7 +2030,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "" #. Re-opening the original file failed! @@ -2663,7 +2663,7 @@ msgid "E477: No ! allowed" msgstr "" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" #: ../globals.h:1036 @@ -4267,7 +4267,7 @@ msgid "E663: At end of changelist" msgstr "" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "" #: ../ops.c:248 diff --git a/src/nvim/po/eo.po b/src/nvim/po/eo.po index 555eb3637e..8215b31e65 100644 --- a/src/nvim/po/eo.po +++ b/src/nvim/po/eo.po @@ -1587,7 +1587,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Uzu w aÅ w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: BedaÅrinde, tiu komando ne haveblas en tiu versio" #: ../ex_docmd.c:3752 @@ -2068,7 +2068,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: La aÅtokomandoj *ReadPre ne rajtas ÅanÄi la aktualan bufron" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Legado el stdin...\n" #. Re-opening the original file failed! @@ -2709,7 +2709,7 @@ msgid "E477: No ! allowed" msgstr "E477: Neniu ! permesebla" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Grafika interfaco ne uzeblas: MalÅaltita dum kompilado" #: ../globals.h:1036 @@ -4411,7 +4411,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ĉe fino de ÅanÄlisto" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Tajpu \":quit<Enenklavo>\" por eliri el Vim" #: ../ops.c:248 diff --git a/src/nvim/po/es.po b/src/nvim/po/es.po index 4673893476..1a5ef991dc 100644 --- a/src/nvim/po/es.po +++ b/src/nvim/po/es.po @@ -1612,7 +1612,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Use \"w\" o \"w>>\"" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Lo siento, esa orden no está disponible en esta versión" #: ../ex_docmd.c:3752 @@ -2112,7 +2112,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Las auto-órdenes \"*ReadPre\" no deben cambiar el búfer en uso" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Leyendo la entrada estándar...\n" # Re-opening the original file failed! @@ -2787,7 +2787,7 @@ msgid "E477: No ! allowed" msgstr "E477: \"!\" no está permitido" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: No se puede usar la interfaz gráfica de usuario: No se activó al " "compilar" @@ -4527,7 +4527,7 @@ msgid "E663: At end of changelist" msgstr "E663: Al final de la lista de cambios" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Escriba \":quit<intro>\" para salir de Vim" #: ../ops.c:248 diff --git a/src/nvim/po/fi.po b/src/nvim/po/fi.po index 565f0fec89..d4082135aa 100644 --- a/src/nvim/po/fi.po +++ b/src/nvim/po/fi.po @@ -1596,7 +1596,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Käytä w:tä tai w>>:aa" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Komento ei ole käytettävissä tässä versiossa" #: ../ex_docmd.c:3752 @@ -2073,7 +2073,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre-autocommand-komennot eivät saa muuttaa puskuria" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Luetaan vakiosyötteestä...\n" #. Re-opening the original file failed! @@ -2730,7 +2730,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! ei sallittu" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUIta ei voi käyttää, koska sitä ei käännetty mukaan" #: ../globals.h:1036 @@ -4424,7 +4424,7 @@ msgid "E663: At end of changelist" msgstr "E663: Muutoslistan lopussa" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Komento :quit<Enter> lopettaa Vimin" #: ../ops.c:248 diff --git a/src/nvim/po/fr.po b/src/nvim/po/fr.po index 4f410fb039..9b2d44ce7d 100644 --- a/src/nvim/po/fr.po +++ b/src/nvim/po/fr.po @@ -1766,7 +1766,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Utilisez w ou w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Désolé, cette commande n'est pas disponible dans cette version" #: ../ex_docmd.c:3752 @@ -2252,7 +2252,7 @@ msgstr "" "courant" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim : Lecture de stdin...\n" #. Re-opening the original file failed! @@ -2909,7 +2909,7 @@ msgid "E477: No ! allowed" msgstr "E477: Le ! n'est pas autorisé" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: L'interface graphique n'a pas été compilée dans cette version" #: ../globals.h:1036 @@ -4616,7 +4616,7 @@ msgid "E663: At end of changelist" msgstr "E663: À la fin de la liste des modifications" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "tapez :q<Entrée> pour quitter Vim" #: ../ops.c:248 diff --git a/src/nvim/po/ga.po b/src/nvim/po/ga.po index 34770267b8..f7117c6e86 100644 --- a/src/nvim/po/ga.po +++ b/src/nvim/po/ga.po @@ -1589,7 +1589,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Bain úsáid as w nó w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Tá brón orm, níl an t-ordú ar fáil sa leagan seo" #: ../ex_docmd.c:3752 @@ -2073,7 +2073,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Ní cheadaítear d'uathorduithe *ReadPre an maolán reatha a athrú" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Ag léamh ón ionchur caighdeánach...\n" #. Re-opening the original file failed! @@ -2725,7 +2725,7 @@ msgid "E477: No ! allowed" msgstr "E477: Ní cheadaítear !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Ní féidir an GUI a úsáid: Níor cumasaíodh é ag am tiomsaithe" #: ../globals.h:1036 @@ -4438,7 +4438,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ag deireadh liosta na n-athruithe" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Clóscríobh :quit<Enter> chun Vim a scor" # ouch - English -ed ? diff --git a/src/nvim/po/it.po b/src/nvim/po/it.po index c7f77aad5b..7fe61c45bc 100644 --- a/src/nvim/po/it.po +++ b/src/nvim/po/it.po @@ -1581,7 +1581,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Usa w oppure w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Spiacente, comando non disponibile in questa versione" #: ../ex_docmd.c:3752 @@ -2064,7 +2064,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Gli autocomandi *ReadPre non devono modificare il buffer in uso" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Leggo da 'stdin'...\n" #. Re-opening the original file failed! @@ -2714,7 +2714,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! non consentito" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI non utilizzabile: Non abilitata in compilazione" #: ../globals.h:1036 @@ -4409,7 +4409,7 @@ msgid "E663: At end of changelist" msgstr "E663: Alla fine della lista modifiche" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Batti :quit<Invio> per uscire da Vim" #: ../ops.c:248 diff --git a/src/nvim/po/ja.euc-jp.po b/src/nvim/po/ja.euc-jp.po index cb1b8dab24..d3061d3c5a 100644 --- a/src/nvim/po/ja.euc-jp.po +++ b/src/nvim/po/ja.euc-jp.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w ¤â¤·¤¯¤Ï w>> ¤ò»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ¤³¤Î¥Ð¡¼¥¸¥ç¥ó¤Ç¤Ï¤³¤Î¥³¥Þ¥ó¥É¤ÏÍøÍѤǤ¤Þ¤»¤ó, ¤´¤á¤ó¤Ê¤µ¤¤" #: ../ex_docmd.c:3752 @@ -2050,7 +2050,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autocommand ¤Ï¸½ºß¤Î¥Ð¥Ã¥Õ¥¡¤òÊѤ¨¤é¤ì¤Þ¤»¤ó" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ɸ½àÆþÎϤ«¤éÆÉ¹þÃæ...\n" #. Re-opening the original file failed! @@ -2689,7 +2689,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! ¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI¤Ï»ÈÍÑÉÔ²Äǽ¤Ç¤¹: ¥³¥ó¥Ñ¥¤¥ë»þ¤Ë̵¸ú¤Ë¤µ¤ì¤Æ¤¤¤Þ¤¹" #: ../globals.h:1036 @@ -4375,7 +4375,7 @@ msgid "E663: At end of changelist" msgstr "E663: Êѹ¹¥ê¥¹¥È¤ÎËöÈø" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Vim¤ò½ªÎ»¤¹¤ë¤Ë¤Ï :quit<Enter> ¤ÈÆþÎϤ·¤Æ¤¯¤À¤µ¤¤" #: ../ops.c:248 diff --git a/src/nvim/po/ja.po b/src/nvim/po/ja.po index 606553f5ca..6bdfcb426f 100644 --- a/src/nvim/po/ja.po +++ b/src/nvim/po/ja.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w ã‚‚ã—ã㯠w>> を使用ã—ã¦ãã ã•ã„" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ã“ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã§ã¯ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯åˆ©ç”¨ã§ãã¾ã›ã‚“, ã”ã‚ã‚“ãªã•ã„" #: ../ex_docmd.c:3752 @@ -2050,7 +2050,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autocommand ã¯ç¾åœ¨ã®ãƒãƒƒãƒ•ァを変ãˆã‚‰ã‚Œã¾ã›ã‚“" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: 標準入力ã‹ã‚‰èªè¾¼ä¸...\n" #. Re-opening the original file failed! @@ -2689,7 +2689,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! ã¯è¨±å¯ã•れã¦ã„ã¾ã›ã‚“" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUIã¯ä½¿ç”¨ä¸å¯èƒ½ã§ã™: コンパイル時ã«ç„¡åйã«ã•れã¦ã„ã¾ã™" #: ../globals.h:1036 @@ -4375,7 +4375,7 @@ msgid "E663: At end of changelist" msgstr "E663: å¤‰æ›´ãƒªã‚¹ãƒˆã®æœ«å°¾" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Vimを終了ã™ã‚‹ã«ã¯ :quit<Enter> ã¨å…¥åŠ›ã—ã¦ãã ã•ã„" #: ../ops.c:248 diff --git a/src/nvim/po/ja.sjis.po b/src/nvim/po/ja.sjis.po index 4b1073f708..7dac89e172 100644 --- a/src/nvim/po/ja.sjis.po +++ b/src/nvim/po/ja.sjis.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w ‚à‚µ‚‚Í w>> ‚ðŽg—p‚µ‚Ä‚‚¾‚³‚¢" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ‚±‚̃o[ƒWƒ‡ƒ“‚ł͂±‚̃Rƒ}ƒ“ƒh‚Í—˜—p‚Å‚«‚Ü‚¹‚ñ, ‚²‚ß‚ñ‚È‚³‚¢" #: ../ex_docmd.c:3752 @@ -2050,7 +2050,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autocommand ‚ÍŒ»Ý‚̃oƒbƒtƒ@‚ð•Ï‚¦‚ç‚ê‚Ü‚¹‚ñ" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: •W€“ü—Í‚©‚ç“Çž’†...\n" #. Re-opening the original file failed! @@ -2689,7 +2689,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! ‚Í‹–‰Â‚³‚ê‚Ä‚¢‚Ü‚¹‚ñ" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI‚ÍŽg—p•s‰Â”\\‚Å‚·: ƒRƒ“ƒpƒCƒ‹Žž‚É–³Œø‚É‚³‚ê‚Ä‚¢‚Ü‚·" #: ../globals.h:1036 @@ -4375,7 +4375,7 @@ msgid "E663: At end of changelist" msgstr "E663: •ÏXƒŠƒXƒg‚Ì––”ö" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Vim‚ðI—¹‚·‚é‚É‚Í :quit<Enter> ‚Æ“ü—Í‚µ‚Ä‚‚¾‚³‚¢" #: ../ops.c:248 diff --git a/src/nvim/po/ko.UTF-8.po b/src/nvim/po/ko.UTF-8.po index 8b43e1ceed..149286eda8 100644 --- a/src/nvim/po/ko.UTF-8.po +++ b/src/nvim/po/ko.UTF-8.po @@ -1577,7 +1577,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w나 w>>를 사용하ì‹ì‹œì˜¤" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: 미안합니다, ê·¸ ëª…ë ¹ì€ í˜„ìž¬ íŒì—서 ì‚¬ìš©í• ìˆ˜ 없습니다" #: ../ex_docmd.c:3752 @@ -2049,7 +2049,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre ìžë™ëª…ë ¹ì€ í˜„ìž¬ 버í¼ë¥¼ 바꾸면 안 ë©ë‹ˆë‹¤" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "ë¹”: í‘œì¤€ìž…ë ¥ì—서 ì½ëŠ” 중...\n" #. Re-opening the original file failed! @@ -2687,7 +2687,7 @@ msgid "E477: No ! allowed" msgstr "E477: !ì€ í—ˆìš©ë˜ì§€ 않습니다" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI는 ì‚¬ìš©í• ìˆ˜ 없습니다: ì»´íŒŒì¼ ë•Œ í¬í•¨ë˜ì§€ 않았습니다" #: ../globals.h:1036 @@ -4373,7 +4373,7 @@ msgid "E663: At end of changelist" msgstr "" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "VIMì„ ë§ˆì¹˜ë ¤ë©´ :quit<Enter> ìž…ë ¥" #: ../ops.c:248 diff --git a/src/nvim/po/ko.po b/src/nvim/po/ko.po index a8965b682c..b6aaf37bbb 100644 --- a/src/nvim/po/ko.po +++ b/src/nvim/po/ko.po @@ -1577,7 +1577,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w³ª w>>¸¦ »ç¿ëÇϽʽÿÀ" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ¹Ì¾ÈÇÕ´Ï´Ù, ±× ¸í·ÉÀº ÇöÀç ÆÇ¿¡¼ »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù" #: ../ex_docmd.c:3752 @@ -2049,7 +2049,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre ÀÚµ¿¸í·ÉÀº ÇöÀç ¹öÆÛ¸¦ ¹Ù²Ù¸é ¾È µË´Ï´Ù" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "ºö: Ç¥ÁØÀԷ¿¡¼ Àд Áß...\n" #. Re-opening the original file failed! @@ -2687,7 +2687,7 @@ msgid "E477: No ! allowed" msgstr "E477: !Àº Çã¿ëµÇÁö ¾Ê½À´Ï´Ù" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI´Â »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù: ÄÄÆÄÀÏ ¶§ Æ÷ÇÔµÇÁö ¾Ê¾Ò½À´Ï´Ù" #: ../globals.h:1036 @@ -4373,7 +4373,7 @@ msgid "E663: At end of changelist" msgstr "" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "VIMÀ» ¸¶Ä¡·Á¸é :quit<Enter> ÀÔ·Â" #: ../ops.c:248 diff --git a/src/nvim/po/nb.po b/src/nvim/po/nb.po index b9bac7b692..ce635e098c 100644 --- a/src/nvim/po/nb.po +++ b/src/nvim/po/nb.po @@ -1605,7 +1605,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Bruk w eller w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Kommandoen er ikke tilgjengelig i denne versjonen" #: ../ex_docmd.c:3752 @@ -2092,7 +2092,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: \"*ReadPre\"-autokommandoer må ikke forandre nåværende buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Leser fra stdin ...\n" #. Re-opening the original file failed! @@ -2738,7 +2738,7 @@ msgid "E477: No ! allowed" msgstr "E477: Ingen ! tillatt" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI kan ikke brukes: Ikke slått på under kompilering" #: ../globals.h:1036 @@ -4428,7 +4428,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ved slutten av forandringsliste" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Skriv :quit<Enter> for å avslutte Vim" #: ../ops.c:248 diff --git a/src/nvim/po/nl.po b/src/nvim/po/nl.po index aa7fe9cf4a..ea609c0f69 100644 --- a/src/nvim/po/nl.po +++ b/src/nvim/po/nl.po @@ -1589,7 +1589,7 @@ msgid "E494: Use w or w>>" msgstr "E494: w of w>> gebruiken" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Helaas, in deze versie is de opdracht niet beschikbaar" #: ../ex_docmd.c:3752 @@ -2072,7 +2072,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autocommands mogen huidige buffer niet wijzigen" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: lezen van standaardinvoer...\n" #. Re-opening the original file failed! @@ -2724,7 +2724,7 @@ msgid "E477: No ! allowed" msgstr "" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" #: ../globals.h:1036 @@ -4424,7 +4424,7 @@ msgid "E663: At end of changelist" msgstr "E663: einde van wijzigingslijst" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Typ :quit<Enter> om Vim te verlaten" #: ../ops.c:248 diff --git a/src/nvim/po/no.po b/src/nvim/po/no.po index b9bac7b692..ce635e098c 100644 --- a/src/nvim/po/no.po +++ b/src/nvim/po/no.po @@ -1605,7 +1605,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Bruk w eller w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Kommandoen er ikke tilgjengelig i denne versjonen" #: ../ex_docmd.c:3752 @@ -2092,7 +2092,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: \"*ReadPre\"-autokommandoer må ikke forandre nåværende buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Leser fra stdin ...\n" #. Re-opening the original file failed! @@ -2738,7 +2738,7 @@ msgid "E477: No ! allowed" msgstr "E477: Ingen ! tillatt" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI kan ikke brukes: Ikke slått på under kompilering" #: ../globals.h:1036 @@ -4428,7 +4428,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ved slutten av forandringsliste" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Skriv :quit<Enter> for å avslutte Vim" #: ../ops.c:248 diff --git a/src/nvim/po/pl.UTF-8.po b/src/nvim/po/pl.UTF-8.po index 6f2d33d8ba..68cb9e72d5 100644 --- a/src/nvim/po/pl.UTF-8.po +++ b/src/nvim/po/pl.UTF-8.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Stosuj w lub w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Przykro mi, ale ta komenda nie jest dostÄ™pna w tej wersji" #: ../ex_docmd.c:3752 @@ -2052,7 +2052,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Autokomendy *ReadPre nie mogÄ… zmieniać bieżącego bufora" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Wczytywanie ze stdin...\n" #. Re-opening the original file failed! @@ -2697,7 +2697,7 @@ msgid "E477: No ! allowed" msgstr "E477: Niedozwolone !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI nie może być użyte: Nie włączono podczas kompilacji" #: ../globals.h:1036 @@ -4392,7 +4392,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na koÅ„cu listy zmian" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "wprowadź :quit<Enter> zakoÅ„czenie programu" #: ../ops.c:248 diff --git a/src/nvim/po/pl.cp1250.po b/src/nvim/po/pl.cp1250.po index c598ff385f..3fcdbfb87d 100644 --- a/src/nvim/po/pl.cp1250.po +++ b/src/nvim/po/pl.cp1250.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Stosuj w lub w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Przykro mi, ale ta komenda nie jest dostêpna w tej wersji" #: ../ex_docmd.c:3752 @@ -2052,7 +2052,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Autokomendy *ReadPre nie mog¹ zmieniaæ bie¿¹cego bufora" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Wczytywanie ze stdin...\n" #. Re-opening the original file failed! @@ -2697,7 +2697,7 @@ msgid "E477: No ! allowed" msgstr "E477: Niedozwolone !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI nie mo¿e byæ u¿yte: Nie w³¹czono podczas kompilacji" #: ../globals.h:1036 @@ -4392,7 +4392,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na koñcu listy zmian" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "wprowadŸ :quit<Enter> zakoñczenie programu" #: ../ops.c:248 diff --git a/src/nvim/po/pl.po b/src/nvim/po/pl.po index 253d8b31ab..2a2d12daac 100644 --- a/src/nvim/po/pl.po +++ b/src/nvim/po/pl.po @@ -1574,7 +1574,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Stosuj w lub w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Przykro mi, ale ta komenda nie jest dostêpna w tej wersji" #: ../ex_docmd.c:3752 @@ -2052,7 +2052,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Autokomendy *ReadPre nie mog± zmieniaæ bie¿±cego bufora" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Wczytywanie ze stdin...\n" #. Re-opening the original file failed! @@ -2697,7 +2697,7 @@ msgid "E477: No ! allowed" msgstr "E477: Niedozwolone !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI nie mo¿e byæ u¿yte: Nie w³±czono podczas kompilacji" #: ../globals.h:1036 @@ -4392,7 +4392,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na koñcu listy zmian" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "wprowad¼ :quit<Enter> zakoñczenie programu" #: ../ops.c:248 diff --git a/src/nvim/po/pt_BR.po b/src/nvim/po/pt_BR.po index b39ae155c8..60c11d4b5a 100644 --- a/src/nvim/po/pt_BR.po +++ b/src/nvim/po/pt_BR.po @@ -2517,7 +2517,7 @@ msgid "E477: No ! allowed" msgstr "E477: '!' não permitido" #: ../globals.h:1034 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: Interface gráfica não pode ser usada, não foi ativada na compilação" @@ -2825,7 +2825,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Os autocomandos *ReadPre não devem alterar o buffer atual" #: ../fileio.c:720 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Lendo da entrada padrão...\n" #. Re-opening the original file failed! @@ -3558,7 +3558,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Use w ou w>>" #: ../ex_docmd.c:3319 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Desculpe, esse comando não está disponível nesta versão" #: ../ex_docmd.c:3616 @@ -4423,7 +4423,7 @@ msgid "E663: At end of changelist" msgstr "E663: No final da lista de modificações" #: ../normal.c:6950 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Digite :quit<Enter> para sair do Vim" #: ../hardcopy.c:296 diff --git a/src/nvim/po/ru.cp1251.po b/src/nvim/po/ru.cp1251.po index 4dd4cec235..29e8c83ee6 100644 --- a/src/nvim/po/ru.cp1251.po +++ b/src/nvim/po/ru.cp1251.po @@ -1580,7 +1580,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Èñïîëüçóéòå w èëè w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Èçâèíèòå, ýòà êîìàíäà íåäîñòóïíà â äàííîé âåðñèè" #: ../ex_docmd.c:3752 @@ -2060,7 +2060,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Àâòîêîìàíäû *ReadPre íå äîëæíû èçìåíÿòü àêòèâíûé áóôåð" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ×òåíèå èç ñòàíäàðòíîãî ïîòîêà ââîäà stdin...\n" #. Re-opening the original file failed! @@ -2717,7 +2717,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! íå äîïóñêàåòñÿ" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: Âîçìîæíîñòü èñïîëüçîâàíèÿ ãðàôè÷åñêîãî èíòåðôåéñà âûêëþ÷åíà ïðè " "êîìïèëÿöèè" @@ -4435,7 +4435,7 @@ msgid "E663: At end of changelist" msgstr "E663:  êîíöå ñïèñêà èçìåíåíèé" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Ââåäèòå :quit<Enter> äëÿ âûõîäà èç Vim" #: ../ops.c:248 diff --git a/src/nvim/po/ru.po b/src/nvim/po/ru.po index 5bdbc33801..c8146e8c47 100644 --- a/src/nvim/po/ru.po +++ b/src/nvim/po/ru.po @@ -1581,7 +1581,7 @@ msgid "E494: Use w or w>>" msgstr "E494: ИÑпользуйте w или w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Извините, Ñта команда недоÑтупна в данной верÑии" #: ../ex_docmd.c:3752 @@ -2058,7 +2058,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Ðвтокоманды *ReadPre не должны изменÑть активный буфер" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Чтение из Ñтандартного потока ввода stdin...\n" #. Re-opening the original file failed! @@ -2715,7 +2715,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! не допуÑкаетÑÑ" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "" "E25: ВозможноÑть иÑÐ¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ð½Ð¸Ñ Ð³Ñ€Ð°Ñ„Ð¸Ñ‡ÐµÑкого интерфейÑа выключена при " "компилÑции" @@ -4433,7 +4433,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ð’ конце ÑпиÑка изменений" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Введите :quit<Enter> Ð´Ð»Ñ Ð²Ñ‹Ñ…Ð¾Ð´Ð° из Vim" #: ../ops.c:248 diff --git a/src/nvim/po/sk.cp1250.po b/src/nvim/po/sk.cp1250.po index 97db400252..e3b7508cdc 100644 --- a/src/nvim/po/sk.cp1250.po +++ b/src/nvim/po/sk.cp1250.po @@ -1595,7 +1595,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Použite w alebo w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ¼utujem, ale tento príkaz nie je dostupný v tejto verzii" #: ../ex_docmd.c:3752 @@ -2080,7 +2080,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: automatické príkazy *ReadPre nesmú meni aktuálny buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: èítam zo štandardného vstupu...\n" #. Re-opening the original file failed! @@ -2728,7 +2728,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! nie je povolený" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Nedá sa použí GUI: nebolo zapnuté pri preklade programu" #: ../globals.h:1036 @@ -4429,7 +4429,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na konci zoznamu zmien" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Zadajte :quit<Enter> pre ukonèenie programu Vim" #: ../ops.c:248 diff --git a/src/nvim/po/sk.po b/src/nvim/po/sk.po index e6f833d52e..53f8a7b911 100644 --- a/src/nvim/po/sk.po +++ b/src/nvim/po/sk.po @@ -1595,7 +1595,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Pou¾ite w alebo w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ¥utujem, ale tento príkaz nie je dostupný v tejto verzii" #: ../ex_docmd.c:3752 @@ -2080,7 +2080,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: automatické príkazy *ReadPre nesmú meni» aktuálny buffer" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: èítam zo ¹tandardného vstupu...\n" #. Re-opening the original file failed! @@ -2728,7 +2728,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! nie je povolený" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Nedá sa pou¾í» GUI: nebolo zapnuté pri preklade programu" #: ../globals.h:1036 @@ -4429,7 +4429,7 @@ msgid "E663: At end of changelist" msgstr "E663: Na konci zoznamu zmien" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Zadajte :quit<Enter> pre ukonèenie programu Vim" #: ../ops.c:248 diff --git a/src/nvim/po/sv.po b/src/nvim/po/sv.po index 4ba06c3d45..eedaecd1e7 100644 --- a/src/nvim/po/sv.po +++ b/src/nvim/po/sv.po @@ -419,7 +419,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre autokommandon får inte ändra nuvarande buffert" #: ../fileio.c:720 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Läser från standard in...\n" #. Re-opening the original file failed! @@ -922,7 +922,7 @@ msgid "E663: At end of changelist" msgstr "E663: Vid slutet av ändringslista" #: ../normal.c:6950 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "skriv :q<Enter> för att avsluta Vim " #: ../ex_cmds2.c:163 @@ -4781,7 +4781,7 @@ msgid "E477: No ! allowed" msgstr "E477: Inget ! tillåtet" #: ../globals.h:1019 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: GUI kan inte användas: Inte aktiverat vid kompilering" #: ../globals.h:1020 @@ -5380,7 +5380,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Använd w eller w>>" #: ../ex_docmd.c:3318 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Tyvärr, kommandot är inte tillgängligt i den här versionen" #: ../ex_docmd.c:3611 diff --git a/src/nvim/po/uk.cp1251.po b/src/nvim/po/uk.cp1251.po index 1c14606740..2c6f3423ae 100644 --- a/src/nvim/po/uk.cp1251.po +++ b/src/nvim/po/uk.cp1251.po @@ -1602,7 +1602,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Ñïðîáóéòå w àáî w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Âèáà÷òå, ö³º¿ êîìàíäè íåìຠó ö³é âåðñ³¿" #: ../ex_docmd.c:3752 @@ -2099,7 +2099,7 @@ msgstr "E201: Àâòîêîìàíäè *ReadPre íå ïîâèíí³ çì³íþâàòè öåé áóôåð" # msgstr "E201: " #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ×èòàºòüñÿ ç stdin...\n" #. Re-opening the original file failed! @@ -2766,7 +2766,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! íå äîçâîëåíî" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Íå ìîæíà âèêîðèñòàòè GUI: Íå ââ³ìêíåíî ï³ä ÷àñ êîìï³ëÿö³¿" # msgstr "E25: " @@ -4514,7 +4514,7 @@ msgid "E663: At end of changelist" msgstr "E663: ʳíåöü ñïèñêó çì³í" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Óâåä³òü :quit<Enter> ùîá âèéòè ç Vim" #: ../ops.c:248 diff --git a/src/nvim/po/uk.po b/src/nvim/po/uk.po index 4471747ff2..eaa3a5bfa9 100644 --- a/src/nvim/po/uk.po +++ b/src/nvim/po/uk.po @@ -1602,7 +1602,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Спробуйте w або w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Вибачте, цієї команди немає у цій верÑÑ–Ñ—" #: ../ex_docmd.c:3752 @@ -2099,7 +2099,7 @@ msgstr "E201: Ðвтокоманди *ReadPre не повинні змінюва # msgstr "E201: " #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ЧитаєтьÑÑ Ð· stdin...\n" #. Re-opening the original file failed! @@ -2766,7 +2766,7 @@ msgid "E477: No ! allowed" msgstr "E477: ! не дозволено" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Ðе можна викориÑтати GUI: Ðе ввімкнено під Ñ‡Ð°Ñ ÐºÐ¾Ð¼Ð¿Ñ–Ð»Ñції" # msgstr "E25: " @@ -4514,7 +4514,7 @@ msgid "E663: At end of changelist" msgstr "E663: Кінець ÑпиÑку змін" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Уведіть :quit<Enter> щоб вийти з Vim" #: ../ops.c:248 diff --git a/src/nvim/po/vi.po b/src/nvim/po/vi.po index 7b6e5865f5..a720510426 100644 --- a/src/nvim/po/vi.po +++ b/src/nvim/po/vi.po @@ -1608,7 +1608,7 @@ msgid "E494: Use w or w>>" msgstr "E494: Hãy sá» dụng w hoặc w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: Xin lá»—i, câu lệnh nà y không có trong phiên bản nà y" #: ../ex_docmd.c:3752 @@ -2099,7 +2099,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: Câu lệnh tá»± động *ReadPre không được thay đổi bá»™ đệm hoạt động" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: Äá»c từ đầu và o tiêu chuẩn stdin...\n" #. Re-opening the original file failed! @@ -2759,7 +2759,7 @@ msgid "E477: No ! allowed" msgstr "E477: Không cho phép !" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: Không sá» dụng được giao diện đồ há»a vì không chá»n khi biên dịch" #: ../globals.h:1036 @@ -4466,7 +4466,7 @@ msgid "E663: At end of changelist" msgstr "E663: Ở cuối danh sách những thay đổi" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "Gõ :quit<Enter> để thoát khá»i Vim" #: ../ops.c:248 diff --git a/src/nvim/po/zh_CN.UTF-8.po b/src/nvim/po/zh_CN.UTF-8.po index f4c7c4a471..82b895d9d6 100644 --- a/src/nvim/po/zh_CN.UTF-8.po +++ b/src/nvim/po/zh_CN.UTF-8.po @@ -1595,7 +1595,7 @@ msgid "E494: Use w or w>>" msgstr "E494: 请使用 w 或 w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: 抱æ‰ï¼Œå‘½ä»¤åœ¨æ¤ç‰ˆæœ¬ä¸ä¸å¯ç”¨" #: ../ex_docmd.c:3752 @@ -2078,7 +2078,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre 自动命令ä¸å…许改å˜å½“å‰ç¼“冲区" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ä»Žæ ‡å‡†è¾“å…¥è¯»å–...\n" #. Re-opening the original file failed! @@ -2714,7 +2714,7 @@ msgid "E477: No ! allowed" msgstr "E477: ä¸èƒ½ä½¿ç”¨ \"!\"" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: æ— æ³•ä½¿ç”¨å›¾å½¢ç•Œé¢: 编译时没有å¯ç”¨" #: ../globals.h:1036 @@ -4416,7 +4416,7 @@ msgid "E663: At end of changelist" msgstr "E663: 已在改å˜åˆ—表的末尾处" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "输入 :quit<Enter> 退出 Vim" #: ../ops.c:248 diff --git a/src/nvim/po/zh_CN.cp936.po b/src/nvim/po/zh_CN.cp936.po index a7ac34726c..cf66010c71 100644 --- a/src/nvim/po/zh_CN.cp936.po +++ b/src/nvim/po/zh_CN.cp936.po @@ -1596,7 +1596,7 @@ msgid "E494: Use w or w>>" msgstr "E494: ÇëʹÓà w »ò w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ±§Ç¸£¬ÃüÁîÔڴ˰汾Öв»¿ÉÓÃ" #: ../ex_docmd.c:3752 @@ -2079,7 +2079,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre ×Ô¶¯ÃüÁî²»ÔÊÐí¸Ä±äµ±Ç°»º³åÇø" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ´Ó±ê×¼ÊäÈë¶ÁÈ¡...\n" #. Re-opening the original file failed! @@ -2715,7 +2715,7 @@ msgid "E477: No ! allowed" msgstr "E477: ²»ÄÜʹÓà \"!\"" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: ÎÞ·¨Ê¹ÓÃͼÐνçÃæ: ±àÒëʱûÓÐÆôÓÃ" #: ../globals.h:1036 @@ -4417,7 +4417,7 @@ msgid "E663: At end of changelist" msgstr "E663: ÒÑÔڸıäÁбíµÄĩβ´¦" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "ÊäÈë :quit<Enter> Í˳ö Vim" #: ../ops.c:248 diff --git a/src/nvim/po/zh_CN.po b/src/nvim/po/zh_CN.po index aec9929fd9..254ebbce6b 100644 --- a/src/nvim/po/zh_CN.po +++ b/src/nvim/po/zh_CN.po @@ -1596,7 +1596,7 @@ msgid "E494: Use w or w>>" msgstr "E494: ÇëʹÓà w »ò w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ±§Ç¸£¬ÃüÁîÔڴ˰汾Öв»¿ÉÓÃ" #: ../ex_docmd.c:3752 @@ -2079,7 +2079,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *ReadPre ×Ô¶¯ÃüÁî²»ÔÊÐí¸Ä±äµ±Ç°»º³åÇø" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ´Ó±ê×¼ÊäÈë¶ÁÈ¡...\n" #. Re-opening the original file failed! @@ -2715,7 +2715,7 @@ msgid "E477: No ! allowed" msgstr "E477: ²»ÄÜʹÓà \"!\"" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: ÎÞ·¨Ê¹ÓÃͼÐνçÃæ: ±àÒëʱûÓÐÆôÓÃ" #: ../globals.h:1036 @@ -4417,7 +4417,7 @@ msgid "E663: At end of changelist" msgstr "E663: ÒÑÔڸıäÁбíµÄĩβ´¦" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "ÊäÈë :quit<Enter> Í˳ö Vim" #: ../ops.c:248 diff --git a/src/nvim/po/zh_TW.UTF-8.po b/src/nvim/po/zh_TW.UTF-8.po index 321ca1c321..627389d8bf 100644 --- a/src/nvim/po/zh_TW.UTF-8.po +++ b/src/nvim/po/zh_TW.UTF-8.po @@ -1638,7 +1638,7 @@ msgid "E494: Use w or w>>" msgstr "E494: 請使用 w 或 w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: 抱æ‰, 本命令在æ¤ç‰ˆæœ¬ä¸æ²’有實作" #: ../ex_docmd.c:3752 @@ -2122,7 +2122,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *Filter* Autocommand ä¸å¯ä»¥æ›´æ”¹ç·©è¡å€çš„內容" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: 從標準輸入讀å–...\n" #. Re-opening the original file failed! @@ -2765,7 +2765,7 @@ msgid "E477: No ! allowed" msgstr "E477: ä¸å¯ä½¿ç”¨ '!'" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: å› ç‚ºç·¨è¯æ™‚æ²’æœ‰åŠ å…¥åœ–åž‹ç•Œé¢çš„程å¼ç¢¼ï¼Œæ‰€ä»¥ç„¡æ³•使用圖型界é¢" #: ../globals.h:1036 @@ -4460,7 +4460,7 @@ msgid "E663: At end of changelist" msgstr "E663: 已在變更列表的çµå°¾" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "è¦é›¢é–‹ Vim 請輸入 :quit<Enter> " #: ../ops.c:248 diff --git a/src/nvim/po/zh_TW.po b/src/nvim/po/zh_TW.po index 3ef5cba071..9a7e6bf488 100644 --- a/src/nvim/po/zh_TW.po +++ b/src/nvim/po/zh_TW.po @@ -1630,7 +1630,7 @@ msgid "E494: Use w or w>>" msgstr "E494: ½Ð¨Ï¥Î w ©Î w>>" #: ../ex_docmd.c:3454 -msgid "E319: Sorry, the command is not available in this version" +msgid "E319: The command is not available in this version" msgstr "E319: ©êºp, ¥»©R¥O¦b¦¹ª©¥»¤¤¨S¦³¹ê§@" #: ../ex_docmd.c:3752 @@ -2114,7 +2114,7 @@ msgid "E201: *ReadPre autocommands must not change current buffer" msgstr "E201: *Filter* Autocommand ¤£¥i¥H§ó§ï½w½Ä°Ïªº¤º®e" #: ../fileio.c:672 -msgid "Vim: Reading from stdin...\n" +msgid "Nvim: Reading from stdin...\n" msgstr "Vim: ±q¼Ð·Ç¿é¤JŪ¨ú...\n" #. Re-opening the original file failed! @@ -2757,7 +2757,7 @@ msgid "E477: No ! allowed" msgstr "E477: ¤£¥i¨Ï¥Î '!'" #: ../globals.h:1035 -msgid "E25: GUI cannot be used: Not enabled at compile time" +msgid "E25: Nvim does not have a built-in GUI" msgstr "E25: ¦]¬°½sͮɍS¦³¥[¤J¹Ï«¬¬É±ªºµ{¦¡½X¡A©Ò¥HµLªk¨Ï¥Î¹Ï«¬¬É±" #: ../globals.h:1036 @@ -4452,7 +4452,7 @@ msgid "E663: At end of changelist" msgstr "E663: ¤w¦bÅܧó¦Cªíªºµ²§À" #: ../normal.c:7053 -msgid "Type :quit<Enter> to exit Vim" +msgid "Type :quit<Enter> to exit Nvim" msgstr "nÂ÷¶} Vim ½Ð¿é¤J :quit<Enter> " #: ../ops.c:248 diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index 1ea12d6862..10012a9775 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -2,6 +2,7 @@ /// /// Popup menu (PUM) // +#include <assert.h> #include <inttypes.h> #include <stdbool.h> @@ -17,6 +18,7 @@ #include "nvim/screen.h" #include "nvim/search.h" #include "nvim/strings.h" +#include "nvim/memory.h" #include "nvim/window.h" #include "nvim/edit.h" @@ -101,7 +103,7 @@ redo: } if ((p_ph > 0) && (pum_height > p_ph)) { - pum_height = p_ph; + pum_height = (int)p_ph; } // Put the pum below "row" if possible. If there are few lines decide on @@ -126,8 +128,8 @@ redo: } if ((p_ph > 0) && (pum_height > p_ph)) { - pum_row += pum_height - p_ph; - pum_height = p_ph; + pum_row += pum_height - (int)p_ph; + pum_height = (int)p_ph; } } else { // pum below "row" @@ -148,7 +150,7 @@ redo: } if ((p_ph > 0) && (pum_height > p_ph)) { - pum_height = p_ph; + pum_height = (int)p_ph; } } @@ -219,7 +221,9 @@ redo: if (curwin->w_p_rl) { pum_width = pum_col - pum_scrollbar + 1; } else { - pum_width = Columns - pum_col - pum_scrollbar; + assert(Columns - pum_col - pum_scrollbar >= INT_MIN + && Columns - pum_col - pum_scrollbar <= INT_MAX); + pum_width = (int)(Columns - pum_col - pum_scrollbar); } if ((pum_width > max_width + kind_width + extra_width + 1) @@ -233,11 +237,13 @@ redo: } else if (Columns < def_width) { // not enough room, will use what we have if (curwin->w_p_rl) { - pum_col = Columns - 1; + assert(Columns - 1 >= INT_MIN); + pum_col = (int)(Columns - 1); } else { pum_col = 0; } - pum_width = Columns - 1; + assert(Columns - 1 >= INT_MIN); + pum_width = (int)(Columns - 1); } else { if (max_width > PUM_DEF_WIDTH) { // truncate @@ -247,7 +253,8 @@ redo: if (curwin->w_p_rl) { pum_col = max_width - 1; } else { - pum_col = Columns - max_width; + assert(Columns - max_width >= INT_MIN && Columns - max_width <= INT_MAX); + pum_col = (int)(Columns - max_width); } pum_width = max_width - pum_scrollbar; } @@ -345,7 +352,7 @@ void pum_redraw(void) // Display the text that fits or comes before a Tab. // First convert it to printable characters. char_u *st; - int saved = *p; + char_u saved = *p; *p = NUL; st = transstr(s); @@ -371,12 +378,12 @@ void pum_redraw(void) } } screen_puts_len(rt, (int)STRLEN(rt), row, col - size + 1, attr); - free(rt_start); - free(st); + xfree(rt_start); + xfree(st); col -= width; } else { screen_puts_len(st, (int)STRLEN(st), row, col, attr); - free(st); + xfree(st); col += width; } @@ -535,7 +542,7 @@ static int pum_set_selected(int n, int repeat) g_do_tagpreview = 3; if ((p_pvh > 0) && (p_pvh < g_do_tagpreview)) { - g_do_tagpreview = p_pvh; + g_do_tagpreview = (int)p_pvh; } RedrawingDisabled++; resized = prepare_tagpreview(false); diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 8e55cced78..7e83132a25 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -784,15 +784,15 @@ qf_init_ok: for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first) { fmt_first = fmt_ptr->next; vim_regfree(fmt_ptr->prog); - free(fmt_ptr); + xfree(fmt_ptr); } qf_clean_dir_stack(&dir_stack); qf_clean_dir_stack(&file_stack); qf_init_end: - free(namebuf); - free(errmsg); - free(pattern); - free(fmtstr); + xfree(namebuf); + xfree(errmsg); + xfree(pattern); + xfree(fmtstr); qf_update_buffer(qi); @@ -855,7 +855,7 @@ static void ll_free_all(qf_info_T **pqi) /* No references to this location list */ for (i = 0; i < qi->qf_listcount; ++i) qf_free(qi, i); - free(qi); + xfree(qi); } } @@ -1091,7 +1091,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname) * directory change. */ if (!os_file_exists(ptr)) { - free(ptr); + xfree(ptr); directory = qf_guess_filepath(fname); if (directory) ptr = concat_fnames(directory, fname, TRUE); @@ -1100,7 +1100,7 @@ static int qf_get_fnum(char_u *directory, char_u *fname) } /* Use concatenated directory name and file name */ fnum = buflist_add(ptr, 0); - free(ptr); + xfree(ptr); return fnum; } return buflist_add(fname, 0); @@ -1134,7 +1134,7 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr) ds_new = (*stackptr)->next; (*stackptr)->dirname = NULL; while (ds_new) { - free((*stackptr)->dirname); + xfree((*stackptr)->dirname); (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, TRUE); if (os_isdir((*stackptr)->dirname)) @@ -1147,13 +1147,13 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr) while ((*stackptr)->next != ds_new) { ds_ptr = (*stackptr)->next; (*stackptr)->next = (*stackptr)->next->next; - free(ds_ptr->dirname); - free(ds_ptr); + xfree(ds_ptr->dirname); + xfree(ds_ptr); } /* Nothing found -> it must be on top level */ if (ds_new == NULL) { - free((*stackptr)->dirname); + xfree((*stackptr)->dirname); (*stackptr)->dirname = vim_strsave(dirbuf); } } @@ -1163,7 +1163,7 @@ static char_u *qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr) else { ds_ptr = *stackptr; *stackptr = (*stackptr)->next; - free(ds_ptr); + xfree(ds_ptr); return NULL; } } @@ -1184,8 +1184,8 @@ static char_u *qf_pop_dir(struct dir_stack_T **stackptr) if (*stackptr != NULL) { ds_ptr = *stackptr; *stackptr = (*stackptr)->next; - free(ds_ptr->dirname); - free(ds_ptr); + xfree(ds_ptr->dirname); + xfree(ds_ptr); } /* return NEW top element as current dir or NULL if stack is empty*/ @@ -1201,8 +1201,8 @@ static void qf_clean_dir_stack(struct dir_stack_T **stackptr) while ((ds_ptr = *stackptr) != NULL) { *stackptr = (*stackptr)->next; - free(ds_ptr->dirname); - free(ds_ptr); + xfree(ds_ptr->dirname); + xfree(ds_ptr); } } @@ -1239,7 +1239,7 @@ static char_u *qf_guess_filepath(char_u *filename) ds_ptr = dir_stack->next; fullname = NULL; while (ds_ptr) { - free(fullname); + xfree(fullname); fullname = concat_fnames(ds_ptr->dirname, filename, TRUE); if (os_file_exists(fullname)) @@ -1248,14 +1248,14 @@ static char_u *qf_guess_filepath(char_u *filename) ds_ptr = ds_ptr->next; } - free(fullname); + xfree(fullname); /* clean up all dirs we already left */ while (dir_stack->next != ds_ptr) { ds_tmp = dir_stack->next; dir_stack->next = dir_stack->next->next; - free(ds_tmp->dirname); - free(ds_tmp); + xfree(ds_tmp->dirname); + xfree(ds_tmp); } return ds_ptr==NULL ? NULL : ds_ptr->dirname; @@ -1876,10 +1876,10 @@ static void qf_free(qf_info_T *qi, int idx) while (qi->qf_lists[idx].qf_count) { qfp = qi->qf_lists[idx].qf_start->qf_next; if (qi->qf_lists[idx].qf_title != NULL && !stop) { - free(qi->qf_lists[idx].qf_start->qf_text); + xfree(qi->qf_lists[idx].qf_start->qf_text); stop = (qi->qf_lists[idx].qf_start == qfp); - free(qi->qf_lists[idx].qf_start->qf_pattern); - free(qi->qf_lists[idx].qf_start); + xfree(qi->qf_lists[idx].qf_start->qf_pattern); + xfree(qi->qf_lists[idx].qf_start); if (stop) /* Somehow qf_count may have an incorrect value, set it to 1 * to avoid crashing when it's wrong. @@ -1889,7 +1889,7 @@ static void qf_free(qf_info_T *qi, int idx) qi->qf_lists[idx].qf_start = qfp; --qi->qf_lists[idx].qf_count; } - free(qi->qf_lists[idx].qf_title); + xfree(qi->qf_lists[idx].qf_title); qi->qf_lists[idx].qf_title = NULL; qi->qf_lists[idx].qf_index = 0; } @@ -2526,8 +2526,8 @@ void ex_make(exarg_T *eap) qf_jump(qi, 0, 0, FALSE); /* display first error */ os_remove((char *)fname); - free(fname); - free(cmd); + xfree(fname); + xfree(cmd); } /* @@ -2573,7 +2573,7 @@ static char_u *get_mef_name(void) if (!file_or_link_found) { break; } - free(name); + xfree(name); } return name; } @@ -2834,7 +2834,7 @@ void ex_vimgrep(exarg_T *eap) msg_outtrans(fname); else { msg_outtrans(p); - free(p); + xfree(p); } msg_clr_eos(); msg_didout = FALSE; /* overwrite this message */ @@ -3021,9 +3021,9 @@ void ex_vimgrep(exarg_T *eap) } theend: - free(dirname_now); - free(dirname_start); - free(target_dir); + xfree(dirname_now); + xfree(dirname_start); + xfree(target_dir); vim_regfree(regmatch.regprog); } @@ -3091,7 +3091,7 @@ static void restore_start_dir(char_u *dirname_start) ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; ex_cd(&ea); } - free(dirname_now); + xfree(dirname_now); } /* @@ -3356,10 +3356,10 @@ int set_errorlist(win_T *wp, list_T *list, int action, char_u *title) type == NULL ? NUL : *type, valid); - free(filename); - free(pattern); - free(text); - free(type); + xfree(filename); + xfree(pattern); + xfree(text); + xfree(type); if (status == FAIL) { retval = FAIL; @@ -3599,12 +3599,12 @@ void ex_helpgrep(exarg_T *eap) ) == FAIL) { got_int = TRUE; if (line != IObuff) - free(line); + xfree(line); break; } } if (line != IObuff) - free(line); + xfree(line); ++lnum; line_breakcheck(); } diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index d5e963c2f8..a260860e17 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1265,7 +1265,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) regcode = r->program; regc(REGMAGIC); if (reg(REG_NOPAREN, &flags) == NULL || reg_toolong) { - free(r); + xfree(r); if (reg_toolong) EMSG_RET_NULL(_("E339: Pattern too long")); return NULL; @@ -1349,7 +1349,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) */ static void bt_regfree(regprog_T *prog) { - free(prog); + xfree(prog); } /* @@ -3236,8 +3236,8 @@ void free_regexp_stuff(void) { ga_clear(®stack); ga_clear(&backpos); - free(reg_tofree); - free(reg_prev_sub); + xfree(reg_tofree); + xfree(reg_prev_sub); } #endif @@ -3509,7 +3509,7 @@ theend: /* Free "reg_tofree" when it's a bit big. * Free regstack and backpos if they are bigger than their initial size. */ if (reg_tofreelen > 400) { - free(reg_tofree); + xfree(reg_tofree); reg_tofree = NULL; } if (regstack.ga_maxlen > REGSTACK_INITIAL) @@ -3551,8 +3551,8 @@ void unref_extmatch(reg_extmatch_T *em) if (em != NULL && --em->refcnt <= 0) { for (i = 0; i < NSUBEXP; ++i) - free(em->matches[i]); - free(em); + xfree(em->matches[i]); + xfree(em); } } @@ -5642,7 +5642,7 @@ static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T e len = (int)STRLEN(regline); if (reg_tofree == NULL || len >= (int)reg_tofreelen) { len += 50; /* get some extra */ - free(reg_tofree); + xfree(reg_tofree); reg_tofree = xmalloc(len); reg_tofreelen = len; } @@ -6382,7 +6382,7 @@ char_u *regtilde(char_u *source, int magic) STRCPY(tmpsub + len + prevlen, p + 1); if (newsub != source) /* already allocated newsub */ - free(newsub); + xfree(newsub); newsub = tmpsub; p = newsub + len + prevlen; } else if (magic) @@ -6398,7 +6398,7 @@ char_u *regtilde(char_u *source, int magic) } } - free(reg_prev_sub); + xfree(reg_prev_sub); if (newsub != source) /* newsub was allocated, just keep it */ reg_prev_sub = newsub; else /* no ~ found, need to save newsub */ @@ -6494,14 +6494,14 @@ static int vim_regsub_both(char_u *source, char_u *dest, int copy, int magic, in if (eval_result != NULL) { STRCPY(dest, eval_result); dst += STRLEN(eval_result); - free(eval_result); + xfree(eval_result); eval_result = NULL; } } else { win_T *save_reg_win; int save_ireg_ic; - free(eval_result); + xfree(eval_result); /* The expression may contain substitute(), which calls us * recursively. Make sure submatch() gets the text from the first @@ -6542,7 +6542,7 @@ static int vim_regsub_both(char_u *source, char_u *dest, int copy, int magic, in if (had_backslash && backslash) { /* Backslashes will be consumed, need to double them. */ s = vim_strsave_escaped(eval_result, (char_u *)"\\"); - free(eval_result); + xfree(eval_result); eval_result = s; } @@ -7073,7 +7073,7 @@ static int vim_regexec_both(regmatch_T *rmp, char_u *line, colnr_T col, bool nl) result = rmp->regprog->engine->regexec_nl(rmp, line, col, nl); } - free(pat); + xfree(pat); p_re = save_p_re; } @@ -7127,7 +7127,7 @@ long vim_regexec_multi( tm); } - free(pat); + xfree(pat); p_re = save_p_re; } diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 1de167c40f..56e488fbd4 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -2886,7 +2886,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size) if (stackp < stack) \ { \ st_error(postfix, end, p); \ - free(stack); \ + xfree(stack); \ return NULL; \ } @@ -3317,13 +3317,13 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size) e = POP(); if (stackp != stack) { - free(stack); + xfree(stack); EMSG_RET_NULL(_("E875: (NFA regexp) (While converting from postfix to NFA)," "too many states left on stack")); } if (istate >= nstate) { - free(stack); + xfree(stack); EMSG_RET_NULL(_("E876: (NFA regexp) " "Not enough space to store the whole NFA ")); } @@ -3337,7 +3337,7 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size) ret = e.start; theend: - free(stack); + xfree(stack); return ret; #undef POP1 @@ -4195,7 +4195,7 @@ addstate_here ( memmove(&(newl[listidx + count]), &(l->t[listidx + 1]), sizeof(nfa_thread_T) * (l->n - count - listidx - 1)); - free(l->t); + xfree(l->t); l->t = newl; } else { /* make space for new states, then move them from the @@ -6033,9 +6033,9 @@ nextchar: theend: /* Free memory */ - free(list[0].t); - free(list[1].t); - free(listids); + xfree(list[0].t); + xfree(list[1].t); + xfree(listids); #undef ADD_STATE_IF_MATCH #ifdef NFA_REGEXP_DEBUG_LOG fclose(debug); @@ -6340,13 +6340,13 @@ static regprog_T *nfa_regcomp(char_u *expr, int re_flags) nfa_regengine.expr = NULL; out: - free(post_start); + xfree(post_start); post_start = post_ptr = post_end = NULL; state_ptr = NULL; return (regprog_T *)prog; fail: - free(prog); + xfree(prog); prog = NULL; #ifdef REGEXP_DEBUG nfa_postfix_dump(expr, FAIL); @@ -6361,9 +6361,9 @@ fail: static void nfa_regfree(regprog_T *prog) { if (prog != NULL) { - free(((nfa_regprog_T *)prog)->match_text); - free(((nfa_regprog_T *)prog)->pattern); - free(prog); + xfree(((nfa_regprog_T *)prog)->match_text); + xfree(((nfa_regprog_T *)prog)->pattern); + xfree(prog); } } diff --git a/src/nvim/screen.c b/src/nvim/screen.c index c32603afb0..acd8e925e0 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1905,7 +1905,7 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T } if (text != buf) - free(text); + xfree(text); /* * 6. set highlighting for the Visual area an other text. @@ -3015,7 +3015,7 @@ win_line ( --n_extra; } else { if (p_extra_free != NULL) { - free(p_extra_free); + xfree(p_extra_free); p_extra_free = NULL; } /* @@ -4700,7 +4700,7 @@ win_redr_status_matches ( } win_redraw_last_status(topframe); - free(buf); + xfree(buf); } /* @@ -4915,7 +4915,7 @@ get_keymap_str ( sprintf((char *)buf, "<%s>", p); else buf[0] = NUL; - free(s); + xfree(s); } return buf[0] != NUL; } @@ -5021,14 +5021,14 @@ win_redr_custom ( width = build_stl_str_hl(ewp, buf, sizeof(buf), stl, use_sandbox, fillchar, maxwidth, hltab, tabtab); - free(stl); + xfree(stl); ewp->w_p_crb = p_crb_save; /* Make all characters printable. */ p = transstr(buf); len = STRLCPY(buf, p, sizeof(buf)); len = (size_t)len < sizeof(buf) ? len : (int)sizeof(buf) - 1; - free(p); + xfree(p); /* fill up with "fillchar" */ while (width < maxwidth && len < (int)sizeof(buf) - 1) { @@ -5999,23 +5999,23 @@ retry: * and over again. */ done_outofmem_msg = TRUE; } - free(new_ScreenLines); + xfree(new_ScreenLines); new_ScreenLines = NULL; - free(new_ScreenLinesUC); + xfree(new_ScreenLinesUC); new_ScreenLinesUC = NULL; for (i = 0; i < p_mco; ++i) { - free(new_ScreenLinesC[i]); + xfree(new_ScreenLinesC[i]); new_ScreenLinesC[i] = NULL; } - free(new_ScreenLines2); + xfree(new_ScreenLines2); new_ScreenLines2 = NULL; - free(new_ScreenAttrs); + xfree(new_ScreenAttrs); new_ScreenAttrs = NULL; - free(new_LineOffset); + xfree(new_LineOffset); new_LineOffset = NULL; - free(new_LineWraps); + xfree(new_LineWraps); new_LineWraps = NULL; - free(new_TabPageIdxs); + xfree(new_TabPageIdxs); new_TabPageIdxs = NULL; } else { done_outofmem_msg = FALSE; @@ -6126,15 +6126,15 @@ void free_screenlines(void) { int i; - free(ScreenLinesUC); + xfree(ScreenLinesUC); for (i = 0; i < Screen_mco; ++i) - free(ScreenLinesC[i]); - free(ScreenLines2); - free(ScreenLines); - free(ScreenAttrs); - free(LineOffset); - free(LineWraps); - free(TabPageIdxs); + xfree(ScreenLinesC[i]); + xfree(ScreenLines2); + xfree(ScreenLines); + xfree(ScreenAttrs); + xfree(LineOffset); + xfree(LineWraps); + xfree(TabPageIdxs); } void screenclear(void) diff --git a/src/nvim/search.c b/src/nvim/search.c index f62aeabd72..f015c233c8 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -179,7 +179,7 @@ search_regcomp ( add_to_history(HIST_SEARCH, pat, TRUE, NUL); if (mr_pattern_alloced) { - free(mr_pattern); + xfree(mr_pattern); mr_pattern_alloced = FALSE; } @@ -249,7 +249,7 @@ char_u *reverse_text(char_u *s) FUNC_ATTR_NONNULL_RET void save_re_pat(int idx, char_u *pat, int magic) { if (spats[idx].pat != pat) { - free(spats[idx].pat); + xfree(spats[idx].pat); spats[idx].pat = vim_strsave(pat); spats[idx].magic = magic; spats[idx].no_scs = no_smartcase; @@ -284,10 +284,10 @@ void save_search_patterns(void) void restore_search_patterns(void) { if (--save_level == 0) { - free(spats[0].pat); + xfree(spats[0].pat); spats[0] = saved_spats[0]; set_vv_searchforward(); - free(spats[1].pat); + xfree(spats[1].pat); spats[1] = saved_spats[1]; last_idx = saved_last_idx; SET_NO_HLSEARCH(saved_no_hlsearch); @@ -297,11 +297,11 @@ void restore_search_patterns(void) #if defined(EXITFREE) void free_search_patterns(void) { - free(spats[0].pat); - free(spats[1].pat); + xfree(spats[0].pat); + xfree(spats[1].pat); if (mr_pattern_alloced) { - free(mr_pattern); + xfree(mr_pattern); mr_pattern_alloced = FALSE; mr_pattern = NULL; } @@ -377,7 +377,7 @@ void reset_search_dir(void) */ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) { - free(spats[idx].pat); + xfree(spats[idx].pat); /* An empty string means that nothing should be matched. */ if (*s == NUL) spats[idx].pat = NULL; @@ -393,7 +393,7 @@ void set_last_search_pat(const char_u *s, int idx, int magic, int setlast) if (setlast) last_idx = idx; if (save_level) { - free(saved_spats[idx].pat); + xfree(saved_spats[idx].pat); saved_spats[idx] = spats[0]; if (spats[idx].pat == NULL) saved_spats[idx].pat = NULL; @@ -1075,17 +1075,17 @@ int do_search( * left, but do reverse the text. */ if (curwin->w_p_rl && *curwin->w_p_rlc == 's') { char_u *r = reverse_text(trunc != NULL ? trunc : msgbuf); - free(trunc); + xfree(trunc); trunc = r; } if (trunc != NULL) { msg_outtrans(trunc); - free(trunc); + xfree(trunc); } else msg_outtrans(msgbuf); msg_clr_eos(); msg_check(); - free(msgbuf); + xfree(msgbuf); gotocmdline(FALSE); ui_flush(); @@ -1203,7 +1203,7 @@ int do_search( end_do_search: if ((options & SEARCH_KEEP) || cmdmod.keeppatterns) spats[0].off = old_off; - free(strcopy); + xfree(strcopy); return retval; } @@ -3246,8 +3246,8 @@ again: r = do_searchpair(spat, (char_u *)"", epat, FORWARD, (char_u *)"", 0, NULL, (linenr_T)0, 0L); - free(spat); - free(epat); + xfree(spat); + xfree(epat); if (r < 1 || lt(curwin->w_cursor, old_end)) { /* Can't find other end or it's before the previous end. Could be a @@ -4006,7 +4006,7 @@ find_pattern_in_path ( /* ignore case according to p_ic, p_scs and pat */ regmatch.rm_ic = ignorecase(pat); regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); - free(pat); + xfree(pat); if (regmatch.regprog == NULL) goto fpip_end; } @@ -4070,7 +4070,7 @@ find_pattern_in_path ( prev_fname = NULL; } } - free(new_fname); + xfree(new_fname); new_fname = NULL; already_searched = TRUE; break; @@ -4173,17 +4173,17 @@ find_pattern_in_path ( bigger[i + max_path_depth] = files[i]; old_files += max_path_depth; max_path_depth *= 2; - free(files); + xfree(files); files = bigger; } if ((files[depth + 1].fp = mch_fopen((char *)new_fname, "r")) == NULL) - free(new_fname); + xfree(new_fname); else { if (++depth == old_files) { // Something wrong. We will forget one of our already visited files // now. - free(files[old_files].name); + xfree(files[old_files].name); ++old_files; } files[depth].name = curr_fname = new_fname; @@ -4491,11 +4491,11 @@ exit_matched: /* Close any files that are still open. */ for (i = 0; i <= depth; i++) { fclose(files[i].fp); - free(files[i].name); + xfree(files[i].name); } for (i = old_files; i < max_path_depth; i++) - free(files[i].name); - free(files); + xfree(files[i].name); + xfree(files); if (type == CHECK_PATH) { if (!did_show) { @@ -4518,7 +4518,7 @@ exit_matched: msg_end(); fpip_end: - free(file_line); + xfree(file_line); vim_regfree(regmatch.regprog); vim_regfree(incl_regmatch.regprog); vim_regfree(def_regmatch.regprog); @@ -4629,7 +4629,7 @@ int read_viminfo_search_pattern(vir_T *virp, int force) if (force || spats[idx].pat == NULL) { val = viminfo_readstring(virp, (int)(lp - virp->vir_line + 1), TRUE); set_last_search_pat(val, idx, magic, setlast); - free(val); + xfree(val); spats[idx].no_scs = no_scs; spats[idx].off.line = off_line; spats[idx].off.end = off_end; diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 6708ad2aa7..7b38b540cb 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2097,7 +2097,7 @@ spell_move_to ( len = (int)STRLEN(line); if (buflen < len + MAXWLEN + 2) { - free(buf); + xfree(buf); buflen = len + MAXWLEN + 2; buf = xmalloc(buflen); } @@ -2172,7 +2172,7 @@ spell_move_to ( if (dir == FORWARD) { // No need to search further. wp->w_cursor = found_pos; - free(buf); + xfree(buf); if (attrp != NULL) *attrp = attr; return len; @@ -2195,7 +2195,7 @@ spell_move_to ( if (dir == BACKWARD && found_pos.lnum != 0) { // Use the last match in the line (before the cursor). wp->w_cursor = found_pos; - free(buf); + xfree(buf); return found_len; } @@ -2259,7 +2259,7 @@ spell_move_to ( line_breakcheck(); } - free(buf); + xfree(buf); return 0; } @@ -2376,26 +2376,26 @@ static slang_T *slang_alloc(char_u *lang) // Free the contents of an slang_T and the structure itself. static void slang_free(slang_T *lp) { - free(lp->sl_name); - free(lp->sl_fname); + xfree(lp->sl_name); + xfree(lp->sl_fname); slang_clear(lp); - free(lp); + xfree(lp); } /// Frees a salitem_T static void free_salitem(salitem_T *smp) { - free(smp->sm_lead); + xfree(smp->sm_lead); // Don't free sm_oneof and sm_rules, they point into sm_lead. - free(smp->sm_to); - free(smp->sm_lead_w); - free(smp->sm_oneof_w); - free(smp->sm_to_w); + xfree(smp->sm_to); + xfree(smp->sm_lead_w); + xfree(smp->sm_oneof_w); + xfree(smp->sm_to_w); } /// Frees a fromto_T static void free_fromto(fromto_T *ftp) { - free(ftp->ft_from); - free(ftp->ft_to); + xfree(ftp->ft_from); + xfree(ftp->ft_to); } // Clear an slang_T so that the file can be reloaded. @@ -2403,18 +2403,18 @@ static void slang_clear(slang_T *lp) { garray_T *gap; - free(lp->sl_fbyts); + xfree(lp->sl_fbyts); lp->sl_fbyts = NULL; - free(lp->sl_kbyts); + xfree(lp->sl_kbyts); lp->sl_kbyts = NULL; - free(lp->sl_pbyts); + xfree(lp->sl_pbyts); lp->sl_pbyts = NULL; - free(lp->sl_fidxs); + xfree(lp->sl_fidxs); lp->sl_fidxs = NULL; - free(lp->sl_kidxs); + xfree(lp->sl_kidxs); lp->sl_kidxs = NULL; - free(lp->sl_pidxs); + xfree(lp->sl_pidxs); lp->sl_pidxs = NULL; GA_DEEP_CLEAR(&lp->sl_rep, fromto_T, free_fromto); @@ -2433,25 +2433,25 @@ static void slang_clear(slang_T *lp) vim_regfree(lp->sl_prefprog[i]); } lp->sl_prefixcnt = 0; - free(lp->sl_prefprog); + xfree(lp->sl_prefprog); lp->sl_prefprog = NULL; - free(lp->sl_info); + xfree(lp->sl_info); lp->sl_info = NULL; - free(lp->sl_midword); + xfree(lp->sl_midword); lp->sl_midword = NULL; vim_regfree(lp->sl_compprog); - free(lp->sl_comprules); - free(lp->sl_compstartflags); - free(lp->sl_compallflags); + xfree(lp->sl_comprules); + xfree(lp->sl_compstartflags); + xfree(lp->sl_compallflags); lp->sl_compprog = NULL; lp->sl_comprules = NULL; lp->sl_compstartflags = NULL; lp->sl_compallflags = NULL; - free(lp->sl_syllable); + xfree(lp->sl_syllable); lp->sl_syllable = NULL; ga_clear(&lp->sl_syl_items); @@ -2474,9 +2474,9 @@ static void slang_clear(slang_T *lp) // Clear the info from the .sug file in "lp". static void slang_clear_sug(slang_T *lp) { - free(lp->sl_sbyts); + xfree(lp->sl_sbyts); lp->sl_sbyts = NULL; - free(lp->sl_sidxs); + xfree(lp->sl_sidxs); lp->sl_sidxs = NULL; close_spellbuf(lp->sl_sugbuf); lp->sl_sugbuf = NULL; @@ -2642,7 +2642,7 @@ spell_load_file ( if (p == NULL) goto endFAIL; set_map_str(lp, p); - free(p); + xfree(p); break; case SN_WORDS: @@ -2799,7 +2799,7 @@ static int read_charflags_section(FILE *fd) // <folcharslen> <folchars> fol = read_cnt_string(fd, 2, &follen); if (follen < 0) { - free(flags); + xfree(flags); return follen; } @@ -2807,8 +2807,8 @@ static int read_charflags_section(FILE *fd) if (flags != NULL && fol != NULL) set_spell_charflags(flags, flagslen, fol); - free(flags); - free(fol); + xfree(flags); + xfree(fol); // When <charflagslen> is zero then <fcharlen> must also be zero. if ((flags == NULL) != (fol == NULL)) @@ -2878,7 +2878,7 @@ static int read_rep_section(FILE *fd, garray_T *gap, short *first) return SP_FORMERROR; ftp->ft_to = read_cnt_string(fd, 1, &c); if (c <= 0) { - free(ftp->ft_from); + xfree(ftp->ft_from); if (c < 0) return c; return SP_FORMERROR; @@ -2973,7 +2973,7 @@ static int read_sal_section(FILE *fd, slang_T *slang) // <saltolen> <salto> smp->sm_to = read_cnt_string(fd, 1, &ccnt); if (ccnt < 0) { - free(smp->sm_lead); + xfree(smp->sm_lead); return ccnt; } @@ -3136,7 +3136,7 @@ static int read_sofo_section(FILE *fd, slang_T *slang) // <sofotolen> <sofoto> to = read_cnt_string(fd, 2, &cnt); if (cnt < 0) { - free(from); + xfree(from); return cnt; } @@ -3148,8 +3148,8 @@ static int read_sofo_section(FILE *fd, slang_T *slang) else res = 0; - free(from); - free(to); + xfree(from); + xfree(to); return res; } @@ -3250,7 +3250,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) while (todo-- > 0) { c = getc(fd); // <compflags> if (c == EOF) { - free(pat); + xfree(pat); return SP_TRUNCERROR; } @@ -3281,7 +3281,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) // Copy flag to "sl_comprules", unless we run into a wildcard. if (crp != NULL) { if (c == '?' || c == '+' || c == '*') { - free(slang->sl_comprules); + xfree(slang->sl_comprules); slang->sl_comprules = NULL; crp = NULL; } else @@ -3311,7 +3311,7 @@ static int read_compound(FILE *fd, slang_T *slang, int len) *crp = NUL; slang->sl_compprog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_STRICT); - free(pat); + xfree(pat); if (slang->sl_compprog == NULL) return SP_FORMERROR; @@ -3961,7 +3961,7 @@ char_u *did_set_spelllang(win_T *wp) } theend: - free(spl_copy); + xfree(spl_copy); recursive = false; redraw_win_later(wp, NOT_VALID); return ret_msg; @@ -3971,7 +3971,7 @@ theend: static void clear_midword(win_T *wp) { memset(wp->w_s->b_spell_ismw, 0, 256); - free(wp->w_s->b_spell_ismw_mb); + xfree(wp->w_s->b_spell_ismw_mb); wp->w_s->b_spell_ismw_mb = NULL; } @@ -4000,7 +4000,7 @@ static void use_midword(slang_T *lp, win_T *wp) // Append multi-byte chars to "b_spell_ismw_mb". n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l); - free(wp->w_s->b_spell_ismw_mb); + xfree(wp->w_s->b_spell_ismw_mb); wp->w_s->b_spell_ismw_mb = bp; STRLCPY(bp + n, p, l + 1); } @@ -4124,7 +4124,7 @@ void spell_delete_wordlist(void) os_remove((char *)int_wordlist); int_wordlist_spl(fname); os_remove((char *)fname); - free(int_wordlist); + xfree(int_wordlist); int_wordlist = NULL; } } @@ -4147,9 +4147,9 @@ void spell_free_all(void) spell_delete_wordlist(); - free(repl_to); + xfree(repl_to); repl_to = NULL; - free(repl_from); + xfree(repl_from); repl_from = NULL; } @@ -4392,7 +4392,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) continue; // Convert from "SET" to 'encoding' when needed. - free(pc); + xfree(pc); if (spin->si_conv.vc_type != CONV_NONE) { pc = string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { @@ -5005,9 +5005,9 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) (void)set_spell_chartab(fol, low, upp); } - free(fol); - free(low); - free(upp); + xfree(fol); + xfree(low); + xfree(upp); } // Use compound specifications of the .aff file for the spell info. @@ -5070,7 +5070,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) spin->si_midword = midword; } - free(pc); + xfree(pc); fclose(fd); return aff; } @@ -5344,7 +5344,7 @@ static void spell_free_aff(afffile_T *aff) affheader_T *ah; affentry_T *ae; - free(aff->af_enc); + xfree(aff->af_enc); // All this trouble to free the "ae_prog" items... for (ht = &aff->af_pref;; ht = &aff->af_suff) { @@ -5461,7 +5461,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) // Skip non-ASCII words when "spin->si_ascii" is true. if (spin->si_ascii && has_non_ascii(w)) { ++non_ascii; - free(pc); + xfree(pc); continue; } @@ -5483,7 +5483,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) dw = getroom_save(spin, w); if (dw == NULL) { retval = FAIL; - free(pc); + xfree(pc); break; } @@ -5542,7 +5542,7 @@ static int spell_read_dic(spellinfo_T *spin, char_u *fname, afffile_T *affile) retval = FAIL; } - free(pc); + xfree(pc); } if (duplicate > 0) @@ -5938,7 +5938,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) rline[l] = NUL; // Convert from "/encoding={encoding}" to 'encoding' when needed. - free(pc); + xfree(pc); if (spin->si_conv.vc_type != CONV_NONE) { pc = string_convert(&spin->si_conv, rline, NULL); if (pc == NULL) { @@ -5974,7 +5974,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) p_enc) == FAIL) smsg((char_u *)_("Conversion in %s not supported: from %s to %s"), fname, line, p_enc); - free(enc); + xfree(enc); spin->si_conv.vc_fail = true; } continue; @@ -6054,7 +6054,7 @@ static int spell_read_wordfile(spellinfo_T *spin, char_u *fname) did_word = true; } - free(pc); + xfree(pc); fclose(fd); if (spin->si_ascii && non_ascii > 0) { @@ -6123,7 +6123,7 @@ static void free_blocks(sblock_T *bl) while (bl != NULL) { next = bl->sb_next; - free(bl); + xfree(bl); bl = next; } } @@ -7167,7 +7167,7 @@ static void spell_make_sugfile(spellinfo_T *spin, char_u *wfname) sug_write(spin, fname); theend: - free(fname); + xfree(fname); if (free_slang) slang_free(slang); free_blocks(spin->si_blocks); @@ -7514,7 +7514,7 @@ static void close_spellbuf(buf_T *buf) { if (buf != NULL) { ml_close(buf, TRUE); - free(buf); + xfree(buf); } } @@ -7737,8 +7737,8 @@ mkspell ( } theend: - free(fname); - free(wfname); + xfree(fname); + xfree(wfname); } // Display a message for spell file processing when 'verbose' is set or using @@ -7812,7 +7812,7 @@ spell_add_word ( break; if (*spf == NUL) { EMSGN(_("E765: 'spellfile' does not have %" PRId64 " entries"), idx); - free(fnamebuf); + xfree(fnamebuf); return; } } @@ -7823,7 +7823,7 @@ spell_add_word ( buf = NULL; if (buf != NULL && bufIsChanged(buf)) { EMSG(_(e_bufloaded)); - free(fnamebuf); + xfree(fnamebuf); return; } @@ -7908,7 +7908,7 @@ spell_add_word ( redraw_all_later(SOME_VALID); } - free(fnamebuf); + xfree(fnamebuf); } // Initialize 'spellfile' for the current buffer. @@ -7977,7 +7977,7 @@ static void init_spellfile(void) aspath = false; } - free(buf); + xfree(buf); } } @@ -8464,9 +8464,9 @@ void spell_suggest(int count) smsg((char_u *)_("Sorry, only %" PRId64 " suggestions"), (int64_t)sug.su_ga.ga_len); } else { - free(repl_from); + xfree(repl_from); repl_from = NULL; - free(repl_to); + xfree(repl_to); repl_to = NULL; // When 'rightleft' is set the list is drawn right-left. @@ -8638,7 +8638,7 @@ static bool check_need_cap(linenr_T lnum, colnr_T col) } } - free(line_copy); + xfree(line_copy); return need_cap; } @@ -8696,7 +8696,7 @@ void ex_spellrepall(exarg_T *eap) p_ws = save_ws; curwin->w_cursor = pos; - free(frompat); + xfree(frompat); if (sub_nsubs == 0) EMSG2(_("E753: Not found: %s"), repl_from); @@ -8849,7 +8849,7 @@ spell_find_suggest ( } } - free(sps_copy); + xfree(sps_copy); if (do_combine) // Combine the two list of suggestions. This must be done last, @@ -9181,7 +9181,7 @@ static void tree_count_words(char_u *byts, idx_T *idxs) // Free the info put in "*su" by spell_find_suggest(). static void spell_find_cleanup(suginfo_T *su) { -# define FREE_SUG_WORD(sug) free(sug->st_word) +# define FREE_SUG_WORD(sug) xfree(sug->st_word) // Free the suggestions. GA_DEEP_CLEAR(&su->su_ga, suggest_T, FREE_SUG_WORD); GA_DEEP_CLEAR(&su->su_sga, suggest_T, FREE_SUG_WORD); @@ -10866,7 +10866,7 @@ static void score_combine(suginfo_T *su) if (j == ga.ga_len) stp[ga.ga_len++] = SUG(*gap, i); else - free(p); + xfree(p); } } } @@ -10877,7 +10877,7 @@ static void score_combine(suginfo_T *su) // Truncate the list to the number of suggestions that will be displayed. if (ga.ga_len > su->su_maxcount) { for (int i = su->su_maxcount; i < ga.ga_len; ++i) { - free(stp[i].st_word); + xfree(stp[i].st_word); } ga.ga_len = su->su_maxcount; } @@ -11004,7 +11004,7 @@ static void suggest_try_soundalike_finish(void) todo = (int)slang->sl_sounddone.ht_used; for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi) if (!HASHITEM_EMPTY(hi)) { - free(HI2SFT(hi)); + xfree(HI2SFT(hi)); --todo; } @@ -11328,7 +11328,7 @@ static void set_map_str(slang_T *lp, char_u *map) // This should have been checked when generating the .spl // file. EMSG(_("E783: duplicate char in MAP entry")); - free(b); + xfree(b); } } else lp->sl_map_array[c] = headc; @@ -11511,7 +11511,7 @@ check_suggestions ( (void)spell_check(curwin, longword, &attr, NULL, false); if (attr != HLF_COUNT) { // Remove this entry. - free(stp[i].st_word); + xfree(stp[i].st_word); --gap->ga_len; if (i < gap->ga_len) memmove(stp + i, stp + i + 1, @@ -11608,7 +11608,7 @@ cleanup_suggestions ( // Truncate the list to the number of suggestions that will be displayed. if (gap->ga_len > keep) { for (int i = keep; i < gap->ga_len; ++i) { - free(stp[i].st_word); + xfree(stp[i].st_word); } gap->ga_len = keep; return stp[keep - 1].st_score; @@ -12548,7 +12548,7 @@ static int spell_edit_score(slang_T *slang, char_u *badword, char_u *goodword) } i = CNT(badlen - 1, goodlen - 1); - free(cnt); + xfree(cnt); return i; } @@ -12906,7 +12906,7 @@ void ex_spelldump(exarg_T *eap) // enable spelling locally in the new window set_option_value((char_u*)"spell", TRUE, (char_u*)"", OPT_LOCAL); set_option_value((char_u*)"spl", dummy, spl, OPT_LOCAL); - free(spl); + xfree(spl); if (!bufempty() || !buf_valid(curbuf)) return; diff --git a/src/nvim/strings.c b/src/nvim/strings.c index dd10184d38..4e70f48860 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -269,7 +269,7 @@ char_u *strup_save(const char_u *orig) memcpy(s, res, (size_t)(p - res)); STRCPY(s + (p - res) + newl, p + l); p = s + (p - res); - free(res); + xfree(res); res = s; } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 20bfbc8db4..8c32e5f06a 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -959,7 +959,7 @@ static void syn_stack_free_block(synblock_T *block) if (block->b_sst_array != NULL) { for (p = block->b_sst_first; p != NULL; p = p->sst_next) clear_syn_state(p); - free(block->b_sst_array); + xfree(block->b_sst_array); block->b_sst_array = NULL; block->b_sst_len = 0; } @@ -1044,7 +1044,7 @@ static void syn_stack_alloc(void) to->sst_next = to + 1; (sstp + len - 1)->sst_next = NULL; - free(syn_block->b_sst_array); + xfree(syn_block->b_sst_array); syn_block->b_sst_array = sstp; syn_block->b_sst_len = len; } @@ -3054,7 +3054,7 @@ void syntax_clear(synblock_T *block) vim_regfree(block->b_syn_linecont_prog); block->b_syn_linecont_prog = NULL; - free(block->b_syn_linecont_pat); + xfree(block->b_syn_linecont_pat); block->b_syn_linecont_pat = NULL; block->b_syn_folditems = 0; @@ -3073,7 +3073,7 @@ void reset_synblock(win_T *wp) { if (wp->w_s != &wp->w_buffer->b_s) { syntax_clear(wp->w_s); - free(wp->w_s); + xfree(wp->w_s); wp->w_s = &wp->w_buffer->b_s; } } @@ -3097,7 +3097,7 @@ static void syntax_sync_clear(void) vim_regfree(curwin->w_s->b_syn_linecont_prog); curwin->w_s->b_syn_linecont_prog = NULL; - free(curwin->w_s->b_syn_linecont_pat); + xfree(curwin->w_s->b_syn_linecont_pat); curwin->w_s->b_syn_linecont_pat = NULL; syn_stack_free_all(curwin->w_s); /* Need to recompute all syntax. */ @@ -3125,13 +3125,13 @@ static void syn_remove_pattern(synblock_T *block, int idx) */ static void syn_clear_pattern(synblock_T *block, int i) { - free(SYN_ITEMS(block)[i].sp_pattern); + xfree(SYN_ITEMS(block)[i].sp_pattern); vim_regfree(SYN_ITEMS(block)[i].sp_prog); /* Only free sp_cont_list and sp_next_list of first start pattern */ if (i == 0 || SYN_ITEMS(block)[i - 1].sp_type != SPTYPE_START) { - free(SYN_ITEMS(block)[i].sp_cont_list); - free(SYN_ITEMS(block)[i].sp_next_list); - free(SYN_ITEMS(block)[i].sp_syn.cont_in_list); + xfree(SYN_ITEMS(block)[i].sp_cont_list); + xfree(SYN_ITEMS(block)[i].sp_next_list); + xfree(SYN_ITEMS(block)[i].sp_syn.cont_in_list); } } @@ -3140,9 +3140,9 @@ static void syn_clear_pattern(synblock_T *block, int i) */ static void syn_clear_cluster(synblock_T *block, int i) { - free(SYN_CLSTR(block)[i].scl_name); - free(SYN_CLSTR(block)[i].scl_name_u); - free(SYN_CLSTR(block)[i].scl_list); + xfree(SYN_CLSTR(block)[i].scl_name); + xfree(SYN_CLSTR(block)[i].scl_name_u); + xfree(SYN_CLSTR(block)[i].scl_list); } /* @@ -3198,7 +3198,7 @@ static void syn_cmd_clear(exarg_T *eap, int syncing) */ short scl_id = id - SYNID_CLUSTER; - free(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); + xfree(SYN_CLSTR(curwin->w_s)[scl_id].scl_list); SYN_CLSTR(curwin->w_s)[scl_id].scl_list = NULL; } } else { @@ -3760,9 +3760,9 @@ static void syn_clear_keyword(int id, hashtab_T *ht) hi->hi_key = KE2HIKEY(kp_next); } else kp_prev->ke_next = kp_next; - free(kp->next_list); - free(kp->k_syn.cont_in_list); - free(kp); + xfree(kp->next_list); + xfree(kp->k_syn.cont_in_list); + xfree(kp); kp = kp_next; } else { kp_prev = kp; @@ -3789,9 +3789,9 @@ static void clear_keywtab(hashtab_T *ht) --todo; for (kp = HI2KE(hi); kp != NULL; kp = kp_next) { kp_next = kp->ke_next; - free(kp->next_list); - free(kp->k_syn.cont_in_list); - free(kp); + xfree(kp->next_list); + xfree(kp->k_syn.cont_in_list); + xfree(kp); } } } @@ -4011,12 +4011,12 @@ get_syn_options ( } if (i < 0) { EMSG2(_("E394: Didn't find region item for %s"), gname); - free(gname); + xfree(gname); return NULL; } } - free(gname); + xfree(gname); arg = skipwhite(arg); } else if (flagtab[fidx].flags == HL_FOLD && foldmethodIsSyntax(curwin)) @@ -4208,9 +4208,9 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing) } } - free(keyword_copy); - free(syn_opt_arg.cont_in_list); - free(syn_opt_arg.next_list); + xfree(keyword_copy); + xfree(syn_opt_arg.cont_in_list); + xfree(syn_opt_arg.next_list); } if (rest != NULL) @@ -4311,10 +4311,10 @@ syn_cmd_match ( * Something failed, free the allocated memory. */ vim_regfree(item.sp_prog); - free(item.sp_pattern); - free(syn_opt_arg.cont_list); - free(syn_opt_arg.cont_in_list); - free(syn_opt_arg.next_list); + xfree(item.sp_pattern); + xfree(syn_opt_arg.cont_list); + xfree(syn_opt_arg.cont_in_list); + xfree(syn_opt_arg.next_list); if (rest == NULL) EMSG2(_(e_invarg2), arg); @@ -4388,7 +4388,7 @@ syn_cmd_region ( key_end = rest; while (*key_end && !vim_iswhite(*key_end) && *key_end != '=') ++key_end; - free(key); + xfree(key); key = vim_strnsave_up(rest, (int)(key_end - rest)); if (STRCMP(key, "MATCHGROUP") == 0) item = ITEM_MATCHGROUP; @@ -4456,7 +4456,7 @@ syn_cmd_region ( ++pat_count; } } - free(key); + xfree(key); if (illegal || not_enough) rest = NULL; @@ -4530,17 +4530,17 @@ syn_cmd_region ( for (ppp = pat_ptrs[item]; ppp != NULL; ppp = ppp_next) { if (!success) { vim_regfree(ppp->pp_synp->sp_prog); - free(ppp->pp_synp->sp_pattern); + xfree(ppp->pp_synp->sp_pattern); } - free(ppp->pp_synp); + xfree(ppp->pp_synp); ppp_next = ppp->pp_next; - free(ppp); + xfree(ppp); } if (!success) { - free(syn_opt_arg.cont_list); - free(syn_opt_arg.cont_in_list); - free(syn_opt_arg.next_list); + xfree(syn_opt_arg.cont_list); + xfree(syn_opt_arg.cont_in_list); + xfree(syn_opt_arg.next_list); if (not_enough) EMSG2(_("E399: Not enough arguments: syntax region %s"), arg); else if (illegal || rest == NULL) @@ -4580,11 +4580,11 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op) return; if (*clstr1 == NULL || list_op == CLUSTER_REPLACE) { if (list_op == CLUSTER_REPLACE) - free(*clstr1); + xfree(*clstr1); if (list_op == CLUSTER_REPLACE || list_op == CLUSTER_ADD) *clstr1 = *clstr2; else - free(*clstr2); + xfree(*clstr2); return; } @@ -4668,8 +4668,8 @@ static void syn_combine_list(short **clstr1, short **clstr2, int list_op) /* * Finally, put the new list in place. */ - free(*clstr1); - free(*clstr2); + xfree(*clstr1); + xfree(*clstr2); *clstr1 = clstr; } @@ -4688,7 +4688,7 @@ static int syn_scl_name2id(char_u *name) break; } } - free(name_u); + xfree(name_u); return i < 0 ? 0 : i + SYNID_CLUSTER; } @@ -4699,7 +4699,7 @@ static int syn_scl_namen2id(char_u *linep, int len) { char_u *name = vim_strnsave(linep, len); int id = syn_scl_name2id(name); - free(name); + xfree(name); return id; } @@ -4721,7 +4721,7 @@ static int syn_check_cluster(char_u *pp, int len) if (id == 0) /* doesn't exist yet */ id = syn_add_cluster(name); else - free(name); + xfree(name); return id; } @@ -4743,7 +4743,7 @@ static int syn_add_cluster(char_u *name) int len = curwin->w_s->b_syn_clusters.ga_len; if (len >= MAX_CLUSTER_ID) { EMSG((char_u *)_("E848: Too many syntax clusters")); - free(name); + xfree(name); return 0; } @@ -4945,7 +4945,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) while (!ends_excmd(*arg_start)) { arg_end = skiptowhite(arg_start); next_arg = skipwhite(arg_end); - free(key); + xfree(key); key = vim_strnsave_up(arg_start, (int)(arg_end - arg_start)); if (STRCMP(key, "CCOMMENT") == 0) { if (!eap->skip) @@ -5013,7 +5013,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) syn_clear_time(&curwin->w_s->b_syn_linecont_time); if (curwin->w_s->b_syn_linecont_prog == NULL) { - free(curwin->w_s->b_syn_linecont_pat); + xfree(curwin->w_s->b_syn_linecont_pat); curwin->w_s->b_syn_linecont_pat = NULL; finished = TRUE; break; @@ -5035,7 +5035,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) } arg_start = next_arg; } - free(key); + xfree(key); if (illegal) EMSG2(_("E404: Illegal arguments: %s"), arg_start); else if (!finished) { @@ -5109,13 +5109,13 @@ get_id_list ( if (TOUPPER_ASC(**arg) != 'C') { EMSG2(_("E407: %s not allowed here"), name + 1); failed = TRUE; - free(name); + xfree(name); break; } if (count != 0) { EMSG2(_("E408: %s must be first in contains list"), name + 1); failed = TRUE; - free(name); + xfree(name); break; } if (name[1] == 'A') @@ -5142,7 +5142,7 @@ get_id_list ( regmatch.regprog = vim_regcomp(name, RE_MAGIC); if (regmatch.regprog == NULL) { failed = TRUE; - free(name); + xfree(name); break; } @@ -5156,7 +5156,7 @@ get_id_list ( * "contains=a.*b,axb". * Go back to first round */ if (count >= total_count) { - free(retval); + xfree(retval); round = 1; } else retval[count] = i + 1; @@ -5168,7 +5168,7 @@ get_id_list ( vim_regfree(regmatch.regprog); } } - free(name); + xfree(name); if (id == 0) { EMSG2(_("E409: Unknown group name: %s"), p); failed = TRUE; @@ -5178,7 +5178,7 @@ get_id_list ( if (round == 2) { /* Got more items than expected, go back to first round */ if (count >= total_count) { - free(retval); + xfree(retval); round = 1; } else retval[count] = id; @@ -5201,14 +5201,14 @@ get_id_list ( *arg = p; if (failed || retval == NULL) { - free(retval); + xfree(retval); return FAIL; } if (*list == NULL) *list = retval; else - free(retval); /* list already found, don't overwrite it */ + xfree(retval); /* list already found, don't overwrite it */ return OK; } @@ -5387,7 +5387,7 @@ void ex_syntax(exarg_T *eap) break; } } - free(subcmd_name); + xfree(subcmd_name); if (eap->skip) --emsg_skip; } @@ -5427,7 +5427,7 @@ void ex_ownsyntax(exarg_T *eap) do_unlet((char_u *)"b:current_syntax", TRUE); else { set_internal_string_var((char_u *)"b:current_syntax", old_value); - free(old_value); + xfree(old_value); } } @@ -5751,183 +5751,94 @@ static void syntime_report(void) * Highlighting stuff * **************************************/ -/* - * The default highlight groups. These are compiled-in for fast startup and - * they still work when the runtime files can't be found. - * When making changes here, also change runtime/colors/default.vim! - * The #ifdefs are needed to reduce the amount of static data. Helps to make - * the 16 bit DOS (museum) version compile. - */ -# define CENT(a, b) b -static char *(highlight_init_both[]) = -{ - CENT( - "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White", - "ErrorMsg term=standout ctermbg=DarkRed ctermfg=White guibg=Red guifg=White"), - CENT("IncSearch term=reverse cterm=reverse", - "IncSearch term=reverse cterm=reverse gui=reverse"), - CENT("ModeMsg term=bold cterm=bold", - "ModeMsg term=bold cterm=bold gui=bold"), - CENT("NonText term=bold ctermfg=Blue", - "NonText term=bold ctermfg=Blue gui=bold guifg=Blue"), - CENT("StatusLine term=reverse,bold cterm=reverse,bold", - "StatusLine term=reverse,bold cterm=reverse,bold gui=reverse,bold"), - CENT("StatusLineNC term=reverse cterm=reverse", - "StatusLineNC term=reverse cterm=reverse gui=reverse"), +// The default highlight groups. These are compiled-in for fast startup and +// they still work when the runtime files can't be found. +// +// When making changes here, also change runtime/colors/default.vim! + +static char *highlight_init_both[] = +{ + "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey", + "DiffText cterm=bold ctermbg=Red gui=bold guibg=Red", + "ErrorMsg ctermbg=DarkRed ctermfg=White guibg=Red guifg=White", + "IncSearch cterm=reverse gui=reverse", + "ModeMsg cterm=bold gui=bold", + "NonText ctermfg=Blue gui=bold guifg=Blue", + "PmenuSbar ctermbg=Grey guibg=Grey", + "StatusLine cterm=reverse,bold gui=reverse,bold", + "StatusLineNC cterm=reverse gui=reverse", + "TabLineFill cterm=reverse gui=reverse", + "TabLineSel cterm=bold gui=bold", + "TermCursor cterm=reverse gui=reverse", + "VertSplit cterm=reverse gui=reverse", + "WildMenu ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black", "default link EndOfBuffer NonText", - CENT("VertSplit term=reverse cterm=reverse", - "VertSplit term=reverse cterm=reverse gui=reverse"), - CENT("DiffText term=reverse cterm=bold ctermbg=Red", - "DiffText term=reverse cterm=bold ctermbg=Red gui=bold guibg=Red"), - CENT("PmenuSbar ctermbg=Grey", - "PmenuSbar ctermbg=Grey guibg=Grey"), - CENT("TabLineSel term=bold cterm=bold", - "TabLineSel term=bold cterm=bold gui=bold"), - CENT("TabLineFill term=reverse cterm=reverse", - "TabLineFill term=reverse cterm=reverse gui=reverse"), NULL }; -static char *(highlight_init_light[]) = -{ - CENT("Directory term=bold ctermfg=DarkBlue", - "Directory term=bold ctermfg=DarkBlue guifg=Blue"), - CENT("LineNr term=underline ctermfg=Brown", - "LineNr term=underline ctermfg=Brown guifg=Brown"), - CENT("CursorLineNr term=bold ctermfg=Brown", - "CursorLineNr term=bold ctermfg=Brown gui=bold guifg=Brown"), - CENT("MoreMsg term=bold ctermfg=DarkGreen", - "MoreMsg term=bold ctermfg=DarkGreen gui=bold guifg=SeaGreen"), - CENT("Question term=standout ctermfg=DarkGreen", - "Question term=standout ctermfg=DarkGreen gui=bold guifg=SeaGreen"), - CENT("Search term=reverse ctermbg=Yellow ctermfg=NONE", - "Search term=reverse ctermbg=Yellow ctermfg=NONE guibg=Yellow guifg=NONE"), - CENT("SpellBad term=reverse ctermbg=LightRed", - "SpellBad term=reverse ctermbg=LightRed guisp=Red gui=undercurl"), - CENT("SpellCap term=reverse ctermbg=LightBlue", - "SpellCap term=reverse ctermbg=LightBlue guisp=Blue gui=undercurl"), - CENT("SpellRare term=reverse ctermbg=LightMagenta", - "SpellRare term=reverse ctermbg=LightMagenta guisp=Magenta gui=undercurl"), - CENT("SpellLocal term=underline ctermbg=Cyan", - "SpellLocal term=underline ctermbg=Cyan guisp=DarkCyan gui=undercurl"), - CENT("PmenuThumb ctermbg=Black", - "PmenuThumb ctermbg=Black guibg=Black"), - CENT("Pmenu ctermbg=LightMagenta ctermfg=Black", - "Pmenu ctermbg=LightMagenta ctermfg=Black guibg=LightMagenta"), - CENT("PmenuSel ctermbg=LightGrey ctermfg=Black", - "PmenuSel ctermbg=LightGrey ctermfg=Black guibg=Grey"), - CENT("SpecialKey term=bold ctermfg=DarkBlue", - "SpecialKey term=bold ctermfg=DarkBlue guifg=Blue"), - CENT("Title term=bold ctermfg=DarkMagenta", - "Title term=bold ctermfg=DarkMagenta gui=bold guifg=Magenta"), - CENT("WarningMsg term=standout ctermfg=DarkRed", - "WarningMsg term=standout ctermfg=DarkRed guifg=Red"), - CENT( - "WildMenu term=standout ctermbg=Yellow ctermfg=Black", - "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), - CENT( - "Folded term=standout ctermbg=Grey ctermfg=DarkBlue", - "Folded term=standout ctermbg=Grey ctermfg=DarkBlue guibg=LightGrey guifg=DarkBlue"), - CENT( - "FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue", - "FoldColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), - CENT("SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue", - "SignColumn term=standout ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue"), - CENT("Visual term=reverse", - "Visual term=reverse guibg=LightGrey"), - CENT("DiffAdd term=bold ctermbg=LightBlue", - "DiffAdd term=bold ctermbg=LightBlue guibg=LightBlue"), - CENT("DiffChange term=bold ctermbg=LightMagenta", - "DiffChange term=bold ctermbg=LightMagenta guibg=LightMagenta"), - CENT( - "DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan", - "DiffDelete term=bold ctermfg=Blue ctermbg=LightCyan gui=bold guifg=Blue guibg=LightCyan"), - CENT( - "TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey", - "TabLine term=underline cterm=underline ctermfg=black ctermbg=LightGrey gui=underline guibg=LightGrey"), - CENT("CursorColumn term=reverse ctermbg=LightGrey", - "CursorColumn term=reverse ctermbg=LightGrey guibg=Grey90"), - CENT("CursorLine term=underline cterm=underline", - "CursorLine term=underline cterm=underline guibg=Grey90"), - CENT("ColorColumn term=reverse ctermbg=LightRed", - "ColorColumn term=reverse ctermbg=LightRed guibg=LightRed"), - CENT( - "Conceal ctermbg=DarkGrey ctermfg=LightGrey", - "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey"), - CENT("MatchParen term=reverse ctermbg=Cyan", - "MatchParen term=reverse ctermbg=Cyan guibg=Cyan"), +static char *highlight_init_light[] = +{ + "ColorColumn ctermbg=LightRed guibg=LightRed", + "CursorColumn ctermbg=LightGrey guibg=Grey90", + "CursorLine cterm=underline guibg=Grey90", + "CursorLineNr ctermfg=Brown gui=bold guifg=Brown", + "DiffAdd ctermbg=LightBlue guibg=LightBlue", + "DiffChange ctermbg=LightMagenta guibg=LightMagenta", + "DiffDelete ctermfg=Blue ctermbg=LightCyan gui=bold guifg=Blue guibg=LightCyan", + "Directory ctermfg=DarkBlue guifg=Blue", + "FoldColumn ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue", + "Folded ctermbg=Grey ctermfg=DarkBlue guibg=LightGrey guifg=DarkBlue", + "LineNr ctermfg=Brown guifg=Brown", + "MatchParen ctermbg=Cyan guibg=Cyan", + "MoreMsg ctermfg=DarkGreen gui=bold guifg=SeaGreen", + "Pmenu ctermbg=LightMagenta ctermfg=Black guibg=LightMagenta", + "PmenuSel ctermbg=LightGrey ctermfg=Black guibg=Grey", + "PmenuThumb ctermbg=Black guibg=Black", + "Question ctermfg=DarkGreen gui=bold guifg=SeaGreen", + "Search ctermbg=Yellow ctermfg=NONE guibg=Yellow guifg=NONE", + "SignColumn ctermbg=Grey ctermfg=DarkBlue guibg=Grey guifg=DarkBlue", + "SpecialKey ctermfg=DarkBlue guifg=Blue", + "SpellBad ctermbg=LightRed guisp=Red gui=undercurl", + "SpellCap ctermbg=LightBlue guisp=Blue gui=undercurl", + "SpellLocal ctermbg=Cyan guisp=DarkCyan gui=undercurl", + "SpellRare ctermbg=LightMagenta guisp=Magenta gui=undercurl", + "TabLine cterm=underline ctermfg=black ctermbg=LightGrey gui=underline guibg=LightGrey", + "Title ctermfg=DarkMagenta gui=bold guifg=Magenta", + "Visual guibg=LightGrey", + "WarningMsg ctermfg=DarkRed guifg=Red", NULL }; -static char *(highlight_init_dark[]) = -{ - CENT("Directory term=bold ctermfg=LightCyan", - "Directory term=bold ctermfg=LightCyan guifg=Cyan"), - CENT("LineNr term=underline ctermfg=Yellow", - "LineNr term=underline ctermfg=Yellow guifg=Yellow"), - CENT("CursorLineNr term=bold ctermfg=Yellow", - "CursorLineNr term=bold ctermfg=Yellow gui=bold guifg=Yellow"), - CENT("MoreMsg term=bold ctermfg=LightGreen", - "MoreMsg term=bold ctermfg=LightGreen gui=bold guifg=SeaGreen"), - CENT("Question term=standout ctermfg=LightGreen", - "Question term=standout ctermfg=LightGreen gui=bold guifg=Green"), - CENT( - "Search term=reverse ctermbg=Yellow ctermfg=Black", - "Search term=reverse ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), - CENT("SpecialKey term=bold ctermfg=LightBlue", - "SpecialKey term=bold ctermfg=LightBlue guifg=Cyan"), - CENT("SpellBad term=reverse ctermbg=Red", - "SpellBad term=reverse ctermbg=Red guisp=Red gui=undercurl"), - CENT("SpellCap term=reverse ctermbg=Blue", - "SpellCap term=reverse ctermbg=Blue guisp=Blue gui=undercurl"), - CENT("SpellRare term=reverse ctermbg=Magenta", - "SpellRare term=reverse ctermbg=Magenta guisp=Magenta gui=undercurl"), - CENT("SpellLocal term=underline ctermbg=Cyan", - "SpellLocal term=underline ctermbg=Cyan guisp=Cyan gui=undercurl"), - CENT("PmenuThumb ctermbg=White", - "PmenuThumb ctermbg=White guibg=White"), - CENT("Pmenu ctermbg=Magenta ctermfg=Black", - "Pmenu ctermbg=Magenta ctermfg=Black guibg=Magenta"), - CENT("PmenuSel ctermbg=Black ctermfg=DarkGrey", - "PmenuSel ctermbg=Black ctermfg=DarkGrey guibg=DarkGrey"), - CENT("Title term=bold ctermfg=LightMagenta", - "Title term=bold ctermfg=LightMagenta gui=bold guifg=Magenta"), - CENT("WarningMsg term=standout ctermfg=LightRed", - "WarningMsg term=standout ctermfg=LightRed guifg=Red"), - CENT( - "WildMenu term=standout ctermbg=Yellow ctermfg=Black", - "WildMenu term=standout ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black"), - CENT( - "Folded term=standout ctermbg=DarkGrey ctermfg=Cyan", - "Folded term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=DarkGrey guifg=Cyan"), - CENT( - "FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", - "FoldColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), - CENT("SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan", - "SignColumn term=standout ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan"), - CENT("Visual term=reverse", - "Visual term=reverse guibg=DarkGrey"), - CENT("DiffAdd term=bold ctermbg=DarkBlue", - "DiffAdd term=bold ctermbg=DarkBlue guibg=DarkBlue"), - CENT("DiffChange term=bold ctermbg=DarkMagenta", - "DiffChange term=bold ctermbg=DarkMagenta guibg=DarkMagenta"), - CENT( - "DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan", - "DiffDelete term=bold ctermfg=Blue ctermbg=DarkCyan gui=bold guifg=Blue guibg=DarkCyan"), - CENT( - "TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey", - "TabLine term=underline cterm=underline ctermfg=white ctermbg=DarkGrey gui=underline guibg=DarkGrey"), - CENT("CursorColumn term=reverse ctermbg=DarkGrey", - "CursorColumn term=reverse ctermbg=DarkGrey guibg=Grey40"), - CENT("CursorLine term=underline cterm=underline", - "CursorLine term=underline cterm=underline guibg=Grey40"), - CENT("ColorColumn term=reverse ctermbg=DarkRed", - "ColorColumn term=reverse ctermbg=DarkRed guibg=DarkRed"), - CENT("MatchParen term=reverse ctermbg=DarkCyan", - "MatchParen term=reverse ctermbg=DarkCyan guibg=DarkCyan"), - CENT( - "Conceal ctermbg=DarkGrey ctermfg=LightGrey", - "Conceal ctermbg=DarkGrey ctermfg=LightGrey guibg=DarkGrey guifg=LightGrey"), +static char *highlight_init_dark[] = +{ + "ColorColumn ctermbg=DarkRed guibg=DarkRed", + "CursorColumn ctermbg=DarkGrey guibg=Grey40", + "CursorLine cterm=underline guibg=Grey40", + "CursorLineNr ctermfg=Yellow gui=bold guifg=Yellow", + "DiffAdd ctermbg=DarkBlue guibg=DarkBlue", + "DiffChange ctermbg=DarkMagenta guibg=DarkMagenta", + "DiffDelete ctermfg=Blue ctermbg=DarkCyan gui=bold guifg=Blue guibg=DarkCyan", + "Directory ctermfg=LightCyan guifg=Cyan", + "FoldColumn ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan", + "Folded ctermbg=DarkGrey ctermfg=Cyan guibg=DarkGrey guifg=Cyan", + "LineNr ctermfg=Yellow guifg=Yellow", + "MatchParen ctermbg=DarkCyan guibg=DarkCyan", + "MoreMsg ctermfg=LightGreen gui=bold guifg=SeaGreen", + "Pmenu ctermbg=Magenta ctermfg=Black guibg=Magenta", + "PmenuSel ctermbg=Black ctermfg=DarkGrey guibg=DarkGrey", + "PmenuThumb ctermbg=White guibg=White", + "Question ctermfg=LightGreen gui=bold guifg=Green", + "Search ctermbg=Yellow ctermfg=Black guibg=Yellow guifg=Black", + "SignColumn ctermbg=DarkGrey ctermfg=Cyan guibg=Grey guifg=Cyan", + "SpecialKey ctermfg=LightBlue guifg=Cyan", + "SpellBad ctermbg=Red guisp=Red gui=undercurl", + "SpellCap ctermbg=Blue guisp=Blue gui=undercurl", + "SpellLocal ctermbg=Cyan guisp=Cyan gui=undercurl", + "SpellRare ctermbg=Magenta guisp=Magenta gui=undercurl", + "TabLine cterm=underline ctermfg=white ctermbg=DarkGrey gui=underline guibg=DarkGrey", + "Title ctermfg=LightMagenta gui=bold guifg=Magenta", + "Visual guibg=DarkGrey", + "WarningMsg ctermfg=LightRed guifg=Red", NULL }; @@ -5951,7 +5862,7 @@ init_highlight ( // p invalid, so copy it. char_u *copy_p = vim_strsave(p); bool okay = load_colors(copy_p); - free(copy_p); + xfree(copy_p); if (okay) { return; } @@ -6032,7 +5943,7 @@ int load_colors(char_u *name) buf = xmalloc(STRLEN(name) + 12); sprintf((char *)buf, "colors/%s.vim", name); retval = source_runtime(buf, FALSE); - free(buf); + xfree(buf); apply_autocmds(EVENT_COLORSCHEME, name, curbuf->b_fname, FALSE, curbuf); recursive = FALSE; @@ -6234,7 +6145,7 @@ do_highlight ( */ while (*linep && !vim_iswhite(*linep) && *linep != '=') ++linep; - free(key); + xfree(key); key = vim_strnsave_up(key_start, (int)(linep - key_start)); linep = skipwhite(linep); @@ -6278,7 +6189,7 @@ do_highlight ( error = TRUE; break; } - free(arg); + xfree(arg); arg = vim_strnsave(arg_start, (int)(linep - arg_start)); if (*linep == '\'') @@ -6483,7 +6394,7 @@ do_highlight ( if (!init) HL_TABLE()[idx].sg_set |= SG_GUI; - free(HL_TABLE()[idx].sg_rgb_fg_name); + xfree(HL_TABLE()[idx].sg_rgb_fg_name); if (STRCMP(arg, "NONE")) { HL_TABLE()[idx].sg_rgb_fg_name = (uint8_t *)xstrdup((char *)arg); HL_TABLE()[idx].sg_rgb_fg = name_to_color(arg); @@ -6501,7 +6412,7 @@ do_highlight ( if (!init) HL_TABLE()[idx].sg_set |= SG_GUI; - free(HL_TABLE()[idx].sg_rgb_bg_name); + xfree(HL_TABLE()[idx].sg_rgb_bg_name); if (STRCMP(arg, "NONE") != 0) { HL_TABLE()[idx].sg_rgb_bg_name = (uint8_t *)xstrdup((char *)arg); HL_TABLE()[idx].sg_rgb_bg = name_to_color(arg); @@ -6551,8 +6462,8 @@ do_highlight ( HL_TABLE()[idx].sg_scriptID = current_SID; redraw_all_later(NOT_VALID); } - free(key); - free(arg); + xfree(key); + xfree(arg); /* Only call highlight_changed() once, after sourcing a syntax file */ need_highlight_changed = TRUE; @@ -6563,8 +6474,8 @@ void free_highlight(void) { for (int i = 0; i < highlight_ga.ga_len; ++i) { highlight_clear(i); - free(HL_TABLE()[i].sg_name); - free(HL_TABLE()[i].sg_name_u); + xfree(HL_TABLE()[i].sg_name); + xfree(HL_TABLE()[i].sg_name_u); } ga_clear(&highlight_ga); } @@ -6611,9 +6522,9 @@ static void highlight_clear(int idx) HL_TABLE()[idx].sg_gui = 0; HL_TABLE()[idx].sg_rgb_fg = -1; HL_TABLE()[idx].sg_rgb_bg = -1; - free(HL_TABLE()[idx].sg_rgb_fg_name); + xfree(HL_TABLE()[idx].sg_rgb_fg_name); HL_TABLE()[idx].sg_rgb_fg_name = NULL; - free(HL_TABLE()[idx].sg_rgb_bg_name); + xfree(HL_TABLE()[idx].sg_rgb_bg_name); HL_TABLE()[idx].sg_rgb_bg_name = NULL; /* Clear the script ID only when there is no link, since that is not * cleared. */ @@ -7048,7 +6959,7 @@ int syn_namen2id(char_u *linep, int len) { char_u *name = vim_strnsave(linep, len); int id = syn_name2id(name); - free(name); + xfree(name); return id; } @@ -7070,7 +6981,7 @@ int syn_check_group(char_u *pp, int len) if (id == 0) /* doesn't exist yet */ id = syn_add_group(name); else - free(name); + xfree(name); return id; } @@ -7087,7 +6998,7 @@ static int syn_add_group(char_u *name) for (p = name; *p != NUL; ++p) { if (!vim_isprintc(*p)) { EMSG(_("E669: Unprintable character in group name")); - free(name); + xfree(name); return 0; } else if (!ASCII_ISALNUM(*p) && *p != '_') { /* This is an error, but since there previously was no check only @@ -7108,7 +7019,7 @@ static int syn_add_group(char_u *name) if (highlight_ga.ga_len >= MAX_HL_ID) { EMSG(_("E849: Too many highlight and syntax groups")); - free(name); + xfree(name); return 0; } @@ -7128,8 +7039,8 @@ static int syn_add_group(char_u *name) static void syn_unadd_group(void) { --highlight_ga.ga_len; - free(HL_TABLE()[highlight_ga.ga_len].sg_name); - free(HL_TABLE()[highlight_ga.ga_len].sg_name_u); + xfree(HL_TABLE()[highlight_ga.ga_len].sg_name); + xfree(HL_TABLE()[highlight_ga.ga_len].sg_name_u); } /* diff --git a/src/nvim/tag.c b/src/nvim/tag.c index d84f5f0208..b9abf3552c 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -246,7 +246,7 @@ do_tag ( cur_match = ptag_entry.cur_match; cur_fnum = ptag_entry.cur_fnum; } else { - free(ptag_entry.tagname); + xfree(ptag_entry.tagname); ptag_entry.tagname = vim_strsave(tag); } } else { @@ -255,12 +255,12 @@ do_tag ( * stack entries above it. */ while (tagstackidx < tagstacklen) - free(tagstack[--tagstacklen].tagname); + xfree(tagstack[--tagstacklen].tagname); /* if the tagstack is full: remove oldest entry */ if (++tagstacklen > TAGSTACKSIZE) { tagstacklen = TAGSTACKSIZE; - free(tagstack[0].tagname); + xfree(tagstack[0].tagname); for (i = 1; i < tagstacklen; ++i) tagstack[i - 1] = tagstack[i]; --tagstackidx; @@ -450,7 +450,7 @@ do_tag ( || (cur_match >= num_matches && max_num_matches != MAXCOL) || other_name) { if (other_name) { - free(tagmatchname); + xfree(tagmatchname); tagmatchname = vim_strsave(name); } @@ -569,7 +569,7 @@ do_tag ( * it and put "..." in the middle */ p = tag_full_fname(&tagp); msg_puts_long_attr(p, hl_attr(HLF_D)); - free(p); + xfree(p); if (msg_col > 0) msg_putchar('\n'); @@ -709,7 +709,7 @@ do_tag ( /* Save the tag file name */ p = tag_full_fname(&tagp); STRLCPY(fname, p, MAXPATHL + 1); - free(p); + xfree(p); /* * Get the line number or the search pattern used to locate @@ -804,8 +804,8 @@ do_tag ( set_errorlist(curwin, list, ' ', IObuff); list_free(list, TRUE); - free(fname); - free(cmd); + xfree(fname); + xfree(cmd); cur_match = 0; /* Jump to the first tag */ } @@ -941,7 +941,7 @@ end_do_tag: */ void tag_freematch(void) { - free(tagmatchname); + xfree(tagmatchname); tagmatchname = NULL; } @@ -983,7 +983,7 @@ void do_tags(exarg_T *eap) msg_outtrans(IObuff); msg_outtrans_attr(name, tagstack[i].fmark.fnum == curbuf->b_fnum ? hl_attr(HLF_D) : 0); - free(name); + xfree(name); } ui_flush(); /* show one line at a time */ } @@ -1411,12 +1411,12 @@ line_read_in: /* Copy or swap lbuf and conv_line. */ len = (int)STRLEN(conv_line) + 1; if (len > lbuf_size) { - free(lbuf); + xfree(lbuf); lbuf = conv_line; lbuf_size = len; } else { STRCPY(lbuf, conv_line); - free(conv_line); + xfree(conv_line); } } } @@ -1873,7 +1873,7 @@ parse_line: [ga_match[mtt].ga_len++] = mfp; ++match_count; } else - free(mfp); + xfree(mfp); } } } @@ -1932,9 +1932,9 @@ parse_line: } findtag_end: - free(lbuf); + xfree(lbuf); vim_regfree(orgpat.regmatch.regprog); - free(tag_fname); + xfree(tag_fname); /* * Move the matches from the ga_match[] arrays into one list of @@ -1952,7 +1952,7 @@ findtag_end: for (int i = 0; i < ga_match[mtt].ga_len; ++i) { mfp = ((struct match_found **)(ga_match[mtt].ga_data))[i]; if (matches == NULL) - free(mfp); + xfree(mfp); else { /* To avoid allocating memory again we turn the struct * match_found into a string. For help the priority was not @@ -1969,7 +1969,7 @@ findtag_end: *num_matches = match_count; curbuf->b_help = help_save; - free(saved_pat); + xfree(saved_pat); return retval; } @@ -1993,7 +1993,7 @@ void free_tag_stuff(void) tag_freematch(); if (ptag_entry.tagname) { - free(ptag_entry.tagname); + xfree(ptag_entry.tagname); ptag_entry.tagname = NULL; } } @@ -2102,7 +2102,7 @@ get_tagfname ( } STRCPY(buf, fname); - free(fname); + xfree(fname); return OK; } @@ -2111,7 +2111,7 @@ get_tagfname ( */ void tagname_free(tagname_T *tnp) { - free(tnp->tn_tags); + xfree(tnp->tn_tags); vim_findfile_cleanup(tnp->tn_search_ctx); tnp->tn_search_ctx = NULL; ga_clear_strings(&tag_fnames); @@ -2362,7 +2362,7 @@ jumpto_tag ( && !has_autocmd(EVENT_BUFREADCMD, fname, NULL) ) { retval = NOTAGFILE; - free(nofile_fname); + xfree(nofile_fname); nofile_fname = vim_strsave(fname); goto erret; } @@ -2565,9 +2565,9 @@ erret: g_do_tagpreview = 0; /* For next time */ if (tagp.fname_end != NULL) *tagp.fname_end = csave; - free(pbuf); - free(tofree_fname); - free(full_fname); + xfree(pbuf); + xfree(tofree_fname); + xfree(full_fname); return retval; } @@ -2611,7 +2611,7 @@ static char_u *expand_tag_fname(char_u *fname, char_u *tag_fname, int expand) } else retval = vim_strsave(fname); - free(expanded_fname); + xfree(expanded_fname); return retval; } @@ -2635,7 +2635,7 @@ static int test_for_current(char_u *fname, char_u *fname_end, char_u *tag_fname, } fullname = expand_tag_fname(fname, tag_fname, TRUE); retval = (path_full_compare(fullname, buf_ffname, TRUE) & kEqualFiles); - free(fullname); + xfree(fullname); *fname_end = c; } @@ -2761,7 +2761,7 @@ add_tag_field ( } buf[len] = NUL; retval = dict_add_nr_str(dict, field_name, 0L, buf); - free(buf); + xfree(buf); return retval; } @@ -2808,7 +2808,7 @@ int get_tags(list_T *list, char_u *pat) || dict_add_nr_str(dict, "static", is_static, NULL) == FAIL) ret = FAIL; - free(full_fname); + xfree(full_fname); if (tp.command_end != NULL) { for (p = tp.command_end + 3; @@ -2848,9 +2848,9 @@ int get_tags(list_T *list, char_u *pat) } } - free(matches[i]); + xfree(matches[i]); } - free(matches); + xfree(matches); } return ret; } diff --git a/src/nvim/tempfile.c b/src/nvim/tempfile.c index 0750be0ab9..1b51b226db 100644 --- a/src/nvim/tempfile.c +++ b/src/nvim/tempfile.c @@ -77,7 +77,7 @@ void vim_deltempdir(void) path_tail(NameBuff)[-1] = NUL; os_rmdir((char *)NameBuff); - free(vim_tempdir); + xfree(vim_tempdir); vim_tempdir = NULL; } } @@ -109,7 +109,7 @@ static bool vim_settempdir(char_u *tempdir) vim_FullName(tempdir, buf, MAXPATHL, false); add_pathsep(buf); vim_tempdir = vim_strsave(buf); - free(buf); + xfree(buf); return true; } diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index daba7b943f..8ee47b2642 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -130,8 +130,6 @@ struct terminal { // the default values are used to obtain the color numbers passed to cterm // colors RgbValue colors[256]; - // attributes for focused/unfocused cursor cells - int focused_cursor_attr_id, unfocused_cursor_attr_id; }; static VTermScreenCallbacks vterm_screen_callbacks = { @@ -245,7 +243,7 @@ Terminal *terminal_open(TerminalOptions opts) char *name = get_config_string(rv, var); if (name) { color_val = name_to_color((uint8_t *)name); - free(name); + xfree(name); if (color_val != -1) { rv->colors[i] = color_val; @@ -260,41 +258,6 @@ Terminal *terminal_open(TerminalOptions opts) } } - // Configure cursor highlighting when focused/unfocused - char *group = get_config_string(rv, "terminal_focused_cursor_highlight"); - if (group) { - int group_id = syn_name2id((uint8_t *)group); - free(group); - - if (group_id) { - rv->focused_cursor_attr_id = syn_id2attr(group_id); - } - } - if (!rv->focused_cursor_attr_id) { - rv->focused_cursor_attr_id = get_attr_entry(&(attrentry_T) { - .rgb_ae_attr = HL_INVERSE, .rgb_fg_color = -1, .rgb_bg_color = -1, - .cterm_ae_attr = HL_INVERSE, .cterm_fg_color = 0, .cterm_bg_color = 0 - }); - } - - group = get_config_string(rv, "terminal_unfocused_cursor_highlight"); - if (group) { - int group_id = syn_name2id((uint8_t *)group); - free(group); - - if (group_id) { - rv->unfocused_cursor_attr_id = syn_id2attr(group_id); - } - } - if (!rv->unfocused_cursor_attr_id) { - int yellow_rgb = RGB(0xfc, 0xe9, 0x4f); - int yellow_term = 12; - rv->unfocused_cursor_attr_id = get_attr_entry(&(attrentry_T) { - .rgb_ae_attr = 0, .rgb_fg_color = -1, .rgb_bg_color = yellow_rgb, - .cterm_ae_attr = 0, .cterm_fg_color = 0, .cterm_bg_color = yellow_term, - }); - } - return rv; } @@ -307,9 +270,12 @@ void terminal_close(Terminal *term, char *msg) term->forward_mouse = false; term->closed = true; if (!msg || exiting) { - // If no msg was given, this was called by close_buffer(buffer.c) so we - // should not wait for the user to press a key. Also cannot wait if - // `exiting == true` + // If no msg was given, this was called by close_buffer(buffer.c). Or if + // exiting, we must inform the buffer the terminal no longer exists so that + // close_buffer() doesn't call this again. + term->buf->terminal = NULL; + term->buf = NULL; + // We should not wait for the user to press a key. term->opts.close_cb(term->opts.data); } else { terminal_receive(term, msg, strlen(msg)); @@ -338,7 +304,7 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height) // terminal in the current tab. FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (!wp->w_closing && wp->w_buffer == term->buf) { - width = (uint16_t)MIN(width, (uint16_t)wp->w_width); + width = (uint16_t)MIN(width, (uint16_t)(wp->w_width - win_col_off(wp))); height = (uint16_t)MIN(height, (uint16_t)wp->w_height); } } @@ -353,8 +319,14 @@ void terminal_resize(Terminal *term, uint16_t width, uint16_t height) invalidate_terminal(term, -1, -1); } -void terminal_enter(Terminal *term, bool process_deferred) +void terminal_enter(bool process_deferred) { + Terminal *term = curbuf->terminal; + assert(term && "should only be called when curbuf has a terminal"); + + // Ensure the terminal is properly sized. + terminal_resize(term, 0, 0); + checkpcmark(); setpcmark(); int save_state = State; @@ -373,7 +345,9 @@ void terminal_enter(Terminal *term, bool process_deferred) int c; bool close = false; - for (;;) { + bool got_bs = false; // True if the last input was <C-\> + + while (term->buf == curbuf) { if (process_deferred) { event_enable_deferred(); } @@ -385,14 +359,6 @@ void terminal_enter(Terminal *term, bool process_deferred) } switch (c) { - case Ctrl_BSL: - c = safe_vgetc(); - if (c == Ctrl_N) { - goto end; - } - terminal_send_key(term, c); - break; - case K_LEFTMOUSE: case K_LEFTDRAG: case K_LEFTRELEASE: @@ -413,12 +379,23 @@ void terminal_enter(Terminal *term, bool process_deferred) event_process(); break; + case Ctrl_N: + if (got_bs) { + goto end; + } + // FALLTHROUGH + default: + if (c == Ctrl_BSL && !got_bs) { + got_bs = true; + break; + } if (term->closed) { close = true; goto end; } + got_bs = false; terminal_send_key(term, c); } } @@ -431,7 +408,7 @@ end: invalidate_terminal(term, term->cursor.row, term->cursor.row + 1); mapped_ctrl_c = save_mapped_ctrl_c; unshowmode(true); - redraw(false); + redraw(term->buf != curbuf); ui_busy_stop(); if (close) { term->opts.close_cb(term->opts.data); @@ -441,15 +418,17 @@ end: void terminal_destroy(Terminal *term) { - term->buf->terminal = NULL; + if (term->buf) { + term->buf->terminal = NULL; + } term->buf = NULL; pmap_del(ptr_t)(invalidated_terminals, term); for (size_t i = 0 ; i < term->sb_current; i++) { - free(term->sb_buffer[i]); + xfree(term->sb_buffer[i]); } - free(term->sb_buffer); + xfree(term->sb_buffer); vterm_free(term->vt); - free(term); + xfree(term); } void terminal_send(Terminal *term, char *data, size_t size) @@ -540,7 +519,7 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, if (term->cursor.visible && term->cursor.row == row && term->cursor.col == col) { attr_id = hl_combine_attr(attr_id, is_focused(term) && wp == curwin ? - term->focused_cursor_attr_id : term->unfocused_cursor_attr_id); + hl_attr(HLF_TERM) : hl_attr(HLF_TERMNC)); } term_attrs[col] = attr_id; @@ -624,7 +603,7 @@ static int term_sb_push(int cols, const VTermScreenCell *cells, void *data) // Recycle old row if it's the right size sbrow = term->sb_buffer[term->sb_current - 1]; } else { - free(term->sb_buffer[term->sb_current - 1]); + xfree(term->sb_buffer[term->sb_current - 1]); } memmove(term->sb_buffer + 1, term->sb_buffer, @@ -685,7 +664,7 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data) cells[col].chars[0] = 0; cells[col].width = 1; } - free(sbrow); + xfree(sbrow); pmap_put(ptr_t)(invalidated_terminals, term, NULL); return 1; @@ -783,11 +762,11 @@ static bool send_mouse_event(Terminal *term, int c) bool drag = false; switch (c) { - case K_LEFTDRAG: drag = true; + case K_LEFTDRAG: drag = true; // FALLTHROUGH case K_LEFTMOUSE: button = 1; break; - case K_MIDDLEDRAG: drag = true; + case K_MIDDLEDRAG: drag = true; // FALLTHROUGH case K_MIDDLEMOUSE: button = 2; break; - case K_RIGHTDRAG: drag = true; + case K_RIGHTDRAG: drag = true; // FALLTHROUGH case K_RIGHTMOUSE: button = 3; break; case K_MOUSEDOWN: button = 4; break; case K_MOUSEUP: button = 5; break; @@ -916,12 +895,16 @@ static void on_refresh(Event event) } Terminal *term; void *stub; (void)(stub); - // dont process autocommands while updating terminal buffers. JobActivity can - // be used act on terminal output. + // don't process autocommands while updating terminal buffers block_autocmds(); map_foreach(invalidated_terminals, term, stub, { - if (!term->buf) { + // TODO(SplinterOfChaos): Find the condition that makes term->buf invalid. + bool valid = true; + if (!term->buf || !(valid = buf_valid(term->buf))) { // destroyed by `close_buffer`. Dont do anything else + if (!valid) { + term->buf = NULL; + } continue; } bool pending_resize = term->pending_resize; @@ -1018,6 +1001,11 @@ static void refresh_screen(Terminal *term) static void redraw(bool restore_cursor) { + Terminal *term = curbuf->terminal; + if (!term) { + restore_cursor = true; + } + int save_row, save_col; if (restore_cursor) { // save the current row/col to restore after updating screen when not @@ -1040,14 +1028,13 @@ static void redraw(bool restore_cursor) showruler(false); - Terminal *term = curbuf->terminal; if (term && is_focused(term)) { curwin->w_wrow = term->cursor.row; curwin->w_wcol = term->cursor.col + win_col_off(curwin); setcursor(); } else if (restore_cursor) { ui_cursor_goto(save_row, save_col); - } else { + } else if (term) { // exiting terminal focus, put the window cursor in a valid position int height, width; vterm_get_size(term->vt, &height, &width); @@ -1099,28 +1086,30 @@ static bool is_focused(Terminal *term) do { \ Error err; \ o = dict_get_value(t->buf->b_vars, cstr_as_string(k), &err); \ - if (obj.type == kObjectTypeNil) { \ + if (o.type == kObjectTypeNil) { \ o = dict_get_value(&globvardict, cstr_as_string(k), &err); \ } \ } while (0) static char *get_config_string(Terminal *term, char *key) { - Object obj = OBJECT_INIT; + Object obj; GET_CONFIG_VALUE(term, key, obj); if (obj.type == kObjectTypeString) { return obj.data.string.data; } + api_free_object(obj); return NULL; } static int get_config_int(Terminal *term, char *key) { - Object obj = OBJECT_INIT; + Object obj; GET_CONFIG_VALUE(term, key, obj); if (obj.type == kObjectTypeInteger) { return (int)obj.data.integer; } + api_free_object(obj); return 0; } diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index c323f10a4f..0a7c16e2cb 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -16,18 +16,18 @@ SCRIPTS := test_autoformat_join.out \ test24.out \ test26.out test27.out test29.out test30.out \ test31.out test32.out test34.out \ - test36.out test37.out test38.out test39.out test40.out \ - test42.out test43.out test44.out test45.out \ + test36.out test37.out test39.out test40.out \ + test42.out test43.out test45.out \ test46.out test47.out test48.out test49.out \ test52.out test53.out test55.out \ test57.out test58.out test59.out test60.out \ test61.out test62.out test63.out test64.out test65.out \ test68.out test69.out \ test71.out test73.out test74.out \ - test76.out test78.out test79.out test80.out \ + test76.out test79.out test80.out \ test82.out test83.out \ test86.out test87.out test88.out \ - test96.out test99.out \ + test96.out \ test_listlbr.out \ test_breakindent.out diff --git a/src/nvim/testdir/test38.in b/src/nvim/testdir/test38.in deleted file mode 100644 index 3e0236251b..0000000000 --- a/src/nvim/testdir/test38.in +++ /dev/null @@ -1,35 +0,0 @@ - -Test Virtual replace mode. - -STARTTEST -:so small.vim -:" make sure that backspace works, no matter what termcap is used -:set t_kD=x7f t_kb=x08 -ggdGa -abcdefghi -jk lmn - opq rst -uvwxyz -gg:set ai -:set bs=2 -gR0 1 -A -BCDEFGHIJ - KL -MNO -PQRG:ka -o0 -abcdefghi -jk lmn - opq rst -uvwxyz -'ajgR0 1 -A -BCDEFGHIJ - KL -MNO -PQR:$ -iab cdefghi jkl0gRAB......CDEFGHI.Jo: -iabcdefghijklmnopqrst0gRAB IJKLMNO QR:wq! test.out -ENDTEST - diff --git a/src/nvim/testdir/test38.ok b/src/nvim/testdir/test38.ok deleted file mode 100644 index e10209667b..0000000000 --- a/src/nvim/testdir/test38.ok +++ /dev/null @@ -1,13 +0,0 @@ - 1 - A - BCDEFGHIJ - KL - MNO - PQR - 1 -abcdefghi -jk lmn - opq rst -uvwxyz -AB......CDEFGHI.Jkl -AB IJKLMNO QRst diff --git a/src/nvim/testdir/test44.in b/src/nvim/testdir/test44.in deleted file mode 100644 index 7b1a13488f..0000000000 --- a/src/nvim/testdir/test44.in +++ /dev/null @@ -1,74 +0,0 @@ -Tests for regexp with multi-byte encoding and various magic settings. -Test matchstr() with a count and multi-byte chars. -See test99 for exactly the same test with re=2. - -STARTTEST -:so mbyte.vim -:set encoding=utf-8 termencoding=latin1 -:set re=1 -/^1 -/a*b\{2}c\+/e -x/\Md\*e\{2}f\+/e -x:set nomagic -/g\*h\{2}i\+/e -x/\mj*k\{2}l\+/e -x/\vm*n{2}o+/e -x/\V^aa$ -x:set magic -/\v(a)(b)\2\1\1/e -x/\V[ab]\(\[xy]\)\1 -x:" Now search for multi-byte without composing char -/ม -x:" Now search for multi-byte with composing char -/ม่ -x:" find word by change of word class -/ã¡\<カヨ\>㯠-x:" Test \%u, [\u] and friends -/\%u20ac -x/[\u4f7f\u5929]\+ -x/\%U12345678 -x/[\U1234abcd\u1234\uabcd] -x/\%d21879b -x/ [[=A=]]* [[=B=]]* [[=C=]]* [[=D=]]* [[=E=]]* [[=F=]]* [[=G=]]* [[=H=]]* [[=I=]]* [[=J=]]* [[=K=]]* [[=L=]]* [[=M=]]* [[=N=]]* [[=O=]]* [[=P=]]* [[=Q=]]* [[=R=]]* [[=S=]]* [[=T=]]* [[=U=]]* [[=V=]]* [[=W=]]* [[=X=]]* [[=Y=]]* [[=Z=]]*/e -x/ [[=a=]]* [[=b=]]* [[=c=]]* [[=d=]]* [[=e=]]* [[=f=]]* [[=g=]]* [[=h=]]* [[=i=]]* [[=j=]]* [[=k=]]* [[=l=]]* [[=m=]]* [[=n=]]* [[=o=]]* [[=p=]]* [[=q=]]* [[=r=]]* [[=s=]]* [[=t=]]* [[=u=]]* [[=v=]]* [[=w=]]* [[=x=]]* [[=y=]]* [[=z=]]*/e -x:" Test backwards search from a multi-byte char -/x -x?. -x:let @w=':%s#comb[i]nations#œ̄ṣÌm̥̄ᾱ̆Ì#g' -:@w -:?^1?,$w! test.out -:e! test.out -G:put =matchstr(\"×בגד\", \".\", 0, 2) " ב -:put =matchstr(\"×בגד\", \"..\", 0, 2) " בג -:put =matchstr(\"×בגד\", \".\", 0, 0) " × -:put =matchstr(\"×בגד\", \".\", 4, -1) " ×’ -:new -:$put =['dog(a', 'cat('] -/(/e+ -"ayn:bd! -:$put ='' -G"ap -:w! -:qa! -ENDTEST - -1 a aa abb abbccc -2 d dd dee deefff -3 g gg ghh ghhiii -4 j jj jkk jkklll -5 m mm mnn mnnooo -6 x ^aa$ x -7 (a)(b) abbaa -8 axx [ab]xx -9 หม่x à¸à¸¡x -a à¸à¸¡x หม่x -b ã¡ã‚«ãƒ¨ã¯ -c x ¬€x -d 天使x -e ü’…™¸y -f ü’Нz -g aå•·bb -h AÀÃÂÃÄÅĀĂĄÇÇžÇ áº¢ BḂḆ CÇĆĈĊČ DÄŽÄḊḎḠEÈÉÊËĒĔĖĘĚẺẼ FḞ GÄœÄžÄ Ä¢Ç¤Ç¦Ç´á¸ HĤĦḢḦḨ IÃŒÃÃŽÃĨĪĬĮİÇỈ JÄ´ KĶǨḰḴ LĹĻĽĿÅḺ MḾṀ NÑŃŅŇṄṈ OÃ’Ã“Ã”Ã•Ã–Ã˜ÅŒÅŽÅÆ ǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠTŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ Vá¹¼ WŴẀẂẄẆ XẊẌ YÃŶŸẎỲỶỸ ZŹŻŽƵáºáº” -i aà áâãäåÄăąǎǟǡả bḃḇ cÃ§Ä‡Ä‰Ä‹Ä dÄđḋá¸á¸‘ eèéêëēĕėęěẻẽ fḟ gÄğġģǥǧǵḡ hĥħḣḧḩẖ iìÃîïĩīÄįÇỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṠnñńņňʼnṅṉ oòóôõöøÅÅőơǒǫÇá» pṕṗ q rŕŗřṙṟ sÅ›Åşšṡ tţťŧṫṯẗ uùúûüũūÅůűųưǔủ vá¹½ wŵáºáºƒáº…ẇẘ xẋẠyýÿŷáºáº™á»³á»·á»¹ zźżžƶẑẕ -j 0123â¤x -k combinations diff --git a/src/nvim/testdir/test44.ok b/src/nvim/testdir/test44.ok deleted file mode 100644 index d9a1206cc2..0000000000 --- a/src/nvim/testdir/test44.ok +++ /dev/null @@ -1,26 +0,0 @@ -1 a aa abb abbcc -2 d dd dee deeff -3 g gg ghh ghhii -4 j jj jkk jkkll -5 m mm mnn mnnoo -6 x aa$ x -7 (a)(b) abba -8 axx ab]xx -9 หม่x à¸x -a à¸à¸¡x หx -b カヨ㯠-c x ¬x -d 使x -e y -f z -g abb -h AÀÃÂÃÄÅĀĂĄÇÇžÇ áº¢ BḂḆ CÇĆĈĊČ DÄŽÄḊḎḠEÈÉÊËĒĔĖĘĚẺẼ FḞ GÄœÄžÄ Ä¢Ç¤Ç¦Ç´á¸ HĤĦḢḦḨ IÃŒÃÃŽÃĨĪĬĮİÇỈ JÄ´ KĶǨḰḴ LĹĻĽĿÅḺ MḾṀ NÑŃŅŇṄṈ OÃ’Ã“Ã”Ã•Ã–Ã˜ÅŒÅŽÅÆ ǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠTŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ Vá¹¼ WŴẀẂẄẆ XẊẌ YÃŶŸẎỲỶỸ ZŹŻŽƵẠ-i aà áâãäåÄăąǎǟǡả bḃḇ cÃ§Ä‡Ä‰Ä‹Ä dÄđḋá¸á¸‘ eèéêëēĕėęěẻẽ fḟ gÄğġģǥǧǵḡ hĥħḣḧḩẖ iìÃîïĩīÄįÇỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṠnñńņňʼnṅṉ oòóôõöøÅÅőơǒǫÇá» pṕṗ q rŕŗřṙṟ sÅ›Åşšṡ tţťŧṫṯẗ uùúûüũūÅůűųưǔủ vá¹½ wŵáºáºƒáº…ẇẘ xẋẠyýÿŷáºáº™á»³á»·á»¹ zźżžƶẑ -j 012⤠-k œ̄ṣÌmÌ¥Ì„Î±Ì„Ì†Ì -ב -בג -× -×’ -a -cat( diff --git a/src/nvim/testdir/test78.in b/src/nvim/testdir/test78.in deleted file mode 100644 index cb0e51edd5..0000000000 --- a/src/nvim/testdir/test78.in +++ /dev/null @@ -1,46 +0,0 @@ -Inserts 10000 lines with text to fill the swap file with two levels of pointer -blocks. Then recovers from the swap file and checks all text is restored. - -We need about 10000 lines of 100 characters to get two levels of pointer -blocks. - -STARTTEST -:so small.vim -:set fileformat=unix undolevels=-1 -:e! Xtest -ggdG -:let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789" -:let i = 1 -:let linecount = 10000 -:while i <= linecount | call append(i - 1, i . text) | let i += 1 | endwhile -:preserve -:" get the name of the swap file -:redir => swapname -:swapname -:redir END -:let swapname = substitute(swapname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '') -:" make a copy of the swap file in Xswap -:set bin -:exe 'sp ' . swapname -:w! Xswap -:echo swapname -:set nobin -:new -:only! -:bwipe! Xtest -:call rename('Xswap', swapname) -:recover Xtest -:call delete(swapname) -:new -:call append(0, 'recovery start') -:wincmd w -:let linedollar = line('$') -:if linedollar < linecount | exe 'wincmd w' | call append(line('$'), "expected " . linecount . " lines but found only " . linedollar) | exe 'wincmd w' | let linecount = linedollar | endif -:let i = 1 -:while i <= linecount | if getline(i) != i . text | exe 'wincmd w' | call append(line('$'), i . ' differs') | exe 'wincmd w' | endif | let i += 1 | endwhile -:q! -:call append(line('$'), 'recovery end') -:w! test.out -:qa! -ENDTEST - diff --git a/src/nvim/testdir/test78.ok b/src/nvim/testdir/test78.ok deleted file mode 100644 index 6c3ecefe3c..0000000000 --- a/src/nvim/testdir/test78.ok +++ /dev/null @@ -1,3 +0,0 @@ -recovery start - -recovery end diff --git a/src/nvim/testdir/test99.in b/src/nvim/testdir/test99.in deleted file mode 100644 index 32bc68cce4..0000000000 --- a/src/nvim/testdir/test99.in +++ /dev/null @@ -1,68 +0,0 @@ -Tests for regexp with multi-byte encoding and various magic settings. -Test matchstr() with a count and multi-byte chars. -See test44 for exactly the same test with re=1. - -STARTTEST -:so mbyte.vim -:set encoding=utf-8 termencoding=latin1 -:set re=2 -/^1 -/a*b\{2}c\+/e -x/\Md\*e\{2}f\+/e -x:set nomagic -/g\*h\{2}i\+/e -x/\mj*k\{2}l\+/e -x/\vm*n{2}o+/e -x/\V^aa$ -x:set magic -/\v(a)(b)\2\1\1/e -x/\V[ab]\(\[xy]\)\1 -x:" Now search for multi-byte without composing char -/ม -x:" Now search for multi-byte with composing char -/ม่ -x:" find word by change of word class -/ã¡\<カヨ\>㯠-x:" Test \%u, [\u] and friends -/\%u20ac -x/[\u4f7f\u5929]\+ -x/\%U12345678 -x/[\U1234abcd\u1234\uabcd] -x/\%d21879b -x/ [[=A=]]* [[=B=]]* [[=C=]]* [[=D=]]* [[=E=]]* [[=F=]]* [[=G=]]* [[=H=]]* [[=I=]]* [[=J=]]* [[=K=]]* [[=L=]]* [[=M=]]* [[=N=]]* [[=O=]]* [[=P=]]* [[=Q=]]* [[=R=]]* [[=S=]]* [[=T=]]* [[=U=]]* [[=V=]]* [[=W=]]* [[=X=]]* [[=Y=]]* [[=Z=]]*/e -x/ [[=a=]]* [[=b=]]* [[=c=]]* [[=d=]]* [[=e=]]* [[=f=]]* [[=g=]]* [[=h=]]* [[=i=]]* [[=j=]]* [[=k=]]* [[=l=]]* [[=m=]]* [[=n=]]* [[=o=]]* [[=p=]]* [[=q=]]* [[=r=]]* [[=s=]]* [[=t=]]* [[=u=]]* [[=v=]]* [[=w=]]* [[=x=]]* [[=y=]]* [[=z=]]*/e -x:" Test backwards search from a multi-byte char -/x -x?. -x:let @w=':%s#comb[i]nations#œ̄ṣÌm̥̄ᾱ̆Ì#g' -:@w -:?^1?,$w! test.out -:e! test.out -G:put =matchstr(\"×בגד\", \".\", 0, 2) " ב -:put =matchstr(\"×בגד\", \"..\", 0, 2) " בג -:put =matchstr(\"×בגד\", \".\", 0, 0) " × -:put =matchstr(\"×בגד\", \".\", 4, -1) " ×’ -:w! -:qa! -ENDTEST - -1 a aa abb abbccc -2 d dd dee deefff -3 g gg ghh ghhiii -4 j jj jkk jkklll -5 m mm mnn mnnooo -6 x ^aa$ x -7 (a)(b) abbaa -8 axx [ab]xx -9 หม่x à¸à¸¡x -a à¸à¸¡x หม่x -b ã¡ã‚«ãƒ¨ã¯ -c x ¬€x -d 天使x -e ü’…™¸y -f ü’Нz -g aå•·bb -h AÀÃÂÃÄÅĀĂĄÇÇžÇ áº¢ BḂḆ CÇĆĈĊČ DÄŽÄḊḎḠEÈÉÊËĒĔĖĘĚẺẼ FḞ GÄœÄžÄ Ä¢Ç¤Ç¦Ç´á¸ HĤĦḢḦḨ IÃŒÃÃŽÃĨĪĬĮİÇỈ JÄ´ KĶǨḰḴ LĹĻĽĿÅḺ MḾṀ NÑŃŅŇṄṈ OÃ’Ã“Ã”Ã•Ã–Ã˜ÅŒÅŽÅÆ ǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠTŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ Vá¹¼ WŴẀẂẄẆ XẊẌ YÃŶŸẎỲỶỸ ZŹŻŽƵáºáº” -i aà áâãäåÄăąǎǟǡả bḃḇ cÃ§Ä‡Ä‰Ä‹Ä dÄđḋá¸á¸‘ eèéêëēĕėęěẻẽ fḟ gÄğġģǥǧǵḡ hĥħḣḧḩẖ iìÃîïĩīÄįÇỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṠnñńņňʼnṅṉ oòóôõöøÅÅőơǒǫÇá» pṕṗ q rŕŗřṙṟ sÅ›Åşšṡ tţťŧṫṯẗ uùúûüũūÅůűųưǔủ vá¹½ wŵáºáºƒáº…ẇẘ xẋẠyýÿŷáºáº™á»³á»·á»¹ zźżžƶẑẕ -j 0123â¤x -k combinations diff --git a/src/nvim/testdir/test99.ok b/src/nvim/testdir/test99.ok deleted file mode 100644 index 0bd0b8ab73..0000000000 --- a/src/nvim/testdir/test99.ok +++ /dev/null @@ -1,24 +0,0 @@ -1 a aa abb abbcc -2 d dd dee deeff -3 g gg ghh ghhii -4 j jj jkk jkkll -5 m mm mnn mnnoo -6 x aa$ x -7 (a)(b) abba -8 axx ab]xx -9 หม่x à¸x -a à¸à¸¡x หx -b カヨ㯠-c x ¬x -d 使x -e y -f z -g abb -h AÀÃÂÃÄÅĀĂĄÇÇžÇ áº¢ BḂḆ CÇĆĈĊČ DÄŽÄḊḎḠEÈÉÊËĒĔĖĘĚẺẼ FḞ GÄœÄžÄ Ä¢Ç¤Ç¦Ç´á¸ HĤĦḢḦḨ IÃŒÃÃŽÃĨĪĬĮİÇỈ JÄ´ KĶǨḰḴ LĹĻĽĿÅḺ MḾṀ NÑŃŅŇṄṈ OÃ’Ã“Ã”Ã•Ã–Ã˜ÅŒÅŽÅÆ ǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠTŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ Vá¹¼ WŴẀẂẄẆ XẊẌ YÃŶŸẎỲỶỸ ZŹŻŽƵẠ-i aà áâãäåÄăąǎǟǡả bḃḇ cÃ§Ä‡Ä‰Ä‹Ä dÄđḋá¸á¸‘ eèéêëēĕėęěẻẽ fḟ gÄğġģǥǧǵḡ hĥħḣḧḩẖ iìÃîïĩīÄįÇỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṠnñńņňʼnṅṉ oòóôõöøÅÅőơǒǫÇá» pṕṗ q rŕŗřṙṟ sÅ›Åşšṡ tţťŧṫṯẗ uùúûüũūÅůűųưǔủ vá¹½ wŵáºáºƒáº…ẇẘ xẋẠyýÿŷáºáº™á»³á»·á»¹ zźżžƶẑ -j 012⤠-k œ̄ṣÌmÌ¥Ì„Î±Ì„Ì†Ì -ב -בג -× -×’ diff --git a/src/nvim/tui/term_input.inl b/src/nvim/tui/term_input.inl index c1ccc863de..ccc47080b8 100644 --- a/src/nvim/tui/term_input.inl +++ b/src/nvim/tui/term_input.inl @@ -296,5 +296,5 @@ static void term_input_destroy(TermInput *input) uv_close((uv_handle_t *)&input->timer_handle, NULL); termkey_destroy(input->tk); event_poll(0); // Run once to remove references to input/timer handles - free(input); + xfree(input); } diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 6d23c2cf74..763a7c0e6d 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -190,12 +190,12 @@ static void tui_stop(UI *ui) if (uv_loop_close(data->write_loop)) { abort(); } - free(data->write_loop); + xfree(data->write_loop); unibi_destroy(data->ut); destroy_screen(data); - free(data); + xfree(data); ui_detach(ui); - free(ui); + xfree(ui); } static void try_resize(Event ev) @@ -851,8 +851,8 @@ static void destroy_screen(TUIData *data) { if (data->screen) { for (int i = 0; i < data->old_height; i++) { - free(data->screen[i]); + xfree(data->screen[i]); } - free(data->screen); + xfree(data->screen); } } diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 601c3af741..d8cf8aa7b7 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -686,11 +686,11 @@ char_u *u_get_undo_file_name(char_u *buf_ffname, int reading) (!reading || os_file_exists(undo_file_name))) { break; } - free(undo_file_name); + xfree(undo_file_name); undo_file_name = NULL; } - free(munged_name); + xfree(munged_name); return undo_file_name; } @@ -710,146 +710,162 @@ static void u_free_uhp(u_header_T *uhp) u_freeentry(uep, uep->ue_size); uep = nuep; } - free(uhp); + xfree(uhp); } -static int serialize_header(FILE *fp, buf_T *buf, char_u *hash) +/// Writes the header. +/// @returns false in case of an error. +static bool serialize_header(bufinfo_T *bi, char_u *hash) + FUNC_ATTR_NONNULL_ALL { - /* Start writing, first the magic marker and undo info version. */ - if (fwrite(UF_START_MAGIC, UF_START_MAGIC_LEN, 1, fp) != 1) - return FAIL; + buf_T *buf = bi->bi_buf; + FILE *fp = bi->bi_fp; - put_bytes(fp, UF_VERSION, 2); - - /* Write a hash of the buffer text, so that we can verify it is still the - * same when reading the buffer text. */ - if (fwrite(hash, UNDO_HASH_SIZE, 1, fp) != 1) - return FAIL; - - /* buffer-specific data */ - put_bytes(fp, (uintmax_t)buf->b_ml.ml_line_count, 4); - size_t len = buf->b_u_line_ptr ? STRLEN(buf->b_u_line_ptr) : 0; - put_bytes(fp, len, 4); - if (len > 0 && fwrite(buf->b_u_line_ptr, len, 1, fp) != 1) - return FAIL; - put_bytes(fp, (uintmax_t)buf->b_u_line_lnum, 4); - put_bytes(fp, (uintmax_t)buf->b_u_line_colnr, 4); - - /* Undo structures header data */ - put_header_ptr(fp, buf->b_u_oldhead); - put_header_ptr(fp, buf->b_u_newhead); - put_header_ptr(fp, buf->b_u_curhead); - - put_bytes(fp, (uintmax_t)buf->b_u_numhead, 4); - put_bytes(fp, (uintmax_t)buf->b_u_seq_last, 4); - put_bytes(fp, (uintmax_t)buf->b_u_seq_cur, 4); - put_time(fp, buf->b_u_time_cur); + // Start writing, first the magic marker and undo info version. + if (fwrite(UF_START_MAGIC, UF_START_MAGIC_LEN, 1, fp) != 1) { + return false; + } - /* Optional fields. */ - putc(4, fp); - putc(UF_LAST_SAVE_NR, fp); - put_bytes(fp, (uintmax_t)buf->b_u_save_nr_last, 4); + undo_write_bytes(bi, UF_VERSION, 2); - putc(0, fp); /* end marker */ + // Write a hash of the buffer text, so that we can verify it is + // still the same when reading the buffer text. + if (!undo_write(bi, hash, UNDO_HASH_SIZE)) { + return false; + } - return OK; + // Write buffer-specific data. + undo_write_bytes(bi, (uintmax_t)buf->b_ml.ml_line_count, 4); + size_t len = buf->b_u_line_ptr ? STRLEN(buf->b_u_line_ptr) : 0; + undo_write_bytes(bi, len, 4); + if (len > 0 && !undo_write(bi, buf->b_u_line_ptr, len)) { + return false; + } + undo_write_bytes(bi, (uintmax_t)buf->b_u_line_lnum, 4); + undo_write_bytes(bi, (uintmax_t)buf->b_u_line_colnr, 4); + + // Write undo structures header data. + put_header_ptr(bi, buf->b_u_oldhead); + put_header_ptr(bi, buf->b_u_newhead); + put_header_ptr(bi, buf->b_u_curhead); + + undo_write_bytes(bi, (uintmax_t)buf->b_u_numhead, 4); + undo_write_bytes(bi, (uintmax_t)buf->b_u_seq_last, 4); + undo_write_bytes(bi, (uintmax_t)buf->b_u_seq_cur, 4); + uint8_t time_buf[8]; + time_to_bytes(buf->b_u_time_cur, time_buf); + undo_write(bi, time_buf, sizeof(time_buf)); + + // Write optional fields. + undo_write_bytes(bi, 4, 1); + undo_write_bytes(bi, UF_LAST_SAVE_NR, 1); + undo_write_bytes(bi, (uintmax_t)buf->b_u_save_nr_last, 4); + + // Write end marker. + undo_write_bytes(bi, 0, 1); + + return true; } -static int serialize_uhp(FILE *fp, buf_T *buf, u_header_T *uhp) +static bool serialize_uhp(bufinfo_T *bi, u_header_T *uhp) { - if (put_bytes(fp, UF_HEADER_MAGIC, 2) == FAIL) - return FAIL; - - put_header_ptr(fp, uhp->uh_next.ptr); - put_header_ptr(fp, uhp->uh_prev.ptr); - put_header_ptr(fp, uhp->uh_alt_next.ptr); - put_header_ptr(fp, uhp->uh_alt_prev.ptr); - put_bytes(fp, (uintmax_t)uhp->uh_seq, 4); - serialize_pos(uhp->uh_cursor, fp); - put_bytes(fp, (uintmax_t)uhp->uh_cursor_vcol, 4); - put_bytes(fp, (uintmax_t)uhp->uh_flags, 2); - /* Assume NMARKS will stay the same. */ - for (size_t i = 0; i < NMARKS; ++i) - serialize_pos(uhp->uh_namedm[i], fp); - serialize_visualinfo(&uhp->uh_visual, fp); - put_time(fp, uhp->uh_time); - - /* Optional fields. */ - putc(4, fp); - putc(UHP_SAVE_NR, fp); - put_bytes(fp, (uintmax_t)uhp->uh_save_nr, 4); - - putc(0, fp); /* end marker */ - - /* Write all the entries. */ + if (!undo_write_bytes(bi, (uintmax_t)UF_HEADER_MAGIC, 2)) { + return false; + } + + put_header_ptr(bi, uhp->uh_next.ptr); + put_header_ptr(bi, uhp->uh_prev.ptr); + put_header_ptr(bi, uhp->uh_alt_next.ptr); + put_header_ptr(bi, uhp->uh_alt_prev.ptr); + undo_write_bytes(bi, (uintmax_t)uhp->uh_seq, 4); + serialize_pos(bi, uhp->uh_cursor); + undo_write_bytes(bi, (uintmax_t)uhp->uh_cursor_vcol, 4); + undo_write_bytes(bi, (uintmax_t)uhp->uh_flags, 2); + // Assume NMARKS will stay the same. + for (size_t i = 0; i < (size_t)NMARKS; i++) { + serialize_pos(bi, uhp->uh_namedm[i]); + } + serialize_visualinfo(bi, &uhp->uh_visual); + uint8_t time_buf[8]; + time_to_bytes(uhp->uh_time, time_buf); + undo_write(bi, time_buf, sizeof(time_buf)); + + // Write optional fields. + undo_write_bytes(bi, 4, 1); + undo_write_bytes(bi, UHP_SAVE_NR, 1); + undo_write_bytes(bi, (uintmax_t)uhp->uh_save_nr, 4); + + // Write end marker. + undo_write_bytes(bi, 0, 1); + + // Write all the entries. for (u_entry_T *uep = uhp->uh_entry; uep; uep = uep->ue_next) { - put_bytes(fp, UF_ENTRY_MAGIC, 2); - if (serialize_uep(fp, buf, uep) == FAIL) - return FAIL; + undo_write_bytes(bi, (uintmax_t)UF_ENTRY_MAGIC, 2); + if (!serialize_uep(bi, uep)) { + return false; + } } - put_bytes(fp, UF_ENTRY_END_MAGIC, 2); - return OK; + undo_write_bytes(bi, (uintmax_t)UF_ENTRY_END_MAGIC, 2); + return true; } -static u_header_T *unserialize_uhp(FILE *fp, char_u *file_name) +static u_header_T *unserialize_uhp(bufinfo_T *bi, char_u *file_name) { - u_header_T *uhp; - int i; - u_entry_T *uep, *last_uep; - int c; - int error; - - uhp = xmalloc(sizeof(u_header_T)); + u_header_T *uhp = xmalloc(sizeof(u_header_T)); memset(uhp, 0, sizeof(u_header_T)); #ifdef U_DEBUG uhp->uh_magic = UH_MAGIC; #endif - uhp->uh_next.seq = get4c(fp); - uhp->uh_prev.seq = get4c(fp); - uhp->uh_alt_next.seq = get4c(fp); - uhp->uh_alt_prev.seq = get4c(fp); - uhp->uh_seq = get4c(fp); + uhp->uh_next.seq = undo_read_4c(bi); + uhp->uh_prev.seq = undo_read_4c(bi); + uhp->uh_alt_next.seq = undo_read_4c(bi); + uhp->uh_alt_prev.seq = undo_read_4c(bi); + uhp->uh_seq = undo_read_4c(bi); if (uhp->uh_seq <= 0) { corruption_error("uh_seq", file_name); - free(uhp); + xfree(uhp); return NULL; } - unserialize_pos(&uhp->uh_cursor, fp); - uhp->uh_cursor_vcol = get4c(fp); - uhp->uh_flags = get2c(fp); - for (i = 0; i < NMARKS; ++i) - unserialize_pos(&uhp->uh_namedm[i], fp); - unserialize_visualinfo(&uhp->uh_visual, fp); - uhp->uh_time = get8ctime(fp); + unserialize_pos(bi, &uhp->uh_cursor); + uhp->uh_cursor_vcol = undo_read_4c(bi); + uhp->uh_flags = undo_read_2c(bi); + for (size_t i = 0; i < (size_t)NMARKS; i++) { + unserialize_pos(bi, &uhp->uh_namedm[i]); + } + unserialize_visualinfo(bi, &uhp->uh_visual); + uhp->uh_time = undo_read_time(bi); - /* Optional fields. */ + // Unserialize optional fields. for (;; ) { - int len = getc(fp); - int what; + int len = undo_read_byte(bi); - if (len == 0) + if (len == 0) { break; - what = getc(fp); + } + int what = undo_read_byte(bi); switch (what) { case UHP_SAVE_NR: - uhp->uh_save_nr = get4c(fp); + uhp->uh_save_nr = undo_read_4c(bi); break; default: - /* field not supported, skip */ - while (--len >= 0) - (void)getc(fp); + // Field not supported, skip it. + while (--len >= 0) { + (void)undo_read_byte(bi); + } } } - /* Unserialize the uep list. */ - last_uep = NULL; - while ((c = get2c(fp)) == UF_ENTRY_MAGIC) { - error = FALSE; - uep = unserialize_uep(fp, &error, file_name); - if (last_uep == NULL) + // Unserialize the uep list. + u_entry_T *last_uep = NULL; + int c; + while ((c = undo_read_2c(bi)) == UF_ENTRY_MAGIC) { + bool error = false; + u_entry_T *uep = unserialize_uep(bi, &error, file_name); + if (last_uep == NULL) { uhp->uh_entry = uep; - else + } else { last_uep->ue_next = uep; + } last_uep = uep; if (uep == NULL || error) { u_free_uhp(uhp); @@ -865,59 +881,60 @@ static u_header_T *unserialize_uhp(FILE *fp, char_u *file_name) return uhp; } -/* - * Serialize "uep" to "fp". - */ -static int serialize_uep(FILE *fp, buf_T *buf, u_entry_T *uep) +/// Serializes "uep". +/// +/// @returns false in case of an error. +static bool serialize_uep(bufinfo_T *bi, u_entry_T *uep) { - put_bytes(fp, (uintmax_t)uep->ue_top, 4); - put_bytes(fp, (uintmax_t)uep->ue_bot, 4); - put_bytes(fp, (uintmax_t)uep->ue_lcount, 4); - put_bytes(fp, (uintmax_t)uep->ue_size, 4); - for (size_t i = 0; i < (size_t)uep->ue_size; ++i) { + undo_write_bytes(bi, (uintmax_t)uep->ue_top, 4); + undo_write_bytes(bi, (uintmax_t)uep->ue_bot, 4); + undo_write_bytes(bi, (uintmax_t)uep->ue_lcount, 4); + undo_write_bytes(bi, (uintmax_t)uep->ue_size, 4); + + for (size_t i = 0; i < (size_t)uep->ue_size; i++) { size_t len = STRLEN(uep->ue_array[i]); - if (put_bytes(fp, len, 4) == FAIL) - return FAIL; - if (len > 0 && fwrite(uep->ue_array[i], len, 1, fp) != 1) - return FAIL; + if (!undo_write_bytes(bi, len, 4)) { + return false; + } + if (len > 0 && !undo_write(bi, uep->ue_array[i], len)) { + return false; + } } - return OK; + return true; } -static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name) +static u_entry_T *unserialize_uep(bufinfo_T * bi, bool *error, char_u *file_name) { - int i; - u_entry_T *uep; - char_u **array; - char_u *line; - int line_len; - - uep = xmalloc(sizeof(u_entry_T)); + u_entry_T *uep = xmalloc(sizeof(u_entry_T)); memset(uep, 0, sizeof(u_entry_T)); #ifdef U_DEBUG uep->ue_magic = UE_MAGIC; #endif - uep->ue_top = get4c(fp); - uep->ue_bot = get4c(fp); - uep->ue_lcount = get4c(fp); - uep->ue_size = get4c(fp); + uep->ue_top = undo_read_4c(bi); + uep->ue_bot = undo_read_4c(bi); + uep->ue_lcount = undo_read_4c(bi); + uep->ue_size = undo_read_4c(bi); + + char_u **array; if (uep->ue_size > 0) { array = xmalloc(sizeof(char_u *) * (size_t)uep->ue_size); memset(array, 0, sizeof(char_u *) * (size_t)uep->ue_size); - } else + } else { array = NULL; + } uep->ue_array = array; - for (i = 0; i < uep->ue_size; ++i) { - line_len = get4c(fp); - if (line_len >= 0) - line = READ_STRING(fp, line_len); - else { + for (size_t i = 0; i < (size_t)uep->ue_size; i++) { + int line_len = undo_read_4c(bi); + char_u *line; + if (line_len >= 0) { + line = undo_read_string(bi, (size_t)line_len); + } else { line = NULL; corruption_error("line length", file_name); } if (line == NULL) { - *error = TRUE; + *error = true; return uep; } array[i] = line; @@ -925,61 +942,47 @@ static u_entry_T *unserialize_uep(FILE *fp, int *error, char_u *file_name) return uep; } -/* - * Serialize "pos" to "fp". - */ -static void serialize_pos(pos_T pos, FILE *fp) +/// Serializes "pos". +static void serialize_pos(bufinfo_T *bi, pos_T pos) { - put_bytes(fp, (uintmax_t)pos.lnum, 4); - put_bytes(fp, (uintmax_t)pos.col, 4); - put_bytes(fp, (uintmax_t)pos.coladd, 4); + undo_write_bytes(bi, (uintmax_t)pos.lnum, 4); + undo_write_bytes(bi, (uintmax_t)pos.col, 4); + undo_write_bytes(bi, (uintmax_t)pos.coladd, 4); } -/* - * Unserialize the pos_T at the current position in fp. - */ -static void unserialize_pos(pos_T *pos, FILE *fp) +/// Unserializes the pos_T at the current position. +static void unserialize_pos(bufinfo_T *bi, pos_T *pos) { - pos->lnum = get4c(fp); - if (pos->lnum < 0) + pos->lnum = undo_read_4c(bi); + if (pos->lnum < 0) { pos->lnum = 0; - pos->col = get4c(fp); - if (pos->col < 0) + } + pos->col = undo_read_4c(bi); + if (pos->col < 0) { pos->col = 0; - pos->coladd = get4c(fp); - if (pos->coladd < 0) + } + pos->coladd = undo_read_4c(bi); + if (pos->coladd < 0) { pos->coladd = 0; + } } -/* - * Serialize "info" to "fp". - */ -static void serialize_visualinfo(visualinfo_T *info, FILE *fp) +/// Serializes "info". +static void serialize_visualinfo(bufinfo_T *bi, visualinfo_T *info) { - serialize_pos(info->vi_start, fp); - serialize_pos(info->vi_end, fp); - put_bytes(fp, (uintmax_t)info->vi_mode, 4); - put_bytes(fp, (uintmax_t)info->vi_curswant, 4); + serialize_pos(bi, info->vi_start); + serialize_pos(bi, info->vi_end); + undo_write_bytes(bi, (uintmax_t)info->vi_mode, 4); + undo_write_bytes(bi, (uintmax_t)info->vi_curswant, 4); } -/* - * Unserialize the visualinfo_T at the current position in fp. - */ -static void unserialize_visualinfo(visualinfo_T *info, FILE *fp) +/// Unserializes the visualinfo_T at the current position. +static void unserialize_visualinfo(bufinfo_T *bi, visualinfo_T *info) { - unserialize_pos(&info->vi_start, fp); - unserialize_pos(&info->vi_end, fp); - info->vi_mode = get4c(fp); - info->vi_curswant = get4c(fp); -} - -/* - * Write the pointer to an undo header. Instead of writing the pointer itself - * we use the sequence number of the header. This is converted back to - * pointers when reading. */ -static void put_header_ptr(FILE *fp, u_header_T *uhp) -{ - put_bytes(fp, (uintmax_t)(uhp != NULL ? uhp->uh_seq : 0), 4); + unserialize_pos(bi, &info->vi_start); + unserialize_pos(bi, &info->vi_end); + info->vi_mode = undo_read_4c(bi); + info->vi_curswant = undo_read_4c(bi); } /* @@ -1003,6 +1006,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) FILE *fp = NULL; int perm; bool write_ok = false; + bufinfo_T bi; if (name == NULL) { file_name = u_get_undo_file_name(buf->b_ffname, FALSE); @@ -1134,8 +1138,11 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) /* * Write the header. */ - if (serialize_header(fp, buf, hash) == FAIL) + bi.bi_buf = buf; + bi.bi_fp = fp; + if (!serialize_header(&bi, hash)) { goto write_error; + } /* * Iteratively serialize UHPs and their UEPs from the top down. @@ -1149,8 +1156,9 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) #ifdef U_DEBUG ++headers_written; #endif - if (serialize_uhp(fp, buf, uhp) == FAIL) + if (!serialize_uhp(&bi, uhp)) { goto write_error; + } } /* Now walk through the tree - algorithm from undo_time(). */ @@ -1168,8 +1176,9 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash) uhp = uhp->uh_next.ptr; } - if (put_bytes(fp, UF_HEADER_END_MAGIC, 2) == OK) + if (undo_write_bytes(&bi, (uintmax_t)UF_HEADER_END_MAGIC, 2)) { write_ok = true; + } #ifdef U_DEBUG if (headers_written != buf->b_u_numhead) { EMSGN("Written %" PRId64 " headers, ...", headers_written); @@ -1195,50 +1204,30 @@ write_error: theend: if (file_name != name) - free(file_name); + xfree(file_name); } -/* - * Load the undo tree from an undo file. - * If "name" is not NULL use it as the undo file name. This also means being - * a bit more verbose. - * Otherwise use curbuf->b_ffname to generate the undo file name. - * "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text. - */ +/// Loads the undo tree from an undo file. +/// If "name" is not NULL use it as the undo file name. This also means being +/// a bit more verbose. +/// Otherwise use curbuf->b_ffname to generate the undo file name. +/// "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text. void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) + FUNC_ATTR_NONNULL_ARG(2) { - char_u *file_name; - FILE *fp; - long version, str_len; - char_u *line_ptr = NULL; - linenr_T line_lnum; - colnr_T line_colnr; - linenr_T line_count; - int num_head = 0; - long old_header_seq, new_header_seq, cur_header_seq; - long seq_last, seq_cur; - long last_save_nr = 0; - short old_idx = -1, new_idx = -1, cur_idx = -1; - long num_read_uhps = 0; - time_t seq_time; - int i, j; - int c; - u_header_T *uhp; - u_header_T **uhp_table = NULL; - char_u read_hash[UNDO_HASH_SIZE]; - char_u magic_buf[UF_START_MAGIC_LEN]; -#ifdef U_DEBUG - int *uhp_table_used; -#endif + u_header_T **uhp_table = NULL; + char_u *line_ptr = NULL; + char_u *file_name; if (name == NULL) { file_name = u_get_undo_file_name(curbuf->b_ffname, TRUE); - if (file_name == NULL) + if (file_name == NULL) { return; + } #ifdef UNIX - /* For safety we only read an undo file if the owner is equal to the - * owner of the text file or equal to the current user. */ + // For safety we only read an undo file if the owner is equal to the + // owner of the text file or equal to the current user. FileInfo file_info_orig; FileInfo file_info_undo; if (os_fileinfo((char *)orig_name, &file_info_orig) @@ -1254,8 +1243,9 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) return; } #endif - } else + } else { file_name = name; + } if (p_verbose > 0) { verbose_enter(); @@ -1263,103 +1253,120 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) verbose_leave(); } - fp = mch_fopen((char *)file_name, "r"); + FILE *fp = mch_fopen((char *)file_name, "r"); if (fp == NULL) { - if (name != NULL || p_verbose > 0) + if (name != NULL || p_verbose > 0) { EMSG2(_("E822: Cannot open undo file for reading: %s"), file_name); + } goto error; } - /* - * Read the undo file header. - */ + bufinfo_T bi; + bi.bi_buf = curbuf; + bi.bi_fp = fp; + + // Read the undo file header. + char_u magic_buf[UF_START_MAGIC_LEN]; if (fread(magic_buf, UF_START_MAGIC_LEN, 1, fp) != 1 || memcmp(magic_buf, UF_START_MAGIC, UF_START_MAGIC_LEN) != 0) { EMSG2(_("E823: Not an undo file: %s"), file_name); goto error; } - version = get2c(fp); + int version = get2c(fp); if (version != UF_VERSION) { EMSG2(_("E824: Incompatible undo file: %s"), file_name); goto error; } - if (fread(read_hash, UNDO_HASH_SIZE, 1, fp) != 1) { + char_u read_hash[UNDO_HASH_SIZE]; + if (!undo_read(&bi, read_hash, UNDO_HASH_SIZE)) { corruption_error("hash", file_name); goto error; } - line_count = (linenr_T)get4c(fp); + linenr_T line_count = (linenr_T)undo_read_4c(&bi); if (memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0 || line_count != curbuf->b_ml.ml_line_count) { if (p_verbose > 0 || name != NULL) { - if (name == NULL) + if (name == NULL) { verbose_enter(); + } give_warning((char_u *) _("File contents changed, cannot use undo info"), true); - if (name == NULL) + if (name == NULL) { verbose_leave(); + } } goto error; } - /* Read undo data for "U" command. */ - str_len = get4c(fp); - if (str_len < 0) + // Read undo data for "U" command. + int str_len = undo_read_4c(&bi); + if (str_len < 0) { goto error; - if (str_len > 0) - line_ptr = READ_STRING(fp, str_len); - line_lnum = (linenr_T)get4c(fp); - line_colnr = (colnr_T)get4c(fp); + } + + if (str_len > 0) { + line_ptr = undo_read_string(&bi, (size_t)str_len); + } + linenr_T line_lnum = (linenr_T)undo_read_4c(&bi); + colnr_T line_colnr = (colnr_T)undo_read_4c(&bi); if (line_lnum < 0 || line_colnr < 0) { corruption_error("line lnum/col", file_name); goto error; } - /* Begin general undo data */ - old_header_seq = get4c(fp); - new_header_seq = get4c(fp); - cur_header_seq = get4c(fp); - num_head = get4c(fp); - seq_last = get4c(fp); - seq_cur = get4c(fp); - seq_time = get8ctime(fp); + // Begin general undo data + int old_header_seq = undo_read_4c(&bi); + int new_header_seq = undo_read_4c(&bi); + int cur_header_seq = undo_read_4c(&bi); + int num_head = undo_read_4c(&bi); + int seq_last = undo_read_4c(&bi); + int seq_cur = undo_read_4c(&bi); + time_t seq_time = undo_read_time(&bi); - /* Optional header fields. */ + // Optional header fields. + long last_save_nr = 0; for (;; ) { - int len = getc(fp); - int what; + int len = undo_read_byte(&bi); - if (len == 0 || len == EOF) + if (len == 0 || len == EOF) { break; - what = getc(fp); + } + int what = undo_read_byte(&bi); switch (what) { - case UF_LAST_SAVE_NR: - last_save_nr = get4c(fp); - break; - default: - /* field not supported, skip */ - while (--len >= 0) - (void)getc(fp); + case UF_LAST_SAVE_NR: + last_save_nr = undo_read_4c(&bi); + break; + + default: + // field not supported, skip + while (--len >= 0) { + (void)undo_read_byte(&bi); + } } } - /* uhp_table will store the freshly created undo headers we allocate - * until we insert them into curbuf. The table remains sorted by the - * sequence numbers of the headers. - * When there are no headers uhp_table is NULL. */ + // uhp_table will store the freshly created undo headers we allocate + // until we insert them into curbuf. The table remains sorted by the + // sequence numbers of the headers. + // When there are no headers uhp_table is NULL. if (num_head > 0) { uhp_table = xmalloc((size_t)num_head * sizeof(u_header_T *)); } - while ((c = get2c(fp)) == UF_HEADER_MAGIC) { + long num_read_uhps = 0; + + int c; + while ((c = undo_read_2c(&bi)) == UF_HEADER_MAGIC) { if (num_read_uhps >= num_head) { corruption_error("num_head too small", file_name); goto error; } - uhp = unserialize_uhp(fp, file_name); - if (uhp == NULL) + u_header_T *uhp = unserialize_uhp(&bi, file_name); + if (uhp == NULL) { goto error; + } uhp_table[num_read_uhps++] = uhp; } @@ -1374,54 +1381,61 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) #ifdef U_DEBUG size_t amount = num_head * sizeof(int) + 1; - uhp_table_used = xmalloc(amount); + int *uhp_table_used = xmalloc(amount); memset(uhp_table_used, 0, amount); # define SET_FLAG(j) ++ uhp_table_used[j] #else # define SET_FLAG(j) #endif - /* We have put all of the headers into a table. Now we iterate through the - * table and swizzle each sequence number we have stored in uh_*_seq into - * a pointer corresponding to the header with that sequence number. */ - for (i = 0; i < num_head; i++) { - uhp = uhp_table[i]; - if (uhp == NULL) + // We have put all of the headers into a table. Now we iterate through the + // table and swizzle each sequence number we have stored in uh_*_seq into + // a pointer corresponding to the header with that sequence number. + short old_idx = -1, new_idx = -1, cur_idx = -1; + for (int i = 0; i < num_head; i++) { + u_header_T *uhp = uhp_table[i]; + if (uhp == NULL) { continue; - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && i != j && uhp_table[i]->uh_seq == uhp_table[j]->uh_seq) { corruption_error("duplicate uh_seq", file_name); goto error; } - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && uhp_table[j]->uh_seq == uhp->uh_next.seq) { uhp->uh_next.ptr = uhp_table[j]; SET_FLAG(j); break; } - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && uhp_table[j]->uh_seq == uhp->uh_prev.seq) { uhp->uh_prev.ptr = uhp_table[j]; SET_FLAG(j); break; } - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && uhp_table[j]->uh_seq == uhp->uh_alt_next.seq) { uhp->uh_alt_next.ptr = uhp_table[j]; SET_FLAG(j); break; } - for (j = 0; j < num_head; j++) + } + for (int j = 0; j < num_head; j++) { if (uhp_table[j] != NULL && uhp_table[j]->uh_seq == uhp->uh_alt_prev.seq) { uhp->uh_alt_prev.ptr = uhp_table[j]; SET_FLAG(j); break; } + } if (old_header_seq > 0 && old_idx < 0 && uhp->uh_seq == old_header_seq) { assert(i <= SHRT_MAX); old_idx = (short)i; @@ -1439,8 +1453,8 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) } } - /* Now that we have read the undo info successfully, free the current undo - * info and use the info from the file. */ + // Now that we have read the undo info successfully, free the current undo + // info and use the info from the file. u_blockfree(curbuf); curbuf->b_u_oldhead = old_idx < 0 ? NULL : uhp_table[old_idx]; curbuf->b_u_newhead = new_idx < 0 ? NULL : uhp_table[new_idx]; @@ -1456,38 +1470,120 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name) curbuf->b_u_save_nr_cur = last_save_nr; curbuf->b_u_synced = true; - free(uhp_table); + xfree(uhp_table); #ifdef U_DEBUG - for (i = 0; i < num_head; ++i) - if (uhp_table_used[i] == 0) + for (int i = 0; i < num_head; i++) { + if (uhp_table_used[i] == 0) { EMSGN("uhp_table entry %" PRId64 " not used, leaking memory", i); - free(uhp_table_used); + } + } + xfree(uhp_table_used); u_check(TRUE); #endif - if (name != NULL) + if (name != NULL) { smsg((char_u *)_("Finished reading undo file %s"), file_name); + } goto theend; error: - free(line_ptr); + xfree(line_ptr); if (uhp_table != NULL) { - for (i = 0; i < num_read_uhps; i++) - if (uhp_table[i] != NULL) + for (long i = 0; i < num_read_uhps; i++) + if (uhp_table[i] != NULL) { u_free_uhp(uhp_table[i]); - free(uhp_table); + } + xfree(uhp_table); } theend: - if (fp != NULL) + if (fp != NULL) { fclose(fp); - if (file_name != name) - free(file_name); - return; + } + if (file_name != name) { + xfree(file_name); + } +} + +/// Writes a sequence of bytes to the undo file. +/// +/// @returns false in case of an error. +static bool undo_write(bufinfo_T *bi, uint8_t *ptr, size_t len) + FUNC_ATTR_NONNULL_ARG(1) +{ + return fwrite(ptr, len, 1, bi->bi_fp) == 1; +} + +/// Writes a number, most significant bit first, in "len" bytes. +/// +/// Must match with undo_read_?c() functions. +/// +/// @returns false in case of an error. +static bool undo_write_bytes(bufinfo_T *bi, uintmax_t nr, size_t len) +{ + assert(len > 0); + uint8_t buf[8]; + for (size_t i = len - 1, bufi = 0; bufi < len; i--, bufi++) { + buf[bufi] = (uint8_t)(nr >> (i * 8)); + } + return undo_write(bi, buf, len); +} + +/// Writes the pointer to an undo header. +/// +/// Instead of writing the pointer itself, we use the sequence +/// number of the header. This is converted back to pointers +/// when reading. +static void put_header_ptr(bufinfo_T *bi, u_header_T *uhp) +{ + assert(uhp == NULL || uhp->uh_seq >= 0); + undo_write_bytes(bi, (uint64_t)(uhp != NULL ? uhp->uh_seq : 0), 4); +} + +static int undo_read_4c(bufinfo_T *bi) +{ + return get4c(bi->bi_fp); } +static int undo_read_2c(bufinfo_T *bi) +{ + return get2c(bi->bi_fp); +} +static int undo_read_byte(bufinfo_T *bi) +{ + return getc(bi->bi_fp); +} + +static time_t undo_read_time(bufinfo_T *bi) +{ + return get8ctime(bi->bi_fp); +} + +/// Reads "buffer[size]" from the undo file. +/// +/// @returns false in case of an error. +static bool undo_read(bufinfo_T *bi, uint8_t *buffer, size_t size) + FUNC_ATTR_NONNULL_ARG(1) +{ + return fread(buffer, size, 1, bi->bi_fp) == 1; +} + +/// Reads a string of length "len" from "bi->bi_fd" and appends a zero to it. +/// +/// @param len can be zero to allocate an empty line. +/// +/// @returns a pointer to allocated memory or NULL in case of an error. +static uint8_t *undo_read_string(bufinfo_T *bi, size_t len) +{ + uint8_t *ptr = xmallocz(len); + if (len > 0 && !undo_read(bi, ptr, len)) { + xfree(ptr); + return NULL; + } + return ptr; +} /* * If 'cpoptions' contains 'u': Undo the previous undo or redo (vi compatible). @@ -2011,9 +2107,9 @@ static void u_undoredo(int undo) ml_replace((linenr_T)1, uep->ue_array[i], TRUE); else ml_append(lnum, uep->ue_array[i], (colnr_T)0, FALSE); - free(uep->ue_array[i]); + xfree(uep->ue_array[i]); } - free((char_u *)uep->ue_array); + xfree((char_u *)uep->ue_array); } /* adjust marks */ @@ -2572,7 +2668,7 @@ u_freeentries ( #ifdef U_DEBUG uhp->uh_magic = 0; #endif - free((char_u *)uhp); + xfree((char_u *)uhp); --buf->b_u_numhead; } @@ -2582,12 +2678,12 @@ u_freeentries ( static void u_freeentry(u_entry_T *uep, long n) { while (n > 0) - free(uep->ue_array[--n]); - free((char_u *)uep->ue_array); + xfree(uep->ue_array[--n]); + xfree((char_u *)uep->ue_array); #ifdef U_DEBUG uep->ue_magic = 0; #endif - free((char_u *)uep); + xfree((char_u *)uep); } /* @@ -2627,7 +2723,7 @@ void u_saveline(linenr_T lnum) void u_clearline(void) { if (curbuf->b_u_line_ptr != NULL) { - free(curbuf->b_u_line_ptr); + xfree(curbuf->b_u_line_ptr); curbuf->b_u_line_ptr = NULL; curbuf->b_u_line_lnum = 0; } @@ -2660,7 +2756,7 @@ void u_undoline(void) oldp = u_save_line(curbuf->b_u_line_lnum); ml_replace(curbuf->b_u_line_lnum, curbuf->b_u_line_ptr, TRUE); changed_bytes(curbuf->b_u_line_lnum, 0); - free(curbuf->b_u_line_ptr); + xfree(curbuf->b_u_line_ptr); curbuf->b_u_line_ptr = oldp; t = curbuf->b_u_line_colnr; @@ -2684,7 +2780,7 @@ void u_blockfree(buf_T *buf) u_freeheader(buf, buf->b_u_oldhead, NULL); assert(buf->b_u_oldhead != previous_oldhead); } - free(buf->b_u_line_ptr); + xfree(buf->b_u_line_ptr); } /* diff --git a/src/nvim/undo_defs.h b/src/nvim/undo_defs.h index 2579f13b93..610adb4367 100644 --- a/src/nvim/undo_defs.h +++ b/src/nvim/undo_defs.h @@ -4,6 +4,7 @@ #include <time.h> // for time_t #include "nvim/pos.h" +#include "nvim/buffer_defs.h" /* Structure to store info about the Visual area. */ typedef struct { @@ -67,4 +68,10 @@ struct u_header { #define UH_CHANGED 0x01 /* b_changed flag before undo/after redo */ #define UH_EMPTYBUF 0x02 /* buffer was empty */ +/// Structure passed around between undofile functions. +typedef struct { + buf_T *bi_buf; + FILE *bi_fp; +} bufinfo_T; + #endif // NVIM_UNDO_DEFS_H diff --git a/src/nvim/version.c b/src/nvim/version.c index 1a5eb523fa..49f374bce4 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -915,13 +915,13 @@ void list_version(void) if (*default_vim_dir != NUL) { version_msg(_(" fall-back for $VIM: \"")); - version_msg((char *)default_vim_dir); + version_msg(default_vim_dir); version_msg("\"\n"); } if (*default_vimruntime_dir != NUL) { version_msg(_(" f-b for $VIMRUNTIME: \"")); - version_msg((char *)default_vimruntime_dir); + version_msg(default_vimruntime_dir); version_msg("\"\n"); } #endif // ifdef HAVE_PATHDEF diff --git a/src/nvim/window.c b/src/nvim/window.c index 9f07f2bddc..caa7ecc041 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -401,7 +401,7 @@ wingotofile: beginline(BL_SOL | BL_FIX); } } - free(ptr); + xfree(ptr); } break; @@ -1766,7 +1766,7 @@ static int close_last_window_tabpage(win_T *win, int free_buf, tabpage_T *prev_c } buf_T *old_curbuf = curbuf; - Terminal *term = win->w_buffer->terminal; + Terminal *term = win->w_buffer ? win->w_buffer->terminal : NULL; if (term) { // Don't free terminal buffers free_buf = false; @@ -2065,7 +2065,7 @@ win_free_mem ( /* Remove the window and its frame from the tree of frames. */ frp = win->w_frame; wp = winframe_remove(win, dirp, tp); - free(frp); + xfree(frp); win_free(win, tp); /* When deleting the current window of another tab page select a new @@ -2209,7 +2209,7 @@ winframe_remove ( if (frp2->fr_win != NULL) frp2->fr_win->w_frame = frp2->fr_parent; frp = frp2->fr_parent; - free(frp2); + xfree(frp2); frp2 = frp->fr_parent; if (frp2 != NULL && frp2->fr_layout == frp->fr_layout) { @@ -2230,7 +2230,7 @@ winframe_remove ( break; } } - free(frp); + xfree(frp); } } @@ -2914,7 +2914,7 @@ void free_tabpage(tabpage_T *tp) - free(tp); + xfree(tp); } /* @@ -2934,7 +2934,7 @@ int win_new_tabpage(int after) /* Remember the current windows in this Tab page. */ if (leave_tabpage(curbuf, TRUE) == FAIL) { - free(newtp); + xfree(newtp); return FAIL; } curtab = newtp; @@ -3528,7 +3528,7 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid, int tri /* Window doesn't have a local directory and we are not in the global * directory: Change to the global directory. */ ignored = os_chdir((char *)globaldir); - free(globaldir); + xfree(globaldir); globaldir = NULL; shorten_fnames(TRUE); } @@ -3702,9 +3702,9 @@ win_free ( win_free_lsize(wp); for (i = 0; i < wp->w_tagstacklen; ++i) - free(wp->w_tagstack[i].tagname); + xfree(wp->w_tagstack[i].tagname); - free(wp->w_localdir); + xfree(wp->w_localdir); /* Remove the window from the b_wininfo lists, it may happen that the * freed memory is re-used for another window. */ @@ -3721,7 +3721,7 @@ win_free ( qf_free_all(wp); - free(wp->w_p_cc_cols); + xfree(wp->w_p_cc_cols); if (wp != aucmd_win) win_remove(wp, tp); @@ -3729,7 +3729,7 @@ win_free ( wp->w_next = au_pending_free_win; au_pending_free_win = wp; } else { - free(wp); + xfree(wp); } unblock_autocmds(); @@ -3839,7 +3839,7 @@ void win_free_lsize(win_T *wp) { // TODO: why would wp be NULL here? if (wp != NULL) { - free(wp->w_lines); + xfree(wp->w_lines); wp->w_lines = NULL; } } @@ -5136,7 +5136,7 @@ static void clear_snapshot_rec(frame_T *fr) if (fr != NULL) { clear_snapshot_rec(fr->fr_next); clear_snapshot_rec(fr->fr_child); - free(fr); + xfree(fr); } } @@ -5472,7 +5472,7 @@ int match_add(win_T *wp, char_u *grp, char_u *pat, int prio, int id, list_T *pos return id; fail: - free(m); + xfree(m); return -1; } @@ -5507,7 +5507,7 @@ int match_delete(win_T *wp, int id, int perr) else prev->next = cur->next; vim_regfree(cur->match.regprog); - free(cur->pattern); + xfree(cur->pattern); if (cur->pos.toplnum != 0) { if (wp->w_buffer->b_mod_set) { if (wp->w_buffer->b_mod_top > cur->pos.toplnum) { @@ -5524,7 +5524,7 @@ int match_delete(win_T *wp, int id, int perr) } rtype = VALID; } - free(cur); + xfree(cur); redraw_later(rtype); return 0; } @@ -5539,8 +5539,8 @@ void clear_matches(win_T *wp) while (wp->w_match_head != NULL) { m = wp->w_match_head->next; vim_regfree(wp->w_match_head->match.regprog); - free(wp->w_match_head->pattern); - free(wp->w_match_head); + xfree(wp->w_match_head->pattern); + xfree(wp->w_match_head); wp->w_match_head = m; } redraw_later(SOME_VALID); |