qemu-patch-raspberry4/include
Markus Armbruster 62815d85ae json: Redesign the callback to consume JSON values
The classical way to structure parser and lexer is to have the client
call the parser to get an abstract syntax tree, the parser call the
lexer to get the next token, and the lexer call some function to get
input characters.

Another way to structure them would be to have the client feed
characters to the lexer, the lexer feed tokens to the parser, and the
parser feed abstract syntax trees to some callback provided by the
client.  This way is more easily integrated into an event loop that
dispatches input characters as they arrive.

Our JSON parser is kind of between the two.  The lexer feeds tokens to
a "streamer" instead of a real parser.  The streamer accumulates
tokens until it got the sequence of tokens that comprise a single JSON
value (it counts curly braces and square brackets to decide).  It
feeds those token sequences to a callback provided by the client.  The
callback passes each token sequence to the parser, and gets back an
abstract syntax tree.

I figure it was done that way to make a straightforward recursive
descent parser possible.  "Get next token" becomes "pop the first
token off the token sequence".  Drawback: we need to store a complete
token sequence.  Each token eats 13 + input characters + malloc
overhead bytes.

Observations:

1. This is not the only way to use recursive descent.  If we replaced
   "get next token" by a coroutine yield, we could do without a
   streamer.

2. The lexer reports errors by passing a JSON_ERROR token to the
   streamer.  This communicates the offending input characters and
   their location, but no more.

3. The streamer reports errors by passing a null token sequence to the
   callback.  The (already poor) lexical error information is thrown
   away.

4. Having the callback receive a token sequence duplicates the code to
   convert token sequence to abstract syntax tree in every callback.

5. Known bug: the streamer silently drops incomplete token sequences.

This commit rectifies 4. by lifting the call of the parser from the
callbacks into the streamer.  Later commits will address 3. and 5.

The lifting removes a bug from qjson.c's parse_json(): it passed a
pointer to a non-null Error * in certain cases, as demonstrated by
check-qjson.c.

json_parser_parse() is now unused.  It's a stupid wrapper around
json_parser_parse_err().  Drop it, and rename json_parser_parse_err()
to json_parser_parse().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180823164025.12553-35-armbru@redhat.com>
2018-08-24 20:26:37 +02:00
..
block block: Fix documentation for BDRV_REQ_MAY_UNMAP 2018-07-30 15:35:37 +02:00
chardev chardev/char-fe: Fix typos 2018-08-23 13:32:50 +02:00
crypto tests: call qcrypto_init instead of gnutls_global_init 2018-07-24 17:33:39 +01:00
disas RISC-V Disassembler 2018-03-07 08:30:28 +13:00
exec linux-user fixes: 2018-08-21 11:36:15 +01:00
fpu softfloat: Add scaling float-to-int routines 2018-08-24 13:17:30 +01:00
hw check/next for 20180822 2018-08-24 14:46:31 +01:00
io qio: non-default context for TLS handshake 2018-03-06 10:19:07 +00:00
libdecnumber Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
migration vmstate.h: Provide VMSTATE_UINT16_SUB_ARRAY 2018-08-14 17:17:20 +01:00
monitor monitor: Fix unsafe sharing of @cur_mon among threads 2018-07-23 14:00:03 +02:00
net net: Remove the deprecated "vlan" parameter 2018-05-14 15:47:14 +08:00
qapi json: Redesign the callback to consume JSON values 2018-08-24 20:26:37 +02:00
qemu json: Reject invalid UTF-8 sequences 2018-08-24 20:26:37 +02:00
qom qom: convert the CPU list to RCU 2018-08-23 18:46:25 +02:00
scsi pr-manager: add query-pr-managers QMP command 2018-06-28 19:05:35 +02:00
standard-headers fw_cfg: import & use linux/qemu_fw_cfg.h 2018-08-23 18:46:25 +02:00
sysemu fw_cfg: ignore suffixes in the bootdevice list dependent on machine class 2018-08-16 22:27:43 -03:00
ui Add gles support to egl-helpers, wire up in egl-headless and gtk. 2018-06-26 13:48:49 +02:00
elf.h elf: Add ELF flags for MIPS machine variants 2018-08-16 19:18:45 +02:00
glib-compat.h glib: enforce the minimum required version and warn about old APIs 2018-06-29 12:22:28 +01:00
qemu-common.h qemu-options: Bail out on unsupported options instead of silently ignoring them 2018-05-09 00:13:39 +02:00
qemu-io.h qemu-io: Let command functions return error code 2018-06-11 16:18:45 +02:00
trace-tcg.h trace: get rid of generated-events.h/generated-events.c 2016-10-12 09:54:52 +02:00