Skip to content

Commit

Permalink
Unify printing of (statements in) kernel functions
Browse files Browse the repository at this point in the history
Moved some code out of PrintFunction into PrintKernelFunction

Fixes gap-system#1373
  • Loading branch information
fingolfin authored and ChrisJefferson committed Oct 25, 2018
1 parent 1ba602d commit 93120b0
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 48 deletions.
44 changes: 23 additions & 21 deletions src/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,27 +1166,7 @@ void PrintFunction (

/* print the body */
if (IsKernelFunction(func)) {
UInt outputtedfunc = 0;
if ( BODY_FUNC(func) ) {
Obj body = BODY_FUNC(func);
if ( GET_FILENAME_BODY(body) ) {
if ( GET_LOCATION_BODY(body) ) {
Pr("<<kernel code from %g:%g>>",
(Int)GET_FILENAME_BODY(body),
(Int)GET_LOCATION_BODY(body));
outputtedfunc = 1;
}
else if ( GET_STARTLINE_BODY(body) ) {
Pr("<<compiled GAP code from %g:%d>>",
(Int)GET_FILENAME_BODY(body),
GET_STARTLINE_BODY(body));
outputtedfunc = 1;
}
}
}
if(!outputtedfunc) {
Pr("<<kernel or compiled code>>",0L,0L);
}
PrintKernelFunction(func);
}
else {
SWITCH_TO_NEW_LVARS( func, narg, NLOC_FUNC(func),
Expand All @@ -1200,6 +1180,28 @@ void PrintFunction (
Pr("end",0L,0L);
}

void PrintKernelFunction(Obj func)
{
GAP_ASSERT(IsKernelFunction(func));
Obj body = BODY_FUNC(func);
Obj filename = body ? GET_FILENAME_BODY(body) : 0;
if (filename) {
if ( GET_LOCATION_BODY(body) ) {
Pr("<<kernel code>> from %g:%g",
(Int)filename,
(Int)GET_LOCATION_BODY(body));
}
else if ( GET_STARTLINE_BODY(body) ) {
Pr("<<compiled GAP code>> from %g:%d",
(Int)filename,
GET_STARTLINE_BODY(body));
}
}
else {
Pr("<<kernel or compiled code>>", 0, 0);
}
}


/****************************************************************************
**
Expand Down
2 changes: 2 additions & 0 deletions src/calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ extern Obj ArgStringToList(const Char *nams_c);
extern void PrintFunction (
Obj func );

extern void PrintKernelFunction(Obj func);


/****************************************************************************
**
Expand Down
48 changes: 24 additions & 24 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,36 +172,36 @@ Obj FuncPRINT_CURRENT_STATEMENT(Obj self, Obj stream, Obj context)
Obj func = FUNC_LVARS(context);
GAP_ASSERT(func);
Stat call = STAT_LVARS(context);
Obj body = BODY_FUNC(func);
if (IsKernelFunction(func)) {
Pr("<compiled statement> ", 0L, 0L);
/* HACK: close the output again */
CloseOutput();
return 0;
PrintKernelFunction(func);
Obj funcname = NAME_FUNC(func);
if (funcname) {
Pr(" in function %g", (Int)funcname, 0);
}
}
Obj body = BODY_FUNC(func);
if (call < OFFSET_FIRST_STAT ||
call > SIZE_BAG(body) - sizeof(StatHeader)) {
else if (call < OFFSET_FIRST_STAT ||
call > SIZE_BAG(body) - sizeof(StatHeader)) {
Pr("<corrupted statement> ", 0L, 0L);
/* HACK: close the output again */
CloseOutput();
return 0;
}
else {
Obj currLVars = STATE(CurrLVars);
SWITCH_TO_OLD_LVARS(context);
GAP_ASSERT(call == BRK_CALL_TO());

Obj currLVars = STATE(CurrLVars);
SWITCH_TO_OLD_LVARS(context);
GAP_ASSERT(call == BRK_CALL_TO());

Int type = TNUM_STAT(call);
Obj filename = GET_FILENAME_BODY(body);
if (FIRST_STAT_TNUM <= type && type <= LAST_STAT_TNUM) {
PrintStat(call);
Pr(" at %g:%d", (Int)filename, LINE_STAT(call));
}
else if (FIRST_EXPR_TNUM <= type && type <= LAST_EXPR_TNUM) {
PrintExpr(call);
Pr(" at %g:%d", (Int)filename, LINE_STAT(call));
Int type = TNUM_STAT(call);
Obj filename = GET_FILENAME_BODY(body);
if (FIRST_STAT_TNUM <= type && type <= LAST_STAT_TNUM) {
PrintStat(call);
Pr(" at %g:%d", (Int)filename, LINE_STAT(call));
}
else if (FIRST_EXPR_TNUM <= type && type <= LAST_EXPR_TNUM) {
PrintExpr(call);
Pr(" at %g:%d", (Int)filename, LINE_STAT(call));
}
SWITCH_TO_OLD_LVARS(currLVars);
}
SWITCH_TO_OLD_LVARS(currLVars);

/* HACK: close the output again */
CloseOutput();
return 0;
Expand Down
6 changes: 3 additions & 3 deletions tst/testinstall/varargs.tst
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ f := function(a,b..) end;
^^
gap> Display(RETURN_FIRST);
function ( object... )
<<kernel code from src/gap.c:RETURN_FIRST>>
<<kernel code>> from src/gap.c:RETURN_FIRST
end
gap> Print(INSTALL_METHOD_FLAGS,"\n");
function ( <<arg-1>>, <<arg-2>>, <<arg-3>>, <<arg-4>>, <<arg-5>>, <<arg-6>> )
<<compiled GAP code from GAPROOT/lib/oper1.g:146>>
<<compiled GAP code>> from GAPROOT/lib/oper1.g:146
end
gap> Display(InstallMethod);
function ( <<arg-1>>... )
<<compiled GAP code from GAPROOT/lib/oper1.g:337>>
<<compiled GAP code>> from GAPROOT/lib/oper1.g:337
end
gap> [1..2];
[ 1, 2 ]
Expand Down
3 changes: 3 additions & 0 deletions tst/testspecial/backtrace.g
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ l := [[1]];; f := {} -> l[2,1];;
f();
Where();
quit;

# verify issue #1373 is fixed
InstallMethod( Matrix, [IsFilter, IsSemiring, IsMatrixObj], {a,b,c} -> fail );
8 changes: 8 additions & 0 deletions tst/testspecial/backtrace.g.out
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,12 @@ return l[2, 1]; at *stdin*:39 called from
<function "f">( <arguments> )
called from read-eval loop at *errin*:1
brk> quit;
gap>
gap> # verify issue #1373 is fixed
gap> InstallMethod( Matrix, [IsFilter, IsSemiring, IsMatrixObj], {a,b,c} -> fail );
Error, <oper> must be an operation in
<<compiled GAP code>> from GAPROOT/lib/oper1.g:377 in function INSTALL_METHOD called from
<<compiled GAP code>> from GAPROOT/lib/oper1.g:337 in function InstallMethod called from
<function "InstallMethod">( <arguments> )
called from read-eval loop at *stdin*:42
gap> QUIT;

0 comments on commit 93120b0

Please sign in to comment.