Emiel Bruijntjes
9d85367679
added tabs instead of spaces to be compatible with rest of code
2015-11-27 16:53:57 +01:00
Emiel Bruijntjes
827f0fd8ef
update indentation
2015-11-27 16:52:17 +01:00
Emiel Bruijntjes
23ee243113
reference increment and decrement is now atomic (when using a GCC compatible compiler), which allows passing json objects between threads
2015-11-27 16:49:32 +01:00
James Myatt
3f012eb0f8
Fix build in Visual Studio
2015-10-09 23:24:55 +01:00
Eric Haszlakiewicz
12916e229c
Merge pull request #196 from rgerhards/improve-performance
...
Performance improvements
2015-09-28 22:25:29 -04:00
Rainer Gerhards
c4f8cc34df
more efficient handling for smalls strings inside json_object
...
smalls strings inside json_objects had a high overhead because dynamic
memory allocation was needed for each of them. This also meant that the
pointer needed to be updated. This is now changed so that small strings
can directly be stored inside the json_object. Note that on the regular
64 bit machines a pointer takes 8 bytes. So even without increasing
memory, we could store string up to 7 bytes directly inside the object.
The max size is configurable. I have selected up to 31 bytes (which
means a buffer of 32 including the NUL byte). This brings a 24-bytes
memory overhead, but I consider that still useful because the memory
allocator usually also has quite some overhead (16 bytes) for
dyn alloced memory blocks. In any case, the max buffer size can be
tweaked via #define.
2015-09-23 15:56:48 +02:00
Rainer Gerhards
1ae4b50bde
remove unneeded data items from hashtable code
...
These items were used for statistics tracking, but no code at all
exists to consume them. By removing them we save
a) space
because they counters required space, and did so in each and every
json object
b) performance
because calloc() needs to write less data and the counters are
no longer maintained; cache performance can be better, load
on OS main memory is lighter
We could conditionally enable/disable these counters, but I have not
done this they were really nowhere used and it looked more like a
left-over from the import of hashtable code.
2015-09-23 12:40:57 +02:00
Rainer Gerhards
2d549662be
add json_object_object_add_ex() API
...
This provides more control over some detail aspects, many
of which are performance related.
2015-09-23 09:43:00 +02:00
Rainer Gerhards
d8e44dc685
reduce duplicate hash computation in json_object_object_add()
...
This can be a very considerable performance saver.
2015-09-22 19:07:30 +02:00
Eric Haszlakiewicz
b594c34f57
Merge pull request #174 from haata/master
...
Adding JSON_C_TO_STRING_PRETTY_TAB flag
2015-05-31 12:10:13 -07:00
Jacob Alexander
92d4cf15f0
Adding JSON_C_TO_STRING_PRETTY_TAB flag
...
- Tabs are easier to read for tired eyes and editor adjustable
2015-05-27 17:37:39 -07:00
James Myatt
18b3c49296
Use more appropriate casts
2015-03-04 10:45:37 +00:00
Eric Haszlakiewicz
484ca368f0
Slight style tweaks to the bsearch changest.
2015-03-04 03:10:10 +00:00
Alexander Dahl
2f5789bdef
add bsearch for arrays
...
Arrays can already be sorted with json_object_array_sort() which uses
qsort() of the standard C library. This adds a counterpart using the
bsearch() from C.
2014-08-21 15:42:50 +02:00
Eric Haszlakiewicz
2149a04ca8
Check for failures when allocating memory; return NULL and set errno=ENOMEM in a few of those cases.
...
Thanks to Susant Sahani for pointing out some of these.
2014-04-19 20:33:05 -04:00
Eric Haszlakiewicz
92a7740e90
Reformat some code in json_object.c
2014-04-19 20:23:54 -04:00
Eric Haszlakiewicz
e6f1322b5e
Issue#114: check for the presence of isnan and isinf, and provide compat macros on MSCV where _isnan and _finite exist instead.
2014-03-02 12:16:37 -05:00
Keith Derrick
c51b88d69a
Avoid potential overflow in json_object_get_double
...
sscanf is always a potential problem when converting numeric
values as it does not correctly handle over- and underflow
(or at least gives no indication that it has done so).
This change converts json_object_get_double() to use strtod()
according to CERT guidelines.
2013-10-01 10:17:00 -07:00
Eric Haszlakiewicz
06450206c4
Issue #59 : change the floating point output format to %.17g so values with more than 6 digits show up in the output.
2013-09-11 21:09:43 -05:00
Eric Haszlakiewicz
a23caf677c
Use sizeof instead of hard coded values when calling snprintf.
2013-09-11 20:28:56 -05:00
Eric Haszlakiewicz
51993c28c2
Added a json_object_new_double_s() convenience function to allow an exact string representation of a double to be specified when creating the object and use it in json_tokener_parse_ex() so a re-serialized object more exactly matches the input.
...
Add json_object_free_userdata() and json_object_userdata_to_json_string() too.
2013-09-11 20:27:39 -05:00
Eric Haszlakiewicz
ef43fe3571
Merge pull request #96 from rouault/remove_strdnup
...
Remove redefinition of strndup() which is no longer used in the codebase
2013-09-08 13:35:28 -07:00
Even Rouault
1a957c2edc
Remove redefinition of strndup() which is no longer used in the codebase
2013-08-12 20:49:19 +02:00
Taneli Mielikainen
c5523a17e8
fixing problem that isinf(-Inf) can be 1 or -1
2013-08-04 00:21:58 +03:00
Eric Haszlakiewicz
98a62a7652
Merge pull request #89 from ayanes/master
...
Support NaN and Infinity
2013-06-18 21:18:27 -07:00
Adrian Yanes
d086e2018c
Fixes for Infinity and NaN
...
Although JSON RFC does not support NaN or Infinity
as numeric values ECMA 262 section 9.8.1 defines
how to handle these cases as strings
2013-06-12 19:48:00 -07:00
Anatol Belski
ed819fb926
snprintf definition is needed here, too
2013-06-04 20:18:05 +02:00
Eric Haszlakiewicz
5b36a432c8
Merge branch 'remicollet-issue-float'
...
Conflicts:
json_util.c
2013-02-26 21:09:10 -06:00
Greg Hazel
cca74c6de6
add json_object_object_length
2013-01-11 01:36:55 -08:00
Abioy
7eaa849e9a
escape '\f' in json_escape_str
...
'\f' is a llegal char and should be escape in printbuf
2012-12-24 22:22:05 +08:00
Remi Collet
32d149c8f6
probably worth an option for this
2012-12-13 11:46:04 +01:00
Remi Collet
8c847968c7
Save space, drop unuseful trailing zeroes
2012-12-13 11:22:31 +01:00
Remi Collet
4014fe86d9
Simple fix to double encode
2012-12-13 11:16:03 +01:00
Eric Haszlakiewicz
4e4af93d66
Fix issue #53 - ensure explicit length string are still NUL terminated, and fix json_tokener_parse() to work properly with embedded unicode \u0000 values in strings.
...
Adjust test_null to check for this case.
See also http://bugs.debian.org/687269
2012-12-09 16:32:11 -06:00
Eric Haszlakiewicz
e36e562872
Reformat json_object_object_get() and json_object_object_get_ex().
2012-10-18 17:16:36 -05:00
Eric Haszlakiewicz
5450bed051
Fix json_object_object_get() so it returns NULL if the incoming json_object is NULL.
2012-10-18 17:14:41 -05:00
Eric Haszlakiewicz
5f4739e2eb
Change json_object_put to return 1 if the object passed was actually freed. (or 0 if only the reference count was decremented)
2012-10-18 17:10:09 -05:00
Eric Haszlakiewicz
38f421a2e7
Add a json_set_serializer() function to allow the string output of a json_object to be customized.
2012-09-02 15:21:56 -05:00
Eric Haszlakiewicz
6988f53fcb
Rewrite json_object_object_add to replace just the value if the key already exists so keys remain valid.
...
This is particularly useful when replacing values in a loop, since it allows
the key used by json_object_object_foreach to continue to be used.
2012-07-24 23:27:41 -05:00
Mateusz Loskot
271c53ebdd
Missing explicit casts from void* to specific pointers required. Added #define strcasecmp for Visual C++.
2012-05-22 23:51:44 +01: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
0cc1db6459
Change the format used for sprintbuf (but not scanf) to use %f instead of %lf because the "l" is unnecessary and some compilers behave differently with it present (e.g. MinGW).
...
Thanks for Mateusz Loskot for the fix.
2012-04-29 11:04:33 -05: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
Eric Haszlakiewicz
4e000a65e6
Since we already use a local json_bool type, replace any stdbool.h usage with
...
that, since not all environments actually have a stdbool.h to use.
2012-04-24 21:54:07 -05:00
Keith Derrick
6917586acf
Add NULL-safe get object method
...
New json_object_object_get_ex() method protects itself against null pointers
and invalid objects being passed in.
2012-04-12 11:50:08 -07:00
Eric Haszlakiewicz
aef439a175
Adjust json_object_is_type and json_object_get_type so they return json_type_null for NULL objects.
2012-03-31 13:47:28 -05:00
Keith Derrick
37e7467476
Rename boolean type to json_bool
...
In building large systems, there are often clashes over the
preferred base type to use for bool/boolean. At least one
experience has been with a 3rd party proprietary library which
can not be changed. In that case, boolean was a synonym for
unsigned char and used widely in packed structures.
2012-03-26 14:29:31 -07: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
Federico Culloca
7ec34c9b39
Added capitalized charaters to json_hex_chars
2011-10-30 12:13:15 +01:00
Frederik Deweerdt
c43871c866
Add new json_object_array_sort function
...
- uses libc's qsort to sort the arraylist
- add test in test1.c
2011-10-07 21:07:18 +02:00