Skip to content

0.3.0: into-string, prn, and documented automatic buffer ownership - #9

Merged
hellerve merged 1 commit into
mainfrom
agent/ownership-into-string
Sep 17, 2026
Merged

hellerve merged 1 commit into
mainfrom
agent/ownership-into-string

Conversation

@hellerve

Copy link
Copy Markdown
Member

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-string consumes a buffer and hands its allocation to the returned String. 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.
  • prn delegates to str, so a StringBuf inside a deftype no longer warns (redis embeds one in RedisPipeline).
  • Docs and examples drop the manual StringBuf.delete calls and explain the ownership model: buffers are deleted at scope exit wherever they live, @ copies them, delete exists because the compiler calls it.
  • Tests no longer delete by hand, and memory-balance regressions cover buffers returned from a function, moved into one, copied, in an array, in a struct, consumed by into-string, and deleted explicitly (still no double free).

Verified with carp -x --log-memory test/strbuf.carp (31/31), angler, carp-fmt --check, and carp -x gendocs.carp. The into-string NUL terminator is red-green checked under AddressSanitizer: without the grow, the exactly-full test is a heap-buffer-overflow.

@hellerve
hellerve merged commit 43e717f into main Sep 17, 2026
2 checks passed
@hellerve
hellerve deleted the agent/ownership-into-string branch September 17, 2026 19:04
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.

design better ownership system

1 participant