cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
06983f1996-09-22Fredrik Hübinette (Hubbe) ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License)
cb22561995-10-11Fredrik Hübinette (Hubbe) ||| See the files COPYING and DISCLAIMER for more information. \*/
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifndef ERROR_H #define ERROR_H
2d31fb1996-08-12Fredrik Hübinette (Hubbe) #include "machine.h" #ifdef HAVE_SETJMP_H
5267b71995-08-09Fredrik Hübinette (Hubbe) #include <setjmp.h>
2d31fb1996-08-12Fredrik Hübinette (Hubbe) #undef HAVE_SETJMP_H #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) #include <stdarg.h>
2d31fb1996-08-12Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "svalue.h"
cb22561995-10-11Fredrik Hübinette (Hubbe) typedef void (*error_call)(void *);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
dfa5b31996-12-05Fredrik Hübinette (Hubbe) #ifndef STRUCT_FRAME_DECLARED #define STRUCT_FRAME_DECLARED
5267b71995-08-09Fredrik Hübinette (Hubbe) struct frame;
dfa5b31996-12-05Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) 
61e9a01998-01-25Fredrik Hübinette (Hubbe) #define THROW_ERROR 1 #define THROW_EXIT 1000
cb22561995-10-11Fredrik Hübinette (Hubbe) typedef struct ONERROR { struct ONERROR *previous; error_call func; void *arg; } ONERROR;
5267b71995-08-09Fredrik Hübinette (Hubbe) typedef struct JMP_BUF { struct JMP_BUF *previous;
e9f9141996-09-29Fredrik Hübinette (Hubbe)  jmp_buf recovery;
5267b71995-08-09Fredrik Hübinette (Hubbe)  struct frame *fp;
f0cd981996-06-21Fredrik Hübinette (Hubbe)  INT32 sp; INT32 mark_sp;
61e9a01998-01-25Fredrik Hübinette (Hubbe)  INT32 severity;
cb22561995-10-11Fredrik Hübinette (Hubbe)  ONERROR *onerror;
5267b71995-08-09Fredrik Hübinette (Hubbe) } JMP_BUF; extern JMP_BUF *recoveries; extern struct svalue throw_value;
61e9a01998-01-25Fredrik Hübinette (Hubbe) extern int throw_severity;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
e9f9141996-09-29Fredrik Hübinette (Hubbe) #define SETJMP(X) setjmp((init_recovery(&X)->recovery))
5267b71995-08-09Fredrik Hübinette (Hubbe) #define UNSETJMP(X) recoveries=X.previous;
cb22561995-10-11Fredrik Hübinette (Hubbe) #define SET_ONERROR(X,Y,Z) \ do{ \ X.func=(error_call)(Y); \ X.arg=(void *)(Z); \
07513e1996-10-04Fredrik Hübinette (Hubbe)  X.previous=recoveries->onerror; \ recoveries->onerror=&X; \
cb22561995-10-11Fredrik Hübinette (Hubbe)  }while(0)
9dd1f91997-10-07Fredrik Hübinette (Hubbe) #ifdef DEBUG #define UNSET_ONERROR(X) do {\ if(recoveries->onerror != &(X)) fatal("UNSET_ONERROR out of sync.\n"); \ recoveries->onerror=(X).previous; \ } while(0) #else
07513e1996-10-04Fredrik Hübinette (Hubbe) #define UNSET_ONERROR(X) recoveries->onerror=X.previous
9dd1f91997-10-07Fredrik Hübinette (Hubbe) #endif
cb22561995-10-11Fredrik Hübinette (Hubbe) 
e9f9141996-09-29Fredrik Hübinette (Hubbe) /* Prototypes begin here */ JMP_BUF *init_recovery(JMP_BUF *r);
dc7cc91998-01-14Fredrik Hübinette (Hubbe) void pike_throw(void) ATTRIBUTE((noreturn));
5267b71995-08-09Fredrik Hübinette (Hubbe) void va_error(char *fmt, va_list args) ATTRIBUTE((noreturn));
dceabb1996-10-09Fredrik Hübinette (Hubbe) void exit_on_error(void *msg); void fatal_on_error(void *msg);
5267b71995-08-09Fredrik Hübinette (Hubbe) void error(char *fmt,...) ATTRIBUTE((noreturn,format (printf, 1, 2))); void fatal(char *fmt, ...) ATTRIBUTE((noreturn,format (printf, 1, 2)));
e9f9141996-09-29Fredrik Hübinette (Hubbe) /* Prototypes end here */
5267b71995-08-09Fredrik Hübinette (Hubbe)  #endif