1
0
Fork 0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-06-11 15:16:10 +02:00

- Added test for neg infinity

- Fixed 64-bit encoding issue on x64 Linux
- Made JSON_DECODE_NUMERIC_AS_DOUBLE disabled by default. Enable it to improve 32-bit performance but with the loss of long integer precision
This commit is contained in:
Jonas Tärnström 2011-03-22 21:22:58 +01:00
parent b42e6a481d
commit 6c19d69796
4 changed files with 20 additions and 1 deletions

Binary file not shown.

View File

@ -80,6 +80,13 @@ static void *PyIntToINT32(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_
return NULL;
}
static void *PyIntToINT64(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
{
PyObject *obj = (PyObject *) _obj;
*((JSINT64 *) outValue) = PyInt_AS_LONG (obj);
return NULL;
}
static void *PyLongToINT64(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
{
PyObject *obj = (PyObject *) _obj;
@ -423,7 +430,11 @@ void Object_beginTypeContext (PyObject *obj, JSONTypeContext *tc)
if (PyInt_Check(obj))
{
PRINTMARK();
#ifdef _LP64
pc->PyTypeToJSON = PyIntToINT64; tc->type = JT_LONG;
#else
pc->PyTypeToJSON = PyIntToINT32; tc->type = JT_INT;
#endif
return;
}
else

View File

@ -226,6 +226,14 @@ class UltraJSONTests(TestCase):
return
assert False, "Wrong exception"
def test_encodeDoubleNegInf(self):
input = -float('inf')
try:
ujson.encode(input)
assert False, "Expected exception!"
except(OverflowError):
return
assert False, "Wrong exception"
def test_decodeJibberish(self):

View File

@ -114,7 +114,7 @@ Encoding in details:
#include <stdio.h>
#define JSON_DECODE_NUMERIC_AS_DOUBLE
//#define JSON_DECODE_NUMERIC_AS_DOUBLE
// Don't decode any extra whitespaces
#define JSON_NO_EXTRA_WHITESPACE