0
0
mirror of https://github.com/vim/vim.git synced 2025-10-08 06:04:08 -04:00

patch 7.4.1058

Problem:    It is not possible to test code that is only reached when memory
            allocation fails.
Solution:   Add the alloc_fail() function.  Try it out with :vimgrep.
This commit is contained in:
Bram Moolenaar
2016-01-07 21:25:08 +01:00
parent 2b7db933b0
commit 75bdf6aa30
8 changed files with 138 additions and 5 deletions

View File

@@ -467,6 +467,7 @@ static void f_abs __ARGS((typval_T *argvars, typval_T *rettv));
static void f_acos __ARGS((typval_T *argvars, typval_T *rettv));
#endif
static void f_add __ARGS((typval_T *argvars, typval_T *rettv));
static void f_alloc_fail __ARGS((typval_T *argvars, typval_T *rettv));
static void f_and __ARGS((typval_T *argvars, typval_T *rettv));
static void f_append __ARGS((typval_T *argvars, typval_T *rettv));
static void f_argc __ARGS((typval_T *argvars, typval_T *rettv));
@@ -8071,6 +8072,7 @@ static struct fst
{"acos", 1, 1, f_acos}, /* WJMc */
#endif
{"add", 2, 2, f_add},
{"alloc_fail", 3, 3, f_alloc_fail},
{"and", 2, 2, f_and},
{"append", 2, 2, f_append},
{"argc", 0, 0, f_argc},
@@ -8983,6 +8985,28 @@ f_add(argvars, rettv)
EMSG(_(e_listreq));
}
/*
* "alloc_fail(id, countdown, repeat)" function
*/
static void
f_alloc_fail(argvars, rettv)
typval_T *argvars;
typval_T *rettv UNUSED;
{
if (argvars[0].v_type != VAR_NUMBER
|| argvars[0].vval.v_number <= 0
|| argvars[1].v_type != VAR_NUMBER
|| argvars[1].vval.v_number < 0
|| argvars[2].v_type != VAR_NUMBER)
EMSG(_(e_invarg));
else
{
alloc_fail_id = argvars[0].vval.v_number;
alloc_fail_countdown = argvars[1].vval.v_number;
alloc_fail_repeat = argvars[2].vval.v_number;
}
}
/*
* "and(expr, expr)" function
*/