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

Runtime issues caused by locale-dependent double parsing #1882

Open
henningkayser opened this issue Jan 23, 2023 · 13 comments
Open

Runtime issues caused by locale-dependent double parsing #1882

henningkayser opened this issue Jan 23, 2023 · 13 comments
Labels
bug Something isn't working E-medium Medium Effort persistent Allows issues to remain open without automatic stalling and closing.

Comments

@henningkayser
Copy link
Member

henningkayser commented Jan 23, 2023

Here is a comment pointing out runtime issues depending on locale settings: #1782 (comment)

Problem
Locale settings define the format for different things, in particular LC_NUMERIC defines how decimal numbers are represented. Usually, we use dot notation for all configs (say XML), but if the system or application (like Qt) uses a locale with comma-separated decimals, double parsing with std::stod will silently cut off the decimals causing confusing issues depending on where it occurs.

Here is the same issue in urdfdom from a couple years ago: ros/urdfdom#98

Solution
I suggest switching to std::from_chars which always uses dot notation. See ros-controls/ros2_control#921 for an example PR.

Some commonly used packages affected (searching for "stod", there are also other variants like "stof"):

PRs very welcome, and please tag this issue to prevent duplicate work ;)

@ChrisThrasher
Copy link
Contributor

ChrisThrasher commented Jan 23, 2023

The <charconv> header has been notoriously one of the last bits of C++17 to get implemented so I worry that we're going to have portability issues if we use it, particular using it for floats which has taken longer to implement than the equivalent integer utilities. It's worth trying, but be forewarned.

@mamoll
Copy link
Contributor

mamoll commented Jan 23, 2023

This has bitten OMPL in the past, too. We worked around it like this.

@henningkayser
Copy link
Member Author

The <charconv> header has been notoriously one of the last bits of C++17 to get implemented so I worry that we're going to have portability issues if we use it, particular using it for floats which has taken longer to implement that the equivalent integer utilities. It's worth trying, but be forewarned.

What kind of portability issues do you mean and would you have a better alternative? I'm not a big fan of using stringstream here or temporarily switching locales.

@ChrisThrasher
Copy link
Contributor

ChrisThrasher commented Jan 23, 2023

What kind of portability issues

The fact that it's taken longer than any other C++17 feature to implement means some platforms or compilers with "complete C++17 support" sometimes come with a caveat about imperfect or incomplete <charconv> support.

I don't have any better alternatives, sorry. We just have to do our homework to figure out if all the platforms/compilers/standard libraries we support already implement this.

@tylerjw
Copy link
Member

tylerjw commented Jan 23, 2023

We just have to do our homework to figure out if all the platforms/compilers/standard libraries we support

Is it working on Ubuntu 22.04 with the default gcc and clang versions? If so, then that seems good enough. We are not offering support for Windows or backporting this.

@gavanderhoorn
Copy link
Member

Is it working on Ubuntu 22.04 with the default gcc and clang versions? If so, then that seems good enough. We are not offering support for Windows or backporting this.

so this is something I would clearly consider a bug / broken functionality, and you're proposing to leave it broken for non-Humble/Rolling releases?

@tylerjw
Copy link
Member

tylerjw commented Jan 23, 2023

I'm suggesting that we don't have to debate the solution of using <charconv> if we don't consider backporting that fix. If we do want this thing to be portable and back-portable, then maybe we consider something else. 🤷

@v4hn
Copy link
Contributor

v4hn commented Jan 23, 2023

I'm somewhat confused why nobody mentioned moveit/moveit#1099 .
We had these issues before in MoveIt and @simonschmeisser implemented utility functions just for this...

@simonschmeisser
Copy link
Contributor

History tends to repeat itself ...

https://github.com/ros-planning/moveit2/blob/c8df8cc2f5ddf13512b677cc795db556a3ec9d3f/moveit_core/utils/include/moveit/utils/lexical_casts.h#L62

is what we came up with back then.

For urdfdom I came up with a locale dependent unit test which could in theory be used to test compatibility of with older compilers:

https://github.com/ros/urdfdom/blob/41838e1f3623e0538a402024b76f296dbbcbed9f/urdf_parser/test/CMakeLists.txt#L48

@henningkayser
Copy link
Member Author

For some reason I didn't make the connection to lexical_casts, even though I knew about it... It's concerning that this bug is still around and has even raised children. It's all over the place and I think there are even some in ROS 1 which I was planning to look at next.

@AndyZe
Copy link
Member

AndyZe commented Jan 27, 2023

I took care of srdfdom: moveit/srdfdom#108

@github-actions
Copy link

github-actions bot commented Sep 5, 2023

This issue is being labeled as stale because it has been open 45 days with no activity. It will be automatically closed after another 45 days without follow-ups.

Copy link

github-actions bot commented Dec 8, 2023

This issue was closed because it has been stalled for 45 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 8, 2023
@github-project-automation github-project-automation bot moved this to ✅ Done in MoveIt Dec 8, 2023
@sjahr sjahr reopened this Dec 8, 2023
@sjahr sjahr added persistent Allows issues to remain open without automatic stalling and closing. and removed stale Inactive issues and PRs are marked as stale and may be closed automatically. labels Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working E-medium Medium Effort persistent Allows issues to remain open without automatic stalling and closing.
Projects
None yet
Development

No branches or pull requests

9 participants