No OOM error conditions in some functions of window.c

- alloc_tabpage()
 - win_alloc_lines()
 - win_alloc_aucmd_win()
 - new_frame()
 - win_alloc()

TODO: don't handle OOM after calls to dict_alloc()
This commit is contained in:
Felipe Oliveira Carvalho 2014-04-19 16:59:49 -03:00 committed by Thiago de Arruda
parent 6d193b0b37
commit 28b03dd190
4 changed files with 30 additions and 70 deletions

View File

@ -6105,10 +6105,8 @@ void set_ref_in_item(typval_T *tv, int copyID)
*/
dict_T *dict_alloc(void)
{
dict_T *d;
dict_T *d = xmalloc(sizeof(dict_T));
d = (dict_T *)alloc(sizeof(dict_T));
if (d != NULL) {
/* Add the dict to the list of dicts for garbage collection. */
if (first_dict != NULL)
first_dict->dv_used_prev = d;
@ -6121,7 +6119,7 @@ dict_T *dict_alloc(void)
d->dv_scope = 0;
d->dv_refcount = 0;
d->dv_copyID = 0;
}
return d;
}

View File

@ -6279,15 +6279,11 @@ retry:
FOR_ALL_TAB_WINDOWS(tp, wp)
{
if (win_alloc_lines(wp) == FAIL) {
outofmem = TRUE;
goto give_up;
win_alloc_lines(wp);
}
if (aucmd_win != NULL && aucmd_win->w_lines == NULL) {
win_alloc_lines(aucmd_win);
}
if (aucmd_win != NULL && aucmd_win->w_lines == NULL
&& win_alloc_lines(aucmd_win) == FAIL)
outofmem = TRUE;
give_up:
for (i = 0; i < p_mco; ++i)
if (new_ScreenLinesC[i] == NULL)

View File

@ -753,10 +753,6 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
return FAIL;
new_frame(wp);
if (wp->w_frame == NULL) {
win_free(wp, NULL);
return FAIL;
}
/* make the contents of the new window the same as the current one */
win_init(wp, curwin, flags);
@ -2755,7 +2751,8 @@ void win_init_empty(win_T *wp)
/*
* Allocate the first window and put an empty buffer in it.
* Called from main().
* Return FAIL when something goes wrong (out of memory).
*
* Return FAIL when something goes wrong.
*/
int win_alloc_first(void)
{
@ -2763,8 +2760,6 @@ int win_alloc_first(void)
return FAIL;
first_tabpage = alloc_tabpage();
if (first_tabpage == NULL)
return FAIL;
first_tabpage->tp_topframe = topframe;
curtab = first_tabpage;
@ -2778,12 +2773,10 @@ int win_alloc_first(void)
void win_alloc_aucmd_win(void)
{
aucmd_win = win_alloc(NULL, TRUE);
if (aucmd_win != NULL) {
win_init_some(aucmd_win, curwin);
RESET_BINDING(aucmd_win);
new_frame(aucmd_win);
}
}
/*
* Allocate the first window or the first window in a new tab page.
@ -2799,7 +2792,7 @@ static int win_alloc_firstwin(win_T *oldwin)
/* Very first window, need to create an empty buffer for it and
* initialize from scratch. */
curbuf = buflist_new(NULL, NULL, 1L, BLN_LISTED);
if (curwin == NULL || curbuf == NULL)
if (curbuf == NULL)
return FAIL;
curwin->w_buffer = curbuf;
curwin->w_s = &(curbuf->b_s);
@ -2815,8 +2808,6 @@ static int win_alloc_firstwin(win_T *oldwin)
}
new_frame(curwin);
if (curwin->w_frame == NULL)
return FAIL;
topframe = curwin->w_frame;
topframe->fr_width = Columns;
topframe->fr_height = Rows - p_ch;
@ -2830,7 +2821,7 @@ static int win_alloc_firstwin(win_T *oldwin)
*/
static void new_frame(win_T *wp)
{
frame_T *frp = (frame_T *)alloc_clear((unsigned)sizeof(frame_T));
frame_T *frp = xcalloc(1, sizeof(frame_T));
wp->w_frame = frp;
frp->fr_layout = FR_LEAF;
@ -2850,21 +2841,13 @@ void win_init_size(void)
/*
* Allocate a new tabpage_T and init the values.
* Returns NULL when out of memory.
*/
static tabpage_T *alloc_tabpage(void)
{
tabpage_T *tp;
tp = (tabpage_T *)alloc_clear((unsigned)sizeof(tabpage_T));
tabpage_T *tp = xcalloc(1, sizeof(tabpage_T));
/* init t: variables */
tp->tp_vars = dict_alloc();
if (tp->tp_vars == NULL) {
vim_free(tp);
return NULL;
}
init_var_dict(tp->tp_vars, &tp->tp_winvar, VAR_SCOPE);
tp->tp_diff_invalid = TRUE;
@ -2903,8 +2886,6 @@ int win_new_tabpage(int after)
int n;
newtp = alloc_tabpage();
if (newtp == NULL)
return FAIL;
/* Remember the current windows in this Tab page. */
if (leave_tabpage(curbuf, TRUE) == FAIL) {
@ -3585,25 +3566,14 @@ win_T *buf_jump_open_tab(buf_T *buf)
*/
static win_T *win_alloc(win_T *after, int hidden)
{
win_T *new_wp;
/*
* allocate window structure and linesizes arrays
*/
new_wp = (win_T *)alloc_clear((unsigned)sizeof(win_T));
if (win_alloc_lines(new_wp) == FAIL) {
vim_free(new_wp);
return NULL;
}
win_T *new_wp = xcalloc(1, sizeof(win_T));
win_alloc_lines(new_wp);
/* init w: variables */
new_wp->w_vars = dict_alloc();
if (new_wp->w_vars == NULL) {
win_free_lsize(new_wp);
vim_free(new_wp);
return NULL;
}
init_var_dict(new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE);
/* Don't execute autocommands while the window is not properly
@ -3794,15 +3764,11 @@ static void frame_remove(frame_T *frp)
/*
* Allocate w_lines[] for window "wp".
* Return FAIL for failure, OK for success.
*/
int win_alloc_lines(win_T *wp)
void win_alloc_lines(win_T *wp)
{
wp->w_lines_valid = 0;
wp->w_lines = (wline_T *)alloc_clear((unsigned)(Rows * sizeof(wline_T)));
if (wp->w_lines == NULL)
return FAIL;
return OK;
wp->w_lines = xcalloc(Rows, sizeof(wline_T));
}
/*

View File

@ -41,7 +41,7 @@ win_T *buf_jump_open_win(buf_T *buf);
win_T *buf_jump_open_tab(buf_T *buf);
void win_append(win_T *after, win_T *wp);
void win_remove(win_T *wp, tabpage_T *tp);
int win_alloc_lines(win_T *wp);
void win_alloc_lines(win_T *wp);
void win_free_lsize(win_T *wp);
void shell_new_rows(void);
void shell_new_columns(void);