summaryrefslogtreecommitdiff
path: root/json-glib/json-parser.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'coverity-leak' into 'master'Emmanuele Bassi2022-10-111-6/+6
|\ | | | | | | | | builder: Don't leak memory if json_builder_get_root fails sanity check See merge request GNOME/json-glib!46
| * builder,parser: Use g_assert for sanity checksRay Strode2021-10-191-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Coverity noticed a leak in json_builder_get_root that can't happen in practice. Namely, if internal state gets screwed up and runtime checks are enabled, json_builder_get_root may return NULL without freeing a copy of the builder root it just made. This is because of a g_return_val_if_fail call to bail early if an internal consistency sanity check fails. This commit addresses the coverity complaint by using g_assert instead of g_return_val_if_fail for this sanity check, and other similar sanity checks, in the code.
* | Drop or mark unused parametersEmmanuele Bassi2022-10-111-1/+1
| | | | | | | | Avoid compiler warnings when running with `-Wunused-parameter`.
* | Fix sign comparison warningsEmmanuele Bassi2022-10-111-6/+4
|/ | | | | When running with `-Wsign-compare` we're raising a lot of signed/unsigned comparison warnings.
* Update the JsonParser documentationEmmanuele Bassi2021-06-101-77/+105
|
* docs: Initial, rough port away from gtk-docEmmanuele Bassi2021-06-081-61/+63
| | | | | | | | | | Drop `SECTION` blurbs. Use gi-docgen syntax for internal links. Use summary lines for gi-docgen indices. Use Markdown syntax for code fragments.
* Do not leak memory for duplicate var assignmentRichard Hughes2021-02-201-0/+2
| | | | Fixes https://gitlab.gnome.org/GNOME/json-glib/-/issues/58
* parser: Ignore UTF-8 BOM if necessaryhandle-utf8-bomJan-Michael Brummer2020-12-311-1/+15
| | | | | | | | | According to JSON spec BOM shouldn't be part of the JSON data, but also recommends to tolerate files with a BOM marker. As this is common in several Windows JSON generators, handle it graceful in json-glib and skip it for UTF-8 BOM. Fixes: https://gitlab.gnome.org/GNOME/json-glib/-/issues/56
* Properly detect multiple top level statementsEmmanuele Bassi2020-08-241-15/+12
| | | | | | | | JSON can only have one top level statement. If we get multiple statements, we should error out appropriately, and we should also avoid leaking the node for the previously parsed statement. Fixes: #45
* json-parser: Support loading files via memory mappingPhilip Withnall2020-06-091-0/+58
| | | | | | | | | | | | | | | Add a new `json_parser_load_from_mapped_file()` to load JSON from files via memory mapping. It’s otherwise similar to `json_parser_load_from_file()`. It’s in the right position to be able to memory map the file it’s reading from: it reads the input once before building a `JsonNode` structure to represent it, doesn’t write to the file, and often deals with large input files. This should speed things up slightly due to reducing time spent allocating a large chunk of heap memory to load the file into, if a caller can support that. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* typo: parser -> parsedAlexandre Viau2020-01-101-1/+1
|
* Merge branch 'leak-fix' into 'master'Emmanuele Bassi2017-12-151-0/+2
|\ | | | | | | | | Leak fix See merge request GNOME/json-glib!6
| * json-parser: Fix a memory leak on two error handling pathsPhilip Withnall2017-12-151-0/+2
| | | | | | | | | | | | | | | | | | Small leak. With some additional fixes to the tests themselves, this makes all the tests run valgrind-clean. (See the following commit.) Signed-off-by: Philip Withnall <withnall@endlessm.com> https://gitlab.gnome.org/GNOME/json-glib/issues/30
* | json-parser: Fix getting immutable root nodes from empty inputPhilip Withnall2017-12-151-5/+14
|/ | | | | | | | | | | | | | If parsing an empty document, it’s allowed to return NULL from json_parser_get_root(). This was broken for immutable parsers when immutability support was added (an assertion fails). Fix that, and also document that json_parser_get_root() may return NULL. Do the same for json_parser_steal_root() too, which is another way that the root node may be NULL. Add a unit test. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* parser: Use g_steal_pointer()Emmanuele Bassi2017-03-181-8/+2
| | | | | GLib already has a convenient API for stealing pointer values and replacing them with NULL, so let's use it.
* core: Add json_parser_steal_root()Ole André Vadla Ravnås2017-03-181-0/+26
| | | | | | This avoids copying the root node for the parse-to-node use-case. https://bugzilla.gnome.org/show_bug.cgi?id=774688
* Stop providing our own marshaller and use the generic oneThibault Saunier2017-03-131-19/+10
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=773603
* Only seal arrays and objects when a parser is immutableEmmanuele Bassi2017-03-131-2/+4
| | | | | | | We seal nodes conditionally on the :immutable property, but we are sealing their contents unconditionally. https://bugzilla.gnome.org/show_bug.cgi?id=779970
* Allow empty string as object member nameDr. David Alan Gilbert2017-03-111-1/+1
| | | | | | | | | | | Commit 028e540 disallowed empty member names in objects, however they are unfortunately valid JSON. This patch reenables an empty string as a member name. Tests are updated to allow the empty string case, and to test the use of an empty string in generation, iteration etc. https://bugzilla.gnome.org/show_bug.cgi?id=747279
* Fix translator commentsPiotr Drąg2017-01-281-4/+4
| | | | They need to be exactly one line above a string to show up in .po files.
* parser: Rename `immutable` bit fieldEmmanuele Bassi2016-03-011-9/+9
|
* docs: Fix the Since tagsEmmanuele Bassi2016-03-011-2/+2
| | | | The newly added API is available since 1.2.
* core: Add JSON node, object, array hashesPhilip Withnall2016-03-011-6/+2
| | | | | | | | | | | | | | | | | | | Now that these objects can be marked as immutable, it is possible to calculate and cache hash values for each of them. This allows efficient hash-based deduplication of large numbers of JSON nodes, as needed by Walbottle for JSON test vector generation. To complement the new hash functions, each of JsonNode, JsonValue, JsonObject and JsonArray also now have an equal() comparison method. This compares them structurally and recursively, using the definition of equality from the JSON Schema specification, which seems as good as any other. http://json-schema.org/latest/json-schema-core.html#anchor9 https://bugzilla.gnome.org/show_bug.cgi?id=756121 Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
* node: Add json_node_ref() and json_node_unref()Philip Withnall2016-03-011-12/+12
| | | | | | | | | | | | | | Add reference counting semantics to JsonNode, in addition to the existing init/unset and alloc/free semantics. json_node_free() must only be used with nodes allocated using json_node_alloc(). json_node_unref() may be used with all nodes (if correctly paired; it may be paired with json_node_alloc()). It is not valid to call json_node_free() on a node whose reference count is not 1. https://bugzilla.gnome.org/show_bug.cgi?id=756121
* core: Add immutability support to core objectsPhilip Withnall2016-03-011-0/+108
| | | | | | | | | | | Add an immutable mode to JsonNode, JsonObject, JsonArray and JsonValue. This is an optional mode which objects enter by calling json_*_seal(). It is a one-way transition, which means that we can build and manipulate objects as much as desired, before sealing them and enjoying the benefits of immutable objects: no need to take copies when handling them, persistent hash values (still to be implemented). https://bugzilla.gnome.org/show_bug.cgi?id=756121
* parser: Detect missing commas in arraysEmmanuele Bassi2016-02-251-1/+14
| | | | | Just like we detect trailing commas, we should also detect missing ones to avoid parsing invalid JSON successfully.
* parser: Correctly increment the array index counterEmmanuele Bassi2016-02-251-1/+2
| | | | | We pass the counter to the JsonParser::array-element signal, but we never really increment it.
* parser: Port to GTaskEmmanuele Bassi2015-06-091-118/+62
| | | | | GSimpleAsyncResult is deprecated in GLib 2.46, so we should drop its use, and simplify the code in the process.
* Drop unnecessary '_' prefix from json_marshalEmmanuele Bassi2014-12-301-9/+9
| | | | | It's not public API anyway, and we use annotations instead of the '_' prefix.
* json-parser: use length parameter when validating utf-8djcb2014-04-171-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=727755
* parser: Use the right length for parsing the stream contentsEmmanuele Bassi2014-04-171-2/+2
| | | | | | | The ByteArray we use to buffer the contents of a stream in order to pass them to the parser may have a bigger length. We should use the cursor position that we use to put a '\0' in the buffer instead. We could also use -1, but this saves us a strlen() later on.
* Remove conditional inclusion of config.hEmmanuele Bassi2014-03-181-2/+0
| | | | All the platforms and build system we support have a config.h header.
* parser: Always perform UTF-8 validationEmmanuele Bassi2013-10-271-0/+9
| | | | | | JSON is defined to be encoded using UTF-8, so we should not rely on the documentation saying so when parsing, but validate the input and eventually provide a recoverable parsing error.
* parser: Always use a valid GError internallyEmmanuele Bassi2013-10-261-2/+15
| | | | | Do not just pass the GError through from the public-facing arguments: we may want to perform error checking internally at any later date.
* parser: Drop a pointless macroEmmanuele Bassi2013-08-221-4/+2
| | | | | The JSON_PARSER_GET_PRIVATE macro is pointless, now that we use the new version of GLib.
* Remove compile time GLib version checkEmmanuele Bassi2013-08-211-13/+1
| | | | | We depend on a new version of GLib, so we can remove a bunch of old version checks.
* Use new macros when compiling against new GLibEmmanuele Bassi2013-07-201-1/+11
| | | | | | | | If we're being compiled against a newer version of GLib, we should use the new macros that add instance private data. Since this is a stable branch, we cannot bump the GLib requirement; so we use version checks to conditionally compile the new code.
* Use G_DEFINE_QUARK macroEmmanuele Bassi2013-05-161-7/+3
| | | | Instead of hand-writing the error domain function ourselves.
* Use typed initializers for JsonNodeEmmanuele Bassi2012-10-271-16/+21
|
* scanner: Remove unused functionsEmmanuele Bassi2012-10-261-29/+23
| | | | | | | | JsonScanner is an internal, modified copy of GScanner; we don't need a bunch of the provided functions, as the type and its related API are meant for internal use only. Fewer functions == better coverage == less code to maintain.
* parser: Empty member names are not validEmmanuele Bassi2012-10-261-0/+13
| | | | | When parsing a JSON object, a member name has to be a valid string, not an empty one.
* parser: Use error codes for invalid assignmentsEmmanuele Bassi2012-10-251-1/+3
| | | | | In case we're parsing an assignment we should use the 'invalid bareword' error code.
* parser: Consolidate value parsingEmmanuele Bassi2012-10-251-25/+12
| | | | | | | Instead of doing a preliminary check when parsing arrays and objects, we should just call json_parse_value() and let it handle all the valid values and eventual error cases. This simplifies error handling and makes it more reliable.
* parser: Show the column in the error messageEmmanuele Bassi2012-10-251-2/+3
| | | | | For JSON parsed from data (which tends to be in a single line) the column holds more information than the line.
* parser: Fix small leak in json_parse_statementMiguel Angel Cabrera Moya2012-10-251-1/+4
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=686096
* Mark GError messages for translationsEmmanuele Bassi2011-06-011-1/+4
| | | | These errors might find their way into a UI.
* Add i18n machineryEmmanuele Bassi2011-06-011-0/+2
| | | | We need to translate the GError messages.
* Add missing introspection annotations.Luca Bruno2011-01-101-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=638932
* parser: Add loading from a GInputStreamEmmanuele Bassi2010-08-021-0/+258
| | | | | JsonParser should be able to use a GInputStream (both synchronously and asynchronously) to retrieve the JSON data and parse it.
* parser: Do not access GScanner:tokenEmmanuele Bassi2010-05-261-3/+6
| | | | | | | | | The GScanner:token member is declared as GTokenType instead of being an unsigned int. This means that comparing it to any other enumeration is going to generate a warning in GCC >= 4.5. Unfortunately, extending the GTokenType enumeration is the idiomatic way of handling new tokens. EPIC. FAIL.