A new attempt at location information for decoded JSON elements#662
Open
n0-1 wants to merge 4 commits intoakheron:masterfrom
Open
A new attempt at location information for decoded JSON elements#662n0-1 wants to merge 4 commits intoakheron:masterfrom
n0-1 wants to merge 4 commits intoakheron:masterfrom
Conversation
This macro is very similar to fail() but supports variable number of arguments to print format strings. Signed-off-by: Phil Sutter <psutter@redhat.com>
This will turn on recording of parsed JSON elements in input. Signed-off-by: Phil Sutter <psutter@redhat.com>
When storing object location, the singleton true, false and null objects are problematic since they are indistinguishable from each other. Overcome this by introducing a refcounted variant to allocate when JSON_STORE_LOCATION flag was given. Signed-off-by: Phil Sutter <psutter@redhat.com>
Aid users in printing semantic errors in JSON input by providing them with location data for each parsed JSON element. An example usage of such data is demonstrated by nftables' error messages: | # nft add chain mytable mychain | Error: No such file or directory | add chain mytable mychain | ^^^^^^^ To reduce overhead for library users not interested in such data, store it only if `JSON_STORE_LOCATION' flag was passed to json_load*() functions. It may then be retrieved using the new API function json_get_location(). Signed-off-by: Phil Sutter <psutter@redhat.com>
Author
|
Rebased onto current HEAD, no functional changes intended. This merge request is lingering uncommented for over a year now. Quite frustrating to receive no feedback at all. Is the implemented feature really unnecessary? How do other folks report semantic errors in JSON input? |
|
It seems like a cool feature to me, and I appreciate that it's optional. @akheron thoughts? |
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.
This is a respin of the rejected #461 containing a reimplementation of the
feature in a less intrusive manner for library users keeping it disabled.
The nftables project is very interested in having this feature to provide
similar error reporting to its JSON API users as there is for non-JSON input.
This new implementation does not introduce any overhead on storage and
negligible on CPU cycles if not enabled: It then boils down to a few extra
function calls returning early after a simple variable value check.
The above is realized by storing json_t objects' location data in a hash table
indexed by the object's address. The table is initialized upon first insert,
which then registers a destructor function using atexit() to free up any data
at program exit (to avoid complaints from memory checkers like valgrind).
If an object is deleted, its corresponding hashtable entry is removed along
with it. To facilitate location data for simple values, the singleton 'true',
'false' and 'null' objects have to be turned into allocated data structures (so
they get a unique address in memory).
This MR contains five commits: