Conversation
Pool::create_buffer(n) allocates n bytes, but ngx_create_temp_buf leaves pos == last, so Buffer::len() is 0 and MutableBuffer::as_bytes_mut() returns an empty slice. There was no safe way to put anything in: neither trait exposed the capacity or a way to set the length, so filling the buffer meant dropping to as_ngx_buf_mut() and advancing last by hand. Add spare_capacity() and append(). Appending more than fits writes nothing and returns None, rather than truncating, so a caller that ignores the result cannot produce a partial value. Fixes nginx#327 Signed-off-by: Y.Horie <u5.horie@gmail.com>
u5surf
force-pushed
the
feat/buffer-append
branch
from
September 14, 2026 23:54
efacd8d to
b5d070c
Compare
u5surf
marked this pull request as ready for review
September 15, 2026 11:24
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 #327.
Adds two methods to
MutableBuffer:So a buffer from
create_buffercan be filled without leaving the safe API:appendwrites nothing and returnsNonewhen the bytes do not fit, ratherthan filling what it can. A caller that ignores the result then gets an empty
buffer instead of a truncated value.
Nothing existing changes behaviour; both methods are new defaults on the trait.
Tests cover a fresh buffer, two appends, and an overflow.