mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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:
parent
6d193b0b37
commit
28b03dd190
28
src/eval.c
28
src/eval.c
@ -6105,23 +6105,21 @@ void set_ref_in_item(typval_T *tv, int copyID)
|
|||||||
*/
|
*/
|
||||||
dict_T *dict_alloc(void)
|
dict_T *dict_alloc(void)
|
||||||
{
|
{
|
||||||
dict_T *d;
|
dict_T *d = xmalloc(sizeof(dict_T));
|
||||||
|
|
||||||
d = (dict_T *)alloc(sizeof(dict_T));
|
/* Add the dict to the list of dicts for garbage collection. */
|
||||||
if (d != NULL) {
|
if (first_dict != NULL)
|
||||||
/* Add the dict to the list of dicts for garbage collection. */
|
first_dict->dv_used_prev = d;
|
||||||
if (first_dict != NULL)
|
d->dv_used_next = first_dict;
|
||||||
first_dict->dv_used_prev = d;
|
d->dv_used_prev = NULL;
|
||||||
d->dv_used_next = first_dict;
|
first_dict = d;
|
||||||
d->dv_used_prev = NULL;
|
|
||||||
first_dict = d;
|
hash_init(&d->dv_hashtab);
|
||||||
|
d->dv_lock = 0;
|
||||||
|
d->dv_scope = 0;
|
||||||
|
d->dv_refcount = 0;
|
||||||
|
d->dv_copyID = 0;
|
||||||
|
|
||||||
hash_init(&d->dv_hashtab);
|
|
||||||
d->dv_lock = 0;
|
|
||||||
d->dv_scope = 0;
|
|
||||||
d->dv_refcount = 0;
|
|
||||||
d->dv_copyID = 0;
|
|
||||||
}
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
src/screen.c
12
src/screen.c
@ -6279,15 +6279,11 @@ retry:
|
|||||||
|
|
||||||
FOR_ALL_TAB_WINDOWS(tp, wp)
|
FOR_ALL_TAB_WINDOWS(tp, wp)
|
||||||
{
|
{
|
||||||
if (win_alloc_lines(wp) == FAIL) {
|
win_alloc_lines(wp);
|
||||||
outofmem = TRUE;
|
}
|
||||||
goto give_up;
|
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)
|
for (i = 0; i < p_mco; ++i)
|
||||||
if (new_ScreenLinesC[i] == NULL)
|
if (new_ScreenLinesC[i] == NULL)
|
||||||
|
58
src/window.c
58
src/window.c
@ -753,10 +753,6 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
new_frame(wp);
|
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 */
|
/* make the contents of the new window the same as the current one */
|
||||||
win_init(wp, curwin, flags);
|
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.
|
* Allocate the first window and put an empty buffer in it.
|
||||||
* Called from main().
|
* Called from main().
|
||||||
* Return FAIL when something goes wrong (out of memory).
|
*
|
||||||
|
* Return FAIL when something goes wrong.
|
||||||
*/
|
*/
|
||||||
int win_alloc_first(void)
|
int win_alloc_first(void)
|
||||||
{
|
{
|
||||||
@ -2763,8 +2760,6 @@ int win_alloc_first(void)
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
|
|
||||||
first_tabpage = alloc_tabpage();
|
first_tabpage = alloc_tabpage();
|
||||||
if (first_tabpage == NULL)
|
|
||||||
return FAIL;
|
|
||||||
first_tabpage->tp_topframe = topframe;
|
first_tabpage->tp_topframe = topframe;
|
||||||
curtab = first_tabpage;
|
curtab = first_tabpage;
|
||||||
|
|
||||||
@ -2778,11 +2773,9 @@ int win_alloc_first(void)
|
|||||||
void win_alloc_aucmd_win(void)
|
void win_alloc_aucmd_win(void)
|
||||||
{
|
{
|
||||||
aucmd_win = win_alloc(NULL, TRUE);
|
aucmd_win = win_alloc(NULL, TRUE);
|
||||||
if (aucmd_win != NULL) {
|
win_init_some(aucmd_win, curwin);
|
||||||
win_init_some(aucmd_win, curwin);
|
RESET_BINDING(aucmd_win);
|
||||||
RESET_BINDING(aucmd_win);
|
new_frame(aucmd_win);
|
||||||
new_frame(aucmd_win);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2799,7 +2792,7 @@ static int win_alloc_firstwin(win_T *oldwin)
|
|||||||
/* Very first window, need to create an empty buffer for it and
|
/* Very first window, need to create an empty buffer for it and
|
||||||
* initialize from scratch. */
|
* initialize from scratch. */
|
||||||
curbuf = buflist_new(NULL, NULL, 1L, BLN_LISTED);
|
curbuf = buflist_new(NULL, NULL, 1L, BLN_LISTED);
|
||||||
if (curwin == NULL || curbuf == NULL)
|
if (curbuf == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
curwin->w_buffer = curbuf;
|
curwin->w_buffer = curbuf;
|
||||||
curwin->w_s = &(curbuf->b_s);
|
curwin->w_s = &(curbuf->b_s);
|
||||||
@ -2815,8 +2808,6 @@ static int win_alloc_firstwin(win_T *oldwin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_frame(curwin);
|
new_frame(curwin);
|
||||||
if (curwin->w_frame == NULL)
|
|
||||||
return FAIL;
|
|
||||||
topframe = curwin->w_frame;
|
topframe = curwin->w_frame;
|
||||||
topframe->fr_width = Columns;
|
topframe->fr_width = Columns;
|
||||||
topframe->fr_height = Rows - p_ch;
|
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)
|
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;
|
wp->w_frame = frp;
|
||||||
frp->fr_layout = FR_LEAF;
|
frp->fr_layout = FR_LEAF;
|
||||||
@ -2850,21 +2841,13 @@ void win_init_size(void)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate a new tabpage_T and init the values.
|
* Allocate a new tabpage_T and init the values.
|
||||||
* Returns NULL when out of memory.
|
|
||||||
*/
|
*/
|
||||||
static tabpage_T *alloc_tabpage(void)
|
static tabpage_T *alloc_tabpage(void)
|
||||||
{
|
{
|
||||||
tabpage_T *tp;
|
tabpage_T *tp = xcalloc(1, sizeof(tabpage_T));
|
||||||
|
|
||||||
|
|
||||||
tp = (tabpage_T *)alloc_clear((unsigned)sizeof(tabpage_T));
|
|
||||||
|
|
||||||
/* init t: variables */
|
/* init t: variables */
|
||||||
tp->tp_vars = dict_alloc();
|
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);
|
init_var_dict(tp->tp_vars, &tp->tp_winvar, VAR_SCOPE);
|
||||||
|
|
||||||
tp->tp_diff_invalid = TRUE;
|
tp->tp_diff_invalid = TRUE;
|
||||||
@ -2903,8 +2886,6 @@ int win_new_tabpage(int after)
|
|||||||
int n;
|
int n;
|
||||||
|
|
||||||
newtp = alloc_tabpage();
|
newtp = alloc_tabpage();
|
||||||
if (newtp == NULL)
|
|
||||||
return FAIL;
|
|
||||||
|
|
||||||
/* Remember the current windows in this Tab page. */
|
/* Remember the current windows in this Tab page. */
|
||||||
if (leave_tabpage(curbuf, TRUE) == FAIL) {
|
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)
|
static win_T *win_alloc(win_T *after, int hidden)
|
||||||
{
|
{
|
||||||
win_T *new_wp;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* allocate window structure and linesizes arrays
|
* allocate window structure and linesizes arrays
|
||||||
*/
|
*/
|
||||||
new_wp = (win_T *)alloc_clear((unsigned)sizeof(win_T));
|
win_T *new_wp = xcalloc(1, sizeof(win_T));
|
||||||
|
win_alloc_lines(new_wp);
|
||||||
if (win_alloc_lines(new_wp) == FAIL) {
|
|
||||||
vim_free(new_wp);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* init w: variables */
|
/* init w: variables */
|
||||||
new_wp->w_vars = dict_alloc();
|
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);
|
init_var_dict(new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE);
|
||||||
|
|
||||||
/* Don't execute autocommands while the window is not properly
|
/* 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".
|
* 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_valid = 0;
|
||||||
wp->w_lines = (wline_T *)alloc_clear((unsigned)(Rows * sizeof(wline_T)));
|
wp->w_lines = xcalloc(Rows, sizeof(wline_T));
|
||||||
if (wp->w_lines == NULL)
|
|
||||||
return FAIL;
|
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -41,7 +41,7 @@ win_T *buf_jump_open_win(buf_T *buf);
|
|||||||
win_T *buf_jump_open_tab(buf_T *buf);
|
win_T *buf_jump_open_tab(buf_T *buf);
|
||||||
void win_append(win_T *after, win_T *wp);
|
void win_append(win_T *after, win_T *wp);
|
||||||
void win_remove(win_T *wp, tabpage_T *tp);
|
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 win_free_lsize(win_T *wp);
|
||||||
void shell_new_rows(void);
|
void shell_new_rows(void);
|
||||||
void shell_new_columns(void);
|
void shell_new_columns(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user