cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | |
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | #include "global.h"
#include "macros.h"
#include "error.h"
#include "interpret.h"
#include "stralloc.h"
#include "builtin_efuns.h"
#include "array.h"
#include "object.h"
char *automatic_fatal;
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | JMP_BUF *recoveries=0;
ONERROR *onerror_stack=0;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | |
|
f170fa | 1996-03-04 | Fredrik Hübinette (Hubbe) | | my_jmp_buf *init_recovery(JMP_BUF *r)
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | {
r->fp=fp;
|
f0cd98 | 1996-06-21 | Fredrik Hübinette (Hubbe) | | r->sp=sp-evaluator_stack;
r->mark_sp=mark_sp - mark_stack;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | r->previous=recoveries;
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | r->onerror=onerror_stack;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | recoveries=r;
|
c71e64 | 1996-03-03 | Fredrik Hübinette (Hubbe) | | return & ( r->recovery );
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | }
void throw()
{
if(!recoveries)
fatal("No error recovery context.\n");
#ifdef DEBUG
|
f0cd98 | 1996-06-21 | Fredrik Hübinette (Hubbe) | | if(sp - evaluator_stack < recoveries->sp)
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | fatal("Error in error.\n");
#endif
while(fp != recoveries->fp)
{
#ifdef DEBUG
if(!fp)
fatal("Popped out of stack frames.\n");
#endif
free_object(fp->current_object);
free_program(fp->context.prog);
fp = fp->parent_frame;
}
|
f0cd98 | 1996-06-21 | Fredrik Hübinette (Hubbe) | | pop_n_elems(sp - evaluator_stack - recoveries->sp);
mark_sp = mark_stack + recoveries->mark_sp;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | |
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | while(recoveries->onerror != onerror_stack)
{
#ifdef DEBUG
if(!onerror_stack)
fatal("Popped out of onerror stack!\n");
#endif
(*onerror_stack->func)(onerror_stack->arg);
onerror_stack=onerror_stack->previous;
}
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | longjmp(recoveries->recovery,1);
}
struct svalue throw_value = { T_INT };
void va_error(char *fmt, va_list args)
{
char buf[2000];
|
5fe7a7 | 1995-11-06 | Fredrik Hübinette (Hubbe) | | static char *in_error;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | if(in_error)
{
|
5fe7a7 | 1995-11-06 | Fredrik Hübinette (Hubbe) | | char *tmp=in_error;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | in_error=0;
|
5fe7a7 | 1995-11-06 | Fredrik Hübinette (Hubbe) | | fatal("Recursive error() calls, original error: %s",tmp);
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | }
|
5fe7a7 | 1995-11-06 | Fredrik Hübinette (Hubbe) | | in_error=buf;
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | |
VSPRINTF(buf, fmt, args);
if(!recoveries || automatic_fatal)
{
if(!automatic_fatal)
automatic_fatal="No error recovery context: ";
fprintf(stderr,"%s %s",automatic_fatal,buf);
abort();
}
|
6b9216 | 1996-05-16 | Fredrik Hübinette (Hubbe) | | if((long)strlen(buf) >= (long)sizeof(buf))
|
5267b7 | 1995-08-09 | Fredrik Hübinette (Hubbe) | | fatal("Buffer overflow in error()\n");
push_string(make_shared_string(buf));
f_backtrace(0);
f_aggregate(2);
free_svalue(& throw_value);
sp--;
throw_value = *sp;
in_error=0;
throw();
}
void error(char *fmt,...)
{
va_list args;
va_start(args,fmt);
va_error(fmt,args);
va_end(args);
}
void fatal(char *fmt, ...)
{
va_list args;
static int in_fatal = 0;
va_start(args,fmt);
if (in_fatal)
{
(void)VFPRINTF(stderr, fmt, args);
abort();
}
in_fatal = 1;
#ifdef DEBUG
dump_backlog();
#endif
(void)VFPRINTF(stderr, fmt, args);
fflush(stderr);
abort();
}
|