Skip to content

Commit de7b9b9

Browse files
embrayfingolfin
authored andcommitted
Backport PR gap-system#3043 (handle ERROR_OUTPUT in kernel)
1 parent 465d77e commit de7b9b9

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/error.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,53 @@
3333

3434

3535
static Obj ErrorInner;
36+
static Obj ERROR_OUTPUT = NULL;
37+
static Obj IsOutputStream;
3638

3739

3840
/****************************************************************************
3941
**
4042
*F * * * * * * * * * * * * * * error functions * * * * * * * * * * * * * * *
4143
*/
4244

45+
/****************************************************************************
46+
**
47+
*F OpenErrorOutput() . . . . . . . open the file or stream assigned to the
48+
** ERROR_OUTPUT global variable defined in
49+
** error.g, or "*errout*" otherwise
50+
*/
51+
UInt OpenErrorOutput( void )
52+
{
53+
/* Try to print the output to stream. Use *errout* as a fallback. */
54+
UInt ret = 0;
55+
56+
if (ERROR_OUTPUT != NULL) {
57+
if (IsStringConv(ERROR_OUTPUT)) {
58+
ret = OpenOutput(CSTR_STRING(ERROR_OUTPUT));
59+
}
60+
else {
61+
if (CALL_1ARGS(IsOutputStream, ERROR_OUTPUT) == True) {
62+
ret = OpenOutputStream(ERROR_OUTPUT);
63+
}
64+
}
65+
}
66+
67+
if (!ret) {
68+
/* It may be we already tried and failed to open *errout* above but
69+
* but this is an extreme case so it can't hurt to try again
70+
* anyways */
71+
ret = OpenOutput("*errout*");
72+
if (ret) {
73+
Pr("failed to open error stream\n", 0, 0);
74+
}
75+
else {
76+
Panic("failed to open *errout*");
77+
}
78+
}
79+
80+
return ret;
81+
}
82+
4383

4484
/****************************************************************************
4585
**
@@ -615,6 +655,8 @@ static Int InitKernel(StructInitInfo * module)
615655
InitHdlrFuncsFromTable(GVarFuncs);
616656

617657
ImportFuncFromLibrary("ErrorInner", &ErrorInner);
658+
ImportFuncFromLibrary("IsOutputStream", &IsOutputStream);
659+
ImportGVarFromLibrary("ERROR_OUTPUT", &ERROR_OUTPUT);
618660

619661
// return success
620662
return 0;

src/error.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ typedef void (*intfunc)(Int);
3030

3131
Int RegisterBreakloopObserver(intfunc func);
3232

33+
/****************************************************************************
34+
**
35+
*F OpenErrorOutput() . . . . . . . open the file or stream assigned to the
36+
** ERROR_OUTPUT global variable defined in
37+
** error.g, or "*errout*" otherwise
38+
*/
39+
extern UInt OpenErrorOutput();
40+
3341
/****************************************************************************
3442
**
3543
*F ErrorQuit( <msg>, <arg1>, <arg2> ) . . . . . . . . . . . print and quit

src/scanner.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "scanner.h"
1818

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

4445
// open error output
45-
OpenOutput("*errout*");
46+
OpenErrorOutput();
4647

4748
// print the message ...
4849
if (error)

0 commit comments

Comments
 (0)