From: Patrick Steinhardt <ps@pks.im>
To: Max Tottenham <mtottenh@akamai.com>
Cc: The development of GNU GRUB <grub-devel@gnu.org>,
Daniel Kiper <dkiper@net-space.pl>
Subject: Re: [PATCH v2 2/6] json: Implement wrapping interface
Date: Sun, 10 Nov 2019 17:44:55 +0100 [thread overview]
Message-ID: <20191110164455.GA17923@xps> (raw)
In-Reply-To: <20191108133028.GF20442@lon-lp55b.london.corp.akamai.com>
[-- Attachment #1: Type: text/plain, Size: 2470 bytes --]
On Fri, Nov 08, 2019 at 01:30:28PM +0000, Max Tottenham wrote:
> On 11/07, Patrick Steinhardt wrote:
> > On Thu, Nov 07, 2019 at 02:51:30AM +0000, Max Tottenham via Grub-devel wrote:
> > > On 11/06, Patrick Steinhardt wrote:
> > > >
> > > > The reason is that we'd have to include "jsmn.h" in
> > > > "include/grub/json.h" to make `jsmntok_t` available. I definitely
> > > > want to avoid this in order to not leak any decls from jsmn into
> > > > users of "json.h" and to be able to have "jsmn.h" live in
> > > > "grub-core/lib/json". It's also not possible to have a forward
> > > > declaration here due to how `jsmntok_t` is declared.
> > > >
> > > > Patrick
> > >
> > >
> > > In which case, looking again at this patchset - grub_json_t
> > > is always used as an opaque value by consumers of json.h .
> > >
> > > Why not put a forward declaration of grub_json_t in include/grub/json.h,
> > > and stick the implementation in grub-core/lib/json.c :
> > >
> > > include/grub/json.h:
> > >
> > > typedef struct grub_json_t grub_json_t;
> > >
> > > grub-core/lib/json.c:
> > > ...
> > > #include <grub/json.h>
> > > #include "jsmn.h"
> > > ...
> > > struct grub_json_t {
> > > jsmntok_t* tokens;
> > > ...
> > > };
> > >
> > >
> > > Unless there is something I'm missing doesn't the above achieve the
> > > desired result?
> >
> > If we'd do that, all calls to `grub_json_get{child,value}` would
> > have to return a dynamically allocated `grub_json_t` structure as
> > the storage size of `grub_json_t` would not be known at compile
> > time and thus cannot be allocated on the caller's stack. Right
> > now, the caller can just declare the structure on-stack and have
> > the interface fill up these structures for him, without any need
> > for dynamic memory allocation.
> >
> > Patrick
>
> Ah, good point. I've been thinking about this for a while and I think
> dealing with casts from void* really is the best we can do.
>
> Perhaps jsmn upstream would accept a patch that does:
>
> - typedef struct {
> + typedef struct jsmntok_t {
> ...
> } jsmntok_t;
>
> If they do we could revisit this later.
I've created a pull request upstream to change exactly that --
let's wait and see. In the meantime we'll have to use the current
`void *` workaround, but I'll make sure to update this as soon as
the PR got merged (if ever).
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-11-10 16:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-05 12:54 [PATCH v2 2/6] json: Implement wrapping interface Max Tottenham
2019-11-05 13:12 ` Patrick Steinhardt
2019-11-06 11:53 ` Daniel Kiper
2019-11-06 14:57 ` Max Tottenham
2019-11-06 20:20 ` Patrick Steinhardt
2019-11-07 2:51 ` Max Tottenham
2019-11-07 6:26 ` Patrick Steinhardt
2019-11-08 13:30 ` Max Tottenham
2019-11-10 16:44 ` Patrick Steinhardt [this message]
2019-11-13 11:43 ` Daniel Kiper
-- strict thread matches above, loose matches on Subject: below --
2019-11-02 18:06 [PATCH 0/6] Support for LUKS2 disc encryption Patrick Steinhardt
2019-11-05 6:58 ` [PATCH v2 0/6] Support for LUKS2 disk encryption Patrick Steinhardt
2019-11-05 6:58 ` [PATCH v2 2/6] json: Implement wrapping interface Patrick Steinhardt
2019-11-05 9:54 ` Max Tottenham
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=20191110164455.GA17923@xps \
--to=ps@pks.im \
--cc=dkiper@net-space.pl \
--cc=grub-devel@gnu.org \
--cc=mtottenh@akamai.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.