diff options
Diffstat (limited to 'src')
77 files changed, 381 insertions, 418 deletions
diff --git a/src/autocmd.c b/src/autocmd.c index 152dabde7d..21b9ab3ba5 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -1193,7 +1193,7 @@ do_autocmd_event( return FAIL; } - ap = (AutoPat *)alloc(sizeof(AutoPat)); + ap = ALLOC_ONE(AutoPat); if (ap == NULL) return FAIL; ap->pat = vim_strnsave(pat, patlen); @@ -1242,7 +1242,7 @@ do_autocmd_event( prev_ac = &(ap->cmds); while ((ac = *prev_ac) != NULL) prev_ac = &ac->next; - ac = (AutoCmd *)alloc(sizeof(AutoCmd)); + ac = ALLOC_ONE(AutoCmd); if (ac == NULL) return FAIL; ac->cmd = vim_strsave(cmd); diff --git a/src/blob.c b/src/blob.c index ec305d6660..cbd26b9f00 100644 --- a/src/blob.c +++ b/src/blob.c @@ -22,7 +22,7 @@ blob_T * blob_alloc(void) { - blob_T *blob = (blob_T *)alloc_clear(sizeof(blob_T)); + blob_T *blob = ALLOC_CLEAR_ONE(blob_T); if (blob != NULL) ga_init2(&blob->bv_ga, 1, 100); diff --git a/src/blowfish.c b/src/blowfish.c index ce49957913..65f89327ed 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -645,7 +645,7 @@ crypt_blowfish_init( char_u* seed, int seed_len) { - bf_state_T *bfs = (bf_state_T *)alloc_clear(sizeof(bf_state_T)); + bf_state_T *bfs = ALLOC_CLEAR_ONE(bf_state_T); if (bfs == NULL) return FAIL; diff --git a/src/buffer.c b/src/buffer.c index 6174d80ce2..ea61c5ad03 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1958,7 +1958,7 @@ buflist_new( } if (buf != curbuf || curbuf == NULL) { - buf = (buf_T *)alloc_clear(sizeof(buf_T)); + buf = ALLOC_CLEAR_ONE(buf_T); if (buf == NULL) { vim_free(ffname); @@ -1985,7 +1985,7 @@ buflist_new( } clear_wininfo(buf); - buf->b_wininfo = (wininfo_T *)alloc_clear(sizeof(wininfo_T)); + buf->b_wininfo = ALLOC_CLEAR_ONE(wininfo_T); if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) || buf->b_wininfo == NULL) @@ -2634,7 +2634,7 @@ ExpandBufnames( break; if (round == 1) { - *file = (char_u **)alloc(count * sizeof(char_u *)); + *file = ALLOC_MULT(char_u *, count); if (*file == NULL) { vim_regfree(regmatch.regprog); @@ -2771,7 +2771,7 @@ buflist_setfpos( if (wip == NULL) { /* allocate a new entry */ - wip = (wininfo_T *)alloc_clear(sizeof(wininfo_T)); + wip = ALLOC_CLEAR_ONE(wininfo_T); if (wip == NULL) return; wip->wi_win = win; @@ -3430,7 +3430,7 @@ fileinfo( char *buffer; size_t len; - buffer = (char *)alloc(IOSIZE); + buffer = alloc(IOSIZE); if (buffer == NULL) return; diff --git a/src/change.c b/src/change.c index 0873dd3d89..11f4b0a169 100644 --- a/src/change.c +++ b/src/change.c @@ -286,7 +286,7 @@ f_listener_add(typval_T *argvars, typval_T *rettv) return; } - lnr = (listener_T *)alloc_clear(sizeof(listener_T)); + lnr = ALLOC_CLEAR_ONE(listener_T); if (lnr == NULL) { free_callback(callback, partial); diff --git a/src/channel.c b/src/channel.c index f6fa13b76f..558e36d336 100644 --- a/src/channel.c +++ b/src/channel.c @@ -294,7 +294,7 @@ static int next_ch_id = 0; add_channel(void) { ch_part_T part; - channel_T *channel = (channel_T *)alloc_clear(sizeof(channel_T)); + channel_T *channel = ALLOC_CLEAR_ONE(channel_T); if (channel == NULL) return NULL; @@ -1354,7 +1354,7 @@ channel_set_req_callback( int id) { cbq_T *head = &channel->ch_part[part].ch_cb_head; - cbq_T *item = (cbq_T *)alloc(sizeof(cbq_T)); + cbq_T *item = ALLOC_ONE(cbq_T); if (item != NULL) { @@ -1875,7 +1875,7 @@ channel_save(channel_T *channel, ch_part_T part, char_u *buf, int len, char_u *p; int i; - node = (readq_T *)alloc(sizeof(readq_T)); + node = ALLOC_ONE(readq_T); if (node == NULL) return FAIL; /* out of memory */ /* A NUL is added at the end, because netbeans code expects that. @@ -2024,7 +2024,7 @@ channel_parse_json(channel_T *channel, ch_part_T part) } else { - item = (jsonq_T *)alloc(sizeof(jsonq_T)); + item = ALLOC_ONE(jsonq_T); if (item == NULL) clear_tv(&listtv); else @@ -2223,7 +2223,7 @@ channel_push_json(channel_T *channel, ch_part_T part, typval_T *rettv) /* append after the last item that was pushed back */ item = item->jq_next; - newitem = (jsonq_T *)alloc(sizeof(jsonq_T)); + newitem = ALLOC_ONE(jsonq_T); if (newitem == NULL) clear_tv(rettv); else @@ -3921,7 +3921,7 @@ channel_send( } else { - writeq_T *last = (writeq_T *)alloc(sizeof(writeq_T)); + writeq_T *last = ALLOC_ONE(writeq_T); if (last != NULL) { @@ -5593,7 +5593,7 @@ job_alloc(void) { job_T *job; - job = (job_T *)alloc_clear(sizeof(job_T)); + job = ALLOC_CLEAR_ONE(job_T); if (job != NULL) { job->jv_refcount = 1; @@ -5822,7 +5822,7 @@ job_start( /* Make a copy of argv_arg for job->jv_argv. */ for (i = 0; argv_arg[i] != NULL; i++) argc++; - argv = (char **)alloc(sizeof(char *) * (argc + 1)); + argv = ALLOC_MULT(char *, argc + 1); if (argv == NULL) goto theend; for (i = 0; i < argc; i++) diff --git a/src/crypt.c b/src/crypt.c index 2846d28103..43a7167b39 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -254,7 +254,7 @@ crypt_create( char_u *seed, int seed_len) { - cryptstate_T *state = (cryptstate_T *)alloc(sizeof(cryptstate_T)); + cryptstate_T *state = ALLOC_ONE(cryptstate_T); if (state == NULL) return state; diff --git a/src/crypt_zip.c b/src/crypt_zip.c index 25b7962a3b..ec8c16edf9 100644 --- a/src/crypt_zip.c +++ b/src/crypt_zip.c @@ -90,7 +90,7 @@ crypt_zip_init( char_u *p; zip_state_T *zs; - zs = (zip_state_T *)alloc(sizeof(zip_state_T)); + zs = ALLOC_ONE(zip_state_T); if (zs == NULL) return FAIL; state->method_state = zs; diff --git a/src/dict.c b/src/dict.c index 40c940e3d9..d6b3b189a6 100644 --- a/src/dict.c +++ b/src/dict.c @@ -28,7 +28,7 @@ dict_alloc(void) { dict_T *d; - d = (dict_T *)alloc(sizeof(dict_T)); + d = ALLOC_ONE(dict_T); if (d != NULL) { /* Add the dict to the list of dicts for garbage collection. */ @@ -210,7 +210,7 @@ dictitem_alloc(char_u *key) { dictitem_T *di; - di = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(key)); + di = alloc(sizeof(dictitem_T) + STRLEN(key)); if (di != NULL) { STRCPY(di->di_key, key); @@ -228,7 +228,7 @@ dictitem_copy(dictitem_T *org) { dictitem_T *di; - di = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(org->di_key)); + di = alloc(sizeof(dictitem_T) + STRLEN(org->di_key)); if (di != NULL) { STRCPY(di->di_key, org->di_key); diff --git a/src/diff.c b/src/diff.c index 0db2820f39..260fdd96d9 100644 --- a/src/diff.c +++ b/src/diff.c @@ -537,7 +537,7 @@ diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) { diff_T *dnew; - dnew = (diff_T *)alloc(sizeof(diff_T)); + dnew = ALLOC_ONE(diff_T); if (dnew != NULL) { dnew->df_next = dp; diff --git a/src/eval.c b/src/eval.c index 7fbd7702dd..dc96e050b0 100644 --- a/src/eval.c +++ b/src/eval.c @@ -491,7 +491,7 @@ var_redir_start(char_u *name, int append) if (redir_varname == NULL) return FAIL; - redir_lval = (lval_T *)alloc_clear(sizeof(lval_T)); + redir_lval = ALLOC_CLEAR_ONE(lval_T); if (redir_lval == NULL) { var_redir_stop(); @@ -1063,7 +1063,7 @@ eval_expr(char_u *arg, char_u **nextcmd) { typval_T *tv; - tv = (typval_T *)alloc(sizeof(typval_T)); + tv = ALLOC_ONE(typval_T); if (tv != NULL && eval0(arg, tv, nextcmd, TRUE) == FAIL) VIM_CLEAR(tv); @@ -2769,7 +2769,7 @@ eval_for_line( *errp = TRUE; /* default: there is an error */ - fi = (forinfo_T *)alloc_clear(sizeof(forinfo_T)); + fi = ALLOC_CLEAR_ONE(forinfo_T); if (fi == NULL) return NULL; @@ -7297,7 +7297,7 @@ handle_subscript( typval_T * alloc_tv(void) { - return (typval_T *)alloc_clear(sizeof(typval_T)); + return ALLOC_CLEAR_ONE(typval_T); } /* @@ -7883,7 +7883,7 @@ 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)); + ALLOC_CLEAR_ONE(scriptvar_T); init_var_dict(&sv->sv_dict, &sv->sv_var, VAR_SCOPE); ++ga_scripts.ga_len; } @@ -8139,7 +8139,7 @@ set_var( if (!valid_varname(varname)) return; - v = (dictitem_T *)alloc(sizeof(dictitem_T) + STRLEN(varname)); + v = alloc(sizeof(dictitem_T) + STRLEN(varname)); if (v == NULL) return; STRCPY(v->di_key, varname); diff --git a/src/evalfunc.c b/src/evalfunc.c index 03e3260244..ccced484ee 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -4465,7 +4465,7 @@ common_function(typval_T *argvars, typval_T *rettv, int is_funcref) } if (dict_idx > 0 || arg_idx > 0 || arg_pt != NULL || is_funcref) { - partial_T *pt = (partial_T *)alloc_clear(sizeof(partial_T)); + partial_T *pt = ALLOC_CLEAR_ONE(partial_T); /* result is a VAR_PARTIAL */ if (pt == NULL) @@ -4484,8 +4484,7 @@ common_function(typval_T *argvars, typval_T *rettv, int is_funcref) if (list != NULL) lv_len = list->lv_len; pt->pt_argc = arg_len + lv_len; - pt->pt_argv = (typval_T *)alloc( - sizeof(typval_T) * pt->pt_argc); + pt->pt_argv = ALLOC_MULT(typval_T, pt->pt_argc); if (pt->pt_argv == NULL) { vim_free(pt); @@ -9615,8 +9614,7 @@ f_readfile(typval_T *argvars, typval_T *rettv) long growmin = (long)((p - start) * 2 + prevlen); prevsize = grow50pc > growmin ? grow50pc : growmin; } - newprev = prev == NULL ? alloc(prevsize) - : vim_realloc(prev, prevsize); + newprev = vim_realloc(prev, prevsize); if (newprev == NULL) { do_outofmem_msg((long_u)prevsize); @@ -11788,7 +11786,7 @@ f_setreg(typval_T *argvars, typval_T *rettv) /* First half: use for pointers to result lines; second half: use for * pointers to allocated copies. */ - lstval = (char_u **)alloc(sizeof(char_u *) * ((len + 1) * 2)); + lstval = ALLOC_MULT(char_u *, (len + 1) * 2); if (lstval == NULL) return; curval = lstval; @@ -12674,7 +12672,7 @@ do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort) } /* Make an array with each entry pointing to an item in the List. */ - ptrs = (sortItem_T *)alloc(len * sizeof(sortItem_T)); + ptrs = ALLOC_MULT(sortItem_T, len); if (ptrs == NULL) goto theend; diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 02750647e1..d7a4187b86 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -397,7 +397,7 @@ ex_sort(exarg_T *eap) sortbuf1 = NULL; sortbuf2 = NULL; regmatch.regprog = NULL; - nrs = (sorti_T *)alloc(count * sizeof(sorti_T)); + nrs = ALLOC_MULT(sorti_T, count); if (nrs == NULL) goto sortend; diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index a0c71694dd..f6d9f331fa 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -293,7 +293,7 @@ free_timer(timer_T *timer) timer_T * create_timer(long msec, int repeat) { - timer_T *timer = (timer_T *)alloc_clear(sizeof(timer_T)); + timer_T *timer = ALLOC_CLEAR_ONE(timer_T); long prev_id = last_timer_id; if (timer == NULL) @@ -444,7 +444,7 @@ check_due_timer(void) bevalexpr_due_set = FALSE; if (balloonEval == NULL) { - balloonEval = (BalloonEval *)alloc_clear(sizeof(BalloonEval)); + balloonEval = ALLOC_CLEAR_ONE(BalloonEval); balloonEvalForTerm = TRUE; } if (balloonEval != NULL) @@ -1312,7 +1312,7 @@ check_changed_any( if (bufcount == 0) return FALSE; - bufnrs = (int *)alloc(sizeof(int) * bufcount); + bufnrs = ALLOC_MULT(int, bufcount); if (bufnrs == NULL) return FALSE; @@ -1783,7 +1783,7 @@ ex_args(exarg_T *eap) */ if (ARGCOUNT > 0) { - char_u **items = (char_u **)alloc(sizeof(char_u *) * ARGCOUNT); + char_u **items = ALLOC_MULT(char_u *, ARGCOUNT); if (items != NULL) { @@ -2994,7 +2994,7 @@ ex_packadd(exarg_T *eap) continue; len = (int)STRLEN(plugpat) + (int)STRLEN(eap->arg) + 5; - pat = (char *)alloc(len); + pat = alloc(len); if (pat == NULL) return; vim_snprintf(pat, len, plugpat, round == 1 ? "start" : "opt", eap->arg); diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 2b16a1e0aa..82f94629be 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -6550,7 +6550,7 @@ alist_unlink(alist_T *al) void alist_new(void) { - curwin->w_alist = (alist_T *)alloc(sizeof(alist_T)); + curwin->w_alist = ALLOC_ONE(alist_T); if (curwin->w_alist == NULL) { curwin->w_alist = &global_alist; @@ -6584,7 +6584,7 @@ alist_expand(int *fnum_list, int fnum_len) * expansion. Also, the vimrc file isn't read yet, thus the user * can't set the options. */ p_su = empty_option; - old_arg_files = (char_u **)alloc(sizeof(char_u *) * GARGCOUNT); + old_arg_files = ALLOC_MULT(char_u *, GARGCOUNT); if (old_arg_files != NULL) { for (i = 0; i < GARGCOUNT; ++i) diff --git a/src/ex_eval.c b/src/ex_eval.c index b1bb7e5ddb..55009e5e43 100644 --- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -251,7 +251,7 @@ cause_errthrow( while (*plist != NULL) plist = &(*plist)->next; - elem = (struct msglist *)alloc(sizeof(struct msglist)); + elem = ALLOC_ONE(struct msglist); if (elem == NULL) { suppress_errthrow = TRUE; @@ -519,7 +519,7 @@ throw_exception(void *value, except_type_T type, char_u *cmdname) } } - excp = (except_T *)alloc(sizeof(except_T)); + excp = ALLOC_ONE(except_T); if (excp == NULL) goto nomem; @@ -1441,7 +1441,7 @@ ex_try(exarg_T *eap) { eslist_T *elem; - elem = (eslist_T *)alloc(sizeof(struct eslist_elem)); + elem = ALLOC_ONE(struct eslist_elem); if (elem == NULL) emsg(_(e_outofmem)); else diff --git a/src/ex_getln.c b/src/ex_getln.c index 80f1855ad3..c6d22e5fc6 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -5294,7 +5294,7 @@ ExpandGeneric( if (count == 0) return OK; *num_file = count; - *file = (char_u **)alloc(count * sizeof(char_u *)); + *file = ALLOC_MULT(char_u *, count); if (*file == NULL) { *file = (char_u **)""; @@ -5914,7 +5914,7 @@ init_history(void) { if (newlen) { - temp = (histentry_T *)alloc(newlen * sizeof(histentry_T)); + temp = ALLOC_MULT(histentry_T, newlen); if (temp == NULL) /* out of memory! */ { if (type == 0) /* first one: just keep the old length */ @@ -6653,8 +6653,7 @@ prepare_viminfo_history(int asklen, int writing) if (len <= 0) viminfo_history[type] = NULL; else - viminfo_history[type] = (histentry_T *)lalloc( - len * sizeof(histentry_T), FALSE); + viminfo_history[type] = LALLOC_MULT(histentry_T, len); if (viminfo_history[type] == NULL) len = 0; viminfo_hislen[type] = len; @@ -6873,8 +6872,8 @@ merge_history(int type) /* Make one long list with all entries. */ max_len = hislen + viminfo_hisidx[type]; - tot_hist = (histentry_T **)alloc(max_len * (int)sizeof(histentry_T *)); - new_hist = (histentry_T *)alloc(hislen * (int)sizeof(histentry_T)); + tot_hist = ALLOC_MULT(histentry_T *, max_len); + new_hist = ALLOC_MULT(histentry_T, hislen ); if (tot_hist == NULL || new_hist == NULL) { vim_free(tot_hist); diff --git a/src/fileio.c b/src/fileio.c index ee8c14d352..d746298a7c 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -6533,7 +6533,7 @@ vim_rename(char_u *from, char_u *to) return -1; } - buffer = (char *)alloc(BUFSIZE); + buffer = alloc(BUFSIZE); if (buffer == NULL) { |