diff options
| -rw-r--r-- | ltests.c | 28 | ||||
| -rw-r--r-- | ltests.h | 8 |
2 files changed, 14 insertions, 22 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.35 2006/01/10 12:50:00 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.36 2006/01/10 13:13:06 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 | */ |
| @@ -82,7 +82,7 @@ static void setnameval (lua_State *L, const char *name, int val) { | |||
| 82 | #endif | 82 | #endif |
| 83 | 83 | ||
| 84 | 84 | ||
| 85 | Memcontrol memcontrol = {0L, 0L, 0L, ULONG_MAX}; | 85 | Memcontrol memcontrol = {0L, 0L, 0L, 0L}; |
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | static void *checkblock (void *block, size_t size) { | 88 | static void *checkblock (void *block, size_t size) { |
| @@ -109,6 +109,10 @@ static void freeblock (Memcontrol *mc, void *block, size_t size) { | |||
| 109 | void *debug_realloc (void *ud, void *block, size_t oldsize, size_t size) { | 109 | void *debug_realloc (void *ud, void *block, size_t oldsize, size_t size) { |
| 110 | Memcontrol *mc = cast(Memcontrol *, ud); | 110 | Memcontrol *mc = cast(Memcontrol *, ud); |
| 111 | lua_assert(oldsize == 0 || checkblocksize(block, oldsize)); | 111 | lua_assert(oldsize == 0 || checkblocksize(block, oldsize)); |
| 112 | if (mc->memlimit == 0) { /* first time? */ | ||
| 113 | char *limit = getenv("MEMLIMIT"); /* initialize memory limit */ | ||
| 114 | mc->memlimit = limit ? strtoul(limit, NULL, 10) : ULONG_MAX; | ||
| 115 | } | ||
| 112 | if (size == 0) { | 116 | if (size == 0) { |
| 113 | freeblock(mc, block, oldsize); | 117 | freeblock(mc, block, oldsize); |
| 114 | return NULL; | 118 | return NULL; |
| @@ -1121,8 +1125,15 @@ static const struct luaL_Reg tests_funcs[] = { | |||
| 1121 | }; | 1125 | }; |
| 1122 | 1126 | ||
| 1123 | 1127 | ||
| 1128 | static void checkfinalmem (void) { | ||
| 1129 | lua_assert(memcontrol.numblocks == 0); | ||
| 1130 | lua_assert(memcontrol.total == 0); | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | |||
| 1124 | int luaB_opentests (lua_State *L) { | 1134 | int luaB_opentests (lua_State *L) { |
| 1125 | void *ud; | 1135 | void *ud; |
| 1136 | atexit(checkfinalmem); | ||
| 1126 | lua_assert(lua_getallocf(L, &ud) == debug_realloc); | 1137 | lua_assert(lua_getallocf(L, &ud) == debug_realloc); |
| 1127 | lua_assert(ud == cast(void *, &memcontrol)); | 1138 | lua_assert(ud == cast(void *, &memcontrol)); |
| 1128 | lua_setallocf(L, lua_getallocf(L, NULL), ud); | 1139 | lua_setallocf(L, lua_getallocf(L, NULL), ud); |
| @@ -1131,17 +1142,4 @@ int luaB_opentests (lua_State *L) { | |||
| 1131 | return 0; | 1142 | return 0; |
| 1132 | } | 1143 | } |
| 1133 | 1144 | ||
| 1134 | |||
| 1135 | #undef main | ||
| 1136 | int main (int argc, char *argv[]) { | ||
| 1137 | int ret; | ||
| 1138 | char *limit = getenv("MEMLIMIT"); | ||
| 1139 | if (limit) | ||
| 1140 | memcontrol.memlimit = strtoul(limit, NULL, 10); | ||
| 1141 | ret = l_main(argc, argv); | ||
| 1142 | lua_assert(memcontrol.numblocks == 0); | ||
| 1143 | lua_assert(memcontrol.total == 0); | ||
| 1144 | return ret; | ||
| 1145 | } | ||
| 1146 | |||
| 1147 | #endif | 1145 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.h,v 2.16 2005/09/14 17:48:57 roberto Exp roberto $ | 2 | ** $Id: ltests.h,v 2.17 2005/12/27 17:12:00 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 | */ |
| @@ -77,12 +77,6 @@ int luaB_opentests (lua_State *L); | |||
| 77 | 77 | ||
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | /* real main will be defined at `ltests.c' */ | ||
| 81 | int l_main (int argc, char *argv[]); | ||
| 82 | #define main l_main | ||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | /* change some sizes to give some bugs a chance */ | 80 | /* change some sizes to give some bugs a chance */ |
| 87 | 81 | ||
| 88 | #undef LUAL_BUFFERSIZE | 82 | #undef LUAL_BUFFERSIZE |
