Skip to content

common/json_parse_simple: make convenience functions inline #8414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions common/json_parse_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ bool json_tok_strneq(const char *buffer, const jsmntok_t *tok,
return memeq(buffer + tok->start, tok->end - tok->start, str, len);
}

bool json_tok_streq(const char *buffer, const jsmntok_t *tok, const char *str)
{
return json_tok_strneq(buffer, tok, str, strlen(str));
}

bool json_tok_startswith(const char *buffer, const jsmntok_t *tok,
const char *prefix)
{
Expand Down Expand Up @@ -217,12 +212,6 @@ const jsmntok_t *json_get_membern(const char *buffer,
return NULL;
}

const jsmntok_t *json_get_member(const char *buffer, const jsmntok_t tok[],
const char *label)
{
return json_get_membern(buffer, tok, label, strlen(label));
}

const jsmntok_t *json_get_arr(const jsmntok_t tok[], size_t index)
{
const jsmntok_t *t;
Expand Down
18 changes: 13 additions & 5 deletions common/json_parse_simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ const char *json_tok_full(const char *buffer, const jsmntok_t *t);
/* Include " if it's a string. */
int json_tok_full_len(const jsmntok_t *t);

/* Is this a string equal to str? */
bool json_tok_streq(const char *buffer, const jsmntok_t *tok, const char *str);

/* Is this a string equal to str of length len? */
bool json_tok_strneq(const char *buffer, const jsmntok_t *tok,
const char *str, size_t len);

/* Is this a string equal to str? */
static inline bool json_tok_streq(const char *buffer, const jsmntok_t *tok,
const char *str)
{
return json_tok_strneq(buffer, tok, str, strlen(str));
}

/* Does this string token start with prefix? */
bool json_tok_startswith(const char *buffer, const jsmntok_t *tok,
const char *prefix);
Expand Down Expand Up @@ -66,8 +70,12 @@ const jsmntok_t *json_get_membern(const char *buffer,
const char *label, size_t len);

/* Get top-level member. */
const jsmntok_t *json_get_member(const char *buffer, const jsmntok_t tok[],
const char *label);
static inline const jsmntok_t *json_get_member(const char *buffer,
const jsmntok_t tok[],
const char *label)
{
return json_get_membern(buffer, tok, label, strlen(label));
}

/* Get index'th array member. */
const jsmntok_t *json_get_arr(const jsmntok_t tok[], size_t index);
Expand Down
16 changes: 9 additions & 7 deletions plugins/bkpr/test/run-bkpr_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ bool is_asterix_notification(const char *notification_name UNNEEDED,
const char *json_get_id(const tal_t *ctx UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *obj UNNEEDED)
{ fprintf(stderr, "json_get_id called!\n"); abort(); }
/* Generated stub for json_get_member */
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED)
{ fprintf(stderr, "json_get_member called!\n"); abort(); }
/* Generated stub for json_get_membern */
const jsmntok_t *json_get_membern(const char *buffer UNNEEDED,
const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_get_membern called!\n"); abort(); }
/* Generated stub for json_next */
const jsmntok_t *json_next(const jsmntok_t *tok UNNEEDED)
{ fprintf(stderr, "json_next called!\n"); abort(); }
Expand Down Expand Up @@ -194,9 +195,10 @@ int json_tok_full_len(const jsmntok_t *t UNNEEDED)
void json_tok_remove(jsmntok_t **tokens UNNEEDED,
jsmntok_t *obj_or_array UNNEEDED, const jsmntok_t *tok UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "json_tok_remove called!\n"); abort(); }
/* Generated stub for json_tok_streq */
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); }
/* Generated stub for json_tok_strneq */
bool json_tok_strneq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char *str UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_tok_strneq called!\n"); abort(); }
/* Generated stub for last_fee_state */
enum htlc_state last_fee_state(enum side opener UNNEEDED)
{ fprintf(stderr, "last_fee_state called!\n"); abort(); }
Expand Down
16 changes: 9 additions & 7 deletions plugins/bkpr/test/run-recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ bool is_asterix_notification(const char *notification_name UNNEEDED,
const char *json_get_id(const tal_t *ctx UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *obj UNNEEDED)
{ fprintf(stderr, "json_get_id called!\n"); abort(); }
/* Generated stub for json_get_member */
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED)
{ fprintf(stderr, "json_get_member called!\n"); abort(); }
/* Generated stub for json_get_membern */
const jsmntok_t *json_get_membern(const char *buffer UNNEEDED,
const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_get_membern called!\n"); abort(); }
/* Generated stub for json_next */
const jsmntok_t *json_next(const jsmntok_t *tok UNNEEDED)
{ fprintf(stderr, "json_next called!\n"); abort(); }
Expand Down Expand Up @@ -200,9 +201,10 @@ int json_tok_full_len(const jsmntok_t *t UNNEEDED)
void json_tok_remove(jsmntok_t **tokens UNNEEDED,
jsmntok_t *obj_or_array UNNEEDED, const jsmntok_t *tok UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "json_tok_remove called!\n"); abort(); }
/* Generated stub for json_tok_streq */
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); }
/* Generated stub for json_tok_strneq */
bool json_tok_strneq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char *str UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_tok_strneq called!\n"); abort(); }
/* Generated stub for last_fee_state */
enum htlc_state last_fee_state(enum side opener UNNEEDED)
{ fprintf(stderr, "last_fee_state called!\n"); abort(); }
Expand Down
16 changes: 9 additions & 7 deletions plugins/test/run-route-calc.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ void json_array_end(struct json_stream *js UNNEEDED)
/* Generated stub for json_array_start */
void json_array_start(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED)
{ fprintf(stderr, "json_array_start called!\n"); abort(); }
/* Generated stub for json_get_member */
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED)
{ fprintf(stderr, "json_get_member called!\n"); abort(); }
/* Generated stub for json_get_membern */
const jsmntok_t *json_get_membern(const char *buffer UNNEEDED,
const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_get_membern called!\n"); abort(); }
/* Generated stub for json_next */
const jsmntok_t *json_next(const jsmntok_t *tok UNNEEDED)
{ fprintf(stderr, "json_next called!\n"); abort(); }
Expand Down Expand Up @@ -245,9 +246,10 @@ const char *json_tok_full(const char *buffer UNNEEDED, const jsmntok_t *t UNNEED
/* Generated stub for json_tok_full_len */
int json_tok_full_len(const jsmntok_t *t UNNEEDED)
{ fprintf(stderr, "json_tok_full_len called!\n"); abort(); }
/* Generated stub for json_tok_streq */
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); }
/* Generated stub for json_tok_strneq */
bool json_tok_strneq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char *str UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_tok_strneq called!\n"); abort(); }
/* Generated stub for jsonrpc_request_start_ */
struct out_req *jsonrpc_request_start_(struct command *cmd UNNEEDED,
const char *method UNNEEDED,
Expand Down
16 changes: 9 additions & 7 deletions plugins/test/run-route-overlong.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ void json_array_end(struct json_stream *js UNNEEDED)
/* Generated stub for json_array_start */
void json_array_start(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED)
{ fprintf(stderr, "json_array_start called!\n"); abort(); }
/* Generated stub for json_get_member */
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED)
{ fprintf(stderr, "json_get_member called!\n"); abort(); }
/* Generated stub for json_get_membern */
const jsmntok_t *json_get_membern(const char *buffer UNNEEDED,
const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_get_membern called!\n"); abort(); }
/* Generated stub for json_next */
const jsmntok_t *json_next(const jsmntok_t *tok UNNEEDED)
{ fprintf(stderr, "json_next called!\n"); abort(); }
Expand Down Expand Up @@ -242,9 +243,10 @@ const char *json_tok_full(const char *buffer UNNEEDED, const jsmntok_t *t UNNEED
/* Generated stub for json_tok_full_len */
int json_tok_full_len(const jsmntok_t *t UNNEEDED)
{ fprintf(stderr, "json_tok_full_len called!\n"); abort(); }
/* Generated stub for json_tok_streq */
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); }
/* Generated stub for json_tok_strneq */
bool json_tok_strneq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char *str UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_tok_strneq called!\n"); abort(); }
/* Generated stub for jsonrpc_request_start_ */
struct out_req *jsonrpc_request_start_(struct command *cmd UNNEEDED,
const char *method UNNEEDED,
Expand Down
16 changes: 9 additions & 7 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,11 @@ void json_array_end(struct json_stream *js UNNEEDED)
/* Generated stub for json_array_start */
void json_array_start(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED)
{ fprintf(stderr, "json_array_start called!\n"); abort(); }
/* Generated stub for json_get_member */
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED)
{ fprintf(stderr, "json_get_member called!\n"); abort(); }
/* Generated stub for json_get_membern */
const jsmntok_t *json_get_membern(const char *buffer UNNEEDED,
const jsmntok_t tok[] UNNEEDED,
const char *label UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_get_membern called!\n"); abort(); }
/* Generated stub for json_next */
const jsmntok_t *json_next(const jsmntok_t *tok UNNEEDED)
{ fprintf(stderr, "json_next called!\n"); abort(); }
Expand Down Expand Up @@ -636,9 +637,10 @@ bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEE
/* Generated stub for json_tok_full */
const char *json_tok_full(const char *buffer UNNEEDED, const jsmntok_t *t UNNEEDED)
{ fprintf(stderr, "json_tok_full called!\n"); abort(); }
/* Generated stub for json_tok_streq */
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); }
/* Generated stub for json_tok_strneq */
bool json_tok_strneq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char *str UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "json_tok_strneq called!\n"); abort(); }
/* Generated stub for kill_uncommitted_channel */
void kill_uncommitted_channel(struct uncommitted_channel *uc UNNEEDED,
const char *why UNNEEDED)
Expand Down
Loading