better use of "ASSERT".

This commit is contained in:
Roberto Ierusalimschy 1998-03-09 18:49:52 -03:00
parent be6d215f67
commit 0969a971cd
9 changed files with 34 additions and 19 deletions

4
lapi.c
View File

@ -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;

View File

@ -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 */
}
}

8
lgc.c
View File

@ -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 */
}
}
}

6
lmem.c
View File

@ -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 <assert.h>
#include <string.h>
@ -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;

View File

@ -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 */
}
}

View File

@ -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

4
ltm.c
View File

@ -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;

View File

@ -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 */ | ';' ;

4
lvm.c
View File

@ -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
}
}