summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-24 14:55:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-24 14:55:51 -0300
commit9d7bae0b6ab66e7e0cff8871e65ecddb55513d6b (patch)
tree18a4b30df4e0518580cd6dc7a370892f5f608021
parent082aded149762ec21a7fa58ef0cc8f9a61038ca7 (diff)
downloadlua-github-9d7bae0b6ab66e7e0cff8871e65ecddb55513d6b.tar.gz
better instrumentation for internal debugging
-rw-r--r--lmem.c19
-rw-r--r--lopcodes.h6
-rw-r--r--lparser.c6
-rw-r--r--lvm.c6
4 files changed, 29 insertions, 8 deletions
diff --git a/lmem.c b/lmem.c
index ccf1a4a8..a1379f24 100644
--- a/lmem.c
+++ b/lmem.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmem.c,v 1.8 1999/01/22 17:28:00 roberto Exp roberto $
+** $Id: lmem.c,v 1.9 1999/01/22 18:08:57 roberto Exp roberto $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/
@@ -24,6 +24,8 @@
+#ifndef DEBUG
+
int luaM_growaux (void **block, unsigned long nelems, int size,
char *errormsg, unsigned long limit) {
if (nelems >= limit)
@@ -36,9 +38,6 @@ int luaM_growaux (void **block, unsigned long nelems, int size,
}
-
-#ifndef DEBUG
-
/*
** generic allocation routine.
*/
@@ -64,6 +63,18 @@ void *luaM_realloc (void *block, unsigned long size) {
#include <string.h>
+int luaM_growaux (void **block, unsigned long nelems, int size,
+ char *errormsg, unsigned long limit) {
+ if (nelems >= limit)
+ lua_error(errormsg);
+ nelems = nelems+1;
+ if (nelems > limit)
+ nelems = limit;
+ *block = luaM_realloc(*block, nelems*size);
+ return (int)nelems;
+}
+
+
#define HEADER (sizeof(double))
#define MARK 55
diff --git a/lopcodes.h b/lopcodes.h
index 886d31d1..f1d6a2e1 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
/*
-** $Id: lopcodes.h,v 1.25 1999/02/09 18:01:55 roberto Exp roberto $
+** $Id: lopcodes.h,v 1.26 1999/02/23 13:38:38 roberto Exp roberto $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -107,7 +107,9 @@ SETLINEW,/* w - - LINE=w */
SETLINE,/* b - - LINE=b */
LONGARGW,/* w (add w*(1<<16) to arg of next instruction) */
-LONGARG /* b (add b*(1<<16) to arg of next instruction) */
+LONGARG,/* b (add b*(1<<16) to arg of next instruction) */
+
+CHECKSTACK /* b (assert #temporaries == b; only for internal debuging!) */
} OpCode;
diff --git a/lparser.c b/lparser.c
index 2bd65ee3..03e05102 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
/*
-** $Id: lparser.c,v 1.20 1999/02/09 18:01:55 roberto Exp roberto $
+** $Id: lparser.c,v 1.21 1999/02/24 15:37:19 roberto Exp roberto $
** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -403,6 +403,10 @@ static void close_exp (LexState *ls, int pc, int nresults) {
deltastack(ls, nresults); /* push results */
deltastack(ls, -(code[pc]+1)); /* pop params (at code[pc]) and function */
}
+#ifdef DEBUG
+ if (nresults != MULT_RET)
+ code_oparg(ls, CHECKSTACK, ls->fs->stacksize, 0);
+#endif
}
diff --git a/lvm.c b/lvm.c
index 5eee2799..fb8e87bc 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
/*
-** $Id: lvm.c,v 1.49 1999/02/09 18:01:55 roberto Exp roberto $
+** $Id: lvm.c,v 1.50 1999/02/23 13:38:38 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@@ -643,6 +643,10 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) {
aux = highbyte(highbyte(aux));
goto switchentry; /* do not reset "aux" */
+ case CHECKSTACK: aux = *pc++;
+ LUA_ASSERT((S->top-S->stack)-base == aux, "wrong stack size");
+ break;
+
}
}
}