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/elf-util.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/elf-util.c')
-rw-r--r-- | src/shared/elf-util.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/shared/elf-util.c b/src/shared/elf-util.c index da095935e5..7428152faa 100644 --- a/src/shared/elf-util.c +++ b/src/shared/elf-util.c @@ -403,7 +403,7 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e /* If we have a build-id, merge it in the same JSON object so that it appears all * nicely together in the logs/metadata. */ if (id_json) { - r = json_variant_merge(&v, id_json); + r = json_variant_merge_object(&v, id_json); if (r < 0) return log_error_errno(r, "json_variant_merge of package meta with buildId failed: %m"); } @@ -419,7 +419,7 @@ static int parse_package_metadata(const char *name, JsonVariant *id_json, Elf *e if (r < 0) return log_error_errno(r, "Failed to build JSON object: %m"); - r = json_variant_merge(c->package_metadata, w); + r = json_variant_merge_object(c->package_metadata, w); if (r < 0) return log_error_errno(r, "json_variant_merge of package meta with buildId failed: %m"); @@ -712,7 +712,7 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r if (r < 0) return log_warning_errno(r, "Failed to build JSON object: %m"); - r = json_variant_merge(&elf_metadata, json_architecture); + r = json_variant_merge_object(&elf_metadata, json_architecture); if (r < 0) return log_warning_errno(r, "Failed to merge JSON objects: %m"); @@ -722,7 +722,7 @@ static int parse_elf(int fd, const char *executable, char **ret, JsonVariant **r #endif /* We always at least have the ELF type, so merge that (and possibly the arch). */ - r = json_variant_merge(&elf_metadata, package_metadata); + r = json_variant_merge_object(&elf_metadata, package_metadata); if (r < 0) return log_warning_errno(r, "Failed to merge JSON objects: %m"); |