summaryrefslogtreecommitdiffstats
path: root/json-parser.c
Commit message (Collapse)AuthorAgeFilesLines
* json-parser: don't replicate tokens at each level of recursionMichael Roth2012-08-161-88/+142
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, when parsing a stream of tokens we make a copy of the token list at the beginning of each level of recursion so that we do not modify the original list in cases where we need to fall back to an earlier state. In the worst case, we will only read 1 or 2 tokens off the list before recursing again, which means an upper bound of roughly N^2 token allocations. For a "reasonably" sized QMP request (in this a QMP representation of cirrus_vga's device state, generated via QIDL, being passed in via qom-set), this caused my 16GB's of memory to be exhausted before any noticeable progress was made by the parser. This patch works around the issue by using single copy of the token list in the form of an indexable array so that we can save/restore state by manipulating indices. A subsequent commit adds a "large_dict" test case which exhibits the same behavior as above. With this patch applied the test case successfully completes in under a second. Tested with valgrind, make check, and QMP. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* json-parser: add handling for NULL token listMichael Roth2011-06-071-1/+5
| | | | | | | | Currently a NULL token list will crash the parser, instead we have it pass back a NULL QObject. Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* json-parser: detect premature EOIAnthony Liguori2011-06-071-1/+57
| | | | | Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* json-parser: propagate error from parserAnthony Liguori2011-06-071-3/+16
| | | | | Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Use GCC_FMT_ATTR (format checking)Stefan Weil2010-10-031-1/+2
| | | | | Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Merge remote branch 'qmp/for-anthony' into stagingAnthony Liguori2010-06-141-0/+4
|\
| * qjson: Handle "\f"Luiz Capitulino2010-06-111-0/+4
| | | | | | | | | | | | It's valid JSON and should be handled. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* | Move stdbool.hPaul Brook2010-06-131-1/+0
|/ | | | | | | Move inclusion of stdbool.h to common header files, instead of including in an ad-hoc manner. Signed-off-by: Paul Brook <paul@codesourcery.com>
* json-parser: Output the content of invalid keywordAmos Kong2010-03-271-1/+7
| | | | | | | | | | | | | | When input some invalid word 'unknowcmd' through QMP port, qemu outputs this error message: "parse error: invalid keyword `%s'" This patch makes qemu output the content of invalid keyword, like: "parse error: invalid keyword `unknowcmd'" Signed-off-by: Amos Kong <akong@redhat.com> Acked-by: Richard Henderson <rth@redhat.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* json-parser: Fix segfault on malformed inputKevin Wolf2010-03-061-1/+1
| | | | | | | | | If the parser fails to parse the key in parse_pair, it will access a NULL pointer. A simple way to trigger this is sending {foo} via QMP. This patch turns the segfault into a syntax error reply. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* json: fix PRId64 on Win32Roy Tam2010-02-101-1/+2
| | | | | | | | | | OK we are fooled by the json lexer and parser. As we use %I64d to print 'long long' variables in Win32, but lexer and parser only deal with %lld but not %I64d, this patch add support for %I64d and solve 'info pci', 'powser_reset' and 'power_powerdown' assert failure in Win32. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* json-parser: remove dead incrementAmit Shah2010-01-131-2/+0
| | | | | | | clang-analyzer points out a redundant increment. Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Add a JSON parserAnthony Liguori2009-11-171-0/+568
This is the third and final stage of the JSON parser. It parses lexical tokens performing grammar validation and creating the final QObject representation. It uses a recursive decent parser. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
OpenPOWER on IntegriCloud