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

Commit 0cdd3ea

Browse files
adrpoOpenModelica-Hudson
authored andcommitted
fix ticket:5134, pass by reference
Belonging to [master]: - #2674 - OpenModelica/OpenModelica-testsuite#1039
1 parent d671df5 commit 0cdd3ea

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

Compiler/Template/CodegenCFunctions.tpl

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -844,14 +844,13 @@ template extReturnType(SimExtArg extArg)
844844
"Generates return type for external function."
845845
::=
846846
match extArg
847-
case ex as SIMEXTARG(__) then extType(type_,true /*Treat this as an input (pass by value)*/,false)
847+
case ex as SIMEXTARG(__) then extType(type_,true /*Treat this as an input (pass by value, except for records)*/,false,true)
848848
case SIMNOEXTARG(__) then "void"
849849
case SIMEXTARGEXP(__) then error(sourceInfo(), 'Expression types are unsupported as return arguments <%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
850850
else error(sourceInfo(), "Unsupported return argument")
851851
end extReturnType;
852852

853-
854-
template extType(Type type, Boolean isInput, Boolean isArray)
853+
template extType(Type type, Boolean isInput, Boolean isArray, Boolean returnType)
855854
"Generates type for external function argument or return value."
856855
::=
857856
let s = match type
@@ -860,11 +859,11 @@ template extType(Type type, Boolean isInput, Boolean isArray)
860859
case T_STRING(__) then "const char*"
861860
case T_BOOL(__) then "int"
862861
case T_ENUMERATION(__) then "int"
863-
case T_ARRAY(__) then extType(ty,isInput,true)
862+
case T_ARRAY(__) then extType(ty,isInput,true,returnType)
864863
case T_COMPLEX(complexClassType=EXTERNAL_OBJ(__))
865864
then "void *"
866865
case T_COMPLEX(complexClassType=RECORD(path=rname))
867-
then '<%underscorePath(rname)%>'
866+
then '<%underscorePath(rname)%><%if returnType then "" else "*"%>'
868867
case T_METATYPE(__)
869868
case T_METABOXED(__)
870869
then "modelica_metatype"
@@ -901,12 +900,12 @@ template extFunDefArg(SimExtArg extArg)
901900
match extArg
902901
case SIMEXTARG(cref=c, isInput=ii, isArray=ia, type_=t) then
903902
let name = contextCref(c,contextFunction,&auxFunction)
904-
let typeStr = extType(t,ii,ia)
903+
let typeStr = extType(t,ii,ia,false)
905904
<<
906905
<%typeStr%> /*<%name%>*/
907906
>>
908907
case SIMEXTARGEXP(__) then
909-
let typeStr = extType(type_,true,false)
908+
let typeStr = extType(type_,true,false,false)
910909
<<
911910
<%typeStr%>
912911
>>
@@ -2127,7 +2126,7 @@ template extFunCallC(Function fun, Text &preExp, Text &varDecls, Text &auxFuncti
21272126
match fun
21282127
case EXTERNAL_FUNCTION(__) then
21292128
/* adpro: 2011-06-24 do vardecls -> extArgs as there might be some sets in there! */
2130-
let &preExp += (List.union(extArgs, extArgs) |> arg => extFunCallVardecl(arg, &varDecls, &auxFunction) ;separator="\n")
2129+
let &preExp += (List.union(extArgs, extArgs) |> arg => extFunCallVardecl(arg, &varDecls, &auxFunction, false) ;separator="\n")
21312130
let _ = (biVars |> bivar => extFunCallBiVar(bivar, &preExp, &varDecls, &auxFunction) ;separator="\n")
21322131
let fname = if dynamicLoad then 'ptr_<%extFunctionName(extName, language)%>' else '<%extName%>'
21332132
let dynamicCheck = if dynamicLoad then
@@ -2145,7 +2144,7 @@ case EXTERNAL_FUNCTION(__) then
21452144
else
21462145
""
21472146
<<
2148-
<%match extReturn case SIMEXTARG(__) then extFunCallVardecl(extReturn, &varDecls, &auxFunction)%>
2147+
<%match extReturn case SIMEXTARG(__) then extFunCallVardecl(extReturn, &varDecls, &auxFunction, true)%>
21492148
<%dynamicCheck%>
21502149
<%returnAssign%><%fname%>(<%args%>);
21512150
<%extArgs |> arg => extFunCallVarcopy(arg, &auxFunction) ;separator="\n"%>
@@ -2187,7 +2186,7 @@ case EXTERNAL_FUNCTION(__) then
21872186

21882187
end extFunCallF77;
21892188

2190-
template extFunCallVardecl(SimExtArg arg, Text &varDecls, Text &auxFunction)
2189+
template extFunCallVardecl(SimExtArg arg, Text &varDecls, Text &auxFunction, Boolean isReturn)
21912190
"Helper to extFunCall."
21922191
::=
21932192
match arg
@@ -2218,15 +2217,15 @@ template extFunCallVardecl(SimExtArg arg, Text &varDecls, Text &auxFunction)
22182217
else
22192218
error(sourceInfo(), 'Got function pointer that is not a CREF_IDENT: <%crefStr(c)%>, <%unparseType(ty)%>'))
22202219
else
2221-
let &varDecls += '<%extType(ty,true,false)%> <%extVarName(c)%>;<%\n%>'
2220+
let &varDecls += '<%extType(ty,true,false,false)%> <%extVarName(c)%>;<%\n%>'
22222221
<<
2223-
<%extVarName(c)%> = (<%extType(ty,true,false)%>)<%contextCref(c,contextFunction,&auxFunction)%>;
2222+
<%extVarName(c)%> = (<%extType(ty,true,false,false)%>)<%match ty case T_COMPLEX(complexClassType=RECORD(__)) then "&" else ""%><%contextCref(c,contextFunction,&auxFunction)%>;
22242223
>>
22252224
case SIMEXTARG(outputIndex=oi, isArray=false, type_=ty, cref=c) then
22262225
match oi case 0 then
22272226
""
22282227
else
2229-
let &varDecls += '<%extType(ty,true,false)%> <%extVarName(c)%>;<%\n%>'
2228+
let &varDecls += '<%extType(ty,true,false,true)%> <%extVarName(c)%>;<%\n%>'
22302229
""
22312230
end extFunCallVardecl;
22322231

@@ -2361,7 +2360,7 @@ template extArg(SimExtArg extArg, Text &preExp, Text &varDecls, Text &auxFunctio
23612360
let shortTypeStr = expTypeShort(t)
23622361
let &varDecls += 'void *<%name%>_c89;<%\n%>'
23632362
let &preExp += '<%name%>_c89 = (void*) data_of_<%shortTypeStr%>_c89_array(&(<%name%>));<%\n%>'
2364-
'(<%extType(t,isInput,true)%>) <%name%>_c89'
2363+
'(<%extType(t,isInput,true,false)%>) <%name%>_c89'
23652364
case SIMEXTARG(cref=c, isInput=ii, outputIndex=0, type_=t) then
23662365
let cr = match t case T_STRING(__) then contextCref(c,contextFunction,&auxFunction) else extVarName(c)
23672366
(match t case T_STRING(__) then 'MMC_STRINGDATA(<%cr%>)' else cr)
@@ -4400,7 +4399,7 @@ template daeExternalCExp(Exp exp, Context context, Text &preExp, Text &varDecls,
44004399
match typeof(exp)
44014400
case T_ARRAY(__) then // Array-expressions
44024401
let shortTypeStr = expTypeShort(typeof(exp))
4403-
'(<%extType(typeof(exp),true,true)%>) data_of_<%shortTypeStr%>_array(&<%daeExp(exp, context, &preExp, &varDecls, &auxFunction)%>)'
4402+
'(<%extType(typeof(exp),true,true,false)%>) data_of_<%shortTypeStr%>_array(&<%daeExp(exp, context, &preExp, &varDecls, &auxFunction)%>)'
44044403
case T_STRING(__) then
44054404
let mstr = daeExp(exp, context, &preExp, &varDecls, &auxFunction)
44064405
'MMC_STRINGDATA(<%mstr%>)'
@@ -4413,7 +4412,7 @@ template daeExternalF77Exp(Exp exp, Context context, Text &preExp, Text &varDecl
44134412
match typeof(exp)
44144413
case T_ARRAY(__) then // Array-expressions
44154414
let shortTypeStr = expTypeShort(typeof(exp))
4416-
'(<%extType(typeof(exp),true,true)%>) data_of_<%shortTypeStr%>_array(&<%daeExp(exp, context, &preExp, &varDecls, &auxFunction)%>)'
4415+
'(<%extType(typeof(exp),true,true,false)%>) data_of_<%shortTypeStr%>_array(&<%daeExp(exp, context, &preExp, &varDecls, &auxFunction)%>)'
44174416
case T_STRING(__) then
44184417
let texp = daeExp(exp, contextFunction, &preExp, &varDecls, &auxFunction)
44194418
let tvar = tempDecl(expTypeFromExpFlag(exp,8),&varDecls)

SimulationRuntime/c/gc/omc_gc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ typedef struct threadData_s {
141141
void *stackBottom; /* Actually offset 64 kB from bottom, just to never reach the bottom */
142142
} threadData_t;
143143

144+
#if defined(OMC_BOOTSTRAPPING_STAGE_1) || defined(OMC_BOOTSTRAPPING_STAGE_2)
144145
typedef threadData_t* OpenModelica_threadData_ThreadData;
146+
#else
147+
typedef threadData_t OpenModelica_threadData_ThreadData;
148+
#endif
145149

146150
#include "meta/meta_modelica_segv.h"
147151
void mmc_do_out_of_memory() __attribute__ ((noreturn));

0 commit comments

Comments
 (0)