[PATCH 5/6] json-writer: include strbuf-safe.h
- From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Sep 18, 2026, 13:02 UTC
- Message-ID
- <6e654dcbac2ac1b6c4d5311e64ce516d0bded0fb.1789736540.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2230.git.1789736540.gitgitgadget@gmail.com>
From: Derrick Stolee <stolee@gmail.com>
We will use json-writer.c as our first 'safe' API, after removing some unsafe methods that reach die(), especially the strbuf API. However, the fact that json-writer.h includes strbuf.h causes someheadaches here.
Normally, we would only declare 'struct strbuf;' as a way to anonymously define a struct and have implementations include the full header as needed. However, 'struct json_writer' needs the full struct info and JSON_WRITER_INIT needs access to STRBUF_INIT.
Thankfully, both are included in strbuf-safe.h, so we can have the header include the safe API and move an include of strbuf.h to json-writer.c.
However, this has some implications to the trace2 API that includes json-writer.h and implicitly depends on that includes of strbuf.h. Have those files include strbuf.h directly to compensate.
Signed-off-by: Derrick Stolee <stolee@gmail.com> --- json-writer.c | 1 + json-writer.h | 2 +- trace2/tr2_tgt_event.c | 1 + trace2/tr2_tgt_perf.c | 1 + 4 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/json-writer.c b/json-writer.c index 34577dc25f..e7fc5775da 100644 --- a/json-writer.c +++ b/json-writer.c @@ -2,6 +2,7 @@ #include "git-compat-util.h" #include "json-writer.h" +#include "strbuf.h" void jw_init(struct json_writer *jw) { diff --git a/json-writer.h b/json-writer.h index 8f845d4d29..fa8cf02253 100644 --- a/json-writer.h +++ b/json-writer.h @@ -70,7 +70,7 @@ * of the given strings. */ -#include "strbuf.h" +#include "strbuf-safe.h" struct json_writer { diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c index 36a746cc10..b25fa0fb30 100644 --- a/trace2/tr2_tgt_event.c +++ b/trace2/tr2_tgt_event.c @@ -5,6 +5,7 @@ #include "json-writer.h" #include "repository.h" #include "run-command.h" +#include "strbuf.h" #include "version.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_tbuf.h" diff --git a/trace2/tr2_tgt_perf.c b/trace2/tr2_tgt_perf.c index 96a5bc7f10..5554081c3c 100644 --- a/trace2/tr2_tgt_perf.c +++ b/trace2/tr2_tgt_perf.c @@ -7,6 +7,7 @@ #include "quote.h" #include "version.h" #include "json-writer.h" +#include "strbuf.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" #include "trace2/tr2_sysenv.h"
-- gitgitgadget