1
0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-11-24 05:12:02 +01:00

- Fixed type type-o on POSIX

This commit is contained in:
Jonas Tärnström 2011-03-21 16:49:48 +01:00
parent dbc34e2aed
commit c5d588506b
5 changed files with 21 additions and 15 deletions

@ -562,6 +562,7 @@ int main (int argc, char **argv)
#define N 10000
obj = new StringObject(indata, indata + sizeof(indata));
obj = new LongObject (-9223372036854775808LL);
JSON_EncodeObject (obj, &encoder, buffer, sizeof (buffer));

Binary file not shown.

@ -114,6 +114,7 @@ Encoding in details:
#include <stdio.h>
#define JSON_DECODE_NUMERIC_AS_DOUBLE
// Don't decode any extra whitespaces
#define JSON_NO_EXTRA_WHITESPACE
@ -126,8 +127,6 @@ Encoding in details:
#define JSON_MAX_RECURSION_DEPTH 256
#endif
// Use the same numeric precision as JavaScript implementations does
#define JSON_NUMERIC_PRECISION_JAVASCRIPT
/*
Dictates and limits how much stack space for buffers UltraJSON will use before resorting to provided heap functions */
@ -146,7 +145,7 @@ typedef uint32_t JSUINT32;
typedef unsigned __int8 JSUINT8;
typedef unsigned __int16 JSUTF16;
typedef unsigned __int32 JSUTF32;
typedef __int64 JSLONG;
#define EXPORTFUNCTION __declspec(dllexport)
@ -158,6 +157,7 @@ typedef unsigned __int32 JSUTF32;
#define __LITTLE_ENDIAN__
#endif
#else
#include <sys/types.h>
@ -175,12 +175,13 @@ typedef u_int32_t uint32_t;
typedef u_int8_t JSUINT8;
typedef u_int16_t JSUTF16;
typedef u_int16_t JSUTF32;
typedef u_int32_t JSUTF32;
typedef int64_t JSLONG;
#define EXPORTFUNCTION
#endif
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__
#endif
@ -374,4 +375,4 @@ typedef struct __JSONObjectDecoder
EXPORTFUNCTION JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer, size_t cbBuffer);
#endif
#endif

@ -75,7 +75,7 @@ static JSOBJ SetError( struct DecoderState *ds, int offset, const char *message)
FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
{
#ifdef JSON_NUMERIC_PRECISION_JAVASCRIPT
#ifdef JSON_DECODE_NUMERIC_AS_DOUBLE
double intNeg = 1;
double intValue;
#else
@ -116,10 +116,10 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
case '9':
//FIXME: Check for arithemtic overflow here
//PERF: Don't do 64-bit arithmetic here unless we know we have to
#ifdef JSON_NUMERIC_PRECISION_JAVASCRIPT
#ifdef JSON_DECODE_NUMERIC_AS_DOUBLE
intValue = intValue * 10.0 + (double) (chr - 48);
#else
intValue = intValue * 10 + (JSLONG) (chr - 48);
intValue = intValue * 10LL + (JSLONG) (chr - 48);
#endif
ds->start ++;
break;
@ -147,7 +147,7 @@ BREAK_INT_LOOP:
//If input string is LONGLONG_MIN here the value is already negative so we should not flip it
#ifdef JSON_NUMERIC_PRECISION_JAVASCRIPT
#ifdef JSON_DECODE_NUMERIC_AS_DOUBLE
#else
if (intValue < 0)
{
@ -158,9 +158,13 @@ BREAK_INT_LOOP:
//dbg1 = (intValue * intNeg);
//dbg2 = (JSLONG) dbg1;
if (intValue > (INT_MAX - 1))
{
RETURN_JSOBJ_NULLCHECK(ds->dec->newLong( (JSINT64) (intValue * intNeg)));
#ifdef JSON_DECODE_NUMERIC_AS_DOUBLE
if (intValue > (double) INT_MAX || intValue < (double) INT_MIN)
#else
if ( (intValue >> 32))
#endif
{
RETURN_JSOBJ_NULLCHECK(ds->dec->newLong( (JSINT64) (intValue * (JSINT64) intNeg)));
}
else
{
@ -264,7 +268,7 @@ DECODE_EXPONENT:
BREAK_EXP_LOOP:
#ifdef JSON_NUMERIC_PRECISION_JAVASCRIPT
#ifdef JSON_DECODE_NUMERIC_AS_DOUBLE
#else
if (intValue < 0)
{

@ -334,7 +334,7 @@ void Buffer_AppendLongUnchecked(JSONObjectEncoder *enc, JSINT64 value)
wstr = enc->offset;
// Conversion. Number is reversed.
do *wstr++ = (char)(48 + (uvalue % 10)); while(uvalue /= 10);
do *wstr++ = (char)(48 + (uvalue % 10ULL)); while(uvalue /= 10ULL);
if (value < 0) *wstr++ = '-';
// Reverse string