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

Implement arbitrary for CString #257

Closed
wants to merge 1 commit into from

Conversation

ThomasdenH
Copy link
Contributor

@ThomasdenH ThomasdenH commented Feb 6, 2020

Closes #165. This implementation builds a CString from either a String or a Vec<u8>. It shrinks using the VecShrinker, everywhere making sure no null characters end up in the CString.

To prevent using as many allocations, it is built using an iterator, which is then filtered directly. I can change that if it's undesirable.

@ThomasdenH
Copy link
Contributor Author

Is this PR acceptable? Should I change anything?

@maxbla
Copy link
Contributor

maxbla commented Jun 6, 2020

@BurntSushi seems to keep pretty busy. He maintains quite a few libraries (just look at his github!). He takes a while to get around to reviewing PRs, but he often does eventually. Mentioning him with @ (as I already did) sometimes helps.

I can give you a comment in the meantime though.

I'm not convinced of the need for your ArbitraryIterator. You say it avoids excess allocations, but I don't understand how. You could do (0..).map(|_| Arbitrary::arbitrary(g)).filter(|&c| c != '\0').take(size).collect(), which I believe is equivalent to your CString code, both in final result and in number of allocations.

BurntSushi pushed a commit that referenced this pull request Dec 27, 2020
We add a little sophistication here for whether the CString is
completely valid UTF-8 or whether it's just an arbitrary mix of bytes.
(Excluding NUL of course.)

Fixes #165, Closes #257
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.

Implement Arbitrary for CString
2 participants