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

Added Extend and various FromIterator implementations to CslStringList. #457

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

metasim
Copy link
Contributor

@metasim metasim commented Oct 26, 2023

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

Addresses some leftover feedback from here.

The docs summarize what this PR enables:

image

@metasim metasim requested review from lnicola and jdroenner October 26, 2023 20:51
@metasim metasim mentioned this pull request Oct 27, 2023
10 tasks
@metasim
Copy link
Contributor Author

metasim commented Oct 29, 2023

@lnicola @jdroenner r+?

@lnicola
Copy link
Member

lnicola commented Oct 29, 2023

Sorry, I was away for the past couple of days. I'll take a look tomorrow.

@@ -1,3 +1,12 @@
<PAMDataset>
<SRS dataAxisToSRSAxisMapping="2,1">GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]</SRS>
<PAMRasterBand band="1">
Copy link
Member

Choose a reason for hiding this comment

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

I don't remember if we want this or not, but perhaps it's harmless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't affect the tests. I got tired of reseting the file every time I ran tests.

src/options.rs Outdated Show resolved Hide resolved
}
}

impl Extend<CslStringListEntry> for CslStringList {
Copy link
Member

Choose a reason for hiding this comment

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

Too bad we can't use CSLMerge here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually started to implement it (and still can) but the C++ implementation scared me as I saw no evidence that it would extend the length of the original array. That said, my C++ is 20 years rusty.

Copy link
Member

Choose a reason for hiding this comment

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

That function just appends one element at a time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Couldn't find a {re|m}alloc in there or in CSLSetNameValue either.

Copy link
Member

Choose a reason for hiding this comment

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

impl Extend<CslStringListEntry> for CslStringList {
fn extend<T: IntoIterator<Item = CslStringListEntry>>(&mut self, iter: T) {
for e in iter {
self.add_entry(&e).unwrap_or_default();
Copy link
Member

Choose a reason for hiding this comment

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

Oof 😔.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lnicola Here's my rational as to why this might be OK.
Most of the time you're going to be extending one CslStringList with another. The only way that call can fail is if your insertion String has \r, \n, or most importantly \0. If iter comes from a CslStringList then that validation has already happened.

However, if iter comes from [CslStringListEntry], then you could presumably circumvent that check. I added this comment for that reason.

The obvious alternative means no Extend, and TryFroms to cover what is probably a rare edge case. On balance, I'd rather have Extend.

Copy link
Member

Choose a reason for hiding this comment

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

Exactly. OOM might be another case where it fails, but it's pretty unlikely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW, Added additional documentation to CslStringListEntry::new_{pair|flag}.

src/cpl.rs Show resolved Hide resolved
Copy link
Member

@lnicola lnicola left a comment

Choose a reason for hiding this comment

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

The error handling makes this a bit icky, but I don't have any good suggestions.

I think it's workable, if not ideal, let's see how jdroenner, feels about it.

@metasim
Copy link
Contributor Author

metasim commented Nov 1, 2023

@jdroenner r+?

///
/// An Entry is ether a single token (`Flag`), or a `name=value` assignment (`Pair`).
///
/// Note: When constructed directly, assumes string values do not contain newline characters nor
Copy link
Member

Choose a reason for hiding this comment

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

We should probably spell out more clearly that those values will be ignored. And not just here, but also on CslStringList.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CslStringList actually propagates the error.

gdal/src/cpl.rs

Lines 116 to 117 in 16f2aef

Self::check_valid_name(name)?;
Self::check_valid_value(value)?;

@metasim metasim force-pushed the feature/csl-extend branch from caa66a6 to ff6a0e3 Compare November 6, 2023 17:12
@metasim
Copy link
Contributor Author

metasim commented Nov 6, 2023

bors r=lnicola

@metasim
Copy link
Contributor Author

metasim commented Nov 6, 2023

bors try

@metasim metasim merged commit a1aee76 into georust:master Nov 6, 2023
8 checks passed
@metasim metasim deleted the feature/csl-extend branch November 6, 2023 18:01
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