Opened 11 years ago
Closed 10 years ago
#3292 closed defect (fixed)
Wrong code for handling string arrays in the external functions
| Reported by: | Adrian Pop | Owned by: | Martin Sjölund |
|---|---|---|---|
| Priority: | high | Milestone: | 1.9.3 |
| Component: | Code Generation | Version: | trunk |
| Keywords: | Cc: |
Description (last modified by )
For string arrays outputs in a function (see also r25730 for an example):
function fmi1GetString input FMI1ModelExchange fmi1me; input Real stringValuesReferences[:]; input Real inFlowStatesInput; output String stringValues[size(stringValuesReferences, 1)]; external "C" fmi1GetString_OMC(fmi1me, size(stringValuesReferences, 1), stringValuesReferences, inFlowStatesInput, stringValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); end fmi1GetString;
we generate code like:
string_array omc_StringParameters__me__FMU_fmi1Functions_fmi1GetString(threadData_t *threadData, modelica_complex _fmi1me, real_array _stringValuesReferences, modelica_real _inFlowStatesInput)
{
void * _fmi1me_ext;
double _inFlowStatesInput_ext;
string_array _stringValues;
modelica_integer tmp1;
tmp1 = size_of_dimension_base_array(_stringValuesReferences, (modelica_integer) 1);
alloc_string_array(&_stringValues, 1, tmp1);
_fmi1me_ext = (void *)_fmi1me;
_inFlowStatesInput_ext = (double)_inFlowStatesInput;
fmi1GetString_OMC(_fmi1me_ext, size_of_dimension_base_array(_stringValuesReferences, (modelica_integer) 1), (const double*) data_of_real_c89_array(&(_stringValuesReferences)), _inFlowStatesInput_ext, (const char**) data_of_string_c89_array(&(_stringValues)), (modelica_integer) 1);
unpack_string_array(&_stringValues);
return _stringValues;
}
which is wrong as inside the external function call fmi1GetString_OMC we set the strings but when we come back we don't use the value that got changed via: (const char**) data_of_string_c89_array().
We should have something like:
X = (const char**) data_of_string_c89_array(); fmi1GetString_OMC(..., X, ...) unpack_string_array(&_stringValues, X);
Currently, running StringParameters.mos (r25730) leads to a crash in unpack_string_array.
Change History (6)
comment:1 by , 11 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 10 years ago
comment:3 by , 10 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → accepted |
comment:4 by , 10 years ago
| Owner: | changed from to |
|---|
comment:5 by , 10 years ago
The seg.fault sometimes occurs because we can't get string data of something that has not been allocated. So allocating a string array should probably initialize to an array of empty strings.
comment:6 by , 10 years ago
| Milestone: | Future → 1.9.3 |
|---|---|
| Resolution: | → fixed |
| Status: | accepted → closed |
Fixed in 50e2ca6.

See also #3391.