grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] json: Update jsmn library to get rid of casts


From: Daniel Kiper
Subject: Re: [PATCH 2/2] json: Update jsmn library to get rid of casts
Date: Tue, 14 Apr 2020 20:19:01 +0200
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Apr 07, 2020 at 06:02:29PM +0200, Patrick Steinhardt wrote:
> Update our embedded version of the jsmn library to upstream commit
> 053d3cd (Merge pull request #175 from pks-t/pks/struct-type,
> 2020-04-02). The update adds a name for the `jsmntok` struct, which
> allows us to add a forward declaration for the struct's typedef. As a
> result, we can now convert the `void *` tokens member of `struct
> grub_json` to `jsmntok_t *` and remove all casts.

Missing SOB...

> ---
>  grub-core/lib/json/jsmn.h | 7 +++++--
>  grub-core/lib/json/json.c | 8 ++++----
>  grub-core/lib/json/json.h | 4 +++-
>  3 files changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/grub-core/lib/json/jsmn.h b/grub-core/lib/json/jsmn.h
> index b95368a20..3178dcc97 100644
> --- a/grub-core/lib/json/jsmn.h
> +++ b/grub-core/lib/json/jsmn.h
> @@ -66,7 +66,7 @@ enum jsmnerr {
>   * start     start position in JSON data string
>   * end               end position in JSON data string
>   */
> -typedef struct {
> +typedef struct jsmntok {
>    jsmntype_t type;
>    int start;
>    int end;
> @@ -80,7 +80,7 @@ typedef struct {
>   * JSON parser. Contains an array of token blocks available. Also stores
>   * the string being parsed now and current position in that string.
>   */
> -typedef struct {
> +typedef struct jsmn_parser {

Commit message says about jsmntok only. Here you add jsmn_parser too.
If it is needed then it should go into separate patch.

>    unsigned int pos;     /* offset in the JSON string */
>    unsigned int toknext; /* next token to allocate */
>    int toksuper;         /* superior token node, e.g. parent object or array 
> */
> @@ -154,6 +154,9 @@ static int jsmn_parse_primitive(jsmn_parser *parser, 
> const char *js,
>      case ']':
>      case '}':
>        goto found;
> +    default:
> +                   /* to quiet a warning from gcc*/
> +      break;

It seems to me that this belongs to separate patch.

>      }
>      if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
>        parser->pos = start;
> diff --git a/grub-core/lib/json/json.c b/grub-core/lib/json/json.c
> index 15c0d9949..694af4f3a 100644
> --- a/grub-core/lib/json/json.c
> +++ b/grub-core/lib/json/json.c
> @@ -95,7 +95,7 @@ grub_json_getsize (grub_size_t *out, const grub_json_t 
> *json)
>  {
>    int size;
>
> -  size = ((jsmntok_t *)json->tokens)[json->idx].size;
> +  size = json->tokens[json->idx].size;
>    if (size < 0)
>      return GRUB_ERR_OUT_OF_RANGE;
>
> @@ -106,7 +106,7 @@ grub_json_getsize (grub_size_t *out, const grub_json_t 
> *json)
>  grub_err_t
>  grub_json_gettype (grub_json_type_t *out, const grub_json_t *json)
>  {
> -  switch (((jsmntok_t *)json->tokens)[json->idx].type)
> +  switch (json->tokens[json->idx].type)
>      {
>      case JSMN_OBJECT:
>        *out = GRUB_JSON_OBJECT;
> @@ -142,7 +142,7 @@ grub_json_getchild (grub_json_t *out, const grub_json_t 
> *parent, grub_size_t n)
>     * array), as well. We thus add the children's size to n on
>     * each iteration.
>     */
> -  p = &((jsmntok_t *)parent->tokens)[parent->idx];
> +  p = &parent->tokens[parent->idx];
>    while (n--)
>      n += p[offset++].size;
>
> @@ -197,7 +197,7 @@ get_value (grub_json_type_t *out_type, const char 
> **out_string, const grub_json_
>        p = &child;
>      }
>
> -  tok = &((jsmntok_t *) p->tokens)[p->idx];
> +  tok = &p->tokens[p->idx];
>    p->string[tok->end] = '\0';
>
>    *out_string = p->string + tok->start;
> diff --git a/grub-core/lib/json/json.h b/grub-core/lib/json/json.h
> index 358e4bca3..d9f99454d 100644
> --- a/grub-core/lib/json/json.h
> +++ b/grub-core/lib/json/json.h
> @@ -36,9 +36,11 @@ enum grub_json_type
>  };
>  typedef enum grub_json_type grub_json_type_t;
>
> +typedef struct jsmntok jsmntok_t;
> +
>  struct grub_json
>  {
> -  void             *tokens;
> +  jsmntok_t   *tokens;
>    char             *string;

Something is messed up with tabs and spaces here...

Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]