Skip to content

Commit

Permalink
Handle external string arrays better (fixes #3292)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Aug 4, 2015
1 parent 8b6bf38 commit 50e2ca6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 68 deletions.
16 changes: 11 additions & 5 deletions Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -1316,8 +1316,8 @@ case efn as EXTERNAL_FUNCTION(__) then
{
<%varDecls%>
<%modelicaLine(info)%>
<%preExp%>
<%outputAlloc%>
<%preExp%>
<%callPart%>
<%outVarAssign%>
<%match outVars
Expand Down Expand Up @@ -2031,7 +2031,7 @@ template extFunCallC(Function fun, Text &preExp, Text &varDecls, Text &auxFuncti
match fun
case EXTERNAL_FUNCTION(__) then
/* adpro: 2011-06-24 do vardecls -> extArgs as there might be some sets in there! */
let varDecs = (List.union(extArgs, extArgs) |> arg => extFunCallVardecl(arg, &varDecls, &auxFunction) ;separator="\n")
let &preExp += (List.union(extArgs, extArgs) |> arg => extFunCallVardecl(arg, &varDecls, &auxFunction) ;separator="\n")
let _ = (biVars |> bivar => extFunCallBiVar(bivar, &preExp, &varDecls, &auxFunction) ;separator="\n")
let fname = if dynamicLoad then 'ptr_<%extFunctionName(extName, language)%>' else '<%extName%>'
let dynamicCheck = if dynamicLoad then
Expand All @@ -2049,7 +2049,6 @@ case EXTERNAL_FUNCTION(__) then
else
""
<<
<%varDecs%>
<%match extReturn case SIMEXTARG(__) then extFunCallVardecl(extReturn, &varDecls, &auxFunction)%>
<%dynamicCheck%>
<%returnAssign%><%fname%>(<%args%>);
Expand Down Expand Up @@ -2101,6 +2100,11 @@ template extFunCallVardecl(SimExtArg arg, Text &varDecls, Text &auxFunction)
case "integer" then
'pack_integer_array(&<%contextCref(c,contextFunction,&auxFunction)%>);'
else ""
case SIMEXTARG(isInput = false, isArray = true, type_ = ty, cref = c) then
match expTypeShort(ty)
case "string" then
'fill_string_array(&<%contextCref(c,contextFunction,&auxFunction)%>, mmc_string_uninitialized);<%\n%>'
else ""
case SIMEXTARG(isInput=true, isArray=false, type_=ty, cref=c) then
match ty
case T_STRING(__) then
Expand Down Expand Up @@ -2214,7 +2218,7 @@ case SIMEXTARG(outputIndex=oi, isArray=true, cref=c, type_=ty) then
case "integer" then
'unpack_integer_array(&<%contextCref(c,contextFunction,&auxFunction)%>);'
case "string" then
'unpack_string_array(&<%contextCref(c,contextFunction,&auxFunction)%>);'
'unpack_string_array(&<%contextCref(c,contextFunction,&auxFunction)%>, <%contextCref(c,contextFunction,&auxFunction)%>_c89);'
else ""
case SIMEXTARG(outputIndex=oi, isArray=false, type_=ty, cref=c) then
let cr = '<%extVarName(c)%>'
Expand Down Expand Up @@ -2251,7 +2255,9 @@ template extArg(SimExtArg extArg, Text &preExp, Text &varDecls, Text &auxFunctio
case SIMEXTARG(cref=c, outputIndex=oi, isArray=true, type_=t) then
let name = contextCref(c,contextFunction,&auxFunction)
let shortTypeStr = expTypeShort(t)
'(<%extType(t,isInput,true)%>) data_of_<%shortTypeStr%>_c89_array(&(<%name%>))'
let &varDecls += 'void *<%name%>_c89;<%\n%>'
let &preExp += '<%name%>_c89 = (void*) data_of_<%shortTypeStr%>_c89_array(&(<%name%>));<%\n%>'
'(<%extType(t,isInput,true)%>) <%name%>_c89'
case SIMEXTARG(cref=c, isInput=ii, outputIndex=0, type_=t) then
let cr = match t case T_STRING(__) then contextCref(c,contextFunction,&auxFunction) else extVarName(c)
(match t case T_STRING(__) then 'MMC_STRINGDATA(<%cr%>)' else cr)
Expand Down
4 changes: 4 additions & 0 deletions SimulationRuntime/c/meta/meta_modelica_gen_string_lit.sh
Expand Up @@ -5,6 +5,7 @@ echo '#ifndef __META_MODELICA_STRING_LIT__H'
echo '#define __META_MODELICA_STRING_LIT__H'
echo 'extern void *mmc_emptystring;'
echo 'extern void *mmc_strings_len1[256];'
echo 'extern void *mmc_string_uninitialized;'
echo '#endif'
exit
fi
Expand Down Expand Up @@ -33,6 +34,9 @@ done
echo "};"
echo

echo 'static MMC_DEFSTRINGLIT(OMC_STRINGLIT_UNINITIALIZED,23,"$#*OMC_UNINITIALIZED*#$");'
echo 'void* mmc_string_uninitialized = MMC_REFSTRINGLIT(OMC_STRINGLIT_UNINITIALIZED);'

exit
# The rest is not used because the gain is not known

Expand Down
32 changes: 2 additions & 30 deletions SimulationRuntime/c/meta/meta_modelica_string_lit.c
@@ -1,33 +1,3 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
* GPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the OSMC (Open Source Modelica Consortium)
* Public License (OSMC-PL) are obtained from OSMC, either from the above
* address, from the URLs: http://www.openmodelica.org or
* http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica
* distribution. GNU version 3 is obtained from:
* http://www.gnu.org/copyleft/gpl.html. The New BSD License is obtained from:
* http://www.opensource.org/licenses/BSD-3-Clause.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS
* EXPRESSLY SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE
* CONDITIONS OF OSMC-PL.
*
*/

#include "meta_modelica.h"
static const MMC_DEFSTRINGLIT(OMC_STRINGLIT_0,0,"");
void* mmc_emptystring = MMC_REFSTRINGLIT(OMC_STRINGLIT_0);
Expand Down Expand Up @@ -545,3 +515,5 @@ MMC_REFSTRINGLIT(OMC_STRINGLIT_1_FE),
MMC_REFSTRINGLIT(OMC_STRINGLIT_1_FF),
};

static MMC_DEFSTRINGLIT(OMC_STRINGLIT_UNINITIALIZED,23,"$#*OMC_UNINITIALIZED*#$");
void* mmc_string_uninitialized = MMC_REFSTRINGLIT(OMC_STRINGLIT_UNINITIALIZED);
31 changes: 1 addition & 30 deletions SimulationRuntime/c/meta/meta_modelica_string_lit.h
@@ -1,35 +1,6 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
* GPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the OSMC (Open Source Modelica Consortium)
* Public License (OSMC-PL) are obtained from OSMC, either from the above
* address, from the URLs: http://www.openmodelica.org or
* http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica
* distribution. GNU version 3 is obtained from:
* http://www.gnu.org/copyleft/gpl.html. The New BSD License is obtained from:
* http://www.opensource.org/licenses/BSD-3-Clause.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS
* EXPRESSLY SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE
* CONDITIONS OF OSMC-PL.
*
*/

#ifndef __META_MODELICA_STRING_LIT__H
#define __META_MODELICA_STRING_LIT__H
extern void *mmc_emptystring;
extern void *mmc_strings_len1[256];
extern void *mmc_string_uninitialized;
#endif
3 changes: 1 addition & 2 deletions SimulationRuntime/c/util/string_array.c
Expand Up @@ -951,11 +951,10 @@ const char** data_of_string_c89_array(const string_array_t *a)
return res;
}

void unpack_string_array(const string_array_t *a)
void unpack_string_array(const string_array_t *a, const char **data)
{
size_t sz = base_array_nr_of_elements(*a);
long i;
void **data = (void**) a->data;
for (i=0; i<sz; i++) {
data[i] = mmc_mk_scon(data[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/util/string_array.h
Expand Up @@ -177,6 +177,6 @@ extern void convert_alloc_string_array_from_f77(const string_array_t * a,

extern void fill_alloc_real_array(real_array_t* dest, modelica_real value, int ndims, ...);

extern void unpack_string_array(const string_array_t *a);
extern void unpack_string_array(const string_array_t *a, const char **data);

#endif

0 comments on commit 50e2ca6

Please sign in to comment.