Skip to content

Commit

Permalink
Make error output use *errout* consistently
Browse files Browse the repository at this point in the history
- PRINT_CURRENT_STATEMENT now takes a stream as additional input.
- Adjust its tests accordingly.
- Make ErrorInner, Where, and WHERE consistently pass "*errout*"
to print functions
  • Loading branch information
ssiccha committed Jun 7, 2018
1 parent 8f47553 commit bedb0f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
14 changes: 7 additions & 7 deletions lib/error.g
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ BIND_GLOBAL("WHERE", function( context, depth, outercontext)
bottom := GetBottomLVars();
lastcontext := outercontext;
while depth > 0 and context <> bottom do
PRINT_CURRENT_STATEMENT(context);
Print(" called from\n");
PRINT_CURRENT_STATEMENT("*errout*", context);
PrintTo("*errout*", " called from\n");
lastcontext := context;
context := ParentLVars(context);
depth := depth-1;
od;
if depth = 0 then
Print("... ");
PrintTo("*errout*", "... ");
else
f := ContentsLVars(lastcontext).func;
Print("<function \"",NAME_FUNC(f)
PrintTo("*errout*", "<function \"",NAME_FUNC(f)
,"\">( <arguments> )\n called from read-eval loop ");
fi;
end);
Expand All @@ -75,11 +75,11 @@ BIND_GLOBAL("Where", function(arg)
fi;

if ErrorLVars = fail or ErrorLVars = GetBottomLVars() then
Print("not in any function ");
PrintTo("*errout*", "not in any function ");
else
WHERE(ParentLVars(ErrorLVars),depth, ErrorLVars);
fi;
Print("at ",INPUT_FILENAME(),":",INPUT_LINENUMBER(),"\n");
PrintTo("*errout*", "at ",INPUT_FILENAME(),":",INPUT_LINENUMBER(),"\n");
end);

OnBreak := Where;
Expand Down Expand Up @@ -204,7 +204,7 @@ BIND_GLOBAL("ErrorInner",
if printThisStatement then
if context <> GetBottomLVars() then
PrintTo("*errout*"," in\n \c");
PRINT_CURRENT_STATEMENT(context);
PRINT_CURRENT_STATEMENT("*errout*", context);
Print("\c");
PrintTo("*errout*"," called from \n");
else
Expand Down
16 changes: 14 additions & 2 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,16 @@ Obj FuncCURRENT_STATEMENT_LOCATION(Obj self, Obj context)
return retlist;
}

Obj FuncPRINT_CURRENT_STATEMENT(Obj self, Obj context)
Obj FuncPRINT_CURRENT_STATEMENT(Obj self, Obj stream, Obj context)
{
/* HACK: we want to redirect output */
int openedOutput = 1;
if ((IsStringConv(stream) && !OpenOutput(CSTR_STRING(stream))) ||
(!IS_STRING(stream) && !OpenOutputStream(stream))) {
Pr("Can't open output stream\n", 0L, 0L);
openedOutput = 0;
}

if (context == STATE(BottomLVars))
return 0;

Expand Down Expand Up @@ -186,6 +194,10 @@ Obj FuncPRINT_CURRENT_STATEMENT(Obj self, Obj context)
Pr(" at %g:%d", (Int)filename, LINE_STAT(call));
}
SWITCH_TO_OLD_LVARS(currLVars);
/* HACK: close the output again */
if (openedOutput) {
CloseOutput();
}
return 0;
}

Expand Down Expand Up @@ -578,7 +590,7 @@ static StructGVarFunc GVarFuncs[] = {
GVAR_FUNC(CALL_WITH_CATCH, 2, "func, args"),
GVAR_FUNC(JUMP_TO_CATCH, 1, "payload"),

GVAR_FUNC(PRINT_CURRENT_STATEMENT, 1, "context"),
GVAR_FUNC(PRINT_CURRENT_STATEMENT, 2, "stream, context"),
GVAR_FUNC(CURRENT_STATEMENT_LOCATION, 1, "context"),

GVAR_FUNC(SetUserHasQuit, 1, "value"),
Expand Down
6 changes: 3 additions & 3 deletions tst/testinstall/kernel/gap.tst
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ Error, usage: UpEnv( [ <depth> ] )
#
gap> CURRENT_STATEMENT_LOCATION(GetCurrentLVars());
fail
gap> PRINT_CURRENT_STATEMENT(GetCurrentLVars());
gap> f:=function() PRINT_CURRENT_STATEMENT(GetCurrentLVars()); Print("\n"); end;; f();
PRINT_CURRENT_STATEMENT( GetCurrentLVars( ) ); at stream:1
gap> PRINT_CURRENT_STATEMENT("*errout*", GetCurrentLVars());
gap> f:=function() PRINT_CURRENT_STATEMENT("*errout*", GetCurrentLVars()); Print("\n"); end;; f();
PRINT_CURRENT_STATEMENT( "*errout*", GetCurrentLVars( ) ); at *stdin*:1
#
gap> CALL_WITH_CATCH(fail,fail);
Expand Down

0 comments on commit bedb0f1

Please sign in to comment.