Opened 10 years ago

Last modified 9 years ago

#3292 closed defect

Wrong code for handling string arrays in the external functions — at Initial Version

Reported by: Adrian Pop Owned by: Lennart Ochel
Priority: high Milestone: 1.9.3
Component: Code Generation Version: trunk
Keywords: Cc:

Description

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 (0)

Note: See TracTickets for help on using tickets.