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

Move SET_BRK_CALL_TO()s in funcs.c to resolve issue #917 #1814

Merged
merged 2 commits into from
Oct 31, 2017
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
98 changes: 50 additions & 48 deletions src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ UInt ExecProccallOpts(
**
** 'ExecProccall<i>args' executes a procedure call to the function
** 'FUNC_CALL(<call>)' with the arguments 'ARGI_CALL(<call>,1)' to
** 'ARGI_CALL(<call>,<i>)'. It returns the value returned by the function.
** 'ARGI_CALL(<call>,<i>)'. It discards the value returned by the function
** and returns the statement execution status (as per EXEC_STAT, q.v.)
** resulting from the procedure call, which in fact is always 0.
*/

static Obj DispatchFuncCall( Obj func, Int nargs, Obj arg1, Obj arg2, Obj arg3, Obj arg4, Obj arg5, Obj arg6)
Expand Down Expand Up @@ -168,10 +170,10 @@ UInt ExecProccall1args (
arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );

/* call the function */
SET_BRK_CALL_TO( call );
if (TNUM_OBJ(func) != T_FUNCTION)
DispatchFuncCall(func, 1, (Obj) arg1, (Obj) 0L, (Obj) 0L, (Obj) 0L, (Obj) 0L, (Obj) 0L);
else {
SET_BRK_CALL_TO( call );
CALL_1ARGS( func, arg1 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
Expand All @@ -198,10 +200,10 @@ UInt ExecProccall2args (
arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );

/* call the function */
SET_BRK_CALL_TO( call );
if (TNUM_OBJ(func) != T_FUNCTION)
DispatchFuncCall(func, 2, (Obj) arg1, (Obj) arg2, (Obj) 0L, (Obj) 0L, (Obj) 0L, (Obj) 0L);
else {
SET_BRK_CALL_TO( call );
CALL_2ARGS( func, arg1, arg2 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
Expand Down Expand Up @@ -230,10 +232,10 @@ UInt ExecProccall3args (
arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );

/* call the function */
SET_BRK_CALL_TO( call );
if (TNUM_OBJ(func) != T_FUNCTION)
DispatchFuncCall(func, 3, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) 0L, (Obj) 0L, (Obj) 0L);
else {
SET_BRK_CALL_TO( call );
CALL_3ARGS( func, arg1, arg2, arg3 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
Expand Down Expand Up @@ -264,10 +266,10 @@ UInt ExecProccall4args (
arg4 = EVAL_EXPR( ARGI_CALL( call, 4 ) );

/* call the function */
SET_BRK_CALL_TO( call );
if (TNUM_OBJ(func) != T_FUNCTION)
DispatchFuncCall(func, 4, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) 0, (Obj) 0);
else {
SET_BRK_CALL_TO( call );
CALL_4ARGS( func, arg1, arg2, arg3, arg4 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
Expand Down Expand Up @@ -300,10 +302,10 @@ UInt ExecProccall5args (
arg5 = EVAL_EXPR( ARGI_CALL( call, 5 ) );

/* call the function */
SET_BRK_CALL_TO( call );
if (TNUM_OBJ(func) != T_FUNCTION)
DispatchFuncCall(func, 5, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) 0L);
else {
SET_BRK_CALL_TO( call );
CALL_5ARGS( func, arg1, arg2, arg3, arg4, arg5 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
Expand Down Expand Up @@ -338,10 +340,10 @@ UInt ExecProccall6args (
arg6 = EVAL_EXPR( ARGI_CALL( call, 6 ) );

/* call the function */
SET_BRK_CALL_TO( call );
if (TNUM_OBJ(func) != T_FUNCTION)
DispatchFuncCall(func, 6, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) arg6);
else {
SET_BRK_CALL_TO( call );
CALL_6ARGS( func, arg1, arg2, arg3, arg4, arg5, arg6 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
Expand Down Expand Up @@ -375,10 +377,10 @@ UInt ExecProccallXargs (
}

/* call the function */
SET_BRK_CALL_TO( call );
if (TNUM_OBJ(func) != T_FUNCTION) {
DoOperation2Args(CallFuncListOper, func, args);
} else {
SET_BRK_CALL_TO( call );
CALL_XARGS( func, args );
}

Expand Down Expand Up @@ -441,13 +443,13 @@ Obj EvalFunccall0args (
/* evaluate the function */
func = EVAL_EXPR( FUNC_CALL( call ) );

if (TNUM_OBJ(func) != T_FUNCTION) {
return DispatchFuncCall(func, 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );
}

/* call the function and return the result */
SET_BRK_CALL_TO( call );
result = CALL_0ARGS( func );
if (TNUM_OBJ(func) != T_FUNCTION) {
result = DispatchFuncCall(func, 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );
} else {
result = CALL_0ARGS( func );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
READ() and the user quit from a break
loop inside it */
Expand All @@ -473,13 +475,13 @@ Obj EvalFunccall1args (
/* evaluate the arguments */
arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );

if (TNUM_OBJ(func) != T_FUNCTION) {
return DispatchFuncCall(func, 1, (Obj) arg1, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );
}

/* call the function and return the result */
SET_BRK_CALL_TO( call );
result = CALL_1ARGS( func, arg1 );
if (TNUM_OBJ(func) != T_FUNCTION) {
result = DispatchFuncCall(func, 1, (Obj) arg1, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );
} else {
result = CALL_1ARGS( func, arg1 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
READ() and the user quit from a break
loop inside it */
Expand Down Expand Up @@ -508,13 +510,13 @@ Obj EvalFunccall2args (
arg1 = EVAL_EXPR( ARGI_CALL( call, 1 ) );
arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );

if (TNUM_OBJ(func) != T_FUNCTION) {
return DispatchFuncCall(func, 2, (Obj) arg1, (Obj) arg2, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );
}

/* call the function and return the result */
SET_BRK_CALL_TO( call );
result = CALL_2ARGS( func, arg1, arg2 );
if (TNUM_OBJ(func) != T_FUNCTION) {
result = DispatchFuncCall(func, 2, (Obj) arg1, (Obj) arg2, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );
} else {
result = CALL_2ARGS( func, arg1, arg2 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
READ() and the user quit from a break
loop inside it */
Expand Down Expand Up @@ -545,13 +547,13 @@ Obj EvalFunccall3args (
arg2 = EVAL_EXPR( ARGI_CALL( call, 2 ) );
arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );

if (TNUM_OBJ(func) != T_FUNCTION) {
return DispatchFuncCall(func, 3, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) 0, (Obj) 0, (Obj) 0 );
}

/* call the function and return the result */
SET_BRK_CALL_TO( call );
result = CALL_3ARGS( func, arg1, arg2, arg3 );
if (TNUM_OBJ(func) != T_FUNCTION) {
result = DispatchFuncCall(func, 3, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) 0, (Obj) 0, (Obj) 0 );
} else {
result = CALL_3ARGS( func, arg1, arg2, arg3 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
READ() and the user quit from a break
loop inside it */
Expand Down Expand Up @@ -583,13 +585,13 @@ Obj EvalFunccall4args (
arg3 = EVAL_EXPR( ARGI_CALL( call, 3 ) );
arg4 = EVAL_EXPR( ARGI_CALL( call, 4 ) );

if (TNUM_OBJ(func) != T_FUNCTION) {
return DispatchFuncCall(func, 4, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) 0, (Obj) 0 );
}

/* call the function and return the result */
SET_BRK_CALL_TO( call );
result = CALL_4ARGS( func, arg1, arg2, arg3, arg4 );
if (TNUM_OBJ(func) != T_FUNCTION) {
result = DispatchFuncCall(func, 4, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) 0, (Obj) 0 );
} else {
result = CALL_4ARGS( func, arg1, arg2, arg3, arg4 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
READ() and the user quit from a break
loop inside it */
Expand Down Expand Up @@ -624,13 +626,13 @@ Obj EvalFunccall5args (
arg4 = EVAL_EXPR( ARGI_CALL( call, 4 ) );
arg5 = EVAL_EXPR( ARGI_CALL( call, 5 ) );

if (TNUM_OBJ(func) != T_FUNCTION) {
return DispatchFuncCall(func, 5, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) 0 );
}

/* call the function and return the result */
SET_BRK_CALL_TO( call );
result = CALL_5ARGS( func, arg1, arg2, arg3, arg4, arg5 );
if (TNUM_OBJ(func) != T_FUNCTION) {
result = DispatchFuncCall(func, 5, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) 0 );
} else {
result = CALL_5ARGS( func, arg1, arg2, arg3, arg4, arg5 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
READ() and the user quit from a break
loop inside it */
Expand Down Expand Up @@ -667,13 +669,13 @@ Obj EvalFunccall6args (
arg5 = EVAL_EXPR( ARGI_CALL( call, 5 ) );
arg6 = EVAL_EXPR( ARGI_CALL( call, 6 ) );

if (TNUM_OBJ(func) != T_FUNCTION) {
return DispatchFuncCall(func, 6, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) arg6 );
}

/* call the function and return the result */
SET_BRK_CALL_TO( call );
result = CALL_6ARGS( func, arg1, arg2, arg3, arg4, arg5, arg6 );
if (TNUM_OBJ(func) != T_FUNCTION) {
result = DispatchFuncCall(func, 6, (Obj) arg1, (Obj) arg2, (Obj) arg3, (Obj) arg4, (Obj) arg5, (Obj) arg6 );
} else {
result = CALL_6ARGS( func, arg1, arg2, arg3, arg4, arg5, arg6 );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
READ() and the user quit from a break
loop inside it */
Expand Down Expand Up @@ -708,13 +710,13 @@ Obj EvalFunccallXargs (
CHANGED_BAG( args );
}

if (TNUM_OBJ(func) != T_FUNCTION) {
return DispatchFuncCall(func, -1, (Obj) args, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );
}

/* call the function and return the result */
SET_BRK_CALL_TO( call );
result = CALL_XARGS( func, args );
if (TNUM_OBJ(func) != T_FUNCTION) {
result = DispatchFuncCall(func, -1, (Obj) args, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0, (Obj) 0 );
} else {
result = CALL_XARGS( func, args );
}
if (STATE(UserHasQuit) || STATE(UserHasQUIT)) /* the procedure must have called
READ() and the user quit from a break
loop inside it */
Expand Down
112 changes: 112 additions & 0 deletions tst/test-error/func-and-proc-call-trace.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
informproc0 := function(l)
Add(l,1);
l();
end;;
informproc0([]);
quit;
Print("\n\n");
informproc1 := function(l)
Add(l,1);
l(1);
end;;
informproc1([]);
quit;
Print("\n\n");
informproc2 := function(l)
Add(l,1);
l(1,2);
end;;
informproc2([]);
quit;
Print("\n\n");
informproc3 := function(l)
Add(l,1);
l(1,2,3);
end;;
informproc3([]);
quit;
Print("\n\n");
informproc4 := function(l)
Add(l,1);
l(1,2,3,4);
end;;
informproc4([]);
quit;
Print("\n\n");
informproc5 := function(l)
Add(l,1);
l(1,2,3,4,5);
end;;
informproc5([]);
quit;
Print("\n\n");
informproc6 := function(l)
Add(l,1);
l(1,2,3,4,5,6);
end;;
informproc6([]);
quit;
Print("\n\n");
informprocmore := function(l)
Add(l,1);
l(1,2,3,4,5,6,7);
end;;
informprocmore([]);
quit;
Print("\n\n");
informfunc0 := function(l)
Add(l,1);
Print(l());
end;;
informfunc0([]);
quit;
Print("\n\n");
informfunc1 := function(l)
Add(l,1);
Print(l(1));
end;;
informfunc1([]);
quit;
Print("\n\n");
informfunc2 := function(l)
Add(l,1);
Print(l(1,2));
end;;
informfunc2([]);
quit;
Print("\n\n");
informfunc3 := function(l)
Add(l,1);
Print(l(1,2,3));
end;;
informfunc3([]);
quit;
Print("\n\n");
informfunc4 := function(l)
Add(l,1);
Print(l(1,2,3,4));
end;;
informfunc4([]);
quit;
Print("\n\n");
informfunc5 := function(l)
Add(l,1);
Print(l(1,2,3,4,5));
end;;
informfunc5([]);
quit;
Print("\n\n");
informfunc6 := function(l)
Add(l,1);
Print(l(1,2,3,4,5,6));
end;;
informfunc6([]);
quit;
Print("\n\n");
informfuncmore := function(l)
Add(l,1);
Print(l(1,2,3,4,5,6,7));
end;;
informfuncmore([]);
quit;
Print("\n\n");
Loading