0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -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

@@ -797,6 +797,21 @@ vim_mem_profile_dump()
#endif /* MEM_PROFILE */
#ifdef FEAT_EVAL
static int
alloc_does_fail()
{
if (alloc_fail_countdown == 0)
{
if (--alloc_fail_repeat <= 0)
alloc_fail_id = 0;
return TRUE;
}
--alloc_fail_countdown;
return FALSE;
}
#endif
/*
* Some memory is reserved for error messages and for being able to
* call mf_release_all(), which needs some memory for mf_trans_add().
@@ -820,6 +835,22 @@ alloc(size)
return (lalloc((long_u)size, TRUE));
}
/*
* alloc() with an ID for alloc_fail().
* LAST_ID_USED: 5
*/
char_u *
alloc_id(size, id)
unsigned size;
int id;
{
#ifdef FEAT_EVAL
if (alloc_fail_id == id && alloc_does_fail())
return NULL;
#endif
return (lalloc((long_u)size, TRUE));
}
/*
* Allocate memory and set all bytes to zero.
*/
@@ -968,6 +999,23 @@ theend:
return p;
}
/*
* lalloc() with an ID for alloc_fail().
* See LAST_ID_USED above.
*/
char_u *
lalloc_id(size, message, id)
long_u size;
int message;
int id;
{
#ifdef FEAT_EVAL
if (alloc_fail_id == id && alloc_does_fail())
return NULL;
#endif
return (lalloc((long_u)size, message));
}
#if defined(MEM_PROFILE) || defined(PROTO)
/*
* realloc() with memory profiling.