Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Handle reporting real stack overflow in Susan
Browse files Browse the repository at this point in the history
We use a fake stack overflow to signal some logic error in the
templates. This also checks for a real stack overflow so we can
report the stack overflow message.

Belonging to [master]:
  - #1978
  - OpenModelica/OpenModelica-testsuite#764
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Nov 6, 2017
1 parent 037d5bb commit b30e47a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions Compiler/Template/Tpl.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2004,22 +2004,27 @@ end failIfTrue;
protected function tplCallHandleErrors
input Tpl_Fun inFun;
input output Text txt = emptyTxt;
input Integer nArg;

partial function Tpl_Fun
input Text in_txt;
output Text out_txt;
end Tpl_Fun;
protected
Integer nErr;
algorithm
nErr := Error.getNumErrorMessages();
try
try
txt := inFun(txt);
else
addTemplateErrorFunc(nArg, inFun);
addTemplateErrorFunc(inFun);
fail();
end try;
else
addTemplateErrorFunc(nArg, inFun);
if StackOverflow.hasStacktraceMessages() then
Error.addInternalError("Stack overflow when evaluating function:\n"+ stringDelimitList(StackOverflow.readableStacktraceMessages(), "\n"), sourceInfo());
end if;
addTemplateErrorFunc(inFun);
fail();
end try annotation(__OpenModelica_stackOverflowCheckpoint=true);
end tplCallHandleErrors;
Expand All @@ -2033,7 +2038,7 @@ public function tplCallWithFailErrorNoArg
output Text out_txt;
end Tpl_Fun;
algorithm
txt := tplCallHandleErrors(inFun, txt, 0);
txt := tplCallHandleErrors(inFun, txt);
end tplCallWithFailErrorNoArg;

public function tplCallWithFailError
Expand All @@ -2049,7 +2054,7 @@ public function tplCallWithFailError
protected
ArgType1 arg;
algorithm
txt := tplCallHandleErrors(function inFun(inArgA=inArg), txt, 1);
txt := tplCallHandleErrors(function inFun(inArgA=inArg), txt);
end tplCallWithFailError;

public function tplCallWithFailError2
Expand All @@ -2068,7 +2073,7 @@ protected
ArgType1 argA;
ArgType2 argB;
algorithm
txt := tplCallHandleErrors(function inFun(inArgA=inArgA, inArgB=inArgB), txt, 2);
txt := tplCallHandleErrors(function inFun(inArgA=inArgA, inArgB=inArgB), txt);
end tplCallWithFailError2;

function tplCallWithFailError3
Expand All @@ -2086,7 +2091,7 @@ function tplCallWithFailError3
output Text out_txt;
end Tpl_Fun;
algorithm
txt := tplCallHandleErrors(function inFun(inArgA=inArgA, inArgB=inArgB, inArgC=inArgC), txt, 3);
txt := tplCallHandleErrors(function inFun(inArgA=inArgA, inArgB=inArgB, inArgC=inArgC), txt);
end tplCallWithFailError3;

function tplCallWithFailError4
Expand All @@ -2106,7 +2111,7 @@ function tplCallWithFailError4
output Text out_txt;
end Tpl_Fun;
algorithm
txt := tplCallHandleErrors(function func(inArgA=argA, inArgB=argB, inArgC=argC, inArgD=argD), txt, 4);
txt := tplCallHandleErrors(function func(inArgA=argA, inArgB=argB, inArgC=argC, inArgD=argD), txt);
end tplCallWithFailError4;

public function tplString
Expand Down Expand Up @@ -2432,10 +2437,9 @@ end addSourceTemplateError;
//for completeness
protected function addTemplateErrorFunc<T>
"Wraps call to Error.addMessage() funtion with Error.TEMPLATE_ERROR and one MessageToken."
input Integer numArg;
input T func;
algorithm
Error.addMessage(Error.TEMPLATE_ERROR_FUNC, {String(numArg), System.dladdr(func)});
Error.addMessage(Error.TEMPLATE_ERROR_FUNC, {System.dladdr(func)});
end addTemplateErrorFunc;

public function addTemplateError
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Util/Error.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ public constant Message SUSAN_NOTIFY = MESSAGE(7012, TRANSLATION(), NOTIFICATION
public constant Message PDEModelica_ERROR = MESSAGE(7013, TRANSLATION(), ERROR(),
Util.gettext("PDEModelica: %s"));
public constant Message TEMPLATE_ERROR_FUNC = MESSAGE(7014, TRANSLATION(), ERROR(),
Util.gettext("Template error: A template call failed (a call with %s parameters: %s). One possible reason could be that a template imported function call failed (which should not happen for functions called from within template code; templates preserve pure 'match'/non-failing semantics)."));
Util.gettext("Template error: A template call failed (%s). One possible reason could be that a template imported function call failed (which should not happen for functions called from within template code; templates assert pure 'match'/non-failing semantics)."));
public constant Message FMU_EXPORT_NOT_SUPPORTED_CPP = MESSAGE(7015, SCRIPTING(), WARNING(),
Util.gettext("Export of FMU type %s is not supported with Cpp target. FMU will be for Model Exchange (me)."));
public constant Message DEPRECATED_API_CALL = MESSAGE(7016, SCRIPTING(), WARNING(),
Expand Down

0 comments on commit b30e47a

Please sign in to comment.