0.3.0: into-string, prn, and documented automatic buffer ownership - #9
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4.
Automatic deletion has worked since 0.2.1, when
(implements delete StringBuf.delete)landed. This release makes that the documented, tested contract and adds the one ownership operation that was missing.into-stringconsumes a buffer and hands its allocation to the returnedString. Nothing is copied and nothing is freed, which replaces the(let-do [s (StringBuf.to-string &sb)] (StringBuf.delete sb) s)idiom that appears 17 times across the org.prndelegates tostr, so aStringBufinside adeftypeno longer warns (redis embeds one inRedisPipeline).StringBuf.deletecalls and explain the ownership model: buffers are deleted at scope exit wherever they live,@copies them,deleteexists because the compiler calls it.into-string, and deleted explicitly (still no double free).Verified with
carp -x --log-memory test/strbuf.carp(31/31), angler,carp-fmt --check, andcarp -x gendocs.carp. Theinto-stringNUL terminator is red-green checked under AddressSanitizer: without the grow, the exactly-full test is a heap-buffer-overflow.