Skip to content

Refactor Mgr::StringParam.str to be a SBuf [DRAFT]#2405

Draft
kinkie wants to merge 1 commit intosquid-cache:masterfrom
kinkie:sbuf-mgr-stringparam-str
Draft

Refactor Mgr::StringParam.str to be a SBuf [DRAFT]#2405
kinkie wants to merge 1 commit intosquid-cache:masterfrom
kinkie:sbuf-mgr-stringparam-str

Conversation

@kinkie
Copy link
Copy Markdown
Contributor

@kinkie kinkie commented Apr 10, 2026

No description provided.

@kinkie
Copy link
Copy Markdown
Contributor Author

kinkie commented Apr 10, 2026

This was run-tested with active workers on Linux. pre-staging test at https://github.com/kinkie/squid/actions/runs/24265673016

Copy link
Copy Markdown
Contributor

@yadij yadij left a comment

Choose a reason for hiding this comment

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

Please replace the existing Ipc::TypedMsgHdr::getString() to work based on the SBuf member instead of what it currently does with char[].

Comment on lines +244 to +245
static SBuf t;
const SBuf& Mgr::StringParam::value() const STUB_RETVAL(t)
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.

We no longer need a separate static declaration.

Suggested change
static SBuf t;
const SBuf& Mgr::StringParam::value() const STUB_RETVAL(t)
const SBuf& Mgr::StringParam::value() const STUB_RETREF(SBuf)

@rousskov rousskov self-requested a review April 11, 2026 10:43
Copy link
Copy Markdown
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

Thank you for improving this code.

Comment on lines +156 to +160
// SBuf doesn't need special handling for empty
if (!length) {
s.clear();
return;
}
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.

The if statement contradicts its comment/description. Please either remove the comment or remove both the comment and the statement. I do recommend removing.

Suggested change
// SBuf doesn't need special handling for empty
if (!length) {
s.clear();
return;
}
if (!length) {
s.clear();
return;
}

or

Suggested change
// SBuf doesn't need special handling for empty
if (!length) {
s.clear();
return;
}

or

Suggested change
// SBuf doesn't need special handling for empty
if (!length) {
s.clear();
return;
}
// zero length OK

{
const int length = getInt();
Must(length >= 0);
// String uses memcpy uncoditionally; TODO: SBuf eliminates this check
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.

Please remove this stale TODO:

-     // String uses memcpy uncoditionally

}

Must(length <= maxSize);
// TODO: use SBuf.reserve() instead of a temporary buffer
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.

Please remove this stale TODO:

-     // TODO: use SBuf.reserve() instead of a temporary buffer

Ipc::TypedMsgHdr::getSBuf(SBuf &s) const
{
const int length = getInt();
Must(length >= 0);
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.

Here and elsewhere, please avoid deprecated Must() in new code. Throw a TextException instead.

Comment on lines 138 to 140
char buf[maxSize];
getRaw(&buf, length);
s.assign(buf, length);
Copy link
Copy Markdown
Contributor

@rousskov rousskov Apr 13, 2026

Choose a reason for hiding this comment

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

Amos at #2405 (review): Please replace the existing Ipc::TypedMsgHdr::getString() to work based on the SBuf member instead of what it currently does with char[].

Please do not change this code in this PR. We do not want to add a temporary heap allocation here. When String users of TypedMsgHdr are gone, this code will be removed.

P.S. There is no "SBuf member" in Ipc::TypedMsgHdr and there should not be any (in the foreseeable future). I assume the quoted suggestion meant to say "local variable" instead of "member", but if my assumption is wrong, then please do not add an SBuf member to Ipc::TypedMsgHdr!

Comment on lines +61 to +62
void getSBuf(SBuf &s) const; ///< load variable-length SBuf
void putSBuf(const SBuf &s); ///< store variable-length SBuf
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 recommend overloading these methods. They are not about the exact storage type (which may change). They are about extracting a {length, data} field.

Suggested change
void getSBuf(SBuf &s) const; ///< load variable-length SBuf
void putSBuf(const SBuf &s); ///< store variable-length SBuf
void getString(SBuf &) const; ///< load a variable-length field
void putString(const SBuf &); ///< store a variable-length field

Overloading would also reduce noise when callers are upgraded to use SBuf.

@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-for-author author action is expected (and usually required)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants