aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-03-09 18:49:52 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-03-09 18:49:52 -0300
commit0969a971cd41921bd5ee72c1da880455bcca3bb4 (patch)
tree74be9a39706eeb1e7f4e5c2cf49693364c399790
parentbe6d215f674f3d148d3f80a0553e8b2aa6da51d7 (diff)
downloadlua-0969a971cd41921bd5ee72c1da880455bcca3bb4.tar.gz
lua-0969a971cd41921bd5ee72c1da880455bcca3bb4.tar.bz2
lua-0969a971cd41921bd5ee72c1da880455bcca3bb4.zip
better use of "ASSERT".
-rw-r--r--lapi.c4
-rw-r--r--lbuiltin.c6
-rw-r--r--lgc.c8
-rw-r--r--lmem.c6
-rw-r--r--lobject.c4
-rw-r--r--lobject.h13
-rw-r--r--ltm.c4
-rw-r--r--lua.stx4
-rw-r--r--lvm.c4
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 @@
1/* 1/*
2** $Id: lapi.c,v 1.22 1998/03/06 16:54:42 roberto Exp roberto $ 2** $Id: lapi.c,v 1.23 1998/03/06 18:47:42 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -404,7 +404,7 @@ int lua_tag (lua_Object lo)
404 return o->value.cl->consts[0].ttype; 404 return o->value.cl->consts[0].ttype;
405#ifdef DEBUG 405#ifdef DEBUG
406 case LUA_T_LINE: 406 case LUA_T_LINE:
407 lua_error("internal error"); 407 LUA_INTERNALERROR("invalid type");
408#endif 408#endif
409 default: 409 default:
410 return t; 410 return t;
diff --git a/lbuiltin.c b/lbuiltin.c
index 683bbd9b..ed6e17b2 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.25 1998/02/12 19:27:10 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.26 1998/03/06 16:54:42 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -160,8 +160,8 @@ static char *to_string (lua_Object obj)
160 } 160 }
161 case LUA_T_NIL: 161 case LUA_T_NIL:
162 return "nil"; 162 return "nil";
163 default: 163 default:
164 lua_error("internal error"); 164 LUA_INTERNALERROR("invalid type");
165 return NULL; /* to avoid warnings */ 165 return NULL; /* to avoid warnings */
166 } 166 }
167} 167}
diff --git a/lgc.c b/lgc.c
index 14b6bceb..b5417f77 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.16 1998/01/19 19:49:22 roberto Exp roberto $ 2** $Id: lgc.c,v 1.17 1998/03/06 16:54:42 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -96,7 +96,7 @@ static int ismarked (TObject *o)
96#ifdef DEBUG 96#ifdef DEBUG
97 case LUA_T_LINE: case LUA_T_CLMARK: 97 case LUA_T_LINE: case LUA_T_CLMARK:
98 case LUA_T_CMARK: case LUA_T_PMARK: 98 case LUA_T_CMARK: case LUA_T_PMARK:
99 lua_error("internal error"); 99 LUA_INTERNALERROR("invalid type");
100#endif 100#endif
101 default: /* nil, number or cproto */ 101 default: /* nil, number or cproto */
102 return 1; 102 return 1;
@@ -212,11 +212,13 @@ static void hashmark (Hash *h)
212static void globalmark (void) 212static void globalmark (void)
213{ 213{
214 TaggedString *g; 214 TaggedString *g;
215 for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next) 215 for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next){
216 LUA_ASSERT(g->constindex >= 0, "userdata in global list");
216 if (g->u.s.globalval.ttype != LUA_T_NIL) { 217 if (g->u.s.globalval.ttype != LUA_T_NIL) {
217 markobject(&g->u.s.globalval); 218 markobject(&g->u.s.globalval);
218 strmark(g); /* cannot collect non nil global variables */ 219 strmark(g); /* cannot collect non nil global variables */
219 } 220 }
221 }
220} 222}
221 223
222 224
diff --git a/lmem.c b/lmem.c
index 15ea9fc3..1cf133ab 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.c,v 1.3 1997/12/01 20:30:44 roberto Exp roberto $ 2** $Id: lmem.c,v 1.4 1997/12/17 20:48:58 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -57,7 +57,6 @@ void *luaM_realloc (void *block, unsigned long size)
57#else 57#else
58/* DEBUG */ 58/* DEBUG */
59 59
60#include <assert.h>
61#include <string.h> 60#include <string.h>
62 61
63 62
@@ -71,7 +70,8 @@ static void *checkblock (void *block)
71{ 70{
72 unsigned long *b = (unsigned long *)block - 1; 71 unsigned long *b = (unsigned long *)block - 1;
73 unsigned long size = *b; 72 unsigned long size = *b;
74 assert(*(((char *)b)+size+sizeof(unsigned long)) == MARK); 73 LUA_ASSERT(*(((char *)b)+size+sizeof(unsigned long)) == MARK,
74 "corrupted block");
75 numblocks--; 75 numblocks--;
76 totalmem -= size; 76 totalmem -= size;
77 return b; 77 return b;
diff --git a/lobject.c b/lobject.c
index 981e236e..e70d50ba 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.9 1997/12/26 18:38:16 roberto Exp roberto $ 2** $Id: lobject.c,v 1.10 1998/01/09 14:44:55 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -52,7 +52,7 @@ int luaO_equalObj (TObject *t1, TObject *t2)
52 case LUA_T_CPROTO: return fvalue(t1) == fvalue(t2); 52 case LUA_T_CPROTO: return fvalue(t1) == fvalue(t2);
53 case LUA_T_CLOSURE: return t1->value.cl == t2->value.cl; 53 case LUA_T_CLOSURE: return t1->value.cl == t2->value.cl;
54 default: 54 default:
55 lua_error("internal error in `lua_equalObj'"); 55 LUA_INTERNALERROR("invalid type");
56 return 0; /* UNREACHEABLE */ 56 return 0; /* UNREACHEABLE */
57 } 57 }
58} 58}
diff --git a/lobject.h b/lobject.h
index 9177f03c..d2abaa1b 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.16 1998/01/19 19:49:22 roberto Exp roberto $ 2** $Id: lobject.h,v 1.17 1998/03/06 16:54:42 roberto Exp $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -13,6 +13,17 @@
13#include "lua.h" 13#include "lua.h"
14 14
15 15
16#ifdef DEBUG
17#include "lauxlib.h"
18#define LUA_INTERNALERROR(s) \
19 luaL_verror("INTERNAL ERROR - %s [%s:%d]",(s),__FILE__,__LINE__)
20#define LUA_ASSERT(c,s) { if (!(c)) LUA_INTERNALERROR(s); }
21#else
22#define LUA_INTERNALERROR(s) /* empty */
23#define LUA_ASSERT(c,s) /* empty */
24#endif
25
26
16/* 27/*
17** "real" is the type "number" of Lua 28** "real" is the type "number" of Lua
18** GREP LUA_NUMBER to change that 29** 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 @@
1/* 1/*
2** $Id: ltm.c,v 1.12 1997/12/15 16:17:20 roberto Exp roberto $ 2** $Id: ltm.c,v 1.13 1998/01/02 17:46:32 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -123,7 +123,7 @@ int luaT_efectivetag (TObject *o)
123#ifdef DEBUG 123#ifdef DEBUG
124 case LUA_T_PMARK: case LUA_T_CMARK: 124 case LUA_T_PMARK: case LUA_T_CMARK:
125 case LUA_T_CLMARK: case LUA_T_LINE: 125 case LUA_T_CLMARK: case LUA_T_LINE:
126 lua_error("internal error"); 126 LUA_INTERNALERROR("invalid type");
127#endif 127#endif
128 default: 128 default:
129 return t; 129 return t;
diff --git a/lua.stx b/lua.stx
index f99ccae6..ad7f3c88 100644
--- a/lua.stx
+++ b/lua.stx
@@ -1,6 +1,6 @@
1%{ 1%{
2/* 2/*
3** $Id: lua.stx,v 1.33 1998/01/12 13:35:37 roberto Exp roberto $ 3** $Id: lua.stx,v 1.34 1998/02/11 20:56:46 roberto Exp roberto $
4** Syntax analizer and code generator 4** Syntax analizer and code generator
5** See Copyright Notice in lua.h 5** See Copyright Notice in lua.h
6*/ 6*/
@@ -679,6 +679,8 @@ chunk : statlist ret ;
679 679
680statlist : /* empty */ 680statlist : /* empty */
681 | statlist stat sc 681 | statlist stat sc
682 { LUA_ASSERT(L->currState->stacksize == L->currState->nlocalvar,
683 "stack size != # local vars"); }
682 ; 684 ;
683 685
684sc : /* empty */ | ';' ; 686sc : /* empty */ | ';' ;
diff --git a/lvm.c b/lvm.c
index dba91979..3bb8d921 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.23 1998/01/14 13:49:15 roberto Exp roberto $ 2** $Id: lvm.c,v 1.24 1998/03/06 16:54:42 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -728,7 +728,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base)
728 728
729#ifdef DEBUG 729#ifdef DEBUG
730 default: 730 default:
731 lua_error("internal error - opcode doesn't match"); 731 LUA_INTERNALERROR("opcode doesn't match");
732#endif 732#endif
733 } 733 }
734 } 734 }