From 0969a971cd41921bd5ee72c1da880455bcca3bb4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 9 Mar 1998 18:49:52 -0300 Subject: better use of "ASSERT". --- lapi.c | 4 ++-- lbuiltin.c | 6 +++--- lgc.c | 8 +++++--- lmem.c | 6 +++--- lobject.c | 4 ++-- lobject.h | 13 ++++++++++++- ltm.c | 4 ++-- lua.stx | 4 +++- lvm.c | 4 ++-- 9 files changed, 34 insertions(+), 19 deletions(-) diff --git a/lapi.c b/lapi.c index 9e1ca5a6..0f6dbaf7 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.22 1998/03/06 16:54:42 roberto Exp roberto $ +** $Id: lapi.c,v 1.23 1998/03/06 18:47:42 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -404,7 +404,7 @@ int lua_tag (lua_Object lo) return o->value.cl->consts[0].ttype; #ifdef DEBUG case LUA_T_LINE: - lua_error("internal error"); + LUA_INTERNALERROR("invalid type"); #endif default: return t; diff --git a/lbuiltin.c b/lbuiltin.c index 683bbd9b..ed6e17b2 100644 --- a/lbuiltin.c +++ b/lbuiltin.c @@ -1,5 +1,5 @@ /* -** $Id: lbuiltin.c,v 1.25 1998/02/12 19:27:10 roberto Exp roberto $ +** $Id: lbuiltin.c,v 1.26 1998/03/06 16:54:42 roberto Exp roberto $ ** Built-in functions ** See Copyright Notice in lua.h */ @@ -160,8 +160,8 @@ static char *to_string (lua_Object obj) } case LUA_T_NIL: return "nil"; - default: - lua_error("internal error"); + default: + LUA_INTERNALERROR("invalid type"); return NULL; /* to avoid warnings */ } } diff --git a/lgc.c b/lgc.c index 14b6bceb..b5417f77 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 1.16 1998/01/19 19:49:22 roberto Exp roberto $ +** $Id: lgc.c,v 1.17 1998/03/06 16:54:42 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -96,7 +96,7 @@ static int ismarked (TObject *o) #ifdef DEBUG case LUA_T_LINE: case LUA_T_CLMARK: case LUA_T_CMARK: case LUA_T_PMARK: - lua_error("internal error"); + LUA_INTERNALERROR("invalid type"); #endif default: /* nil, number or cproto */ return 1; @@ -212,11 +212,13 @@ static void hashmark (Hash *h) static void globalmark (void) { TaggedString *g; - for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next) + for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next){ + LUA_ASSERT(g->constindex >= 0, "userdata in global list"); if (g->u.s.globalval.ttype != LUA_T_NIL) { markobject(&g->u.s.globalval); strmark(g); /* cannot collect non nil global variables */ } + } } diff --git a/lmem.c b/lmem.c index 15ea9fc3..1cf133ab 100644 --- a/lmem.c +++ b/lmem.c @@ -1,5 +1,5 @@ /* -** $Id: lmem.c,v 1.3 1997/12/01 20:30:44 roberto Exp roberto $ +** $Id: lmem.c,v 1.4 1997/12/17 20:48:58 roberto Exp roberto $ ** Interface to Memory Manager ** See Copyright Notice in lua.h */ @@ -57,7 +57,6 @@ void *luaM_realloc (void *block, unsigned long size) #else /* DEBUG */ -#include #include @@ -71,7 +70,8 @@ static void *checkblock (void *block) { unsigned long *b = (unsigned long *)block - 1; unsigned long size = *b; - assert(*(((char *)b)+size+sizeof(unsigned long)) == MARK); + LUA_ASSERT(*(((char *)b)+size+sizeof(unsigned long)) == MARK, + "corrupted block"); numblocks--; totalmem -= size; return b; diff --git a/lobject.c b/lobject.c index 981e236e..e70d50ba 100644 --- a/lobject.c +++ b/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 1.9 1997/12/26 18:38:16 roberto Exp roberto $ +** $Id: lobject.c,v 1.10 1998/01/09 14:44:55 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -52,7 +52,7 @@ int luaO_equalObj (TObject *t1, TObject *t2) case LUA_T_CPROTO: return fvalue(t1) == fvalue(t2); case LUA_T_CLOSURE: return t1->value.cl == t2->value.cl; default: - lua_error("internal error in `lua_equalObj'"); + LUA_INTERNALERROR("invalid type"); return 0; /* UNREACHEABLE */ } } diff --git a/lobject.h b/lobject.h index 9177f03c..d2abaa1b 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 1.16 1998/01/19 19:49:22 roberto Exp roberto $ +** $Id: lobject.h,v 1.17 1998/03/06 16:54:42 roberto Exp $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -13,6 +13,17 @@ #include "lua.h" +#ifdef DEBUG +#include "lauxlib.h" +#define LUA_INTERNALERROR(s) \ + luaL_verror("INTERNAL ERROR - %s [%s:%d]",(s),__FILE__,__LINE__) +#define LUA_ASSERT(c,s) { if (!(c)) LUA_INTERNALERROR(s); } +#else +#define LUA_INTERNALERROR(s) /* empty */ +#define LUA_ASSERT(c,s) /* empty */ +#endif + + /* ** "real" is the type "number" of Lua ** GREP LUA_NUMBER to change that diff --git a/ltm.c b/ltm.c index 3c788f41..af332f04 100644 --- a/ltm.c +++ b/ltm.c @@ -1,5 +1,5 @@ /* -** $Id: ltm.c,v 1.12 1997/12/15 16:17:20 roberto Exp roberto $ +** $Id: ltm.c,v 1.13 1998/01/02 17:46:32 roberto Exp roberto $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -123,7 +123,7 @@ int luaT_efectivetag (TObject *o) #ifdef DEBUG case LUA_T_PMARK: case LUA_T_CMARK: case LUA_T_CLMARK: case LUA_T_LINE: - lua_error("internal error"); + LUA_INTERNALERROR("invalid type"); #endif default: return t; diff --git a/lua.stx b/lua.stx index f99ccae6..ad7f3c88 100644 --- a/lua.stx +++ b/lua.stx @@ -1,6 +1,6 @@ %{ /* -** $Id: lua.stx,v 1.33 1998/01/12 13:35:37 roberto Exp roberto $ +** $Id: lua.stx,v 1.34 1998/02/11 20:56:46 roberto Exp roberto $ ** Syntax analizer and code generator ** See Copyright Notice in lua.h */ @@ -679,6 +679,8 @@ chunk : statlist ret ; statlist : /* empty */ | statlist stat sc + { LUA_ASSERT(L->currState->stacksize == L->currState->nlocalvar, + "stack size != # local vars"); } ; sc : /* empty */ | ';' ; diff --git a/lvm.c b/lvm.c index dba91979..3bb8d921 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.23 1998/01/14 13:49:15 roberto Exp roberto $ +** $Id: lvm.c,v 1.24 1998/03/06 16:54:42 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -728,7 +728,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) #ifdef DEBUG default: - lua_error("internal error - opcode doesn't match"); + LUA_INTERNALERROR("opcode doesn't match"); #endif } } -- cgit v1.2.3-55-g6feb