git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC PATCH v2 1/2] json-writer: add docstrings to jw_* functions

From
Patrick Steinhardt <ps@pks.im>
Date
May 14, 2025, 02:41 UTC
Message-ID
<aCQCz_jl5WOdhiAa@pks.im>
In-Reply-To
<CBE59EF3-4C4D-4FD0-80E7-D9BAF70EFDAB@gmail.com>
On Tue, May 13, 2025 at 07:05:21PM -0300, Lucas Seiki Oshiro wrote:
Show 29 quoted lines
> > void jw_object_begin(struct json_writer *jw, int pretty);
> > 
> > I think it would be interesting to learn _when_ to use this function. Is
> > it mandatory to call it? Can it be nested? Why is there no corresponding
> > `jw_object_end()`?
> > 
> >> void jw_array_begin(struct json_writer *jw, int pretty);
> > 
> > Same questions here.
> 
> A JSON can be a list or an object, composed by other lists or objects.
> Those functions, then, define if the current json_writer will output a
> list or an object.
> 
> Internal lists and objects are declared with
> jw_{array, object}_inline_begin_{array, object}, depending if we want
> to begin a list or an object and depending if we want to begin it
> inside a list or an object.
> 
> In all those cases, there's no need to jw_object_end or jw_array_end.
> jw_end covers both.
> 
> >> void jw_object_string(struct json_writer *jw, const char *key,
> >>      const char *value);
> > 
> > What happens when called after `jw_array_begin()`? Same question is true
> > for all the other `jw_object_*` functions.
> 
> It raises a bug: "json-writer: array: not in array

Okay. Information like this is very valuable context to have in the per-function docs.

Show 14 quoted lines
> > 
> >> void jw_object_inline_begin_object(struct json_writer *jw, const char *key);
> >> 
> >> void jw_object_inline_begin_array(struct json_writer *jw, const char *key);
> > 
> > Do these nest? E.g. can you call `inline_begin_object()` multiple times?
> 
> They are only tested up to the second nesting level. However, based
> on the source code it looks like they should.
> 
> json_writer has a stack. The *inline_begin* functions basically append { or
> [ to the buffer and to the stack.
> 
> Perhaps it would be a good idea to include a test for those cases?
That would certainly be welcome :)
Patrick
Previous: Lucas Seiki OshiroNext: Karthik Nayak
Message 5 of 12 in “json-writer: describe the jw_* functions”
  1. 0/2 json-writer: describe the jw_* functionsLucas Seiki Oshiro, May 12, 2025
  2. 1/2 json-writer: add docstrings to jw_* functionsLucas Seiki Oshiro, May 12, 2025
  3. Patrick SteinhardtMay 12, 2025
  4. Lucas Seiki OshiroMay 13, 2025
  5. Patrick SteinhardtMay 14, 2025
  6. Karthik NayakMay 12, 2025
  7. 2/2 json-writer: describe the usage of jw_* functionsLucas Seiki Oshiro, May 12, 2025
  8. Patrick SteinhardtMay 12, 2025
  9. Karthik NayakMay 12, 2025
  10. Lucas Seiki OshiroMay 13, 2025
  11. Patrick SteinhardtMay 14, 2025
  12. Karthik NayakMay 12, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.