From: Junio C Hamano <gitster@pobox.com>
To: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, peff@peff.net, newren@gmail.com,
Derrick Stolee <stolee@gmail.com>
Subject: Re: [PATCH 6/6] strbuf-safe: add init and release methods
Date: Mon, 21 Sep 2026 14:44:49 -0700 [thread overview]
Message-ID: <xmqqld8ul1ny.fsf@gitster.g> (raw)
In-Reply-To: <dea925f31647e7c08f3fa467b8058351b463f593.1789736540.git.gitgitgadget@gmail.com> (Derrick Stolee via GitGitGadget's message of "Fri, 18 Sep 2026 13:02:20 +0000")
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
> +int jw_release(struct json_writer *jw)
> {
> - strbuf_release(&jw->json);
> - strbuf_release(&jw->open_stack);
> + enum safe_result result = SUCCESS;
> +
> + /* attempt both removals without short-circuiting. */
> + result = sstrbuf_release(&jw->json) || result;
> + result = sstrbuf_release(&jw->open_stack) || result;
> +
> + return result;
> }
This is puzzling in a few ways.
"enum safe_result" so far has been SUCCESS==0 and MEMORY_ERROR==1.
Presumably in some future we would gain other kind of error symbols,
but when that happens is this meant to act as an enumeration of
different kinds errors? Or an enumeration of bitmasks that can
signal different kinds of errors?
If we mean "enum safe_result" is an enumeration of different kinds
of errors, then the "result" variable and the returned value from
here would be able to report a *single* kind of error, and it may
be common to report the first error we encounter, in which case
enum safe_result result = SUCCESS;
enum safe_result res;
res = sstrbuf_release(&jw->json);
if (!result && res)
result = res;
res = sstrbuf_release(&jw->open_stack);
if (!result && res)
result = res;
return result;
would be slightly longer, far easier to reason about, and is a lot
more futureproof. What you wrote, with "||", does not really allow
anything other than "is it still zero, or coalesce any non-zero
value to 1".
On the other hand, if we mean "enum safe_result" is an enumeration
of bitmasks, each bit representing different kind of error, then
enum safe_result result = 0;
result |= sstrbuf_release(&jw->json);
result |= sstrbuf_release(&jw->open_stack);
return result;
would probably be what you want. That way you can add different
functions that returns different bit to signal a different kind of
error and or it in.
result |= some_function();
next prev parent reply other threads:[~2026-09-21 21:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 13:02 [PATCH 0/6] [RFC] Create a 'safe' strbuf API Derrick Stolee via GitGitGadget
2026-09-18 13:02 ` [PATCH 1/6] strbuf: add header for 'safe' API Derrick Stolee via GitGitGadget
2026-09-21 21:18 ` Junio C Hamano
2026-09-23 19:25 ` Mark C. Chu-Carroll
2026-09-23 20:14 ` Junio C Hamano
2026-09-18 13:02 ` [PATCH 2/6] wrapper: initialize GIT_ALLOC_LIMIT proactively Derrick Stolee via GitGitGadget
2026-09-18 13:02 ` [PATCH 3/6] wrapper: create safe_memory_limit_check() Derrick Stolee via GitGitGadget
2026-09-21 21:24 ` Junio C Hamano
2026-09-18 13:02 ` [PATCH 4/6] strbuf-safe: add sstrbuf_grow() Derrick Stolee via GitGitGadget
2026-09-21 21:29 ` Junio C Hamano
2026-09-18 13:02 ` [PATCH 5/6] json-writer: include strbuf-safe.h Derrick Stolee via GitGitGadget
2026-09-18 13:02 ` [PATCH 6/6] strbuf-safe: add init and release methods Derrick Stolee via GitGitGadget
2026-09-21 21:44 ` Junio C Hamano [this message]
2026-09-21 22:34 ` Junio C Hamano
2026-09-19 15:23 ` [PATCH 0/6] [RFC] Create a 'safe' strbuf API Phillip Wood
2026-09-23 19:46 ` Jeff King
2026-10-06 14:33 ` Derrick Stolee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqld8ul1ny.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=stolee@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.