[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] json: Remove invalid typedef redefinition
From: |
Daniel Axtens |
Subject: |
Re: [PATCH] json: Remove invalid typedef redefinition |
Date: |
Sat, 30 May 2020 00:37:31 +1000 |
Hi Patrick,
> The C standard does not allow for typedef redefinitions, even if they
> map to the same underlying type. In order to avoid including the
> "jsmn.h" in "json.h" and thus exposing jsmn's internals, we have exactly
> such a forward-declaring typedef in "json.h". If enforcing the GNU99 C
> standard, clang may generate a warning about this non-standard
> construct.
>
> Fix the issue by using a simple `struct jsmntok` forward declaration
> instead of using a typedef.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
Tested-by: Daniel Axtens <dja@axtens.net> # clang build test for emu target only
With this patch, clang can compile master again. Thanks Patrick!
Regards,
Daniel
> ---
>
> Sorry for the late response, didn't notice at first that this directly
> impacts code I wrote. I don't have Clang available on my computer and
> GCC seems to lack the equivalent option for this, so I wasn't able to
> reproduce the warning. Below patch should fix the issue, though, as we
> simply avoid using a typedef for the forward declaration.
>
> grub-core/lib/json/json.h | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/grub-core/lib/json/json.h b/grub-core/lib/json/json.h
> index d9f99454d..2e2b0bd07 100644
> --- a/grub-core/lib/json/json.h
> +++ b/grub-core/lib/json/json.h
> @@ -36,13 +36,14 @@ enum grub_json_type
> };
> typedef enum grub_json_type grub_json_type_t;
>
> -typedef struct jsmntok jsmntok_t;
> +/* Forward-declaration to avoid including "jsmn.h" */
> +struct jsmntok;
>
> struct grub_json
> {
> - jsmntok_t *tokens;
> - char *string;
> - grub_size_t idx;
> + struct jsmntok *tokens;
> + char *string;
> + grub_size_t idx;
> };
> typedef struct grub_json grub_json_t;
>
> --
> 2.26.2
- Re: [PATCH v3 5/5] autogen: Replace -iname with -ipath in find command, (continued)
- [PATCH v3 2/5] configure: Set gnu99 C language standard by default, Daniel Kiper, 2020/05/13
- Re: [PATCH v3 2/5] configure: Set gnu99 C language standard by default, Daniel Axtens, 2020/05/14
- Re: [PATCH v3 2/5] configure: Set gnu99 C language standard by default, Daniel Kiper, 2020/05/18
- Re: [PATCH v3 2/5] configure: Set gnu99 C language standard by default, Javier Martinez Canillas, 2020/05/18
- Re: [PATCH v3 2/5] configure: Set gnu99 C language standard by default, Daniel Axtens, 2020/05/18
- Re: [PATCH v3 2/5] configure: Set gnu99 C language standard by default, Javier Martinez Canillas, 2020/05/19
- Re: [PATCH v3 2/5] configure: Set gnu99 C language standard by default, Daniel Axtens, 2020/05/19
- [PATCH] json: Remove invalid typedef redefinition, Patrick Steinhardt, 2020/05/27
- Re: [PATCH] json: Remove invalid typedef redefinition, Daniel Kiper, 2020/05/29
- Re: [PATCH] json: Remove invalid typedef redefinition,
Daniel Axtens <=
[PATCH v3 3/5] INSTALL/configure: Update install doc and configure comment, Daniel Kiper, 2020/05/13
Re: [PATCH v3 0/5] Various build and doc fixes, Leif Lindholm, 2020/05/13