Skip to content

Commit

Permalink
Backport PR #3043 (handle ERROR_OUTPUT in kernel)
Browse files Browse the repository at this point in the history
  • Loading branch information
embray authored and fingolfin committed Dec 14, 2018
1 parent 465d77e commit de7b9b9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,53 @@


static Obj ErrorInner;
static Obj ERROR_OUTPUT = NULL;
static Obj IsOutputStream;


/****************************************************************************
**
*F * * * * * * * * * * * * * * error functions * * * * * * * * * * * * * * *
*/

/****************************************************************************
**
*F OpenErrorOutput() . . . . . . . open the file or stream assigned to the
** ERROR_OUTPUT global variable defined in
** error.g, or "*errout*" otherwise
*/
UInt OpenErrorOutput( void )
{
/* Try to print the output to stream. Use *errout* as a fallback. */
UInt ret = 0;

if (ERROR_OUTPUT != NULL) {
if (IsStringConv(ERROR_OUTPUT)) {
ret = OpenOutput(CSTR_STRING(ERROR_OUTPUT));
}
else {
if (CALL_1ARGS(IsOutputStream, ERROR_OUTPUT) == True) {
ret = OpenOutputStream(ERROR_OUTPUT);
}
}
}

if (!ret) {
/* It may be we already tried and failed to open *errout* above but
* but this is an extreme case so it can't hurt to try again
* anyways */
ret = OpenOutput("*errout*");
if (ret) {
Pr("failed to open error stream\n", 0, 0);
}
else {
Panic("failed to open *errout*");
}
}

return ret;
}


/****************************************************************************
**
Expand Down Expand Up @@ -615,6 +655,8 @@ static Int InitKernel(StructInitInfo * module)
InitHdlrFuncsFromTable(GVarFuncs);

ImportFuncFromLibrary("ErrorInner", &ErrorInner);
ImportFuncFromLibrary("IsOutputStream", &IsOutputStream);
ImportGVarFromLibrary("ERROR_OUTPUT", &ERROR_OUTPUT);

// return success
return 0;
Expand Down
8 changes: 8 additions & 0 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ typedef void (*intfunc)(Int);

Int RegisterBreakloopObserver(intfunc func);

/****************************************************************************
**
*F OpenErrorOutput() . . . . . . . open the file or stream assigned to the
** ERROR_OUTPUT global variable defined in
** error.g, or "*errout*" otherwise
*/
extern UInt OpenErrorOutput();

/****************************************************************************
**
*F ErrorQuit( <msg>, <arg1>, <arg2> ) . . . . . . . . . . . print and quit
Expand Down
3 changes: 2 additions & 1 deletion src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "scanner.h"

#include "error.h"
#include "gapstate.h"
#include "gaputils.h"
#include "io.h"
Expand All @@ -42,7 +43,7 @@ static void SyntaxErrorOrWarning(const Char * msg, UInt error)
if (STATE(NrErrLine) == 0) {

// open error output
OpenOutput("*errout*");
OpenErrorOutput();

// print the message ...
if (error)
Expand Down

0 comments on commit de7b9b9

Please sign in to comment.