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-4321fde2a7059b5d5adcedd4f607f695ea30ff8b.tar.gz lua-4321fde2a7059b5d5adcedd4f607f695ea30ff8b.tar.bz2 lua-4321fde2a7059b5d5adcedd4f607f695ea30ff8b.zip | |
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 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_fallback="$Id: fallback.c,v 2.8 1997/06/17 17:27:07 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 2.10 1997/07/03 22:06:06 roberto Exp $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| @@ -238,34 +238,19 @@ void luaI_settagmethod (void) | |||
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | 240 | ||
| 241 | static void stderrorim (void) | ||
| 242 | { | ||
| 243 | lua_Object s = lua_getparam(1); | ||
| 244 | if (lua_isstring(s)) | ||
| 245 | fprintf(stderr, "lua: %s\n", lua_getstring(s)); | ||
| 246 | } | ||
| 247 | |||
| 248 | static TObject errorim = {LUA_T_CFUNCTION, {stderrorim}}; | ||
| 249 | |||
| 250 | |||
| 251 | TObject *luaI_geterrorim (void) | ||
| 252 | { | ||
| 253 | return &errorim; | ||
| 254 | } | ||
| 255 | |||
| 256 | void luaI_seterrormethod (void) | 241 | void luaI_seterrormethod (void) |
| 257 | { | 242 | { |
| 258 | lua_Object func = lua_getparam(1); | 243 | lua_Object func = lua_getparam(1); |
| 259 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), | 244 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), |
| 260 | 1, "function expected"); | 245 | 1, "function expected"); |
| 261 | luaI_pushobject(&errorim); | 246 | luaI_pushobject(&luaI_errorim); |
| 262 | errorim = *luaI_Address(func); | 247 | luaI_errorim = *luaI_Address(func); |
| 263 | } | 248 | } |
| 264 | 249 | ||
| 265 | char *luaI_travfallbacks (int (*fn)(TObject *)) | 250 | char *luaI_travfallbacks (int (*fn)(TObject *)) |
| 266 | { | 251 | { |
| 267 | int e; | 252 | int e; |
| 268 | if (fn(&errorim)) | 253 | if (fn(&luaI_errorim)) |
| 269 | return "error"; | 254 | return "error"; |
| 270 | for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ | 255 | for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ |
| 271 | int t; | 256 | int t; |
| @@ -322,8 +307,8 @@ void luaI_setfallback (void) | |||
| 322 | luaL_arg_check(lua_isfunction(func), 2, "function expected"); | 307 | luaL_arg_check(lua_isfunction(func), 2, "function expected"); |
| 323 | switch (luaI_findstring(name, oldnames)) { | 308 | switch (luaI_findstring(name, oldnames)) { |
| 324 | case 0: /* old error fallback */ | 309 | case 0: /* old error fallback */ |
| 325 | oldfunc = errorim; | 310 | oldfunc = luaI_errorim; |
| 326 | errorim = *luaI_Address(func); | 311 | luaI_errorim = *luaI_Address(func); |
| 327 | replace = errorFB; | 312 | replace = errorFB; |
| 328 | break; | 313 | break; |
| 329 | case 1: /* old getglobal fallback */ | 314 | case 1: /* old getglobal fallback */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: fallback.h,v 1.22 1997/04/04 22:24:51 roberto Exp roberto $ | 2 | ** $Id: fallback.h,v 1.24 1997/07/03 22:06:06 roberto Exp $ |
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | #ifndef fallback_h | 5 | #ifndef fallback_h |
| @@ -54,7 +54,6 @@ char *luaI_travfallbacks (int (*fn)(TObject *)); | |||
| 54 | 54 | ||
| 55 | void luaI_settag (int tag, TObject *o); | 55 | void luaI_settag (int tag, TObject *o); |
| 56 | void luaI_realtag (int tag); | 56 | void luaI_realtag (int tag); |
| 57 | TObject *luaI_geterrorim (void); | ||
| 58 | int luaI_efectivetag (TObject *o); | 57 | int luaI_efectivetag (TObject *o); |
| 59 | void luaI_settagmethod (void); | 58 | void luaI_settagmethod (void); |
| 60 | void luaI_gettagmethod (void); | 59 | void luaI_gettagmethod (void); |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_opcode="$Id: opcode.c,v 4.15 1997/06/26 21:40:57 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 4.17 1997/07/03 22:06:06 roberto Exp $"; |
| 7 | 7 | ||
| 8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -465,12 +465,39 @@ void lua_travstack (int (*fn)(TObject *)) | |||
| 465 | ** Error messages and debug functions | 465 | ** Error messages and debug functions |
| 466 | */ | 466 | */ |
| 467 | 467 | ||
| 468 | |||
| 469 | static void auxerrorim (char *form) | ||
| 470 | { | ||
| 471 | lua_Object s = lua_getparam(1); | ||
| 472 | if (lua_isstring(s)) | ||
| 473 | fprintf(stderr, form, lua_getstring(s)); | ||
| 474 | } | ||
| 475 | |||
| 476 | |||
| 477 | static void emergencyerrorf (void) | ||
| 478 | { | ||
| 479 | auxerrorim("WARNING - THERE WAS AN ERROR INSIDE AN ERROR METHOD:\n%s\n"); | ||
| 480 | } | ||
| 481 | |||
| 482 | |||
| 483 | static void stderrorim (void) | ||
| 484 | { | ||
| 485 | auxerrorim("lua: %s\n"); | ||
| 486 | } | ||
| 487 | |||
| 488 | |||
| 489 | TObject luaI_errorim = {LUA_T_CFUNCTION, {stderrorim}}; | ||
| 490 | |||
| 491 | |||
| 468 | static void lua_message (char *s) | 492 | static void lua_message (char *s) |
| 469 | { | 493 | { |
| 470 | TObject *im = luaI_geterrorim(); | 494 | TObject im = luaI_errorim; |
| 471 | if (ttype(im) != LUA_T_NIL) { | 495 | if (ttype(&im) != LUA_T_NIL) { |
| 496 | luaI_errorim.ttype = LUA_T_CFUNCTION; | ||
| 497 | luaI_errorim.value.f = emergencyerrorf; | ||
| 472 | lua_pushstring(s); | 498 | lua_pushstring(s); |
| 473 | callIM(im, 1, 0); | 499 | callIM(&im, 1, 0); |
| 500 | luaI_errorim = im; | ||
| 474 | } | 501 | } |
| 475 | } | 502 | } |
| 476 | 503 | ||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
| 3 | ** $Id: opcode.h,v 3.33 1997/04/11 21:34:53 roberto Exp roberto $ | 3 | ** $Id: opcode.h,v 3.35 1997/07/03 22:06:06 roberto Exp $ |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
| @@ -168,4 +168,6 @@ void luaI_gcIM (TObject *o); | |||
| 168 | int luaI_dorun (TFunc *tf); | 168 | int luaI_dorun (TFunc *tf); |
| 169 | int lua_domain (void); | 169 | int lua_domain (void); |
| 170 | 170 | ||
| 171 | extern TObject luaI_errorim; | ||
| 172 | |||
| 171 | #endif | 173 | #endif |
