Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a long standing bug which prevented SetPrintFormattingStatus( "*stdout*", false ); from working as expected #4132

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,14 @@ typedef const struct init_info StructInitInfo;
typedef struct TypInputFile TypInputFile;


/****************************************************************************
**
*T TypOutputFile . . . . . . . . . . structure of an open output file, local
**
** This is a forward declaration so that TypOutputFiles can be used in
** header files. The actual declaration is in io.h.
*/
typedef struct TypOutputFile TypOutputFile;


#endif // GAP_COMMON_H
14 changes: 5 additions & 9 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5190,21 +5190,17 @@ static void CompFunc(Obj func)

/****************************************************************************
**
*F CompileFunc( <output>, <func>, <name>, <magic1>, <magic2> ) . . . compile
*F CompileFunc( <filename>, <func>, <name>, <magic1>, <magic2> ) . . compile
*/
Int CompileFunc (
Obj output,
Obj func,
Obj name,
Int magic1,
Obj magic2 )
Int CompileFunc(Obj filename, Obj func, Obj name, Int magic1, Obj magic2)
{
Int i; /* loop variable */
UInt col;
UInt compFunctionsNr;

/* open the output file */
if (!OpenOutput(CONST_CSTR_STRING(output), FALSE)) {
TypOutputFile output = { 0 };
if (!OpenOutput(&output, CONST_CSTR_STRING(filename), FALSE)) {
return 0;
}
col = SyNrCols;
Expand Down Expand Up @@ -5371,7 +5367,7 @@ Int CompileFunc (

/* close the output file */
SyNrCols = col;
CloseOutput();
CloseOutput(&output);

return compFunctionsNr;
}
Expand Down
17 changes: 9 additions & 8 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ static Obj IsOutputStream;
** ERROR_OUTPUT global variable defined in
** error.g, or "*errout*" otherwise
*/
UInt OpenErrorOutput( void )
UInt OpenErrorOutput(TypOutputFile * output)
{
/* 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(CONST_CSTR_STRING(ERROR_OUTPUT), FALSE);
ret = OpenOutput(output, CONST_CSTR_STRING(ERROR_OUTPUT), FALSE);
}
else {
if (CALL_1ARGS(IsOutputStream, ERROR_OUTPUT) == True) {
ret = OpenOutputStream(ERROR_OUTPUT);
ret = OpenOutputStream(output, ERROR_OUTPUT);
}
}
}
Expand All @@ -75,7 +75,7 @@ UInt OpenErrorOutput( void )
/* 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*", FALSE);
ret = OpenOutput(output, "*errout*", FALSE);
if (ret) {
Pr("failed to open error stream\n", 0, 0);
}
Expand Down Expand Up @@ -173,10 +173,11 @@ static Obj FuncPRINT_CURRENT_STATEMENT(Obj self, Obj stream, Obj context)

/* HACK: we want to redirect output */
/* Try to print the output to stream. Use *errout* as a fallback. */
TypOutputFile output = { 0 };
if ((IsStringConv(stream) &&
!OpenOutput(CONST_CSTR_STRING(stream), FALSE)) ||
(!IS_STRING(stream) && !OpenOutputStream(stream))) {
if (OpenOutput("*errout*", FALSE)) {
!OpenOutput(&output, CONST_CSTR_STRING(stream), FALSE)) ||
(!IS_STRING(stream) && !OpenOutputStream(&output, stream))) {
if (OpenOutput(&output, "*errout*", FALSE)) {
Pr("PRINT_CURRENT_STATEMENT: failed to open error stream\n", 0, 0);
}
else {
Expand Down Expand Up @@ -216,7 +217,7 @@ static Obj FuncPRINT_CURRENT_STATEMENT(Obj self, Obj stream, Obj context)
}

/* HACK: close the output again */
CloseOutput();
CloseOutput(&output);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Int RegisterBreakloopObserver(intfunc func);
** ERROR_OUTPUT global variable defined in
** error.g, or "*errout*" otherwise
*/
UInt OpenErrorOutput(void);
UInt OpenErrorOutput(TypOutputFile * output);

/****************************************************************************
**
Expand Down
7 changes: 4 additions & 3 deletions src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,14 @@ static Obj Shell(Obj context,
}

/* read-eval-print loop */
if (!OpenOutput(outFile, FALSE))
TypOutputFile output = { 0 };
if (!OpenOutput(&output, outFile, FALSE))
ErrorQuit("SHELL: can't open outfile %s",(Int)outFile,0);

TypInputFile input = { 0 };
if (!OpenInput(&input, inFile))
{
CloseOutput();
CloseOutput(&output);
ErrorQuit("SHELL: can't open infile %s",(Int)inFile,0);
}

Expand Down Expand Up @@ -317,7 +318,7 @@ static Obj Shell(Obj context,

SetPrintObjState(oldPrintObjState);
CloseInput(&input);
CloseOutput();
CloseOutput(&output);
STATE(ErrorLLevel) = oldErrorLLevel;
SetRecursionDepth(oldRecursionDepth);

Expand Down
Loading