Add libjansson compile-time validation and support header#1004
Open
Add libjansson compile-time validation and support header#1004
Conversation
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
af1eaa3 to
067767d
Compare
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
067767d to
1cf4acc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I've started to look into the places where we are parsing/unpacking JSON values and noticed several subtle errors. There are various places where the format strings are not matching the argument lists, so I've implemented a "quick-and-dirty" compile-time validated wrapper around
json_unpackandjson_packthat raises compile errors when the format string is not matching the arguments.Compatiblility with #1001
I'm still working on #1001 where I want to move the configuration parsing from
libjanssontonlohmann::jsonbut theJanssonPtrsmart pointer and format string validators are a nice first step in improving our existing JSON parsing code. And especially the smart pointer is really useful for the incremental conversion discussed in #1001.Examples
Incompatible argument type
Let's look at this initial change I did in
common/lib/hist.cpp:This is the error I received here:
The type of
totalis actuallycnt_t(an alias tounsigned long) which is incompatible withint. The error isn't perfect, as it doesn't tell us which specific variable or format specifier is wrong here, but it is good enough as a basic direction.Unused arguments
Let's look at this example in
lib/nodes/webrtc.cpp:ret = json_unpack_ex( json, &err, 0, "{ s: s, s?: s, s?: s, s?: i, s?: i, s?: b, s?: o }", "session", &sess, "peer", &pr, "server", &svr, "wait_seconds", &wait_seconds, "max_retransmits", &rexmit, "ordered", &ord, "ice", &json_ice, "format", &json_format);Can you spot the error? The
"format", &json_formatarguments do not have a corresponding specifier in the format string and thus were always just ignored.This becomes more obvious after a little cleanup:
And the compiler helps me with this error here: