Thread (16 messages) 16 messages, 5 authors, 9d ago

Re: [PATCH 6/6] strbuf-safe: add init and release methods

From: Junio C Hamano <hidden>
Date: 2026-09-21 22:34:46

Junio C Hamano [off-list ref] writes:
"Derrick Stolee via GitGitGadget" [off-list ref] writes:
quoted
+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.
If we mean "enum safe_result" is an enumeration of different kinds
of errors, then the "result" variable and the returned value from
...
On the other hand, if we mean "enum safe_result" is an enumeration
of bitmasks, each bit representing different kind of error, then
...
I forgot the third possibility.  Regardless of which interpretation
of "enum safe_result" we use, if jw_release() is designed to say "0
for success, non-zero for failure", then almost as written but
declaring "result" as a plain "int"

    int result = 0;

    result = sstrbuf_release(&jw->json) || result;
    result = sstrbuf_release(&jw->open_stack) || result;

    return result;

would probably make sense, even though the "|| result" construct is
a bit unusual in C.

Thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help