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:
48
src/misc2.c
48
src/misc2.c
@@ -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.
|
||||
|
Reference in New Issue
Block a user