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

Don't assume string_view::iterator is const char* #2324

Merged

Conversation

hzeller
Copy link
Collaborator

@hzeller hzeller commented Jan 12, 2025

There were a few assumptions in the code that these types are equivalent, but they are not on all platforms.

The fixes sometimes involve ugly &*some_iterator constructs to get to the underlying location. Some of these should be re-considered after switching to c++20.

Issues: #2323

@hzeller hzeller force-pushed the feature-20250112-it-not-constchar branch 3 times, most recently from b22cdbe to 7900a1e Compare January 12, 2025 21:20
@hzeller hzeller marked this pull request as draft January 12, 2025 21:21
@hzeller hzeller force-pushed the feature-20250112-it-not-constchar branch 7 times, most recently from 21e7cf3 to 4a45f97 Compare January 13, 2025 17:01
@hzeller hzeller requested a review from fangism January 13, 2025 18:03
@hzeller hzeller marked this pull request as ready for review January 13, 2025 18:03
// TODO: find something platform independent that is less ugly.
// Or maybe revisit the place where we need this and see if they could
// be actually represented by a const char * nullptr.
inline absl::string_view::iterator string_view_null_iterator() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably in a different file; or in no file at all, just using absl::string_view::iterator{} everywhere (but that would then be less explicit).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe place in common/strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I narrowed its use to anything that anyway uses format-token.h, so decided to leave it there for now.
(otherwise it would be a bit awkward to have a strings/null-iterator.h with a single inlined one-liner function in it...)

Copy link
Collaborator

@fangism fangism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the general direction of this clean-up.

// TODO: find something platform independent that is less ugly.
// Or maybe revisit the place where we need this and see if they could
// be actually represented by a const char * nullptr.
inline absl::string_view::iterator string_view_null_iterator() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe place in common/strings?

@hzeller hzeller force-pushed the feature-20250112-it-not-constchar branch from 4a45f97 to fbda6cc Compare January 13, 2025 19:28
There were a few assumptions in the code that these types are equivalent,
but they are not on all platforms.

The fixes sometimes involve ugly `&*some_iterator` constructs to get to
the underlying location. Some of these should be re-considered after
switching to c++20.

We also have a `string_view_null_iterator()` function to generate
an iterator that is not initialized to be used in place where we
previously used comparison against nullptr.

Issues: chipsalliance#2323
@hzeller hzeller force-pushed the feature-20250112-it-not-constchar branch from fbda6cc to ecc7bdc Compare January 14, 2025 01:31
@hzeller hzeller merged commit 4629128 into chipsalliance:master Jan 14, 2025
28 of 29 checks passed
hzeller added a commit to hzeller/verible that referenced this pull request Jan 14, 2025
Now that we're compatible with all systems after
PR chipsalliance#2324, can switch to use std::string_view now.
hzeller added a commit to hzeller/verible that referenced this pull request Jan 14, 2025
Now that we're compatible with all systems after
PR chipsalliance#2324, can switch to use std::string_view now.
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 this pull request may close these issues.

2 participants