diff options
| -rw-r--r-- | ltests.c | 21 | ||||
| -rw-r--r-- | ltests.h | 3 |
2 files changed, 20 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.232 2017/11/09 13:31:29 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.233 2017/11/23 15:38:42 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -102,7 +102,7 @@ typedef union Header { | |||
| 102 | 102 | ||
| 103 | 103 | ||
| 104 | Memcontrol l_memcontrol = | 104 | Memcontrol l_memcontrol = |
| 105 | {0L, 0L, 0L, 0L, {0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L}}; | 105 | {0L, 0L, 0L, 0L, (~0L), {0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L}}; |
| 106 | 106 | ||
| 107 | 107 | ||
| 108 | static void freeblock (Memcontrol *mc, Header *block) { | 108 | static void freeblock (Memcontrol *mc, Header *block) { |
| @@ -141,7 +141,12 @@ void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) { | |||
| 141 | freeblock(mc, block); | 141 | freeblock(mc, block); |
| 142 | return NULL; | 142 | return NULL; |
| 143 | } | 143 | } |
| 144 | else if (size > oldsize && mc->total+size-oldsize > mc->memlimit) | 144 | if (mc->countlimit != ~0UL && size > oldsize) { /* count limit in use? */ |
| 145 | if (mc->countlimit == 0) | ||
| 146 | return NULL; /* fake a memory allocation error */ | ||
| 147 | mc->countlimit--; | ||
| 148 | } | ||
| 149 | if (size > oldsize && mc->total+size-oldsize > mc->memlimit) | ||
| 145 | return NULL; /* fake a memory allocation error */ | 150 | return NULL; /* fake a memory allocation error */ |
| 146 | else { | 151 | else { |
| 147 | Header *newblock; | 152 | Header *newblock; |
| @@ -695,6 +700,15 @@ static int mem_query (lua_State *L) { | |||
| 695 | } | 700 | } |
| 696 | 701 | ||
| 697 | 702 | ||
| 703 | static int alloc_count (lua_State *L) { | ||
| 704 | if (lua_isnone(L, 1)) | ||
| 705 | l_memcontrol.countlimit = ~0L; | ||
| 706 | else | ||
| 707 | l_memcontrol.countlimit = luaL_checkinteger(L, 1); | ||
| 708 | return 0; | ||
| 709 | } | ||
| 710 | |||
| 711 | |||
| 698 | static int settrick (lua_State *L) { | 712 | static int settrick (lua_State *L) { |
| 699 | if (ttisnil(obj_at(L, 1))) | 713 | if (ttisnil(obj_at(L, 1))) |
| 700 | l_Trick = NULL; | 714 | l_Trick = NULL; |
| @@ -1673,6 +1687,7 @@ static const struct luaL_Reg tests_funcs[] = { | |||
| 1673 | {"testC", testC}, | 1687 | {"testC", testC}, |
| 1674 | {"makeCfunc", makeCfunc}, | 1688 | {"makeCfunc", makeCfunc}, |
| 1675 | {"totalmem", mem_query}, | 1689 | {"totalmem", mem_query}, |
| 1690 | {"alloccount", alloc_count}, | ||
| 1676 | {"trick", settrick}, | 1691 | {"trick", settrick}, |
| 1677 | {"udataval", udataval}, | 1692 | {"udataval", udataval}, |
| 1678 | {"unref", unref}, | 1693 | {"unref", unref}, |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.h,v 2.52 2017/11/13 12:19:35 roberto Exp roberto $ | 2 | ** $Id: ltests.h,v 2.53 2017/11/23 16:35:54 roberto Exp roberto $ |
| 3 | ** Internal Header for Debugging of the Lua Implementation | 3 | ** Internal Header for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -57,6 +57,7 @@ typedef struct Memcontrol { | |||
| 57 | unsigned long total; | 57 | unsigned long total; |
| 58 | unsigned long maxmem; | 58 | unsigned long maxmem; |
| 59 | unsigned long memlimit; | 59 | unsigned long memlimit; |
| 60 | unsigned long countlimit; | ||
| 60 | unsigned long objcount[LUA_NUMTAGS]; | 61 | unsigned long objcount[LUA_NUMTAGS]; |
| 61 | } Memcontrol; | 62 | } Memcontrol; |
| 62 | 63 | ||
