-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json/ext 1.5.0 on 32-bit ree-1.8.7 sometimes produces garbage output on Bignums #46
Comments
Forgot to mention - the problem doesn't seem to exist on 64-bit machines. Or maybe it does and we just need a much bigger number! |
we're seeing this in script/console in a rails 2.3.8 app on 32-bit machines. slightly easier repro steps are to run this in script/console from a rails app: |
I see the same issue. I found out that it's connected to the garbage collector. See:
if you run this multiple times, it always creates corrupt bignum-json on iteration 1554. That was a clear indication for a GC problem. So I tried it and alas, this works:
So it looks as if the GC in REE 1.8.7 p330 is somehow corrupt? |
I've posted a fix for this at http://redmine.ruby-lang.org/issues/5173 |
I ported my changes against Ruby to the standalone Gem repo. git pull git://bogomips.org/ruby-json.git master There's also a second patch in there found by nobu. Patches individually downloadable at: http://bogomips.org/ruby-json.git/patch/?id=8a82bffe927e8928e304b96 nobu had another bug in the aforementioned redmine ticket I don't have time to |
I applied your patch, it's in master now. |
flori reply@reply.github.com wrote:
Thanks, I'd really like to get this in the next Ruby 1.9.3 RC, too. |
I merged 2149f41 in r33122 (trunk) and r33123 (ruby_1_9_3), thanks! |
Great, thanks! |
2011-08-31 (1.5.4) * Fix memory leak when used from multiple JRuby. (Patch by jfirebaugh@github). * Apply patch by Eric Wong <nocode@yhbt.net> that fixes garbage collection problem reported in ruby/json#46. * Add :quirks_mode option to parser and generator. * Add support for Rational and Complex number additions via json/add/complex and json/add/rational requires.
Here's a sample program that exhibits the problem:
ree-1.8.7@jsonbug1 steinbergd@davedev:~/dev/timing-bug$ cat test1.rb
require 'rubygems'
require 'json/ext'
puts "JSON Version: #{JSON::VERSION}"
1000000.times do |i|
s = 12345678900000.to_json
puts s
end
ree-1.8.7@jsonbug1 steinbergd@davedev:
/dev/timing-bug$ ruby test1.rb | sort | uniq -c/dev/timing-bug$ uname -a2 �ï¿5678900000
999461 12345678900000
1 �ï¿5678900000
533 ï¿5678900000
3 @ï¿5678900000
1 JSON Version: 1.5.0
ree-1.8.7@jsonbug1 steinbergd@davedev:
Linux davedev 2.6.32-24-generic #41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686 GNU/Linux
Also on pastebin: http://pastebin.com/fpxF5Tzd
Switching the test program to json/pure fixes it. In addition, monkey patching Bignum.to_s like so:
class Bignum
def to_json
return self.to_s
end
end
also seems to fix it.
The text was updated successfully, but these errors were encountered: