mirror of https://github.com/rusefi/lua.git
error inside an error method could break the stack.
This commit is contained in:
parent
8f3df1d471
commit
4321fde2a7
27
fallback.c
27
fallback.c
|
@ -3,7 +3,7 @@
|
||||||
** TecCGraf - PUC-Rio
|
** 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 <stdio.h>
|
||||||
#include <string.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)
|
void luaI_seterrormethod (void)
|
||||||
{
|
{
|
||||||
lua_Object func = lua_getparam(1);
|
lua_Object func = lua_getparam(1);
|
||||||
luaL_arg_check(lua_isnil(func) || lua_isfunction(func),
|
luaL_arg_check(lua_isnil(func) || lua_isfunction(func),
|
||||||
1, "function expected");
|
1, "function expected");
|
||||||
luaI_pushobject(&errorim);
|
luaI_pushobject(&luaI_errorim);
|
||||||
errorim = *luaI_Address(func);
|
luaI_errorim = *luaI_Address(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *luaI_travfallbacks (int (*fn)(TObject *))
|
char *luaI_travfallbacks (int (*fn)(TObject *))
|
||||||
{
|
{
|
||||||
int e;
|
int e;
|
||||||
if (fn(&errorim))
|
if (fn(&luaI_errorim))
|
||||||
return "error";
|
return "error";
|
||||||
for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */
|
for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */
|
||||||
int t;
|
int t;
|
||||||
|
@ -322,8 +307,8 @@ void luaI_setfallback (void)
|
||||||
luaL_arg_check(lua_isfunction(func), 2, "function expected");
|
luaL_arg_check(lua_isfunction(func), 2, "function expected");
|
||||||
switch (luaI_findstring(name, oldnames)) {
|
switch (luaI_findstring(name, oldnames)) {
|
||||||
case 0: /* old error fallback */
|
case 0: /* old error fallback */
|
||||||
oldfunc = errorim;
|
oldfunc = luaI_errorim;
|
||||||
errorim = *luaI_Address(func);
|
luaI_errorim = *luaI_Address(func);
|
||||||
replace = errorFB;
|
replace = errorFB;
|
||||||
break;
|
break;
|
||||||
case 1: /* old getglobal fallback */
|
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
|
#ifndef fallback_h
|
||||||
|
@ -54,7 +54,6 @@ char *luaI_travfallbacks (int (*fn)(TObject *));
|
||||||
|
|
||||||
void luaI_settag (int tag, TObject *o);
|
void luaI_settag (int tag, TObject *o);
|
||||||
void luaI_realtag (int tag);
|
void luaI_realtag (int tag);
|
||||||
TObject *luaI_geterrorim (void);
|
|
||||||
int luaI_efectivetag (TObject *o);
|
int luaI_efectivetag (TObject *o);
|
||||||
void luaI_settagmethod (void);
|
void luaI_settagmethod (void);
|
||||||
void luaI_gettagmethod (void);
|
void luaI_gettagmethod (void);
|
||||||
|
|
35
opcode.c
35
opcode.c
|
@ -3,7 +3,7 @@
|
||||||
** TecCGraf - PUC-Rio
|
** 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 <setjmp.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -465,12 +465,39 @@ void lua_travstack (int (*fn)(TObject *))
|
||||||
** Error messages and debug functions
|
** 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)
|
static void lua_message (char *s)
|
||||||
{
|
{
|
||||||
TObject *im = luaI_geterrorim();
|
TObject im = luaI_errorim;
|
||||||
if (ttype(im) != LUA_T_NIL) {
|
if (ttype(&im) != LUA_T_NIL) {
|
||||||
|
luaI_errorim.ttype = LUA_T_CFUNCTION;
|
||||||
|
luaI_errorim.value.f = emergencyerrorf;
|
||||||
lua_pushstring(s);
|
lua_pushstring(s);
|
||||||
callIM(im, 1, 0);
|
callIM(&im, 1, 0);
|
||||||
|
luaI_errorim = im;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
opcode.h
4
opcode.h
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
** TeCGraf - PUC-Rio
|
** 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
|
#ifndef opcode_h
|
||||||
|
@ -168,4 +168,6 @@ void luaI_gcIM (TObject *o);
|
||||||
int luaI_dorun (TFunc *tf);
|
int luaI_dorun (TFunc *tf);
|
||||||
int lua_domain (void);
|
int lua_domain (void);
|
||||||
|
|
||||||
|
extern TObject luaI_errorim;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue