summaryrefslogtreecommitdiff
path: root/json-glib
Commit message (Collapse)AuthorAgeFilesLines
* parser: Ignore UTF-8 BOM if necessaryhandle-utf8-bomJan-Michael Brummer2020-12-314-1/+46
| | | | | | | | | 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
* tests: Add surrogate pair testsJames Westman2020-11-301-0/+3
|
* scanner: Fix crash on malformed surrogate pairsJames Westman2020-11-301-4/+24
| | | | | | | | | | | JSON-GLib would crash when trying to decode escaped Unicode characters, if a character of a surrogate pair was detected but it was in the wrong range, or if the following character was not in the correct range. Fixed by emitting an error ("Parse error: scanner: malformed surrogate pair") before the assertion is run. Fixes #26.
* Fix build reproducibilityAlexander Kanavin2020-11-011-2/+2
| | | | | | | | | Changes the comment and include to reference the file basename instead of the full path. This ensures that the generated file is reproducible when it is included in source packages meant for debugging. Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
* Gracefully handle empty arrays and objectsEmmanuele Bassi2020-08-242-11/+14
| | | | | | Don't pretty print newlines. This requires a change in the generator test, but the pretty printing format is not stable anyway, so we can get away with it.
* build: Maintain Autotools compatibility on DarwinEmmanuele Bassi2020-08-241-0/+1
| | | | | | | | | | | | | JSON-GLib 1.2 was the last release using Autotools on Darwin, which means we cannot use "1" as the compatibility version argument. We should also use the `darwin_versions` argument for `library()` to let Meson do the right thing depending on the platform, instead of passing linker flags ourselves. Original patch by: Tom Schoonjans Fixes: #41
* Properly detect multiple top level statementsEmmanuele Bassi2020-08-242-15/+13
| | | | | | | | 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
* Plug leaks in json-glib-formatEmmanuele Bassi2020-08-241-3/+14
| | | | | We're leaking a bunch of strings in error paths, as well as the stream for the input file.
* Document json_from_string() nullabilityEmmanuele Bassi2020-08-241-2/+2
| | | | | | | | The function can return NULL even without setting an error, so we need to add a `nullable` annotation. While at it, document the handling of empty strings more explicitly. Fixes: #46
* Assert that foreach_member() won't mutate the objectEmmanuele Bassi2020-08-241-0/+5
| | | | | | | We document that it's not safe, but we kind of rely on GHashTable to do that for us. Instead, let's use the newly added age field to protect against accidental mutations during iteration, just like we do for the iterator API.
* Document the iteration order for foreach_member()Emmanuele Bassi2020-08-241-0/+3
| | | | | The iteration order is the insertion order, and has been for a long time.
* Add ordered iterator for JsonObjectEmmanuele Bassi2020-08-244-10/+183
| | | | | | | | | The current iterator API does not guarantee the iteration order, as it's based off of the hash table iterator. JsonObject, though, can guarantee the iteration order—we do that for json_object_foreach_member(). Instead of changing the behaviour of json_object_iter_next(), we can add API to initialize and iterate a JsonObjectIter in insertion order.
* Use non-deprecated GObject constructor and typesEmmanuele Bassi2020-08-241-28/+23
| | | | | Both g_object_newv() and GParameter have been deprecated for a long time.
* build: Remove unnecessary argumentEmmanuele Bassi2020-08-241-1/+0
| | | | | The configure_file() function does not need an `install` argument with an unconditional value.
* scanner: use macro instead of cast to convert pointer to integerDimitry Andric2020-08-191-1/+1
| | | | | | | | | Clang 11 build failed due to a new warning (part of -Werror=pointer-to-int-cast): ../json-glib/json-scanner.c:928:13: error: cast to smaller integer type 'GTokenType' from 'gpointer' (aka 'void *') [-Werror,-Wvoid-pointer-to-enum-cast] *token_p = (GTokenType) value_p->v_symbol; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jan Beich <jbeich@FreeBSD.org>
* json-parser: Support loading files via memory mappingPhilip Withnall2020-06-095-0/+120
| | | | | | | | | | | | | | | 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>
* tests: Factor out a helper functionPhilip Withnall2020-06-091-9/+17
| | | | | | | This introduces no functional changes, but will allow that code to be reused in the following commit. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* json-gvariant: Fix poorly written patch in 212f925Robert Ancell2020-04-071-6/+9
| | | | | | | | Don't double do the integer conversion. Catch errors in double conversion. Do correct unsiged conversion. Friends don't let friends do end-of-day last minute MRs.
* json-gvariant: Stop string to GVariant conversion failing due to unrelated ↵Robert Ancell2020-04-061-7/+26
| | | | | | | | | | errno changes This was observed as failing due to some codepath inside g_variant_new_string setting errno to EAGAIN. Json Glib was erroneously detecting this in the checks designed to catch string to integer conversions. Solved by making errno only checked after the integer conversions.
* serializable: Fix default deserialization method.Jeremy Philippe2020-01-131-0/+9
| | | | | | | | | json_serializable_default_deserialize_property() fails when called with an uninitialized value. This violates the API since value is marked as an out parameter. Fixes https://gitlab.gnome.org/GNOME/json-glib/issues/39
* Merge branch 'dab_add_conditional_tests' into 'master'Emmanuele Bassi2020-01-131-1/+3
|\ | | | | | | | | meson: add tests option See merge request GNOME/json-glib!19
| * meson: add tests optionStéphane Cerveau2020-01-091-1/+3
| | | | | | | | Give an option to meson to disable `tests` build
* | typo: parser -> parsedAlexandre Viau2020-01-101-1/+1
|/
* serializable: Add (nullable) annotationNiels De Graef2020-01-071-2/+2
| | | | | `json_serializable_serialize_property()` can return NULL, so make that clear in the documentation (and to GIR).
* Annotate json_builder_new_immutable()Emmanuele Bassi2019-02-281-1/+1
| | | | | We shouldn't rely on g-ir-scanner doing pattern matching on the name of the function to determine if it's a constructor or not.
* Change introspection option to feature typeXavier Claessens2019-01-071-2/+2
|
* Meson: Add glib fallbackXavier Claessens2019-01-071-2/+2
|
* docs: Clarify some expections of the json_object_get_*_member APIsDebarshi Ray2018-03-141-14/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | It is an error to use the following with a missing member: • json_object_get_int_member • json_object_get_double_member • json_object_get_boolean_member • json_object_get_null_member • json_object_get_string_member • json_object_get_array_member • json_object_get_object_member Doing so will lead to CRITICALs like these: Json-CRITICAL **: json_object_get_string_member: assertion 'node != NULL' failed Instead one of these should be used to determine the existence of the member: • json_object_get_member • json_object_has_member Or, when available, one can use the corresponding json_object_get_<type>_member_with_default. https://gitlab.gnome.org/GNOME/json-glib/issues/24
* Refresh the build systemEmmanuele Bassi2018-03-132-69/+90
| | | | | | | | | | We should use more idiomatic Meson: - improve the coding style - ensure that the `json_glib_dep` dependency object also includes the introspection data, if enabled - add a separate option for the man page generation - ensure that json-glib can be used as a subproject
* Add `--output` option to json-glib-formatEmmanuele Bassi2018-03-131-10/+39
| | | | | | We should allow redirecting the output of the format utility to a file, instead of dumping everything on the standard output. This makes it easier to use json-glib-format inside a build system or a CI pipeline.
* Merge branch 'get-with-default' into 'master'Emmanuele Bassi2017-12-154-85/+198
|\ | | | | | | | | | | | | Add JsonObject getters with fallback value Closes #4 See merge request GNOME/json-glib!4
| * Add with_default() variant for JsonObject gettersEmmanuele Bassi2017-11-143-85/+178
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using the typed getters for JsonObject, the existing API will automatically fail if the member requested is not present. This is generally good practice, because JSON data typically does not have a schema, and thus is has to be validated "on the go"; a JSON object member that contains `null`, or `0`, or `false`, is indistinguishable from a JSON object member that does not exist, so we cannot simply return a scalar value and be done with it. We can provide an escape hatch, though, for the crowd writing parsers for JSON data; by using Python as the model, we can add methods that take a default value as a parameter, and return it as a fallback value if the requested object member does not exist, or if it's set to `null`.
| * Open the development cycle towards 1.6Emmanuele Bassi2017-11-141-0/+20
| |
* | Merge branch 'leak-fix' into 'master'Emmanuele Bassi2017-12-154-1/+7
|\ \ | | | | | | | | | | | | Leak fix See merge request GNOME/json-glib!6
| * | tests: Fix some memory leaks in the testsPhilip Withnall2017-12-153-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | We can’t do this by porting to g_autoptr(), because json-glib needs to be buildable using MSVC. Sad panda. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://gitlab.gnome.org/GNOME/json-glib/issues/30
| * | 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
* | | Merge branch 'parsing-empty-string' into 'master'Emmanuele Bassi2017-12-152-10/+31
|\ \ \ | |/ / |/| | | | | | | | json-parser: Fix getting immutable root nodes from empty input See merge request GNOME/json-glib!8
| * | json-parser: Fix getting immutable root nodes from empty inputPhilip Withnall2017-12-152-10/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | | json-node: Clarify documentation regarding programmer errorsPhilip Withnall2017-12-151-19/+33
|/ / | | | | | | | | | | | | | | | | | | | | | | Despite my efforts in commit 011c1e424b7 (parts of which were completely incorrect), the JsonNode documentation still wasn’t particularly helpful about differentiating between methods which return NULL if the JsonNode is not of the right type, and methods which emit a critical warning. Try and improve that across the board, hopefully without saying blatantly incorrect things this time. Signed-off-by: Philip Withnall <withnall@endlessm.com>
* | node: Use json_node_unref for the JsonNode autoptr cleanupRobert Ancell2017-12-061-1/+1
| | | | | | | | | | | | json_node_unref was added after the autoptr macros were written. This fixes an assertion failure if using autoptr and json_node_ref.
* | Update json-enum-types.h.inRavish Bhatia2017-11-141-1/+1
|/
* Use fuzzy comparison for floating point valuesEmmanuele Bassi2017-11-044-32/+14
| | | | | | Direct comparison should never be used for floating point values. Fixes #27 and #28.
* Add float comparison utility macros for testsEmmanuele Bassi2017-11-041-0/+21
| | | | | We do compare floating point values elsewhere in our code, so we should ensure that we're doing that with a certain amount of fuzziness.
* build: Clean up configuration optionsEmmanuele Bassi2017-09-121-1/+1
| | | | | Drop the Autotool-isms, and use something more in line with what Meson expects for configuration options.
* build: Rework the introspection optionEmmanuele Bassi2017-09-051-0/+2
| | | | | | | | | | | Instead of using `disable_introspection=false`, flip the condition around, and use `enable-introspection=true`. This avoids the double negative. Additionally, we should drop the cross-compilation check; it's entirely possible to cross-compile introspection data for different platforms and architectures; this allows the Yocto project to drop a patch for JSON-GLib.
* Merge branch 'master-old'Emmanuele Bassi2017-07-108-81/+91
|\
| * generator: Add an GString-based methodGarrett Regier2017-06-162-11/+34
| | | | | | | | | | | | This allows callers to avoid extra allocations when dumping to a preexisting string. https://bugzilla.gnome.org/show_bug.cgi?id=773504
| * core: Avoid json_object_get_members()Garrett Regier2017-06-167-52/+47
| | | | | | | | | | | | | | Use JsonObject's private members_ordered GQueue instead. This avoids a g_list_copy(). https://bugzilla.gnome.org/show_bug.cgi?id=773504
| * object: Use a GQueue for members_orderedGarrett Regier2017-06-162-19/+11
| | | | | | | | | | | | | | | | This makes the list always ordered and removes the g_list_reverse() in json_object_get_members(). https://bugzilla.gnome.org/show_bug.cgi?id=773504
* | gobject: Ignore deprecation warning for g_object_newv()Emmanuele Bassi2017-07-101-0/+2
| | | | | | | | | | We're going to replace it once we bump the dependency on GObject, to avoid a nasty ifdef hell.