summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-15 07:37:45 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-15 07:37:45 +0000
commit164ced04de494d709f9006cac920579d84b6befd (patch)
treef392aea78209d3110032434710b3a1ac9b40e0ab
parent57fb2199059cb55b632d093c2e64c8a3c60acfbb (diff)
Add debug prints to inspect TC_JSONGenerate#test_gc's timeout issue.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/json/fbuffer/fbuffer.h1
-rw-r--r--ext/json/generator/generator.c1
-rwxr-xr-xtest/json/test_json_generate.rb30
3 files changed, 17 insertions, 15 deletions
diff --git a/ext/json/fbuffer/fbuffer.h b/ext/json/fbuffer/fbuffer.h
index 3ff9288..47e0c07 100644
--- a/ext/json/fbuffer/fbuffer.h
+++ b/ext/json/fbuffer/fbuffer.h
@@ -68,6 +68,7 @@ static void fbuffer_inc_capa(FBuffer *fb, unsigned long requested)
if (!fb->ptr) {
fb->ptr = ALLOC_N(char, fb->initial_length);
fb->capa = fb->initial_length;
+ fb->len = 0;
}
for (required = fb->capa; requested > required - fb->len; required <<= 1);
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index 21fef2b..6eea7ff 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -762,6 +762,7 @@ static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
{
VALUE tmp = rb_funcall(obj, i_to_s, 0);
fbuffer_append_str(buffer, tmp);
+ RB_GC_GUARD(tmp);
}
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
diff --git a/test/json/test_json_generate.rb b/test/json/test_json_generate.rb
index 2766109..ed38e5d 100755
--- a/test/json/test_json_generate.rb
+++ b/test/json/test_json_generate.rb
@@ -214,25 +214,25 @@ EOT
assert_equal 128, s.buffer_initial_length
end
- require'timeout'
def test_gc
+ $stdout.puts 'debug: %s:%d:' % [__FILE__, __LINE__]
bignum_too_long_to_embed_as_string = 1234567890123456789012345
- expect = nil
- stress = nil
- timeout(1) do
- expect = bignum_too_long_to_embed_as_string.to_s
- end
- timeout(30) do
- GC.start
- stress, GC.stress = GC.stress, true
- end
+ $stdout.puts 'debug: %s:%d:' % [__FILE__, __LINE__]
+ expect = bignum_too_long_to_embed_as_string.to_s
+ $stdout.puts 'debug: %s:%d:' % [__FILE__, __LINE__]
+ GC.start
+ $stdout.puts 'debug: %s:%d:' % [__FILE__, __LINE__]
+ stress, GC.stress = GC.stress, true
+ $stdout.puts 'debug: %s:%d:' % [__FILE__, __LINE__]
- timeout(30) do
- 10.times do |i|
- tmp = bignum_too_long_to_embed_as_string.to_json
- assert_equal expect, tmp
- end
+ 10.times do |i|
+ $stdout.puts 'debug: %s:%d:' % [__FILE__, __LINE__]
+ tmp = bignum_too_long_to_embed_as_string.to_json
+ $stdout.puts 'debug: %s:%d:' % [__FILE__, __LINE__]
+ assert_equal expect, tmp
+ $stdout.puts 'debug: %s:%d:' % [__FILE__, __LINE__]
end
+ $stdout.puts 'debug: %s:%d:' % [__FILE__, __LINE__]
ensure
GC.stress = stress
end if GC.respond_to?(:stress=)