mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Remove alloc_clear
Use `xcalloc` instead. Inline `alloc_tv` and `alloc_string_tv` in eval.c
This commit is contained in:
parent
c70a526a5d
commit
4e1b364a3e
13
src/buffer.c
13
src/buffer.c
@ -1378,14 +1378,9 @@ buflist_new (
|
||||
}
|
||||
}
|
||||
if (buf != curbuf || curbuf == NULL) {
|
||||
buf = (buf_T *)alloc_clear((unsigned)sizeof(buf_T));
|
||||
buf = xcalloc(1, sizeof(buf_T));
|
||||
/* init b: variables */
|
||||
buf->b_vars = dict_alloc();
|
||||
if (buf->b_vars == NULL) {
|
||||
vim_free(ffname);
|
||||
vim_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
init_var_dict(buf->b_vars, &buf->b_bufvar, VAR_SCOPE);
|
||||
}
|
||||
|
||||
@ -1395,7 +1390,7 @@ buflist_new (
|
||||
}
|
||||
|
||||
clear_wininfo(buf);
|
||||
buf->b_wininfo = (wininfo_T *)alloc_clear((unsigned)sizeof(wininfo_T));
|
||||
buf->b_wininfo = xcalloc(1, sizeof(wininfo_T));
|
||||
|
||||
if (ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) {
|
||||
vim_free(buf->b_ffname);
|
||||
@ -2004,7 +1999,7 @@ static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col,
|
||||
break;
|
||||
if (wip == NULL) {
|
||||
/* allocate a new entry */
|
||||
wip = (wininfo_T *)alloc_clear((unsigned)sizeof(wininfo_T));
|
||||
wip = xcalloc(1, sizeof(wininfo_T));
|
||||
wip->wi_win = win;
|
||||
if (lnum == 0) /* set lnum even when it's 0 */
|
||||
lnum = 1;
|
||||
@ -3699,7 +3694,7 @@ do_arg_all (
|
||||
setpcmark();
|
||||
|
||||
opened_len = ARGCOUNT;
|
||||
opened = alloc_clear((unsigned)opened_len);
|
||||
opened = xcalloc(opened_len, 1);
|
||||
|
||||
/* Autocommands may do anything to the argument list. Make sure it's not
|
||||
* freed while we are working here by "locking" it. We still have to
|
||||
|
@ -2125,7 +2125,7 @@ ins_compl_add (
|
||||
* Allocate a new match structure.
|
||||
* Copy the values to the new match structure.
|
||||
*/
|
||||
match = (compl_T *)alloc_clear((unsigned)sizeof(compl_T));
|
||||
match = xcalloc(1, sizeof(compl_T));
|
||||
match->cp_number = -1;
|
||||
if (flags & ORIGINAL_TEXT)
|
||||
match->cp_number = 0;
|
||||
@ -2460,9 +2460,9 @@ void ins_compl_show_pum(void)
|
||||
} while (compl != NULL && compl != compl_first_match);
|
||||
if (compl_match_arraysize == 0)
|
||||
return;
|
||||
compl_match_array = (pumitem_T *)alloc_clear(
|
||||
(unsigned)(sizeof(pumitem_T)
|
||||
* compl_match_arraysize));
|
||||
|
||||
assert(compl_match_arraysize >= 0);
|
||||
compl_match_array = xcalloc(compl_match_arraysize, sizeof(pumitem_T));
|
||||
/* If the current match is the original text don't find the first
|
||||
* match after it, don't highlight anything. */
|
||||
if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
|
||||
|
106
src/eval.c
106
src/eval.c
@ -799,8 +799,6 @@ static int get_var_tv(char_u *name, int len, typval_T *rettv,
|
||||
int no_autoload);
|
||||
static int handle_subscript(char_u **arg, typval_T *rettv, int evaluate,
|
||||
int verbose);
|
||||
static typval_T *alloc_tv(void);
|
||||
static typval_T *alloc_string_tv(char_u *string);
|
||||
static void init_tv(typval_T *varp);
|
||||
static long get_tv_number(typval_T *varp);
|
||||
static linenr_T get_tv_lnum(typval_T *argvars);
|
||||
@ -1005,17 +1003,13 @@ int current_func_returned(void)
|
||||
*/
|
||||
void set_internal_string_var(char_u *name, char_u *value)
|
||||
{
|
||||
char_u *val;
|
||||
typval_T *tvp;
|
||||
char_u *val = vim_strsave(value);
|
||||
typval_T *tvp = xcalloc(1, sizeof(typval_T));
|
||||
|
||||
val = vim_strsave(value);
|
||||
if (val != NULL) {
|
||||
tvp = alloc_string_tv(val);
|
||||
if (tvp != NULL) {
|
||||
set_var(name, tvp, FALSE);
|
||||
free_tv(tvp);
|
||||
}
|
||||
}
|
||||
tvp->v_type = VAR_STRING;
|
||||
tvp->vval.v_string = val;
|
||||
set_var(name, tvp, FALSE);
|
||||
free_tv(tvp);
|
||||
}
|
||||
|
||||
static lval_T *redir_lval = NULL;
|
||||
@ -1048,11 +1042,7 @@ var_redir_start (
|
||||
if (redir_varname == NULL)
|
||||
return FAIL;
|
||||
|
||||
redir_lval = (lval_T *)alloc_clear((unsigned)sizeof(lval_T));
|
||||
if (redir_lval == NULL) {
|
||||
var_redir_stop();
|
||||
return FAIL;
|
||||
}
|
||||
redir_lval = xcalloc(1, sizeof(lval_T));
|
||||
|
||||
/* The output is stored in growarray "redir_ga" until redirection ends. */
|
||||
ga_init(&redir_ga, (int)sizeof(char), 500);
|
||||
@ -2871,17 +2861,13 @@ static void list_fix_watch(list_T *l, listitem_T *item)
|
||||
*/
|
||||
void *eval_for_line(char_u *arg, int *errp, char_u **nextcmdp, int skip)
|
||||
{
|
||||
forinfo_T *fi;
|
||||
forinfo_T *fi = xcalloc(1, sizeof(forinfo_T));
|
||||
char_u *expr;
|
||||
typval_T tv;
|
||||
list_T *l;
|
||||
|
||||
*errp = TRUE; /* default: there is an error */
|
||||
|
||||
fi = (forinfo_T *)alloc_clear(sizeof(forinfo_T));
|
||||
if (fi == NULL)
|
||||
return NULL;
|
||||
|
||||
expr = skip_var_list(arg, &fi->fi_varcount, &fi->fi_semicolon);
|
||||
if (expr == NULL)
|
||||
return fi;
|
||||
@ -5143,18 +5129,15 @@ failret:
|
||||
*/
|
||||
list_T *list_alloc(void)
|
||||
{
|
||||
list_T *l;
|
||||
list_T *list = xcalloc(1, sizeof(list_T));
|
||||
|
||||
l = (list_T *)alloc_clear(sizeof(list_T));
|
||||
if (l != NULL) {
|
||||
/* Prepend the list to the list of lists for garbage collection. */
|
||||
if (first_list != NULL)
|
||||
first_list->lv_used_prev = l;
|
||||
l->lv_used_prev = NULL;
|
||||
l->lv_used_next = first_list;
|
||||
first_list = l;
|
||||
}
|
||||
return l;
|
||||
/* Prepend the list to the list of lists for garbage collection. */
|
||||
if (first_list != NULL)
|
||||
first_list->lv_used_prev = list;
|
||||
list->lv_used_prev = NULL;
|
||||
list->lv_used_next = first_list;
|
||||
first_list = list;
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -16202,33 +16185,6 @@ handle_subscript (
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate memory for a variable type-value, and make it empty (0 or NULL
|
||||
* value).
|
||||
*/
|
||||
static typval_T *alloc_tv(void)
|
||||
{
|
||||
return (typval_T *)alloc_clear((unsigned)sizeof(typval_T));
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate memory for a variable type-value, and assign a string to it.
|
||||
* The string "s" must have been allocated, it is consumed.
|
||||
* Return NULL for out of memory, the variable otherwise.
|
||||
*/
|
||||
static typval_T *alloc_string_tv(char_u *s)
|
||||
{
|
||||
typval_T *rettv;
|
||||
|
||||
rettv = alloc_tv();
|
||||
if (rettv != NULL) {
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = s;
|
||||
} else
|
||||
vim_free(s);
|
||||
return rettv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the memory for a variable type-value.
|
||||
*/
|
||||
@ -16603,8 +16559,7 @@ void new_script_vars(scid_T id)
|
||||
}
|
||||
|
||||
while (ga_scripts.ga_len < id) {
|
||||
sv = SCRIPT_SV(ga_scripts.ga_len + 1) =
|
||||
(scriptvar_T *)alloc_clear(sizeof(scriptvar_T));
|
||||
sv = SCRIPT_SV(ga_scripts.ga_len + 1) = xcalloc(1, sizeof(scriptvar_T));
|
||||
init_var_dict(&sv->sv_dict, &sv->sv_var, VAR_SCOPE);
|
||||
++ga_scripts.ga_len;
|
||||
}
|
||||
@ -18195,14 +18150,19 @@ static void func_do_profile(ufunc_T *fp)
|
||||
fp->uf_tm_count = 0;
|
||||
profile_zero(&fp->uf_tm_self);
|
||||
profile_zero(&fp->uf_tm_total);
|
||||
if (fp->uf_tml_count == NULL)
|
||||
fp->uf_tml_count = (int *)alloc_clear((unsigned) (sizeof(int) * len));
|
||||
if (fp->uf_tml_total == NULL)
|
||||
fp->uf_tml_total = (proftime_T *)alloc_clear((unsigned)
|
||||
(sizeof(proftime_T) * len));
|
||||
if (fp->uf_tml_self == NULL)
|
||||
fp->uf_tml_self = (proftime_T *)alloc_clear((unsigned)
|
||||
(sizeof(proftime_T) * len));
|
||||
|
||||
if (fp->uf_tml_count == NULL) {
|
||||
fp->uf_tml_count = xcalloc(len, sizeof(int));
|
||||
}
|
||||
|
||||
if (fp->uf_tml_total == NULL) {
|
||||
fp->uf_tml_total = xcalloc(len, sizeof(proftime_T));
|
||||
}
|
||||
|
||||
if (fp->uf_tml_self == NULL) {
|
||||
fp->uf_tml_self = xcalloc(len, sizeof(proftime_T));
|
||||
}
|
||||
|
||||
fp->uf_tml_idx = -1;
|
||||
if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL
|
||||
|| fp->uf_tml_self == NULL)
|
||||
@ -19048,10 +19008,8 @@ int do_return(exarg_T *eap, int reanimate, int is_cmd, void *rettv)
|
||||
|
||||
if (rettv != NULL) {
|
||||
/* Store the value of the pending return. */
|
||||
if ((cstack->cs_rettv[idx] = alloc_tv()) != NULL)
|
||||
*(typval_T *)cstack->cs_rettv[idx] = *(typval_T *)rettv;
|
||||
else
|
||||
EMSG(_(e_outofmem));
|
||||
cstack->cs_rettv[idx] = xcalloc(1, sizeof(typval_T));
|
||||
*(typval_T *)cstack->cs_rettv[idx] = *(typval_T *)rettv;
|
||||
} else
|
||||
cstack->cs_rettv[idx] = NULL;
|
||||
|
||||
|
@ -5829,9 +5829,7 @@ void ex_sign(exarg_T *eap)
|
||||
int start = next_sign_typenr;
|
||||
|
||||
/* Allocate a new sign. */
|
||||
sp = (sign_T *)alloc_clear((unsigned)sizeof(sign_T));
|
||||
if (sp == NULL)
|
||||
return;
|
||||
sp = xcalloc(1, sizeof(sign_T));
|
||||
|
||||
/* Check that next_sign_typenr is not already being used.
|
||||
* This only happens after wrapping around. Hopefully
|
||||
|
@ -2361,14 +2361,13 @@ int prepare_crypt_read(FILE *fp)
|
||||
*/
|
||||
char_u *prepare_crypt_write(buf_T *buf, int *lenp)
|
||||
{
|
||||
char_u *header;
|
||||
char_u *header = xcalloc(1, CRYPT_MAGIC_LEN + CRYPT_SALT_LEN_MAX
|
||||
+ CRYPT_SEED_LEN_MAX + 2);
|
||||
int seed_len = crypt_seed_len[get_crypt_method(buf)];
|
||||
int salt_len = crypt_salt_len[get_crypt_method(buf)];
|
||||
char_u *salt;
|
||||
char_u *seed;
|
||||
|
||||
header = alloc_clear(CRYPT_MAGIC_LEN + CRYPT_SALT_LEN_MAX
|
||||
+ CRYPT_SEED_LEN_MAX + 2);
|
||||
crypt_push_state();
|
||||
use_crypt_method = get_crypt_method(buf); /* select zip or blowfish */
|
||||
vim_strncpy(header, (char_u *)crypt_magic[use_crypt_method],
|
||||
|
@ -1286,7 +1286,7 @@ static int cs_insert_filelist(char *fname, char *ppath, char *flags, struct stat
|
||||
* be enough for most users. If more is needed, csinfo will be
|
||||
* reallocated. */
|
||||
csinfo_size = 1;
|
||||
csinfo = (csinfo_T *)alloc_clear(sizeof(csinfo_T));
|
||||
csinfo = xcalloc(1, sizeof(csinfo_T));
|
||||
} else {
|
||||
/* Reallocate space for more connections. */
|
||||
csinfo_size *= 2;
|
||||
|
@ -53,14 +53,6 @@ char_u *alloc(unsigned size)
|
||||
return lalloc((long_u)size, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate memory and set all bytes to zero.
|
||||
*/
|
||||
char_u *alloc_clear(unsigned size)
|
||||
{
|
||||
return (char_u *)xcalloc(1, (size_t)size);
|
||||
}
|
||||
|
||||
/// Try to free memory. Used when trying to recover from out of memory errors.
|
||||
/// @see {xmalloc}
|
||||
static void try_to_free_memory()
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "vim.h"
|
||||
|
||||
char_u *alloc(unsigned size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1);
|
||||
char_u *alloc_clear(unsigned size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1);
|
||||
|
||||
/// malloc() wrapper
|
||||
///
|
||||
|
@ -373,7 +373,7 @@ add_menu_path (
|
||||
}
|
||||
|
||||
/* Not already there, so lets add it */
|
||||
menu = (vimmenu_T *)alloc_clear((unsigned)sizeof(vimmenu_T));
|
||||
menu = xcalloc(1, sizeof(vimmenu_T));
|
||||
|
||||
menu->modes = modes;
|
||||
menu->enabled = MENU_ALL_MODES;
|
||||
|
@ -754,7 +754,7 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
|
||||
os_dirname(curdir, MAXPATHL);
|
||||
expand_path_option(curdir, &path_ga);
|
||||
|
||||
in_curdir = (char_u **)alloc_clear(gap->ga_len * sizeof(char_u *));
|
||||
in_curdir = xcalloc(gap->ga_len, sizeof(char_u *));
|
||||
|
||||
for (i = 0; i < gap->ga_len && !got_int; i++) {
|
||||
char_u *path = fnames[i];
|
||||
|
@ -326,7 +326,7 @@ qf_init_ext (
|
||||
/*
|
||||
* Allocate a new eformat structure and put it at the end of the list
|
||||
*/
|
||||
fmt_ptr = (efm_T *)alloc_clear((unsigned)sizeof(efm_T));
|
||||
fmt_ptr = xcalloc(1, sizeof(efm_T));
|
||||
if (fmt_first == NULL) /* first one */
|
||||
fmt_first = fmt_ptr;
|
||||
else
|
||||
|
@ -3586,9 +3586,7 @@ static reg_extmatch_T *make_extmatch(void);
|
||||
*/
|
||||
static reg_extmatch_T *make_extmatch(void)
|
||||
{
|
||||
reg_extmatch_T *em;
|
||||
|
||||
em = (reg_extmatch_T *)alloc_clear((unsigned)sizeof(reg_extmatch_T));
|
||||
reg_extmatch_T *em = xcalloc(1, sizeof(reg_extmatch_T));
|
||||
em->refcnt = 1;
|
||||
return em;
|
||||
}
|
||||
|
13
src/spell.c
13
src/spell.c
@ -2853,8 +2853,7 @@ static int read_prefcond_section(FILE *fd, slang_T *lp)
|
||||
if (cnt <= 0)
|
||||
return SP_FORMERROR;
|
||||
|
||||
lp->sl_prefprog = (regprog_T **)alloc_clear(
|
||||
(unsigned)sizeof(regprog_T *) * cnt);
|
||||
lp->sl_prefprog = xcalloc(cnt, sizeof(regprog_T *));
|
||||
lp->sl_prefixcnt = cnt;
|
||||
|
||||
for (i = 0; i < cnt; ++i) {
|
||||
@ -6523,15 +6522,7 @@ getroom (
|
||||
bl = NULL;
|
||||
else
|
||||
/* Allocate a block of memory. It is not freed until much later. */
|
||||
bl = (sblock_T *)alloc_clear(
|
||||
(unsigned)(sizeof(sblock_T) + SBLOCKSIZE));
|
||||
if (bl == NULL) {
|
||||
if (!spin->si_did_emsg) {
|
||||
EMSG(_("E845: Insufficient memory, word list will be incomplete"));
|
||||
spin->si_did_emsg = TRUE;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
bl = xcalloc(1, (sizeof(sblock_T) + SBLOCKSIZE));
|
||||
bl->sb_next = spin->si_blocks;
|
||||
spin->si_blocks = bl;
|
||||
bl->sb_used = 0;
|
||||
|
@ -1123,7 +1123,8 @@ static void syn_stack_alloc(void)
|
||||
len = syn_block->b_sst_len - syn_block->b_sst_freecount + 2;
|
||||
}
|
||||
|
||||
sstp = (synstate_T *)alloc_clear((unsigned)(len * sizeof(synstate_T)));
|
||||
assert(len >= 0);
|
||||
sstp = xcalloc(len, sizeof(synstate_T));
|
||||
|
||||
to = sstp - 1;
|
||||
if (syn_block->b_sst_array != NULL) {
|
||||
@ -4553,7 +4554,7 @@ syn_cmd_region (
|
||||
ppp = (struct pat_ptr *)alloc((unsigned)sizeof(struct pat_ptr));
|
||||
ppp->pp_next = pat_ptrs[item];
|
||||
pat_ptrs[item] = ppp;
|
||||
ppp->pp_synp = (synpat_T *)alloc_clear((unsigned)sizeof(synpat_T));
|
||||
ppp->pp_synp = xcalloc(1, sizeof(synpat_T));
|
||||
|
||||
/*
|
||||
* Get the syntax pattern and the following offset(s).
|
||||
|
@ -1509,8 +1509,9 @@ void u_read_undo(char_u *name, char_u *hash, char_u *orig_name)
|
||||
}
|
||||
|
||||
#ifdef U_DEBUG
|
||||
uhp_table_used = (int *)alloc_clear(
|
||||
(unsigned)(sizeof(int) * num_head + 1));
|
||||
size_t amount = num_head * sizeof(int) + 1;
|
||||
uhp_table_used = xmalloc(amount);
|
||||
memset(uhp_table_used, 0, amount);
|
||||
# define SET_FLAG(j) ++ uhp_table_used[j]
|
||||
#else
|
||||
# define SET_FLAG(j)
|
||||
|
@ -784,7 +784,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
|
||||
}
|
||||
if (curfrp->fr_parent == NULL || curfrp->fr_parent->fr_layout != layout) {
|
||||
/* Need to create a new frame in the tree to make a branch. */
|
||||
frp = (frame_T *)alloc_clear((unsigned)sizeof(frame_T));
|
||||
frp = xcalloc(1, sizeof(frame_T));
|
||||
*frp = *curfrp;
|
||||
curfrp->fr_layout = layout;
|
||||
frp->fr_parent = curfrp;
|
||||
@ -2847,7 +2847,6 @@ static tabpage_T *alloc_tabpage(void)
|
||||
/* init t: variables */
|
||||
tp->tp_vars = dict_alloc();
|
||||
init_var_dict(tp->tp_vars, &tp->tp_winvar, VAR_SCOPE);
|
||||
|
||||
tp->tp_diff_invalid = TRUE;
|
||||
tp->tp_ch_used = p_ch;
|
||||
|
||||
@ -3766,6 +3765,7 @@ static void frame_remove(frame_T *frp)
|
||||
void win_alloc_lines(win_T *wp)
|
||||
{
|
||||
wp->w_lines_valid = 0;
|
||||
assert(Rows >= 0);
|
||||
wp->w_lines = xcalloc(Rows, sizeof(wline_T));
|
||||
}
|
||||
|
||||
@ -5019,7 +5019,7 @@ void make_snapshot(int idx)
|
||||
|
||||
static void make_snapshot_rec(frame_T *fr, frame_T **frp)
|
||||
{
|
||||
*frp = (frame_T *)alloc_clear((unsigned)sizeof(frame_T));
|
||||
*frp = xcalloc(1, sizeof(frame_T));
|
||||
(*frp)->fr_layout = fr->fr_layout;
|
||||
(*frp)->fr_width = fr->fr_width;
|
||||
(*frp)->fr_height = fr->fr_height;
|
||||
|
Loading…
Reference in New Issue
Block a user