Skip to content

Commit

Permalink
Fixed T_FIXNUM bug on 64bit architectures.
Browse files Browse the repository at this point in the history
  • Loading branch information
flori committed Apr 25, 2010
1 parent 590ac11 commit d34d8a2
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2010-04-25 (1.4.1)
* Fix for a bug reported by Dan DeLeo <[email protected]>, caused by T_FIXNUM
being different on 32bit/64bit architectures.
2010-04-23 (1.4.0)
* Major speed improvements and building with simplified
directory/file-structure.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.0
1.4.1
10 changes: 5 additions & 5 deletions benchmarks/parser2_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Parser2BenchmarkExt < Bullshit::RepeatCase
include Parser2BenchmarkCommon

warmup yes
iterations 500
iterations 2000

truncate_data do
enabled false
Expand Down Expand Up @@ -76,7 +76,7 @@ class Parser2BenchmarkPure < Bullshit::RepeatCase
include Parser2BenchmarkCommon

warmup yes
iterations 100
iterations 400

truncate_data do
enabled false
Expand Down Expand Up @@ -111,7 +111,7 @@ def benchmark_parser_symbolic

class Parser2BenchmarkYAML < Bullshit::RepeatCase
warmup yes
iterations 100
iterations 400

truncate_data do
enabled false
Expand Down Expand Up @@ -146,7 +146,7 @@ def generic_reset_method

class Parser2BenchmarkRails < Bullshit::RepeatCase
warmup yes
iterations 100
iterations 400

truncate_data do
alpha_level 0.05
Expand Down Expand Up @@ -182,7 +182,7 @@ def generic_reset_method

class Parser2BenchmarkYajl < Bullshit::RepeatCase
warmup yes
iterations 500
iterations 2000

truncate_data do
alpha_level 0.05
Expand Down
12 changes: 6 additions & 6 deletions ext/json/ext/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ static void freverse(char *start, char *end)
}
}

static int fitoa(int number, char *buf)
static int fltoa(long number, char *buf)
{
static char digits[] = "0123456789";
int sign = number;
long sign = number;
char* tmp = buf;

if (sign < 0) number = -number;
Expand All @@ -380,10 +380,10 @@ static int fitoa(int number, char *buf)
return tmp - buf;
}

static void fbuffer_append_integer(FBuffer *fb, int number)
static void fbuffer_append_long(FBuffer *fb, long number)
{
char buf[12];
int len = fitoa(number, buf);
char buf[20];
int len = fltoa(number, buf);
fbuffer_append(fb, buf, len);
}

Expand Down Expand Up @@ -841,7 +841,7 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
fbuffer_append(buffer, "true", 4);
break;
case T_FIXNUM:
fbuffer_append_integer(buffer, FIX2INT(obj));
fbuffer_append_long(buffer, FIX2LONG(obj));
break;
case T_BIGNUM:
tmp = rb_funcall(obj, i_to_s, 0);
Expand Down
2 changes: 1 addition & 1 deletion ext/json/ext/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void fbuffer_free(FBuffer *fb);
static void fbuffer_free_only_buffer(FBuffer *fb);
static void fbuffer_clear(FBuffer *fb);
static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned int len);
static void fbuffer_append_integer(FBuffer *fb, int number);
static void fbuffer_append_long(FBuffer *fb, long number);
static void fbuffer_append_char(FBuffer *fb, char newchr);
static FBuffer *fbuffer_dup(FBuffer *fb);

Expand Down
2 changes: 1 addition & 1 deletion lib/json/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module JSON
# JSON version
VERSION = '1.4.0'
VERSION = '1.4.1'
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,17 @@ def test_load_dump
JSON.dump(eval(too_deep), output, 20)
assert_equal too_deep, output.string
end

def test_big_integers
json1 = JSON([orig = (1 << 31) - 1])
assert_equal orig, JSON[json1][0]
json2 = JSON([orig = 1 << 31])
assert_equal orig, JSON[json2][0]
json3 = JSON([orig = (1 << 62) - 1])
assert_equal orig, JSON[json3][0]
json4 = JSON([orig = 1 << 62])
assert_equal orig, JSON[json4][0]
json5 = JSON([orig = 1 << 64])
assert_equal orig, JSON[json5][0]
end
end

0 comments on commit d34d8a2

Please sign in to comment.