git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org, gitster@pobox.com, karthik.188@gmail.com
Subject: Re: [GSoC PATCH v2 1/2] json-writer: add docstrings to jw_* functions
Date: Tue, 13 May 2025 19:05:21 -0300	[thread overview]
Message-ID: <CBE59EF3-4C4D-4FD0-80E7-D9BAF70EFDAB@gmail.com> (raw)
In-Reply-To: <aCG2XkW2lJ1qYHKW@pks.im>


> I don't think there's a need to add "Mentored-by" trailers to every
> commit just because we happen to be your mentors right now :) If we
> actually helped then sure, makes sense. But to the best of my knowledge
> we didn't, so I'd just leave them out for now.

Ok! But given that now both of you are helping me here I think it's
fair to give at least a Helped-by :-)

> 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

> 
>> 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?

> Patrick

Thanks!


  reply	other threads:[~2025-05-13 22:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12  2:09 [GSoC PATCH v2 0/2] json-writer: describe the jw_* functions Lucas Seiki Oshiro
2025-05-12  2:09 ` [GSoC PATCH v2 1/2] json-writer: add docstrings to " Lucas Seiki Oshiro
2025-05-12  8:50   ` Patrick Steinhardt
2025-05-13 22:05     ` Lucas Seiki Oshiro [this message]
2025-05-14  2:41       ` Patrick Steinhardt
2025-05-12  9:36   ` Karthik Nayak
2025-05-12  2:09 ` [GSoC PATCH v2 2/2] json-writer: describe the usage of " Lucas Seiki Oshiro
2025-05-12  8:50   ` Patrick Steinhardt
2025-05-12  9:41   ` Karthik Nayak
2025-05-13 22:22     ` Lucas Seiki Oshiro
2025-05-14  2:40       ` Patrick Steinhardt
2025-05-12  8:49 ` [GSoC PATCH v2 0/2] json-writer: describe the " Karthik Nayak

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=CBE59EF3-4C4D-4FD0-80E7-D9BAF70EFDAB@gmail.com \
    --to=lucasseikioshiro@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=ps@pks.im \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).