summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ltests.c28
-rw-r--r--ltests.h8
2 files changed, 14 insertions, 22 deletions
diff --git a/ltests.c b/ltests.c
index 3c077a1c..7ae9ba6f 100644
--- a/ltests.c
+++ b/ltests.c
@@ -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
85Memcontrol memcontrol = {0L, 0L, 0L, ULONG_MAX}; 85Memcontrol memcontrol = {0L, 0L, 0L, 0L};
86 86
87 87
88static void *checkblock (void *block, size_t size) { 88static void *checkblock (void *block, size_t size) {
@@ -109,6 +109,10 @@ static void freeblock (Memcontrol *mc, void *block, size_t size) {
109void *debug_realloc (void *ud, void *block, size_t oldsize, size_t size) { 109void *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
1128static void checkfinalmem (void) {
1129 lua_assert(memcontrol.numblocks == 0);
1130 lua_assert(memcontrol.total == 0);
1131}
1132
1133
1124int luaB_opentests (lua_State *L) { 1134int 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
1136int 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
diff --git a/ltests.h b/ltests.h
index bedf8570..42a560c7 100644
--- a/ltests.h
+++ b/ltests.h
@@ -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' */
81int 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