Skip to content

Commit

Permalink
- Fixed type type-o on POSIX
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas T�rnstr�m committed Mar 21, 2011
1 parent dbc34e2 commit c5d5885
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions dectest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Binary file modified python/lib/ujson.lib
Binary file not shown.
13 changes: 7 additions & 6 deletions ultrajson.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
Expand All @@ -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)

Expand All @@ -158,6 +157,7 @@ typedef unsigned __int32 JSUTF32;
#define __LITTLE_ENDIAN__
#endif


#else

#include <sys/types.h>
Expand All @@ -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
Expand Down Expand Up @@ -374,4 +375,4 @@ typedef struct __JSONObjectDecoder

EXPORTFUNCTION JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer, size_t cbBuffer);

#endif
#endif
20 changes: 12 additions & 8 deletions ultrajsondec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -147,7 +147,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)

//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)
{
Expand All @@ -158,9 +158,13 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
//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
{
Expand Down Expand Up @@ -264,7 +268,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)

BREAK_EXP_LOOP:

#ifdef JSON_NUMERIC_PRECISION_JAVASCRIPT
#ifdef JSON_DECODE_NUMERIC_AS_DOUBLE
#else
if (intValue < 0)
{
Expand Down
2 changes: 1 addition & 1 deletion ultrajsonenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5d5885

Please sign in to comment.