Skip to content

docs: comments for blob, stuffer methods#5326

Merged
jmayclin merged 5 commits intoaws:mainfrom
jmayclin:blob-comment
Oct 30, 2025
Merged

docs: comments for blob, stuffer methods#5326
jmayclin merged 5 commits intoaws:mainfrom
jmayclin:blob-comment

Conversation

@jmayclin
Copy link
Copy Markdown
Contributor

Description of changes:

Add comments for some stuffer and blob methods.

I have reread the implementations of a lot of stuffer/blob methods many times because I keep forgetting what they do, and can't tell from the name.

I acknowledge that most of the methods are small so reading them shouldn't be a big deal, but having to jump in and out of the files when I am reviewing PR's is not fun. By adding comments, my IDE will just tell me what the functions do when I mouse over them.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jmayclin jmayclin requested review from goatgoose and lrstewart May 22, 2025 00:42
@github-actions github-actions bot added the s2n-core team label May 22, 2025
@jmayclin jmayclin marked this pull request as ready for review May 22, 2025 02:14
### s2n_blob: keeping track of memory ranges

`s2n_blob` is a very simple data structure:
`s2n_blob` is a data structure representing allocated, "owned" memory or a reference to some other slice of memory.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you later say "or a reference to some other slice of memory", but I worry that someone is still still going to read this as "blobs are always allocated". Maybe just "s2n_blob is a data structure representing a slice of memory"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to add an explicit "either ... or" and "non-owned slice of memory".

s2n_blob is a data structure representing either allocated, "owned" memory or a reference to some other non-owned slice of memory.

I know it's a little bit wordy but I prefer that over "slice of memory", because I want to stress that blobs have two semantically different use cases and if you confuse them it will blow up in your face 🙃

Comment on lines +200 to +201
* Resize a blob to `size`. The blob must be allocated or empty.
*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean "growable"?

Suggested change
* Resize a blob to `size`. The blob must be allocated or empty.
*
* Resize a blob to `size`. The blob must be growable or empty.
*

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I did mean "allocated". This was a concious decision because I always have to mentally wrangle with the meaning of "growable" everytime I see it.

s2n-tls/utils/s2n_blob.h

Lines 40 to 48 in e8042c0

/* An allocated blob (e.g.`s2n_alloc`) is always growable. A "reference"
* blob (from `s2n_blob_init`) is never growable.
*
* This field is necessary to distinguish zero-sized allocated blobs from
* zero-sized "reference" blobs. Zero-sized allocated blobs can not be
* constructed with s2n_alloc or s2n_realloc, but they are directly initialized
* in s2n_free_object.
*/
unsigned growable : 1;

Mentally my main distinction in blobs is whether they are allocated/owned or references.

The concept of "growable" confuses me because I then expect it to be an additional quality outside of the owned/reference distinction. Basically it makes me think that blobs support "allocated, non-growable" blobs. But that is incorrect, and aside from a weird 0-size edge case, "is it growable" is just "is it allocated".

Lmk if you still prefer the "growable" term and I'll go ahead and update it.

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

}

/**
* Copy the internal data of `stuffer` to `out`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only copies from the read cursor to the write cursor, not sure if that is helpful point to make.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, I someone missed that this one already has a comment in the header file. We really need to consolidate our comments into one or the other 🥲

Removing this comment for now (since it's already in the header file)

@jmayclin jmayclin enabled auto-merge October 30, 2025 00:47
@jmayclin jmayclin added this pull request to the merge queue Oct 30, 2025
Merged via the queue into aws:main with commit 7ef63f2 Oct 30, 2025
50 of 51 checks passed
@jmayclin jmayclin deleted the blob-comment branch October 30, 2025 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants