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

Make count_with more consistent for builtin types. #318

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kitlith
Copy link
Collaborator

@kitlith kitlith commented Feb 22, 2025

Splitting this off from #317, as there's more solution space to sort through there, and I think fixing this is more important.

While writing this PR description, I thought of a less contrived example and test where this would break: reading 24 bit integers, which we already provide a helper for. count_with(N, read_u24) will currently read N u32s, instead of N u24s, and I have updated the test to reflect this.

The main thing I'm uncertain about here is the last commit, where I modify the API of count to make it callable from Vec::read_options. That may be a semver breakage, I'm not sure.

Before merging, I figure I'll do an interactive rebase to squash all of the commits prefixed with fixup!.

@kitlith
Copy link
Collaborator Author

kitlith commented Feb 22, 2025

same minor UI test failure on nightly as before. I don't see a reason why this would be more likely to fail on 1.66 than the other, so I'm not bothering to re-run the cancelled checks.

@jam1garner
Copy link
Owner

I think that change is breaking for anyone using turbofish syntax for count at minimum? maybe in practice that's acceptable, unclear

@jam1garner
Copy link
Owner

Not sure I 100% understand your meaning about the u24 example. Did it previously read 4 bytes a piece?

@kitlith
Copy link
Collaborator Author

kitlith commented Feb 24, 2025

Did it previously read 4 bytes a piece?

Yes, it did, and the resulting "u24" (which we represent as a u32) can have it's high 8 bits set. So it's not a u24 at all, when going through count_with.

edit: if you check out the commit before i fix this, 6b43f69 , you can observe that the new test fails with the equivalent of "unexpected EOF"

@csnover
Copy link
Collaborator

csnover commented Feb 24, 2025

The main thing I'm uncertain about here is the last commit, where I modify the API of count to make it callable from Vec::read_options. That may be a semver breakage, I'm not sure.

I think this is fine. I’m not worried about the signature change at least. I thought I had done something similar to this in some uncommitted code change but I can’t find it in any of my stashes, so it must have been an experiment I abandoned.

This change makes sense to me and seems fine if you want to wrap it up. I’ve pushed a commit to master with updated outputs for the nightly UI tests so that will not fail any more on rebase.

@kitlith
Copy link
Collaborator Author

kitlith commented Feb 24, 2025

... i squashed one too many commits in the rebase. sec.

Test is written to "what a user would expect", this currently fails.
We should either move the optimization to the count helper, or fix
it in some other way.
count_with can't make any assumptions about the read function it's
been given, unless we find a way to specialize on "read function
is "T::read_options"

This fixes the test introduced in the previous commit.
Note: this changes the signature of binrw::helpers::count,
which may require a semver bump.
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.

3 participants