summaryrefslogtreecommitdiff
path: root/json_object.c
Commit message (Collapse)AuthorAgeFilesLines
* Reformat the json_object-split branch with clang-formatjson_object-splitEric Haszlakiewicz2020-06-161-38/+31
|
* Drop the _delete field from struct json_object and call the type-specific ↵Eric Haszlakiewicz2020-06-131-16/+30
| | | | delete functions directly from json_object_put. (Thanks @dota17 for the suggestion in PR #632!)
* Drop the useless "char data[1]" from struct json_object. Fix a typo in a ↵Eric Haszlakiewicz2020-06-131-1/+1
| | | | comment.
* The split of json_object into type-specific sub-structures is now ↵Eric Haszlakiewicz2020-06-071-399/+75
| | | | | | functionally complete. Remove all of the temporary defines, structures, old compat fuctions, extra fields, etc... that were needed during the conversion to a split set of json_object_* structures.
* More fixes for old MSVC builds.Eric Haszlakiewicz2020-06-071-5/+5
|
* Kick json_type_string out of struct json_object.Eric Haszlakiewicz2020-06-071-91/+142
| | | | | The default is now that string data is stored inline at the end of json_object, though to allow for json_object_set_string() to set a _longer_ string, we still need to allow for the possibility of a separate char * pointer. All json types have been split out now, next step it cleanup.
* Kick json_type_int and json_type_double out of struct json_object.Eric Haszlakiewicz2020-05-261-135/+170
| | | | Clean up the code in json_object_new_* a bit by dropping unnecesary json_object_base variables.
* Declare variables earlier, to appease Visual Studio 2010.Eric Haszlakiewicz2020-05-251-3/+6
|
* Kick json_type_boolean out of struct json_object.Eric Haszlakiewicz2020-05-251-15/+36
|
* Add some backwards compat for Visual Studio 2013.Eric Haszlakiewicz2020-05-251-0/+5
|
* Kick json_type_array out of struct json_object; re-enable the test_deep_copy ↵Eric Haszlakiewicz2020-05-251-28/+81
| | | | test.
* Start splitting struct json_object into multiple sub-types, as descibed at ↵Eric Haszlakiewicz2020-05-251-49/+335
| | | | | | | | | | | | https://github.com/json-c/json-c/wiki/Proposal:-struct-json_object-split The current changes split out _only_ json_type_object, and thus have a number of hacks to allow the code to continue to build and work. Originally mentioned in issue #535. When complete, this will probably invalidate #552. This is likely to cause notable conflicts in any other significant un-merged changes, such as PR#620.
* Prevent truncation on custom double formatters.Tobias Stoeckmann2020-05-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | A custom double formatter can lead to truncation of the rest of the JSON document. If a custom formatter completely fills the buffer used by snprintf with a trailing dot or comma and the formatting option JSON_C_TO_STRING_NOZERO has been specified, then an iterator moves past the ending '\0' (off-by-one buffer overflow) to set an additional '\0' and adds the first '\0' into the printbuf. Since '\0' will eventually be considered the terminating character of the complete printbuf result, all trailing characters are lost. This leads to an incomplete JSON string as can be seen with the test case. The off-by-one can be noticed if compiled with address sanitizer. Since this is a very special case and a malformed formatter could do way more harm and is the responsibility of the user of this library, this is just a protective measure to keep json-c code as robust as possible.
* Revert part of PR#606 and use isnan/isinf again, but provide macro ↵Eric Haszlakiewicz2020-05-161-6/+1
| | | | implementations of those in math_compat.h is needed, as it seems to be on AIX and IBM i systems.
* Improved support for IBM operating systemsDavid McCann2020-05-141-1/+8
| | | | Fix compiler errors and warnings when building on IBM operating systems such as AIX and IBM i.
* Re-do clang-format.Eric Haszlakiewicz2020-04-181-1/+0
|
* Make json_abort() internal to json_object.cEric Haszlakiewicz2020-04-181-0/+25
|
* Enforce strict prototypes.Björn Esser2020-04-131-1/+1
|
* Clean trailing white-space.Björn Esser2020-04-111-1/+1
|
* Fix one more assert("!invalid cint_type") to use json_abort(...) instead.Eric Haszlakiewicz2020-04-101-1/+1
|
* clang-format the filesdota172020-04-031-479/+451
|
* add the disabling formatting coments and adjust the partial code manulydota172020-04-031-20/+21
|
* Changed order of calloc args to match stdlibRobert2020-04-021-1/+1
| | | Although it is currently working, it's worth to stick with the stdlib definition to avoid further problems
* add test casesdota172020-03-311-1/+2
|
* Fixes various Wreturn-type and Wimplicit-fallthrough errors on Mingw-w64Jehan2020-03-161-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a recent regression since commit 6359b798479d379a3202e02c6a938d9b40c0d856 which added various assert(0) calls (often replacing return-s). With Ming-W64 compiler, json-c build was failing with various errors of the sort: > /home/jehan/dev/src/json-c/json_object.c: In function 'json_object_int_inc': > /home/jehan/dev/src/json-c/json_object.c:841:1: error: control reaches end of non-void function [-Werror=return-type] > 841 | } > | ^ > In file included from /home/jehan/dev/src/json-c/json_object.c:17: > /home/jehan/dev/src/json-c/json_object.c: In function 'json_object_get_double': > /home/jehan/.local/share/crossroad/roads/w64/json-c/include/assert.h:76:4: error: this statement may fall through [-Werror=implicit-fallthrough=] > 76 | (_assert(#_Expression,__FILE__,__LINE__),0)) > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > /home/jehan/dev/src/json-c/json_object.c:1070:7: note: in expansion of macro 'assert' > 1070 | assert(0); > | ^~~~~~ > /home/jehan/dev/src/json-c/json_object.c:1072:3: note: here > 1072 | case json_type_boolean: > | ^~~~ The problem is that Mingw-w64 does not consider assert() as a noreturn (even assert(0)), because it has to be compatible by Microsoft libraries. See the discussion here: https://sourceforge.net/p/mingw-w64/bugs/306/ Instead let's create a new json_abort() function which is basically just an abort() function with an optional message, for such cases where abortion was non-conditional (using assert() and using the assertion condition as a message here was clearly a misuse of the function). And mark json_abort() as 'noreturn', as well as 'cold' for optimization purpose (this is code we expect to never run, unless there is a bug, that is). Finally let's use this json_abort() instead of previous misused assert() calls.
* Follow up the PR#542: improve assert() calls, simplify code in ↵Eric Haszlakiewicz2020-03-021-21/+18
| | | | json_object_equal().
* update json_object.c and testcase, delete json_object_uint_inc()dota172020-02-281-48/+19
|
* modify partial functions and testcase, in order to support automatic ↵dota172020-02-281-33/+79
| | | | conversion for int64/uint64
* modify the json_object, replace c_int64/c_uint64 with struct{union{int64, ↵dota172020-02-271-66/+86
| | | | uint64},...}
* add uint64 data to json-cdota172020-02-251-0/+95
|
* Issue #539: use a internal-only serializer function in ↵Eric Haszlakiewicz2020-02-141-3/+16
| | | | json_object_new_double_s() to avoid potential conflicts with user code that uses the json_object_userdata_to_json_string serializer. Also, document the serializer-resetting behavior of json_object_set_double().
* Issue #539: reset the serializer when json_object_set_double() is called and ↵Eric Haszlakiewicz2020-02-131-0/+2
| | | | the current serializer is the one that json_object_new_double_s() used.
* add json_object_new_nulldota172020-01-201-0/+5
|
* Fix some Windows compile issues, add JSON_EXPORT's, fix bogus character ↵Eric Haszlakiewicz2019-11-231-1/+1
| | | | escapes, define __func__ and omit unistd.h if needed.
* Add an explicit cast to double to squash a -Wimplicit-int-float-conversion ↵Eric Haszlakiewicz2019-08-121-1/+3
| | | | | | | | warning. Though we will no longer be comparing exactly against INT64_MAX, this is ok because any value of that magnitude stored in a double will *also* have been rounded up, so the comparison will work appropriately.
* Issue #486: append a missing ".0" to negative double values too.Eric Haszlakiewicz2019-05-281-3/+8
|
* Merge pull request #453 from darjankrijan/masterEric Haszlakiewicz2018-12-111-4/+4
|\ | | | | Fixed misalignment in JSON string due to space after \n being printed...
| * Removed spaces after \n for arrays as wellDarjan Krijan2018-11-211-2/+2
| |
| * Fixed misalignment in JSON string due to space after \n being printed when ↵Darjan Krijan2018-11-201-2/+2
| | | | | | | | choosing JSON_C_TO_STRING_SPACED together with JSON_C_TO_STRING_PRETTY in json_object_array_to_json_string
* | Merge pull request #454 from ramiropolla/json_object_privateEric Haszlakiewicz2018-11-301-1/+1
|\ \ | | | | | | json_object_private: save 8 bytes in struct json_object in 64-bit arc…
| * | json_object_private: save 8 bytes in struct json_object in 64-bit architecturesRamiro Polla2018-11-241-1/+1
| |/ | | | | | | | | | | | | - there is no need for _ref_count to be uint_fast32_t (the compiler might decide to use a 64-bit int). make it uint32_t instead. - reorder the 32-bit integer fields (o_type and _ref_count) so that there is no wasted 4-byte gap after each of them.
* | Merge pull request #461 from andy5995/issue_422Eric Haszlakiewicz2018-11-281-2/+9
|\ \ | | | | | | json_object.c:set errno in json_object_get_double()
| * | json_object.c:set errno in json_object_get_double()andy59952018-11-261-2/+9
| |/ | | | | | | closes #422
* | json_object.h:document json_object_new_string_len()andy59952018-11-271-1/+1
|/ | | | | | I also added a couple trivial, but related, suggestions. closes #460
* Issue #407: fix incorrect casts in calls to ctype functions (isdigit and ↵Eric Haszlakiewicz2018-03-251-1/+1
| | | | isspace) so we don't crash when asserts are enabled on certain platforms and characters > 128 are parsed.
* PR#394: fix breakage with VS build.Eric Haszlakiewicz2017-12-241-1/+1
|
* PR#394: don't always append the ".0" if the double value rounds to zero ↵Eric Haszlakiewicz2017-12-241-27/+43
| | | | | | because some custom formats *will* include it (e.g. %.2f). Also try to accomodate formats to explicitly exclude the decimal (e.g. %.0f).
* Remove the TRUE and FALSE defines.Eric Haszlakiewicz2017-12-231-4/+4
|
* json_object_private: Use unsigned 32-bit integer type for refcountBjörn Esser2017-12-171-0/+3
|
* json_object: Avoid invalid free (and thus a segfault) when ref_count gets < 0Björn Esser2017-12-141-0/+5
|