Problem: Clearing a struct is verbose.
Solution: Define and use CLEAR_FIELD() and CLEAR_POINTER().
UINT32_T ui = 0xffffffffUL;
bf_state_T state;
- vim_memset(&state, 0, sizeof(bf_state_T));
+ CLEAR_FIELD(state);
state.cfb_len = BF_MAX_CFB_LEN;
// We can't simply use sizeof(UINT32_T), it would generate a compiler
// Get the server internet address and put into addr structure fill in the
// socket address structure and connect to server.
#ifdef FEAT_IPV6
- vim_memset(&hints, 0, sizeof(hints));
+ CLEAR_FIELD(hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
# ifdef AI_ADDRCONFIG
freeaddrinfo(res);
#else
- vim_memset((char *)&server, 0, sizeof(server));
+ CLEAR_FIELD(server);
server.sin_family = AF_INET;
server.sin_port = htons(port);
if ((host = gethostbyname(hostname)) == NULL)
exarg_T ea;
ch_log(channel, "Executing normal command '%s'", (char *)arg);
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ea.arg = arg;
ea.addr_count = 0;
ea.forceit = TRUE; // no mapping
exarg_T ea;
ch_log(channel, "redraw");
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ea.forceit = *arg != NUL;
ex_redraw(&ea);
showruler(FALSE);
void
clear_job_options(jobopt_T *opt)
{
- vim_memset(opt, 0, sizeof(jobopt_T));
+ CLEAR_POINTER(opt);
}
/*
/*
* Init word char flags all to FALSE
*/
- vim_memset(buf->b_chartab, 0, (size_t)32);
+ CLEAR_FIELD(buf->b_chartab);
if (enc_dbcs != 0)
for (c = 0; c < 256; ++c)
{
clear_oparg(&oa);
oa.regname = (cbd == &clip_plus ? '+' : '*');
oa.op_type = OP_YANK;
- vim_memset(&ca, 0, sizeof(ca));
+ CLEAR_FIELD(ca);
ca.oap = &oa;
ca.cmdchar = 'y';
ca.count1 = 1;
goto theend;
// Only use the internal method if it did not fail for one of the buffers.
- vim_memset(&diffio, 0, sizeof(diffio));
+ CLEAR_FIELD(diffio);
diffio.dio_internal = diff_internal() && !diff_internal_failed();
diff_try_update(&diffio, idx_orig, eap);
if (diffio.dio_internal && diff_internal_failed())
{
// Internal diff failed, use external diff instead.
- vim_memset(&diffio, 0, sizeof(diffio));
+ CLEAR_FIELD(diffio);
diff_try_update(&diffio, idx_orig, eap);
}
xdemitconf_t emit_cfg;
xdemitcb_t emit_cb;
- vim_memset(¶m, 0, sizeof(param));
- vim_memset(&emit_cfg, 0, sizeof(emit_cfg));
- vim_memset(&emit_cb, 0, sizeof(emit_cb));
+ CLEAR_FIELD(param);
+ CLEAR_FIELD(emit_cfg);
+ CLEAR_FIELD(emit_cb);
param.flags = diff_algorithm;
s = expr->vval.v_string;
if (s == NULL || *s == NUL)
return FAIL;
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.evaluate = TRUE;
if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL)
return FAIL;
s = partial_name(partial);
if (s == NULL || *s == NUL)
return FAIL;
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.evaluate = TRUE;
funcexe.partial = partial;
if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL)
funcexe_T funcexe;
rettv->v_type = VAR_UNKNOWN; // clear_tv() uses this
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.firstline = curwin->w_cursor.lnum;
funcexe.lastline = curwin->w_cursor.lnum;
funcexe.evaluate = TRUE;
int quiet = flags & GLV_QUIET;
// Clear everything in "lp".
- vim_memset(lp, 0, sizeof(lval_T));
+ CLEAR_POINTER(lp);
if (skip)
{
funcexe_T funcexe;
// Invoke the function.
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.firstline = curwin->w_cursor.lnum;
funcexe.lastline = curwin->w_cursor.lnum;
funcexe.evaluate = evaluate;
else
s = (char_u *)"";
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.firstline = curwin->w_cursor.lnum;
funcexe.lastline = curwin->w_cursor.lnum;
funcexe.evaluate = evaluate;
init_tv(typval_T *varp)
{
if (varp != NULL)
- vim_memset(varp, 0, sizeof(typval_T));
+ CLEAR_POINTER(varp);
}
/*
pt = argvars[0].vval.v_partial;
else
{
- vim_memset(&fref_pt, 0, sizeof(fref_pt));
+ CLEAR_FIELD(fref_pt);
fref_pt.pt_name = argvars[0].vval.v_string;
pt = &fref_pt;
}
}
pos = save_cursor = curwin->w_cursor;
- vim_memset(&sia, 0, sizeof(sia));
+ CLEAR_FIELD(sia);
sia.sa_stop_lnum = (linenr_T)lnum_stop;
#ifdef FEAT_RELTIME
sia.sa_tm = &tm;
{
searchit_arg_T sia;
- vim_memset(&sia, 0, sizeof(sia));
+ CLEAR_FIELD(sia);
sia.sa_stop_lnum = lnum_stop;
#ifdef FEAT_RELTIME
sia.sa_tm = &tm;
lnum = tv_get_lnum(argvars); // -1 on type error
col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error
- vim_memset(str, NUL, sizeof(str));
+ CLEAR_FIELD(str);
if (rettv_list_alloc(rettv) != FAIL)
{
// Init ea pseudo-structure, this is needed for the check_overwrite()
// function.
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
if (ret == VIM_YES)
{
* unobtrusive message.
*/
if (eap == NULL)
- vim_memset(&ex, 0, sizeof(ex));
+ CLEAR_FIELD(ex);
else
ex = *eap;
ex.arg = fname;
if (flags & DOCMD_EXCRESET)
save_dbg_stuff(&debug_saved);
else
- vim_memset(&debug_saved, 0, sizeof(debug_saved));
+ CLEAR_FIELD(debug_saved);
initial_trylevel = trylevel;
int starts_with_colon;
#endif
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ea.line1 = 1;
ea.line2 = 1;
#ifdef FEAT_EVAL
{
char_u *p;
- vim_memset(&cmdmod, 0, sizeof(cmdmod));
+ CLEAR_FIELD(cmdmod);
eap->verbose_save = -1;
eap->save_msg_silent = -1;
* Move to the first file.
*/
// Fake up a minimal "next" command for do_argfile()
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ea.cmd = (char_u *)"next";
do_argfile(&ea, 0);
{
exarg_T ea;
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ea.cmdidx = CMD_tabnew;
ea.cmd = (char_u *)"tabn";
ea.arg = (char_u *)"";
return FALSE;
++emsg_off;
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ea.line1 = 1;
ea.line2 = 1;
ea.cmd = ccline.cmdbuff;
search_flags += SEARCH_START;
ccline.cmdbuff[skiplen + patlen] = NUL;
#ifdef FEAT_RELTIME
- vim_memset(&sia, 0, sizeof(sia));
+ CLEAR_FIELD(sia);
sia.sa_tm = &tm;
#endif
found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim,
void
cmdline_init(void)
{
- vim_memset(&ccline, 0, sizeof(cmdline_info_T));
+ CLEAR_FIELD(ccline);
}
/*
did_save_ccline = TRUE;
}
if (init_ccline)
- vim_memset(&ccline, 0, sizeof(cmdline_info_T));
+ CLEAR_FIELD(ccline);
#ifdef FEAT_EVAL
if (firstc == -1)
did_save_ccline = TRUE;
}
- vim_memset(&ccline, 0, sizeof(cmdline_info_T));
+ CLEAR_FIELD(ccline);
ccline.cmdprompt = prompt;
ccline.cmdattr = attr;
# ifdef FEAT_EVAL
{
if (!prev_ccline_used)
{
- vim_memset(&prev_ccline, 0, sizeof(cmdline_info_T));
+ CLEAR_FIELD(prev_ccline);
prev_ccline_used = TRUE;
}
*ccp = prev_ccline;
search_ctx = search_ctx_arg;
else
{
- search_ctx = ALLOC_ONE(ff_search_ctx_T);
+ search_ctx = ALLOC_CLEAR_ONE(ff_search_ctx_T);
if (search_ctx == NULL)
goto error_return;
- vim_memset(search_ctx, 0, sizeof(ff_search_ctx_T));
}
search_ctx->ffsc_find_what = find_what;
search_ctx->ffsc_tagfile = tagfile;
{
GtkTypeInfo form_info;
- vim_memset(&form_info, 0, sizeof(form_info));
+ CLEAR_FIELD(form_info);
form_info.type_name = "GtkForm";
form_info.object_size = sizeof(GtkForm);
form_info.class_size = sizeof(GtkFormClass);
button = 0;
// initialize the hotkey mapping
- vim_memset(hotKeys, 0, sizeof(hotKeys));
+ CLEAR_FIELD(hotKeys);
for (;*buttonChar != 0;)
{
XmProcessTraversal(w, XmTRAVERSE_CURRENT);
- vim_memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent));
+ CLEAR_FIELD(keyEvent);
keyEvent.type = KeyPress;
keyEvent.serial = 1;
keyEvent.send_event = True;
// Convert the filter to Windows format.
filterp = convert_filterW(filter);
- vim_memset(&fileStruct, 0, sizeof(OPENFILENAMEW));
+ CLEAR_FIELD(fileStruct);
# ifdef OPENFILENAME_SIZE_VERSION_400W
// be compatible with Windows NT 4.0
fileStruct.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
// Mouse hovers over popup window, scroll it if possible.
mouse_row = wp->w_winrow;
mouse_col = wp->w_wincol;
- vim_memset(&cap, 0, sizeof(cap));
+ CLEAR_FIELD(cap);
cap.arg = zDelta < 0 ? MSCR_UP : MSCR_DOWN;
cap.cmdchar = zDelta < 0 ? K_MOUSEUP : K_MOUSEDOWN;
clear_oparg(&oa);
{
TBBUTTON newtb;
- vim_memset(&newtb, 0, sizeof(newtb));
+ CLEAR_FIELD(newtb);
if (menu_is_separator(menu->name))
{
newtb.iBitmap = 0;
return (guicolor_T)available.pixel;
#endif
colormap = DefaultColormap(gui.dpy, DefaultScreen(gui.dpy));
- vim_memset(&available, 0, sizeof(XColor));
+ CLEAR_FIELD(available);
available.red = r << 8;
available.green = g << 8;
available.blue = b << 8;
int page_line;
int jobsplit;
- vim_memset(&settings, 0, sizeof(prt_settings_T));
+ CLEAR_FIELD(settings);
settings.has_color = TRUE;
# ifdef FEAT_POSTSCRIPT
prt_pos_T page_prtpos; // print position at page start
int side;
- vim_memset(&page_prtpos, 0, sizeof(prt_pos_T));
+ CLEAR_FIELD(page_prtpos);
page_prtpos.file_line = eap->line1;
prtpos = page_prtpos;
semsg(_("E624: Can't open file \"%s\""), resource->filename);
return FALSE;
}
- vim_memset(prt_resfile.buffer, NUL, PRT_FILE_BUFFER_LEN);
+ CLEAR_FIELD(prt_resfile.buffer);
// Parse first line to ensure valid resource file
prt_resfile.len = (int)fread((char *)prt_resfile.buffer, sizeof(char_u),
hash_init(hashtab_T *ht)
{
// This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray".
- vim_memset(ht, 0, sizeof(hashtab_T));
+ CLEAR_POINTER(ht);
ht->ht_array = ht->ht_smallarray;
ht->ht_mask = HT_INIT_SIZE - 1;
}
}
else
oldarray = ht->ht_array;
+ CLEAR_FIELD(ht->ht_smallarray);
}
else
{
// Allocate an array.
- newarray = ALLOC_MULT(hashitem_T, newsize);
+ newarray = ALLOC_CLEAR_MULT(hashitem_T, newsize);
if (newarray == NULL)
{
// Out of memory. When there are NULL items still return OK.
}
oldarray = ht->ht_array;
}
- vim_memset(newarray, 0, (size_t)(sizeof(hashitem_T) * newsize));
/*
* Move all the items from the old array to the new one, placing them in
return 0;
taep = &(((attrentry_T *)table->ga_data)[table->ga_len]);
- vim_memset(taep, 0, sizeof(attrentry_T));
+ CLEAR_POINTER(taep);
taep->ae_attr = aep->ae_attr;
#ifdef FEAT_GUI
if (table == &gui_attr_table)
{
attrentry_T at_en;
- vim_memset(&at_en, 0, sizeof(attrentry_T));
+ CLEAR_FIELD(at_en);
#ifdef FEAT_TERMGUICOLORS
at_en.ae_u.cterm.fg_rgb = INVALCOLOR;
at_en.ae_u.cterm.bg_rgb = INVALCOLOR;
{
attrentry_T at_en;
- vim_memset(&at_en, 0, sizeof(attrentry_T));
+ CLEAR_FIELD(at_en);
at_en.ae_attr = attr;
if (fg == INVALCOLOR && bg == INVALCOLOR)
{
{
attrentry_T at_en;
- vim_memset(&at_en, 0, sizeof(attrentry_T));
+ CLEAR_FIELD(at_en);
at_en.ae_attr = attr;
at_en.ae_u.gui.fg_color = fg;
at_en.ae_u.gui.bg_color = bg;
new_en = *char_aep;
else
{
- vim_memset(&new_en, 0, sizeof(new_en));
+ CLEAR_FIELD(new_en);
new_en.ae_u.gui.fg_color = INVALCOLOR;
new_en.ae_u.gui.bg_color = INVALCOLOR;
new_en.ae_u.gui.sp_color = INVALCOLOR;
new_en = *char_aep;
else
{
- vim_memset(&new_en, 0, sizeof(new_en));
+ CLEAR_FIELD(new_en);
#ifdef FEAT_TERMGUICOLORS
new_en.ae_u.cterm.bg_rgb = INVALCOLOR;
new_en.ae_u.cterm.fg_rgb = INVALCOLOR;
new_en = *char_aep;
else
{
- vim_memset(&new_en, 0, sizeof(new_en));
+ CLEAR_FIELD(new_en);
if (char_attr <= HL_ALL)
new_en.ae_attr = char_attr;
}
return 0;
}
- vim_memset(&(HL_TABLE()[highlight_ga.ga_len]), 0, sizeof(hl_group_T));
+ CLEAR_POINTER(&(HL_TABLE()[highlight_ga.ga_len]));
HL_TABLE()[highlight_ga.ga_len].sg_name = name;
HL_TABLE()[highlight_ga.ga_len].sg_name_u = name_up;
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
if (id_alt == 0)
{
- vim_memset(&hlt[hlcnt + i], 0, sizeof(hl_group_T));
+ CLEAR_POINTER(&hlt[hlcnt + i]);
hlt[hlcnt + i].sg_term = highlight_attr[hlf];
hlt[hlcnt + i].sg_cterm = highlight_attr[hlf];
# if defined(FEAT_GUI) || defined(FEAT_EVAL)
{
// Make sure id_S is always valid to simplify code below. Use the last
// entry.
- vim_memset(&HL_TABLE()[hlcnt + 27], 0, sizeof(hl_group_T));
+ CLEAR_POINTER(&HL_TABLE()[hlcnt + 27]);
HL_TABLE()[hlcnt + 18].sg_term = highlight_attr[HLF_S];
id_S = hlcnt + 19;
}
MZ_GC_REG();
self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_window));
- vim_memset(self, 0, sizeof(vim_mz_window));
+ CLEAR_POINTER(self);
#ifndef MZ_PRECISE_GC
scheme_dont_gc_ptr(self); // because win isn't visible to GC
#else
MZ_GC_REG();
self = scheme_malloc_fail_ok(scheme_malloc_tagged, sizeof(vim_mz_buffer));
- vim_memset(self, 0, sizeof(vim_mz_buffer));
+ CLEAR_POINTER(self);
#ifndef MZ_PRECISE_GC
scheme_dont_gc_ptr(self); // because buf isn't visible to GC
#else
MZ_GC_VAR_IN_REG(1, rest);
MZ_GC_REG();
- array = ALLOC_MULT(char *, new_len + 1);
- vim_memset(array, 0, (new_len+1) * sizeof(char *));
+ array = ALLOC_CLEAR_MULT(char *, new_len + 1);
rest = line_list;
for (i = 0; i < new_len; ++i)
MZ_GC_VAR_IN_REG(1, rest);
MZ_GC_REG();
- array = ALLOC_MULT(char *, size + 1);
- vim_memset(array, 0, (size+1) * sizeof(char *));
+ array = ALLOC_CLEAR_MULT(char *, size + 1);
rest = list;
for (i = 0; i < size; ++i)
if (self->argv || self->self)
{
- vim_memset(&pt, 0, sizeof(partial_T));
+ CLEAR_FIELD(pt);
set_partial(self, &pt, FALSE);
pt_ptr = &pt;
}
static void
init_structs(void)
{
- vim_memset(&OutputType, 0, sizeof(OutputType));
+ CLEAR_FIELD(OutputType);
OutputType.tp_name = "vim.message";
OutputType.tp_basicsize = sizeof(OutputObject);
OutputType.tp_flags = Py_TPFLAGS_DEFAULT;
// OutputType.tp_base = &PyFile_Type;
#endif
- vim_memset(&IterType, 0, sizeof(IterType));
+ CLEAR_FIELD(IterType);
IterType.tp_name = "vim.iter";
IterType.tp_basicsize = sizeof(IterObject);
IterType.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC;
IterType.tp_traverse = (traverseproc)IterTraverse;
IterType.tp_clear = (inquiry)IterClear;
- vim_memset(&BufferType, 0, sizeof(BufferType));
+ CLEAR_FIELD(BufferType);
BufferType.tp_name = "vim.buffer";
BufferType.tp_basicsize = sizeof(BufferType);
BufferType.tp_dealloc = (destructor)BufferDestructor;
BufferType.tp_setattr = (setattrfunc)BufferSetattr;
#endif
- vim_memset(&WindowType, 0, sizeof(WindowType));
+ CLEAR_FIELD(WindowType);
WindowType.tp_name = "vim.window";
WindowType.tp_basicsize = sizeof(WindowObject);
WindowType.tp_dealloc = (destructor)WindowDestructor;
WindowType.tp_setattr = (setattrfunc)WindowSetattr;
#endif
- vim_memset(&TabPageType, 0, sizeof(TabPageType));
+ CLEAR_FIELD(TabPageType);
TabPageType.tp_name = "vim.tabpage";
TabPageType.tp_basicsize = sizeof(TabPageObject);
TabPageType.tp_dealloc = (destructor)TabPageDestructor;
TabPageType.tp_getattr = (getattrfunc)TabPageGetattr;
#endif
- vim_memset(&BufMapType, 0, sizeof(BufMapType));
+ CLEAR_FIELD(BufMapType);
BufMapType.tp_name = "vim.bufferlist";
BufMapType.tp_basicsize = sizeof(BufMapObject);
BufMapType.tp_as_mapping = &BufMapAsMapping;
BufMapType.tp_iter = BufMapIter;
BufferType.tp_doc = "vim buffer list";
- vim_memset(&WinListType, 0, sizeof(WinListType));
+ CLEAR_FIELD(WinListType);
WinListType.tp_name = "vim.windowlist";
WinListType.tp_basicsize = sizeof(WinListType);
WinListType.tp_as_sequence = &WinListAsSeq;
WinListType.tp_doc = "vim window list";
WinListType.tp_dealloc = (destructor)WinListDestructor;
- vim_memset(&TabListType, 0, sizeof(TabListType));
+ CLEAR_FIELD(TabListType);
TabListType.tp_name = "vim.tabpagelist";
TabListType.tp_basicsize = sizeof(TabListType);
TabListType.tp_as_sequence = &TabListAsSeq;
TabListType.tp_flags = Py_TPFLAGS_DEFAULT;
TabListType.tp_doc = "vim tab page list";
- vim_memset(&RangeType, 0, sizeof(RangeType));
+ CLEAR_FIELD(RangeType);
RangeType.tp_name = "vim.range";
RangeType.tp_basicsize = sizeof(RangeObject);
RangeType.tp_dealloc = (destructor)RangeDestructor;
RangeType.tp_getattr = (getattrfunc)RangeGetattr;
#endif
- vim_memset(&CurrentType, 0, sizeof(CurrentType));
+ CLEAR_FIELD(CurrentType);
CurrentType.tp_name = "vim.currentdata";
CurrentType.tp_basicsize = sizeof(CurrentObject);
CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
CurrentType.tp_setattr = (setattrfunc)CurrentSetattr;
#endif
- vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
+ CLEAR_FIELD(DictionaryType);
DictionaryType.tp_name = "vim.dictionary";
DictionaryType.tp_basicsize = sizeof(DictionaryObject);
DictionaryType.tp_dealloc = (destructor)DictionaryDestructor;
DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr;
#endif
- vim_memset(&ListType, 0, sizeof(ListType));
+ CLEAR_FIELD(ListType);
ListType.tp_name = "vim.list";
ListType.tp_dealloc = (destructor)ListDestructor;
ListType.tp_basicsize = sizeof(ListObject);
ListType.tp_setattr = (setattrfunc)ListSetattr;
#endif
- vim_memset(&FunctionType, 0, sizeof(FunctionType));
+ CLEAR_FIELD(FunctionType);
FunctionType.tp_name = "vim.function";
FunctionType.tp_basicsize = sizeof(FunctionObject);
FunctionType.tp_dealloc = (destructor)FunctionDestructor;
FunctionType.tp_getattr = (getattrfunc)FunctionGetattr;
#endif
- vim_memset(&OptionsType, 0, sizeof(OptionsType));
+ CLEAR_FIELD(OptionsType);
OptionsType.tp_name = "vim.options";
OptionsType.tp_basicsize = sizeof(OptionsObject);
OptionsType.tp_as_sequence = &OptionsAsSeq;
OptionsType.tp_clear = (inquiry)OptionsClear;
#if PY_VERSION_HEX < 0x030700f0
- vim_memset(&LoaderType, 0, sizeof(LoaderType));
+ CLEAR_FIELD(LoaderType);
LoaderType.tp_name = "vim.Loader";
LoaderType.tp_basicsize = sizeof(LoaderObject);
LoaderType.tp_flags = Py_TPFLAGS_DEFAULT;
#endif
#if PY_MAJOR_VERSION >= 3
- vim_memset(&vimmodule, 0, sizeof(vimmodule));
+ CLEAR_FIELD(vimmodule);
vimmodule.m_name = "vim";
vimmodule.m_doc = "Vim Python interface\n";
vimmodule.m_size = -1;
else
{
word = tv_get_string_chk(tv);
- vim_memset(cptext, 0, sizeof(cptext));
+ CLEAR_FIELD(cptext);
}
if (word == NULL || (!empty && *word == NUL))
return FAIL;
buf_T buf;
int c;
- vim_memset(&buf, 0, sizeof(buf));
+ CLEAR_FIELD(buf);
p_enc = (char_u *)"utf-8";
p_isi = (char_u *)"";
p_isp = (char_u *)"";
copy_tv(&si2->item->li_tv, &argv[1]);
rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.evaluate = TRUE;
funcexe.partial = partial;
funcexe.selfdict = sortinfo->item_compare_selfdict;
// Many variables are in "params" so that we can pass them to invoked
// functions without a lot of arguments. "argc" and "argv" are also
// copied, so that they can be changed.
- vim_memset(¶ms, 0, sizeof(params));
+ CLEAR_FIELD(params);
params.argc = argc;
params.argv = argv;
params.want_full_screen = TRUE;
{
if (!maphash_valid)
{
- vim_memset(maphash, 0, sizeof(maphash));
+ CLEAR_FIELD(maphash);
maphash_valid = TRUE;
}
}
static void
mf_hash_init(mf_hashtab_T *mht)
{
- vim_memset(mht, 0, sizeof(mf_hashtab_T));
+ CLEAR_POINTER(mht);
mht->mht_buckets = mht->mht_small_buckets;
mht->mht_mask = MHT_INIT_SIZE - 1;
}
* a power of two.
*/
- vim_memset(tails, 0, sizeof(tails));
+ CLEAR_FIELD(tails);
for (mhi = mht->mht_buckets[i]; mhi != NULL; mhi = mhi->mhi_next)
{
int
main(int argc, char **argv)
{
- vim_memset(¶ms, 0, sizeof(params));
+ CLEAR_FIELD(params);
params.argc = argc;
params.argv = argv;
common_init(¶ms);
{
char_u buf[4];
- vim_memset(buf, 0, sizeof(buf));
+ CLEAR_FIELD(buf);
if (time_for_testing == 93784)
{
// disappear.
do_bufdel(DOBUF_DEL, (char_u *)"", 1,
buf->bufp->b_fnum, buf->bufp->b_fnum, TRUE);
- vim_memset(buf, 0, sizeof(nbbuf_T));
+ CLEAR_POINTER(buf);
}
}
// =====================================================================
int set_prevcount = FALSE;
#endif
- vim_memset(&ca, 0, sizeof(ca)); // also resets ca.retval
+ CLEAR_FIELD(ca); // also resets ca.retval
ca.oap = oap;
// Use a count remembered from before entering an operator. After typing
cmdarg_T ca;
clear_oparg(&oa);
- vim_memset(&ca, 0, sizeof(ca));
+ CLEAR_FIELD(ca);
ca.oap = &oa;
ca.cmdchar = c1;
ca.nchar = c2;
cap->oap->use_reg_one = TRUE;
curwin->w_set_curswant = TRUE;
- vim_memset(&sia, 0, sizeof(sia));
+ CLEAR_FIELD(sia);
i = do_search(cap->oap, dir, dir, pat, cap->count1,
opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG, &sia);
if (wrapped != NULL)
void
clear_oparg(oparg_T *oap)
{
- vim_memset(oap, 0, sizeof(oparg_T));
+ CLEAR_POINTER(oap);
}
/*
}
/*
- * allow '=' and ':' for hystorical reasons (MSDOS command.com
+ * allow '=' and ':' for historical reasons (MSDOS command.com
* allows only one '=' character per "set" command line. grrr. (jw)
*/
if (nextchar == '?'
if (should_copy || (flags & BCO_ALWAYS))
{
#ifdef FEAT_EVAL
- vim_memset(buf->b_p_script_ctx, 0, sizeof(buf->b_p_script_ctx));
+ CLEAR_FIELD(buf->b_p_script_ctx);
init_buf_opt_idx();
#endif
// Don't copy the options specific to a help buffer when
int i;
bUserAbort = &(psettings->user_abort);
- vim_memset(&prt_dlg, 0, sizeof(PRINTDLGW));
+ CLEAR_FIELD(prt_dlg);
prt_dlg.lStructSize = sizeof(PRINTDLGW);
# if !defined(FEAT_GUI) || defined(VIMDLL)
# ifdef VIMDLL
/*
* Initialise the font according to 'printfont'
*/
- vim_memset(&fLogFont, 0, sizeof(fLogFont));
+ CLEAR_FIELD(fLogFont);
if (get_logfont(&fLogFont, p_pfn, prt_dlg.hDC, TRUE) == FAIL)
{
semsg(_("E613: Unknown printer font: %s"), p_pfn);
{
DOCINFOW di;
- vim_memset(&di, 0, sizeof(di));
+ CLEAR_FIELD(di);
di.cbSize = sizeof(di);
di.lpszDocName = wp;
ret = StartDocW(prt_dlg.hDC, &di);
# if defined(FEAT_GUI_MSWIN)
CHOOSEFONTW cf;
// if name is "*", bring up std font dialog:
- vim_memset(&cf, 0, sizeof(cf));
+ CLEAR_FIELD(cf);
cf.lStructSize = sizeof(cf);
cf.hwndOwner = s_hwnd;
cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_INITTOLOGFONTSTRUCT;
if (pker->UChar != 0)
return 1;
- vim_memset(abKeystate, 0, sizeof (abKeystate));
+ CLEAR_FIELD(abKeystate);
// Clear any pending dead keys
ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0);
FOR_ALL_CHILD_MENUS(menu, mp)
if ((mp->modes & mp->enabled & mode) && idx++ == pum_selected)
{
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
execute_menu(&ea, mp, -1);
break;
}
// Do not used the cached buffer, it may have been wiped out.
VIM_CLEAR(qf_last_bufname);
- vim_memset(&state, 0, sizeof(state));
- vim_memset(&fields, 0, sizeof(fields));
+ CLEAR_FIELD(state);
+ CLEAR_FIELD(fields);
if ((qf_alloc_fields(&fields) == FAIL) ||
(qf_setup_state(&state, enc, efile, tv, buf,
lnumfirst, lnumlast) == FAIL))
else
qi->qf_curlist = qi->qf_listcount++;
qfl = qf_get_curlist(qi);
- vim_memset(qfl, 0, (size_t)(sizeof(qf_list_T)));
+ CLEAR_POINTER(qfl);
qf_store_title(qfl, qf_title);
qfl->qfl_type = qi->qfl_type;
qfl->qf_id = ++last_qf_id;
{
exarg_T ea;
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ea.arg = target_dir;
ea.cmdidx = CMD_lcd;
ex_cd(&ea);
// appropriate ex command and executing it.
exarg_T ea;
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ea.arg = dirname_start;
ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd;
ex_cd(&ea);
argv[0].v_type = VAR_LIST;
argv[0].vval.v_list = &matchList.sl_list;
matchList.sl_list.lv_len = 0;
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.argv_func = fill_submatch_list;
funcexe.evaluate = TRUE;
if (expr->v_type == VAR_FUNC)
num_complex_braces = 0;
regnpar = 1;
- vim_memset(had_endbrace, 0, sizeof(had_endbrace));
+ CLEAR_FIELD(had_endbrace);
#ifdef FEAT_SYN_HL
regnzpar = 1;
re_has_z = 0;
// avoid compiler warnings
save_ptr = NULL;
- vim_memset(&save_multipos, 0, sizeof(save_multipos));
+ CLEAR_FIELD(save_multipos);
// Set the position (with "off" added) in the subexpression. Save
// and restore it when it was in use. Otherwise fill any gap.
save_ptr = sub->list.line[subidx].end;
sub->list.line[subidx].end = rex.input + off;
// avoid compiler warnings
- vim_memset(&save_multipos, 0, sizeof(save_multipos));
+ CLEAR_FIELD(save_multipos);
}
subs = addstate(l, state->out, subs, pim, off_arg);
if (len)
memcpy(lastc_bytes, s, len);
else
- vim_memset(lastc_bytes, 0, sizeof(lastc_bytes));
+ CLEAR_FIELD(lastc_bytes);
}
#endif
sign_T *sp;
buf_T *buf = wp->w_buffer;
- vim_memset(sattr, 0, sizeof(sign_attrs_T));
+ CLEAR_POINTER(sattr);
FOR_ALL_SIGNS_IN_BUF(buf, sign)
{
if (wp->w_s->b_langp.ga_len == 0)
return 1;
- vim_memset(&mi, 0, sizeof(matchinf_T));
+ CLEAR_FIELD(mi);
// A number is always OK. Also skip hexadecimal numbers 0xFF99 and
// 0X99FF. But always do check spelling to find "3GPP" and "11
static void
clear_midword(win_T *wp)
{
- vim_memset(wp->w_s->b_spell_ismw, 0, 256);
+ CLEAR_FIELD(wp->w_s->b_spell_ismw);
VIM_CLEAR(wp->w_s->b_spell_ismw_mb);
}
{
int i;
- // Init everything to FALSE.
- vim_memset(sp->st_isw, FALSE, sizeof(sp->st_isw));
- vim_memset(sp->st_isu, FALSE, sizeof(sp->st_isu));
+ // Init everything to FALSE (zero).
+ CLEAR_FIELD(sp->st_isw);
+ CLEAR_FIELD(sp->st_isu);
for (i = 0; i < 256; ++i)
{
sp->st_fold[i] = i;
{
n = spin->si_first_free;
spin->si_first_free = n->wn_child;
- vim_memset(n, 0, sizeof(wordnode_T));
+ CLEAR_POINTER(n);
--spin->si_free_count;
}
#ifdef SPELL_PRINTTREE
int error = FALSE;
spellinfo_T spin;
- vim_memset(&spin, 0, sizeof(spin));
+ CLEAR_FIELD(spin);
spin.si_verbose = !added_word;
spin.si_ascii = ascii;
spin.si_followup = TRUE;
langp_T *lp;
// Set the info in "*su".
- vim_memset(su, 0, sizeof(suginfo_T));
+ CLEAR_POINTER(su);
ga_init2(&su->su_ga, (int)sizeof(suggest_T), 10);
ga_init2(&su->su_sga, (int)sizeof(suggest_T), 10);
if (*badptr == NUL)
// word).
depth = 0;
sp = &stack[0];
- vim_memset(sp, 0, sizeof(trystate_T));
+ CLEAR_POINTER(sp);
sp->ts_curi = 1;
if (soundfold)
{
if (ga_grow(¤t_state, 1) == FAIL)
return FAIL;
- vim_memset(&CUR_STATE(current_state.ga_len), 0, sizeof(stateitem_T));
+ CLEAR_POINTER(&CUR_STATE(current_state.ga_len));
CUR_STATE(current_state.ga_len).si_idx = idx;
++current_state.ga_len;
return OK;
// get the pattern.
init_syn_patterns();
- vim_memset(&item, 0, sizeof(item));
+ CLEAR_FIELD(item);
rest = get_syn_pattern(rest, &item);
if (vim_regcomp_had_eol() && !(syn_opt_arg.flags & HL_EXCLUDENL))
syn_opt_arg.flags |= HL_HAS_EOL;
return 0;
}
- vim_memset(&(SYN_CLSTR(curwin->w_s)[len]), 0, sizeof(syn_cluster_T));
+ CLEAR_POINTER(&(SYN_CLSTR(curwin->w_s)[len]));
SYN_CLSTR(curwin->w_s)[len].scl_name = name;
SYN_CLSTR(curwin->w_s)[len].scl_name_u = vim_strsave_up(name);
SYN_CLSTR(curwin->w_s)[len].scl_list = NULL;
#ifdef FEAT_TAG_BINS
// This is only to avoid a compiler warning for using search_info
// uninitialised.
- vim_memset(&search_info, 0, (size_t)1);
+ CLEAR_FIELD(search_info);
#endif
#ifdef FEAT_EVAL
#endif
)
{
- vim_memset(&tagp, 0, sizeof(tagp));
+ CLEAR_FIELD(tagp);
tagp.tagname = lbuf;
tagp.tagname_end = vim_strchr(lbuf, TAB);
if (tagp.tagname_end == NULL)
int i;
if (first)
- vim_memset(tnp, 0, sizeof(tagname_T));
+ CLEAR_POINTER(tnp);
if (curbuf->b_help)
{
ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300);
ga_init2(&term->tl_scrollback_postponed, sizeof(sb_line_T), 300);
- vim_memset(&split_ea, 0, sizeof(split_ea));
+ CLEAR_FIELD(split_ea);
if (opt->jo_curwin)
{
// Create a new buffer in the current window.
if (vterm_screen_get_cell(screen, pos, &cell) == 0)
{
width = 1;
- vim_memset(p + pos.col, 0, sizeof(cellattr_T));
+ CLEAR_POINTER(p + pos.col);
if (ga_grow(&ga, 1) == OK)
ga.ga_len += utf_char2bytes(' ',
(char_u *)ga.ga_data + ga.ga_len);
int id;
guicolor_T term_fg, term_bg;
- vim_memset(&entry, 0, sizeof(entry));
+ CLEAR_FIELD(entry);
entry.shape = entry.mshape =
term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR :
term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER :
static void
hl2vtermAttr(int attr, cellattr_T *cell)
{
- vim_memset(&cell->attrs, 0, sizeof(VTermScreenCellAttrs));
+ CLEAR_FIELD(cell->attrs);
if (attr & HL_BOLD)
cell->attrs.bold = 1;
if (attr & HL_UNDERLINE)
VTermScreenCellAttrs attr;
int clear_attr;
- vim_memset(&attr, 0, sizeof(attr));
+ CLEAR_FIELD(attr);
while (for_all_windows_and_curwin(&wp, &did_curwin))
{
{
exarg_T ea;
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ex_quit(&ea);
return TRUE;
}
int c;
if (vterm_screen_get_cell(screen, *pos, &cell) == 0)
- vim_memset(&cell, 0, sizeof(cell));
+ CLEAR_FIELD(cell);
c = cell.chars[0];
if (c == NUL)
int fgval, bgval;
int id;
- vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs));
+ CLEAR_FIELD(term->tl_default_color.attrs);
term->tl_default_color.width = 1;
fg = &term->tl_default_color.fg;
bg = &term->tl_default_color.bg;
}
}
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
if (opt_item != NULL && opt_item->li_tv.v_type == VAR_DICT
&& opt_item->li_tv.vval.v_dict != NULL)
argvars[0].v_type = VAR_NUMBER;
argvars[0].vval.v_number = term->tl_buffer->b_fnum;
argvars[1] = item->li_next->li_tv;
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.firstline = 1L;
funcexe.lastline = 1L;
funcexe.evaluate = TRUE;
return;
}
- vim_memset(&prev_cell, 0, sizeof(prev_cell));
+ CLEAR_FIELD(prev_cell);
screen = vterm_obtain_screen(term->tl_vterm);
state = vterm_obtain_state(term->tl_vterm);
&& pos.row == cursor_pos.row);
if (vterm_screen_get_cell(screen, pos, &cell) == 0)
- vim_memset(&cell, 0, sizeof(cell));
+ CLEAR_FIELD(cell);
for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i)
{
ga_init2(&ga_text, 1, 90);
ga_init2(&ga_cell, sizeof(cellattr_T), 90);
- vim_memset(&cell, 0, sizeof(cell));
- vim_memset(&empty_cell, 0, sizeof(empty_cell));
+ CLEAR_FIELD(cell);
+ CLEAR_FIELD(empty_cell);
cursor_pos->row = -1;
cursor_pos->col = -1;
vimconv_T conv;
char_u *enc;
- vim_memset(&tmval, NUL, sizeof(tmval));
+ CLEAR_FIELD(tmval);
fmt = tv_get_string(&argvars[0]);
str = tv_get_string(&argvars[1]);
uep = U_ALLOC_LINE(sizeof(u_entry_T));
if (uep == NULL)
goto nomem;
- vim_memset(uep, 0, sizeof(u_entry_T));
+ CLEAR_POINTER(uep);
#ifdef U_DEBUG
uep->ue_magic = UE_MAGIC;
#endif
uhp = U_ALLOC_LINE(sizeof(u_header_T));
if (uhp == NULL)
return NULL;
- vim_memset(uhp, 0, sizeof(u_header_T));
+ CLEAR_POINTER(uhp);
#ifdef U_DEBUG
uhp->uh_magic = UH_MAGIC;
#endif
uep = U_ALLOC_LINE(sizeof(u_entry_T));
if (uep == NULL)
return NULL;
- vim_memset(uep, 0, sizeof(u_entry_T));
+ CLEAR_POINTER(uep);
#ifdef U_DEBUG
uep->ue_magic = UE_MAGIC;
#endif
#endif
bufinfo_T bi;
- vim_memset(&bi, 0, sizeof(bi));
+ CLEAR_FIELD(bi);
if (name == NULL)
{
#endif
bufinfo_T bi;
- vim_memset(&bi, 0, sizeof(bi));
+ CLEAR_FIELD(bi);
line_ptr.ul_len = 0;
line_ptr.ul_line = NULL;
v->di_tv.v_lock = VAR_FIXED;
v->di_tv.vval.v_list = &fc->l_varlist;
}
- vim_memset(&fc->l_varlist, 0, sizeof(list_T));
+ CLEAR_FIELD(fc->l_varlist);
fc->l_varlist.lv_refcount = DO_NOT_FREE_CNT;
fc->l_varlist.lv_lock = VAR_FIXED;
{
funcexe_T funcexe;
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.firstline = curwin->w_cursor.lnum;
funcexe.lastline = curwin->w_cursor.lnum;
funcexe.evaluate = TRUE;
funcexe_T funcexe;
int ret;
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.evaluate = TRUE;
funcexe.partial = callback->cb_partial;
++callback_depth;
int vim9script;
if (fdp != NULL)
- vim_memset(fdp, 0, sizeof(funcdict_T));
+ CLEAR_POINTER(fdp);
start = *pp;
// Check for hard coded <SNR>: already translated function ID (from a user
}
arg = startarg;
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.firstline = eap->line1;
funcexe.lastline = eap->line2;
funcexe.doesrange = &doesrange;
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 559,
/**/
558,
/**/
#define LALLOC_CLEAR_MULT(type, count) (type *)lalloc_clear(sizeof(type) * (count), FALSE)
#define LALLOC_MULT(type, count) (type *)lalloc(sizeof(type) * (count), FALSE)
+#ifdef HAVE_MEMSET
+# define vim_memset(ptr, c, size) memset((ptr), (c), (size))
+#else
+void *vim_memset(void *, int, size_t);
+#endif
+#define CLEAR_FIELD(field) vim_memset(&(field), 0, sizeof(field))
+#define CLEAR_POINTER(ptr) vim_memset((ptr), 0, sizeof(*(ptr)))
+
/*
* defines to avoid typecasts from (char_u *) to (char *) and back
* (vim_strchr() and vim_strrchr() are now in alloc.c)
#define fnamecmp(x, y) vim_fnamecmp((char_u *)(x), (char_u *)(y))
#define fnamencmp(x, y, n) vim_fnamencmp((char_u *)(x), (char_u *)(y), (size_t)(n))
-#ifdef HAVE_MEMSET
-# define vim_memset(ptr, c, size) memset((ptr), (c), (size))
-#else
-void *vim_memset(void *, int, size_t);
-#endif
-
#if defined(UNIX) || defined(FEAT_GUI) || defined(VMS) \
|| defined(FEAT_CLIENTSERVER)
# define USE_INPUT_BUF
if (ga_grow(&def_functions, 1) == FAIL)
return;
dfunc = ((dfunc_T *)def_functions.ga_data) + def_functions.ga_len;
- vim_memset(dfunc, 0, sizeof(dfunc_T));
+ CLEAR_POINTER(dfunc);
dfunc->df_idx = def_functions.ga_len;
ufunc->uf_dfunc_idx = dfunc->df_idx;
dfunc->df_ufunc = ufunc;
}
}
- vim_memset(&cctx, 0, sizeof(cctx));
+ CLEAR_FIELD(cctx);
cctx.ctx_ufunc = ufunc;
cctx.ctx_lnum = -1;
ga_init2(&cctx.ctx_locals, sizeof(lvar_T), 10);
emsg_before = called_emsg;
had_return = FALSE;
- vim_memset(&ea, 0, sizeof(ea));
+ CLEAR_FIELD(ea);
ea.cmdlinep = &line;
ea.cmd = skipwhite(line);
if (call_prepare(argcount, argvars, ectx) == FAIL)
return FAIL;
- vim_memset(&funcexe, 0, sizeof(funcexe));
+ CLEAR_FIELD(funcexe);
funcexe.evaluate = TRUE;
// Call the user function. Result goes in last position on the stack.
// Get pointer to a local variable on the stack. Negative for arguments.
#define STACK_TV_VAR(idx) (((typval_T *)ectx.ec_stack.ga_data) + ectx.ec_frame + STACK_FRAME_SIZE + idx)
- vim_memset(&ectx, 0, sizeof(ectx));
+ CLEAR_FIELD(ectx);
ga_init2(&ectx.ec_stack, sizeof(typval_T), 500);
if (ga_grow(&ectx.ec_stack, 20) == FAIL)
return FAIL;