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

Distinct preice::string_views when implicitly constructing from std::string or literal #28

Closed
mathiskelm opened this issue Dec 18, 2023 · 1 comment · Fixed by #30
Closed

Comments

@mathiskelm
Copy link
Collaborator

Description

Several interfaces of the CouplingAdapter such as announceQuantity and getQuantityVector use the new precice::string_view after the port to precice:develop / preCICEv3. One can pass also std::strings or "string"-literals, which are then converted. As literals such as "dataName" are \0-terminated char[], their size is 1 greater than the string and they produce a different string_view.

std::string("dataName") seems to be compatible with precice::string_view("dataName", 8) while "dataName" produces precice::string_view("dataName", 9).

This currently allows to announce the same quantity twice, since the adapter checks whether the string_view has already been announced (false) and preCICE seems to view them both as equal to the name registered in the preCICE config file.

Environment

Ubuntu 22.04 LTS, preCICE:develop, DuMuX 3.8, DuMuX-preCICE:develop

Steps to reproduce

Announce a quantity twice, using once a std::string and once a literal

Expected behavior

If passing a std::string and literal are allowed, they should refer to the same quantity.

Actual behavior

Depending on how the string_view is created, the quantities are treated as distinct.

@fsimonis
Copy link
Member

fsimonis commented Dec 18, 2023

You noticed an implementation detail of using the precice::span-based precice::string_views in the API.

While you are correct about the literals containing the NULL byte, preCICE handles this internally.
In src/precice/Participant.cpp, we convert all precice::string_views to std::string_view before passing them ParticipantImpl.

This step removes the NULL byte and everything past it from given string_views.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants