Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record seem to be not fully copied when passed to external C function #8849

Closed
mwetter opened this issue Apr 21, 2022 · 2 comments
Closed

Record seem to be not fully copied when passed to external C function #8849

mwetter opened this issue Apr 21, 2022 · 2 comments
Labels
COMP/OMC/Runtime Issues and pull requests related to the runtime for OMC (not simulation runtime).
Milestone

Comments

@mwetter
Copy link

mwetter commented Apr 21, 2022

Description

The model below uses a C function to print the value of a record. The first element of the record is printed correctly, but the second element is incorrectly 0. It looks like the value is not set when passing the record to the C function.

Steps to Reproduce

Run the model:

model TestRecord

  record MyRec
    parameter Integer i = 5;
    parameter Integer j = 6;
  end MyRec;

  parameter MyRec rec;

  function printRecord
    input MyRec rec;

    external "C" myPrint(rec, rec.i, rec.j);
    annotation (Include="#include \"myPrint.c\"");
  end printRecord;

initial equation
  printRecord(rec);
end TestRecord;

using the C function

#include "ModelicaUtilities.h"

typedef struct{
    int i;
    int j;
} myStruc;

void myPrint(
  const myStruc* myRecord,
  int i,
  int j){
    ModelicaFormatMessage("i: Record value = %i, primitive value = %i", myRecord->i, i);
    ModelicaFormatMessage("j: Record value = %i, primitive value = %i", myRecord->j, j);
  }

Expected Behavior

i and j should each have the same value, but myRecord->j is 0. The console output is

i: Record value = 5, primitive value = 5
j: Record value = 0, primitive value = 6

Version and OS

  • OpenModelica Version: OpenModelica 1.20.0~dev
  • OS: Linux Ubuntu 20.04

Additional Context

The model gives the following compile time warning which would be good to correct as well, assuming my code is correct:

TestRecord_functions.c:33:11: warning: incompatible pointer types passing 'TestRecord_MyRec *' to parameter of type 'const myStruc *' [-Wincompatible-pointer-types]
  myPrint(_rec_ext, _rec_extPi, _rec_extPj);
          ^~~~~~~~
/home/mwetter/test/structure/Resources/Include/myPrint.c:9:18: note: passing argument to parameter 'myRecord' here
  const myStruc* myRecord,
                 ^
1 warning generated.
@perost
Copy link
Member

perost commented Apr 21, 2022

Probably a duplicate of #8591.

@mwetter
Copy link
Author

mwetter commented Nov 14, 2023

This is fixed. Tested with OpenModelica 1.23.0~dev-120-g5ba5f91 on Linux.

@mwetter mwetter closed this as completed Nov 14, 2023
@casella casella added this to the 1.23.0 milestone Nov 17, 2023
@casella casella added the COMP/OMC/Runtime Issues and pull requests related to the runtime for OMC (not simulation runtime). label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
COMP/OMC/Runtime Issues and pull requests related to the runtime for OMC (not simulation runtime).
Projects
None yet
Development

No branches or pull requests

3 participants