To fix issues with floating-point precision we've made use of Google's
double-conversion lib to handle conversions of doubles to and from strings.
In addition to fixing our precision problems this will improve double
encoding by 4-5x. Decoding is however slightly slower according to the
benchmarks - but accurate at least.
This change removes the double_precision encoding option and the
precise_float decoding option.
To better align with the standard json module this removes ujson
default serialization of date/datetime objects to unix-timestamps.
Trying to serialize such an object will now raise a TypeError "repr(obj)
is not JSON serializable".
The behavior of ujson has always been to try to serialize all objects in
any way possible. This has been quite a deviation from other json
libraries, including Pythons standard json module, and the source of a
lot of confusion and bugs. Removing this quirk moves ultrajson closer to
the expected behavior.
Instead of trying to coerce serialization ultrajson will now throw a
TypeError: "repr(obj) is not JSON serializable" exception.
Previously a None dict item key would be outputted in JSON as "None".
To better align with the standard json module this was changed to output
"null". There's no proper representation of null object keys in JSON so
this is implementation specific but it seems more natural to follow
suit when it can be done without a significant performance hit.
Added and used branch prediction macros (LIKELY/UNLIKELY) as well.
This was caused by checking for "__json__" using PyObject_HasAttrString
which clears the error set by a previous long overflow. Thus this was dependent
on the order of processing of dict items, which explains why it was
seemingly random as the dict items are likely ordered by a hash of
the key.
This fixes GH224 and GH240.
- Fixed segfault when using sort_keys=True on dict with unorderable keys (GH247)
- Fixed refcount becoming negative when using sort_keys=True (GH243)
- Fixed compile error when defining JSON_NO_EXTRA_WHITESPACE
caused by a wrongly named variable. (GH245)
1. It reduces clutter in symbol table.
2. It fixes issues with C99 inline semantics for functions
marked as inline (#237, #180, #222), which manifests
when compiled with GCC>=5.
Before:
$ python3.4 -m timeit -n 10000 -s 'import ujson; x = ["a"*10]*100' 'ujson.dumps(x)'
10000 loops, best of 3: 15.8 usec per loop
After:
$ python -m timeit -n 10000 -s 'import ujson; x = ["a"*10]*100' 'ujson.dumps(x)'
10000 loops, best of 3: 7.14 usec per loop
Other unicode objects creates utf-8 cache in PyUnicode_AsUTF8AndSize().
It consume extra memory.
- The following unit tests were causing segfaults:
```
test_doubleLongDecimalIssue
test_invalidDoublePrecision
test_doublePrecisionTest
test_encodeDecimal
test_doubleLongIssue
test_encodeDecodeLongDecimal
```
- I changed a constant that couldn't be `const` because it can be overwritten by
a passed in parameter
ujson crashed Python if decimal.py wasn't
available. This fix makes ujson ignore the problem
and instead assume no Decimal object will be
passed in to ujson.dumps().