Skip to content

Commit

Permalink
Update bootstrapping sources, strdup workarounds for string assignments
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17055 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 3, 2013
1 parent bbe882a commit 77a3051
Showing 1 changed file with 0 additions and 66 deletions.
66 changes: 0 additions & 66 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -5271,53 +5271,6 @@ template varOutput(Variable var, String dest, Integer ix, Text &varDecls,
"Generates code to copy result value from a function to dest."
::=
match var
/* The storage size of arrays is known at call time, so they can be allocated
* before set_memory_state. Strings are not known, so we copy them, etc...
*/
case var as VARIABLE(ty = T_STRING(__)) then
if not acceptMetaModelicaGrammar() then
// We need to strdup() all strings, then allocate them on the memory pool again, then free the temporary string
if instDims then
let instDimsInit = (instDims |> exp =>
daeExp(exp, contextFunction, &varInits /*BUFC*/, &varDecls /*BUFD*/)
;separator=", ")
let loopVar = tempDecl("long", &varDecls)
let sz = tempDecl("long", &varDecls)
let strVar = tempDecl("modelica_string_t *", &varDecls)
let &varCopy += '<%sz%> = base_array_nr_of_elements(&<%contextCref(var.name,contextFunction)%>);<%\n%>'
let &varCopy +=
<<
<%strVar%> = (modelica_string_t*) malloc(<%sz%>*sizeof(modelica_string_t));
for (<%loopVar%>=0;<%loopVar%><<%sz%>;<%loopVar%>++)
{
<%strVar%>[<%loopVar%>] = strdup(string_get(&<%contextCref(var.name,contextFunction)%>,<%loopVar%>));<%\n%>
}
<%\n%>>>
let destTarget = '(&<%dest%>.c<%ix%>)'
let &varInits += 'alloc_<%expTypeShort(var.ty)%>_array(<%destTarget%>, <%listLength(instDims)%>, <%instDimsInit%>);<%\n%>'
// let &varAssign += 'copy_<%expTypeShort(var.ty)%>_array_data(&<%contextCref(var.name,contextFunction)%>, &<%dest%>.c<%ix%>);<%\n%>'
let &varAssign +=
<<
for (<%loopVar%>=0;<%loopVar%><<%sz%>;<%loopVar%>++)
{
((modelica_string_t*) <%destTarget%>->data)[<%loopVar%>] = init_modelica_string(<%strVar%>[<%loopVar%>]);
free(<%strVar%>[<%loopVar%>]);<%\n%>
}
free(<%strVar%>);<%\n%>
>>
""
else
let strVar = tempDecl("modelica_string_t", &varDecls)
let &varCopy += '<%strVar%> = strdup(<%contextCref(var.name,contextFunction)%>);<%\n%>'
let &varAssign +=
<<
<%dest%>.c<%ix%> = init_modelica_string(<%strVar%>);
free(<%strVar%>);<%\n%>
>>
""
else
let &varAssign += '<%dest%>.c<%ix%> = <%contextCref(var.name,contextFunction)%>;<%\n%>'
""
case var as VARIABLE(__) then
let instDimsInit = (instDims |> exp =>
daeExp(exp, contextFunction, &varInits /*BUFC*/, &varDecls /*BUFD*/)
Expand Down Expand Up @@ -5403,24 +5356,6 @@ template varOutputKernelInterface(Variable var, String dest, Integer ix, Text &v
"Generates code to copy result value from a function to dest."
::=
match var
/* The storage size of arrays is known at call time, so they can be allocated
* before set_memory_state. Strings are not known, so we copy them, etc...
*/
case var as VARIABLE(ty = T_STRING(__)) then
if not acceptMetaModelicaGrammar() then
// We need to strdup() all strings, then allocate them on the memory pool again, then free the temporary string
let strVar = tempDecl("modelica_string_t", &varDecls)
let &varCopy += '<%strVar%> = strdup(<%contextCref(var.name,contextFunction)%>);<%\n%>'
let &varAssign +=
<<
<%dest%>.c<%ix%> = init_modelica_string(<%strVar%>);
free(<%strVar%>);<%\n%>
>>
""
else
let &varAssign += '<%dest%>.c<%ix%> = <%contextCref(var.name,contextFunction)%>;<%\n%>'
""

case var as VARIABLE(parallelism = PARGLOBAL(__)) then
let &varDecls += '<%varType(var)%> <%contextCref(var.name,contextFunction)%>;<%\n%>'
let varName = '<%contextCref(var.name,contextFunction)%>'
Expand Down Expand Up @@ -9760,7 +9695,6 @@ int rml_execution_failed(mmc_GC_local_state_type local_GC_state)

int main(int argc, char **argv)
{
OpenModelica_ExternalC_allocation_function = mmc_mk_scon_len_ret_ptr;
init_metamodelica_segv_handler();
mmc_GC_init(mmc_GC_settings_default);
Expand Down

0 comments on commit 77a3051

Please sign in to comment.