Skip to content

c_str cleanup #8532

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

Closed
wants to merge 5 commits into from
Closed

c_str cleanup #8532

wants to merge 5 commits into from

Conversation

lilyball
Copy link
Contributor

Implement interior null checking in .to_c_str(), among other changes.

CString.unwrap() drops ownership of the buffer on the floor. Put this in
the docs.
Previous dicussions about CString suggested that interior nulls should
throw an error. This was never implemented. Add this now, using a
condition (named null_byte) to allow for recovery.

Add method .to_c_str_unchecked() that skips this check.
.with_c_str() is a replacement for the old .as_c_str(), to avoid
unnecessary boilerplate.

Replace all usages of .to_c_str().with_ref() with .with_c_str().
LLVMConstStringInContext() doesn't need a null-terminated string. It
takes a length instead. Using .to_c_str() here triggers an ICE whenever
the string literal embeds a null, as in "\x00".
@erickt
Copy link
Contributor

erickt commented Aug 15, 2013

This is awesome! Thanks so much for cleaning up the API!

bors added a commit that referenced this pull request Aug 16, 2013
Implement interior null checking in `.to_c_str()`, among other changes.
@bors bors closed this Aug 16, 2013
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