diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-04 11:55:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-07-04 11:55:37 -0300 |
commit | 4321fde2a7059b5d5adcedd4f607f695ea30ff8b (patch) | |
tree | 97d6cf3b89c8e59e659ee4a4cc6165c739d14358 | |
parent | 8f3df1d471d4b7e643492f0e65fac2bdc960398a (diff) | |
download | lua-github-4321fde2a7059b5d5adcedd4f607f695ea30ff8b.tar.gz |
error inside an error method could break the stack.
-rw-r--r-- | fallback.c | 27 | ||||
-rw-r--r-- | fallback.h | 3 | ||||
-rw-r--r-- | opcode.c | 35 | ||||
-rw-r--r-- | opcode.h | 4 |
4 files changed, 41 insertions, 28 deletions
@@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_fallback="$Id: fallback.c,v 2.8 1997/06/17 17:27:07 roberto Exp roberto $"; +char *rcs_fallback="$Id: fallback.c,v 2.10 1997/07/03 22:06:06 roberto Exp $"; #include <stdio.h> #include <string.h> @@ -238,34 +238,19 @@ void luaI_settagmethod (void) } -static void stderrorim (void) -{ - lua_Object s = lua_getparam(1); - if (lua_isstring(s)) - fprintf(stderr, "lua: %s\n", lua_getstring(s)); -} - -static TObject errorim = {LUA_T_CFUNCTION, {stderrorim}}; - - -TObject *luaI_geterrorim (void) -{ - return &errorim; -} - void luaI_seterrormethod (void) { lua_Object func = lua_getparam(1); luaL_arg_check(lua_isnil(func) || lua_isfunction(func), 1, "function expected"); - luaI_pushobject(&errorim); - errorim = *luaI_Address(func); + luaI_pushobject(&luaI_errorim); + luaI_errorim = *luaI_Address(func); } char *luaI_travfallbacks (int (*fn)(TObject *)) { int e; - if (fn(&errorim)) + if (fn(&luaI_errorim)) return "error"; for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ int t; @@ -322,8 +307,8 @@ void luaI_setfallback (void) luaL_arg_check(lua_isfunction(func), 2, "function expected"); switch (luaI_findstring(name, oldnames)) { case 0: /* old error fallback */ - oldfunc = errorim; - errorim = *luaI_Address(func); + oldfunc = luaI_errorim; + luaI_errorim = *luaI_Address(func); replace = errorFB; break; case 1: /* old getglobal fallback */ @@ -1,5 +1,5 @@ /* -** $Id: fallback.h,v 1.22 1997/04/04 22:24:51 roberto Exp roberto $ +** $Id: fallback.h,v 1.24 1997/07/03 22:06:06 roberto Exp $ */ #ifndef fallback_h @@ -54,7 +54,6 @@ char *luaI_travfallbacks (int (*fn)(TObject *)); void luaI_settag (int tag, TObject *o); void luaI_realtag (int tag); -TObject *luaI_geterrorim (void); int luaI_efectivetag (TObject *o); void luaI_settagmethod (void); void luaI_gettagmethod (void); @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 4.15 1997/06/26 21:40:57 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 4.17 1997/07/03 22:06:06 roberto Exp $"; #include <setjmp.h> #include <stdio.h> @@ -465,12 +465,39 @@ void lua_travstack (int (*fn)(TObject *)) ** Error messages and debug functions */ + +static void auxerrorim (char *form) +{ + lua_Object s = lua_getparam(1); + if (lua_isstring(s)) + fprintf(stderr, form, lua_getstring(s)); +} + + +static void emergencyerrorf (void) +{ + auxerrorim("WARNING - THERE WAS AN ERROR INSIDE AN ERROR METHOD:\n%s\n"); +} + + +static void stderrorim (void) +{ + auxerrorim("lua: %s\n"); +} + + +TObject luaI_errorim = {LUA_T_CFUNCTION, {stderrorim}}; + + static void lua_message (char *s) { - TObject *im = luaI_geterrorim(); - if (ttype(im) != LUA_T_NIL) { + TObject im = luaI_errorim; + if (ttype(&im) != LUA_T_NIL) { + luaI_errorim.ttype = LUA_T_CFUNCTION; + luaI_errorim.value.f = emergencyerrorf; lua_pushstring(s); - callIM(im, 1, 0); + callIM(&im, 1, 0); + luaI_errorim = im; } } @@ -1,6 +1,6 @@ /* ** TeCGraf - PUC-Rio -** $Id: opcode.h,v 3.33 1997/04/11 21:34:53 roberto Exp roberto $ +** $Id: opcode.h,v 3.35 1997/07/03 22:06:06 roberto Exp $ */ #ifndef opcode_h @@ -168,4 +168,6 @@ void luaI_gcIM (TObject *o); int luaI_dorun (TFunc *tf); int lua_domain (void); +extern TObject luaI_errorim; + #endif |