diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-08-24 09:41:48 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-08-24 13:20:39 +0200 |
commit | e931768eb4687ac5a456987fe5bea4ec87225637 (patch) | |
tree | 6ee676773c99f6fd5158f2ef5543f8fdcc5203e5 /src/shared/bootspec.c | |
parent | tree-wide: use json_variant_append_arrayb() at many places (diff) | |
download | systemd-e931768eb4687ac5a456987fe5bea4ec87225637.tar.xz systemd-e931768eb4687ac5a456987fe5bea4ec87225637.zip |
json: rename json_append() → json_variant_merge_objectb()
json_append() is a useful wrapper around json_variant_merge(). However,
I think the naming sould be cleaned up a bit of both functions.
I thinker "merge" is the better word than "append", since it does
decidedly more than just append: it replaces existing fields of the same
name, hence "merge" sounds more appropriate. This is as opposed to the
similar operations for arrays, where no such override logic is applied
and we really just append, hence those functions are called "append"
already.
To make clearer that "merge" is about objects, and "append" about
arrays, also include "object" in the name.
Also, include "json_variant" in the name, like we do for almost all
other functions in the JSON API that take a JSON object as primary
input, and hence are kinda object methods.
Finally, let's follow the logic that helpers that combine json_build()
with some other operation get suffixed with "b" like we already have in
some cases.
Hence:
json_variant_merge() → json_variant_merge_object()
json_append() → json_variant_merge_objectb()
This mirrors nicely the existing:
json_variant_append_array()
json_vairant_append_arrayb()
This also drops the variant of json_append() that takes a va_arg
parameter (i.e. json_appendv()). We have no user of that so far, and
given the nature as a helper function only I don#t see that happening,
and if it happens after all it's trivial to bring back.
Diffstat (limited to 'src/shared/bootspec.c')
-rw-r--r-- | src/shared/bootspec.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 6459f5d2f8..8d16b36be1 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -1428,7 +1428,8 @@ int show_boot_entries(const BootConfig *config, JsonFormatFlags json_format) { return log_oom(); } - r = json_append(&v, JSON_BUILD_OBJECT( + r = json_variant_merge_objectb( + &v, JSON_BUILD_OBJECT( JSON_BUILD_PAIR("type", JSON_BUILD_STRING(boot_entry_type_json_to_string(e->type))), JSON_BUILD_PAIR_CONDITION(e->id, "id", JSON_BUILD_STRING(e->id)), JSON_BUILD_PAIR_CONDITION(e->path, "path", JSON_BUILD_STRING(e->path)), @@ -1451,7 +1452,8 @@ int show_boot_entries(const BootConfig *config, JsonFormatFlags json_format) { /* Sanitizers (only memory sanitizer?) do not like function call with too many * arguments and trigger false positive warnings. Let's not add too many json objects * at once. */ - r = json_append(&v, JSON_BUILD_OBJECT( + r = json_variant_merge_objectb( + &v, JSON_BUILD_OBJECT( JSON_BUILD_PAIR("isReported", JSON_BUILD_BOOLEAN(e->reported_by_loader)), JSON_BUILD_PAIR_CONDITION(e->tries_left != UINT_MAX, "triesLeft", JSON_BUILD_UNSIGNED(e->tries_left)), JSON_BUILD_PAIR_CONDITION(e->tries_done != UINT_MAX, "triesDone", JSON_BUILD_UNSIGNED(e->tries_done)), |