Commit Graph

52 Commits

Author SHA1 Message Date
Pierce Lopez
003b58782b fix json_parse_uint64() usage of errno
introduced in #542
fixes #601
2020-05-10 13:38:12 -04:00
Eric Haszlakiewicz
ecb9354bb1 Re-do clang-format. 2020-04-18 02:14:13 +00:00
Eric Haszlakiewicz
23ddcbd4da Make json_abort() internal to json_object.c 2020-04-18 02:05:37 +00:00
Eric Haszlakiewicz
545464322b Issue #568: fix the strtoll and strtoull handing so config.h ends up creating defines for those only when needed, which should exclude mingw environments. 2020-04-09 20:58:28 +00:00
dota17
8b162c4b89 clang-format the files 2020-04-03 11:39:30 +08:00
dota17
c117d8a8a8 add the disabling formatting coments and adjust the partial code manuly 2020-04-03 11:28:04 +08:00
Jehan
b15e7ba470 Fixes various Wreturn-type and Wimplicit-fallthrough errors on Mingw-w64
This is a recent regression since commit
6359b79847 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.
2020-03-16 19:53:28 +01:00
dota17
c816de212b modify the json_object, replace c_int64/c_uint64 with struct{union{int64, uint64},...} 2020-02-27 10:26:27 +08:00
dota17
3c3b5920f7 add uint64 data to json-c 2020-02-25 14:51:35 +08:00
Eric Haszlakiewicz
af8dd4a307 Define vars earlier to fix old Windows builds. 2019-11-10 20:35:30 -05:00
Eric Haszlakiewicz
baed9983b3 Add a json_object_from_fd_ex() function, to allow the max nesting depth to be specified. 2019-11-10 00:14:44 -05:00
Eric Haszlakiewicz
437716c5b4 Rename _set_last_err() to _json_c_set_last_err(). 2017-11-29 09:36:53 -05:00
Eric Haszlakiewicz
05c85ddc21 On VS 2013 and newer, actually use strtoll instead of redefining it to _strtoi64. 2017-11-26 14:17:17 -05:00
Alexandru Ardelean
03f3b95248 json_util: define strtoll as _strtoi64 for MSVC
Got the idea from this blog post:
  http://www.enchantedage.com/node/231

Simple & concise stuff :)

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2017-11-07 16:51:01 +02:00
Jason King
5355d387e9 Use strtoll to parse ints 2017-09-07 17:21:14 +00:00
Eric Haszlakiewicz
b2afca4560 Issue #173: since some sscanf implementations return 0 for non-zero inputs, directly check for "0" in the input. 2017-09-05 01:53:13 -04:00
Eric Haszlakiewicz
81f6edbfd5 PR#331: for Visual Studio, use a snprintf/vsnprintf wrapper that ensures the string is terminated. 2017-08-25 01:15:39 -04:00
topilski
65884f4d9e Fix parsing doubles for mingw 2017-07-30 07:30:05 +03:00
Alexandru Ardelean
fb72160caf build: make strerror() override-able
If we want to override `strerror()` in libjson-c
to make tests consistent across platforms, we
need to do it build-wide as configure/build
option.

Apple linkers make it really hard to override functions
at link-time, and this seems to be locked down on travis-ci.org
[ for security reasons I assume ].
While I got it to work locally, it did not work
when running on travis.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2017-07-13 10:27:24 +03:00
Eric Haszlakiewicz
e8e574fbe4 Issue #161: add a json_object_to_fd() function. 2017-06-18 18:44:45 +00:00
Eric Haszlakiewicz
8581806558 Make _set_last_err() non-static so it can be used outside of json_util.c 2017-06-18 18:11:17 +00:00
Eric Haszlakiewicz
29ef73f21d Issue #189: Eliminate use of MC_ERROR from json_util.c, and add a json_util_get_last_err() function to retrieve the error for those callers that care about it.
Add tests and descriptions for the functions in json_util.c
2016-06-26 02:20:33 +00:00
Michael Heimpold
a7534dbb7e Introduce json_object_from_fd
Also refactor json_object_from_file to use json_object_from_fd
internally.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
2014-07-21 23:15:45 +02:00
Eric Haszlakiewicz
d4e81f9ec8 Move the json_min() and json_max() macros to json_util.h and mark everything else in bits.h deprecated.
Eliminate all uses of bits.h within the json-c code.
2014-05-04 22:33:26 -04:00
Pascal Bach
20e4708c8a Update json_util
filename should be passed as const char* to functions
json_object_to_file and json_object_to_file
2013-08-13 18:27:02 +02:00
Eric Haszlakiewicz
b3bce4d594 Eliminate use of MC_ABORT in json-c code, and mark MC_ABORT/mc_abort deprecated.
Also adjust an error message in json_util to make it unique.  Fixes #87.
2013-06-29 15:31:18 -05:00
Anatol Belski
990fa8e3ee Fix C89 compat needed by MSVC 2013-06-04 20:18:28 +02:00
Eric Haszlakiewicz
5b36a432c8 Merge branch 'remicollet-issue-float'
Conflicts:
	json_util.c
2013-02-26 21:09:10 -06:00
Eric Haszlakiewicz
bfb329223a Add a runtime check to see if parse_int64 needs to workaround sscanf bugs. If that workaround is not needed parsing is nearly twice as fast. 2013-02-09 17:35:33 -06:00
Eric Haszlakiewicz
ca8b27d183 Enable -Werror and fix a number of minor warnings that existed. 2013-02-09 16:35:24 -06:00
Greg Hazel
77d0493b70 rename _errno 2013-01-03 16:54:04 -08:00
Remi Collet
a01b659ace move locale change to be global for perf 2012-12-13 09:47:33 +01:00
Remi Collet
16a4a32e29 float parsing must be locale independent 2012-11-27 11:06:49 +01:00
Eric Haszlakiewicz
77c6239465 Initialize errno before calling sscanf in json_parse_int64() so parsing valid numbers after parsing an out of range number works. 2012-07-29 12:13:54 -05:00
Eric Haszlakiewicz
eead1a7dc4 Remove unnecessary comment from json_util.c 2012-07-08 20:32:12 -05:00
Mateusz Loskot
a6f39a3c0c Replaced #if HAVE_X with #ifdef HAVE_X as the former test is troublemaker with #define HAVE_X where #define HAVE_X 1|0 is meant. 2012-05-21 23:22:36 +01:00
Eric Haszlakiewicz
3fcffe1bb0 Add a json_object_to_json_string_ext() function to allow the formatting of output to be selected.
There are now three options: JSON_C_TO_STRING_SPACED, JSON_C_TO_STRING_PLAIN and JSON_C_TO_STRING_PRETTY.
This also add a json_object_to_file_ext() that takes the same flags.
Existing output of json_object_to_json_string() is unchanged, and uses JSON_C_TO_STRING_SPACED.
Thanks fo Grant Edwards for the initial patches.
2012-04-28 13:26:09 -05:00
John Arbash Meinel
6a231e4b41 Some updates to make the code compatible with VC 9 (2008)
VC 9 doesn't support late variable declarations, and doesn't have inttypes
so we need some direct definitions of a couple of more types.
2012-02-01 09:27:49 +01:00
Eric Haszlakiewicz
886c4fbebf Add a json_type_to_name() function which returns a string that describes the type. Useful for logging.
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@67 327403b1-1117-474d-bef2-5cb71233fd97
2011-05-03 20:40:49 +00:00
ehaszla
252669cee6 Simplify things by storing integer values only as int64_t's internally, and
omit the range check during parsing since we already have the checks when
 accessing the value. There is no longer a json_type_int64, only json_type_int.
Fix some problems with parsing 0 and -0 values, and add a couple of tests.
Fix some minor compile issues on HPUX environments.


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@60 327403b1-1117-474d-bef2-5cb71233fd97
2010-12-07 18:15:35 +00:00
Michael Clark
f1ae67dbf0 * Fix file descriptor leak if memory allocation fails in json_util
Zachary Blair, zack_blair at hotmail dot com



git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@59 327403b1-1117-474d-bef2-5cb71233fd97
2010-10-13 14:10:51 +00:00
Michael Clark
bd0a567673 * Fix file descriptor leak if memory allocation fails in json_util
Zachary Blair, zack_blair at hotmail dot com



git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@58 327403b1-1117-474d-bef2-5cb71233fd97
2010-10-13 14:09:41 +00:00
Michael Clark
c4dceae1c5 * Add int64 support. Two new functions json_object_net_int64 and
json_object_get_int64. Binary compatibility preserved.
    Eric Haszlakiewicz, EHASZLA at transunion com
    Rui Miguel Silva Seabra, rms at 1407 dot org



git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@56 327403b1-1117-474d-bef2-5cb71233fd97
2010-10-06 16:39:20 +00:00
Michael Clark
88ded9ceb8 * Make json_object_from_file take const char *filename
Spotted by Vikram Raj V, vsagar at attinteractive dot com


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@55 327403b1-1117-474d-bef2-5cb71233fd97
2009-08-27 06:40:59 +00:00
Michael Clark
aaec1ef3c5 * Don't use this as a variable, so we can compile with a C++ compiler
* Add casts from void* to type of assignment when using malloc 
  * Add #ifdef __cplusplus guards to all of the headers
  * Add typedefs for json_object, json_tokener, array_list, printbuf, lh_table
    Michael Clark, <michael@metaparadigm.com>


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@33 327403b1-1117-474d-bef2-5cb71233fd97
2009-02-25 02:31:32 +00:00
Michael Clark
68cafad078 Add const correctness to public interfaces
Gerard Krol, g dot c dot krol at student dot tudelft dot nl

Update version number to 0.9



git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@27 327403b1-1117-474d-bef2-5cb71233fd97
2009-01-06 22:56:57 +00:00
Michael Clark
c8f4a6e7de * Fix bug with use of capital E in numbers with exponents
Mateusz Loskot, mateusz at loskot dot net
  * Add stddef.h include



git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@19 327403b1-1117-474d-bef2-5cb71233fd97
2007-12-07 02:44:24 +00:00
Michael Clark
dfaf670436 * Add macros to enable compiling out debug code
Geoffrey Young, geoff at modperlcookbook dot org


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@18 327403b1-1117-474d-bef2-5cb71233fd97
2007-10-25 02:26:00 +00:00
Michael Clark
837240f75f * Fix bug in escaping of control characters
Johan Bj�rklund, johbjo09 at kth dot se
  * Remove include "config.h" from headers (should only
    be included from .c files)
    Michael Clark <michael@metaparadigm.com>


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@12 327403b1-1117-474d-bef2-5cb71233fd97
2007-03-13 08:26:25 +00:00
Michael Clark
f6a6e486ff * Make headers C++ compatible by change *this to *obj
* Add ifdef C++ extern "C" to headers
  * Use simpler definition of min and max in bits.h
    Larry Lansing, llansing at fuzzynerd dot com

  * Remove automake 1.6 requirement
  * Move autogen commands into autogen.sh. Update README
  * Remove error pointer special case for Windows
  * Change license from LGPL to MIT
    Michael Clark <michael@metaparadigm.com>


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@10 327403b1-1117-474d-bef2-5cb71233fd97
2007-03-13 08:26:23 +00:00