Make our JSON APIs a public interface sd-json.h#32628
Make our JSON APIs a public interface sd-json.h#32628poettering merged 5 commits intosystemd:mainfrom
Conversation
|
This is v257 material, in case this wasn't clear. |
|
|
||
| _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_json_variant, sd_json_variant_unref); | ||
|
|
||
| const char *sd_json_variant_string(sd_json_variant *v); |
There was a problem hiding this comment.
Not addressed, though not a big matter.
| int sd_json_variant_unbase64(sd_json_variant *v, void **ret, size_t *ret_size); | ||
| int sd_json_variant_unhex(sd_json_variant *v, void **ret, size_t *ret_size); | ||
|
|
||
| const char *sd_json_variant_type_to_string(sd_json_variant_type_t t); |
In some recent PRs (e.g. systemd#32628) I started to systematically name return parameters that shall only be initialized on failure (because they carry additional error meta information, such as the line/column number of parse failures or so). Let's make this official in the coding style.
The functions more or less do the same thing. Merge them. This makes json_dispatch_path() the common resulting implementation. it learnt: 1. Will reset the path to NULL if specified as null in JSON 2. Depending on the JSON_SAFE flag will insist on normalized path or not With this the two implementations are identical, except for the differences now toggable via JSON_SAFE flag
This is preparation for making our Varlink API a public API. Since our Varlink API is built on top of our JSON API we need to make that public first (it's a nice API, but JSON APIs there are already enough, this is purely about the Varlink angle). I made most of the json.h APIs public, and just placed them in sd-json.h. Sometimes I wasn't so sure however, since the underlying data structures would have to be made public too. If in doubt I didn#t risk it, and moved the relevant API to src/libsystemd/sd-json/json-util.h instead (without any sd_* symbol prefixes). This is mostly a giant search/replace patch.
The flag is fairly generic these days and just selects a slightly stricter validation, with details depending on the selected dispatch function. Hence, let's give it more precise name, in particular one that mirrors the SD_JSON_RELAXED flag nicely (which does the opposite: relaxes parsing)
In some recent PRs (e.g. systemd#32628) I started to systematically name return parameters that shall only be initialized on failure (because they carry additional error meta information, such as the line/column number of parse failures or so). Let's make this official in the coding style.
In some recent PRs (e.g. #32628) I started to systematically name return parameters that shall only be initialized on failure (because they carry additional error meta information, such as the line/column number of parse failures or so). Let's make this official in the coding style.
| uint16_t depth; | ||
|
|
||
| JsonVariantType type:8; | ||
| int type:8; /* actually sd_json_variant_type_t, but reduced to 8bit size */ |
There was a problem hiding this comment.
Bit field type of type int should have explicitly unsigned integral, explicitly signed integral, or enumeration type.
There was a problem hiding this comment.
@poettering is this a false positive? Or does it need fixup?
There was a problem hiding this comment.
dunno, sd_json_variant_type_t is actually always going to be mapped to a signed int by the compiler. But of course we know that in this context it never can be negative, we are only going to store valid sd_json_variant_type_t in this field, i.e. not -EINVAL or so. Hence, the code as it is now is safe. I can understand the tools reasoning to cmplain abou this.
I'd probably say that it's a false positive, and leave the code as is.
There was a problem hiding this comment.
or maybe we can add the signed before it.
There was a problem hiding this comment.
Can you give that a shot? It should become apparent in the PR if it is enough to fix it
In some recent PRs (e.g. systemd#32628) I started to systematically name return parameters that shall only be initialized on failure (because they carry additional error meta information, such as the line/column number of parse failures or so). Let's make this official in the coding style. (cherry picked from commit 7811864)
In some recent PRs (e.g. #32628) I started to systematically name return parameters that shall only be initialized on failure (because they carry additional error meta information, such as the line/column number of parse failures or so). Let's make this official in the coding style. (cherry picked from commit 7811864)
This is preparation for making our Varlink API a public API. Since our Varlink API is built on top of our JSON API we need to make that public first (it's a nice API, but JSON APIs there are already enough, this is purely about the Varlink angle).