Bug #5172

[PATCH] bigdecimal: RB_GC_GUARD rb_inspect() output

Added by Eric Wong over 3 years ago. Updated over 3 years ago.

Assignee:Kenta Murata
ruby -v:ruby 1.9.4dev (2011-08-07 trunk 32885) [x86_64-linux] Backport:


ext/bigdecimal/bigdecimal.c: RB_GC_GUARD rb_inspect() output

We can't directly use RSTRING_PTR() on rb_inspect() because the
GC may collect the VALUE returned by rb_inspect(). This is a
problem for Symbols with long names that return non-embedded
Strings when inspected.

test/bigdecimal/test_bigdecimal.rb (test_gc): updated for BigDecimal#coerce
test/bigdecimal/test_bigmath.rb (test_gc): added test case

0001-ext-bigdecimal-bigdecimal.c-RB_GC_GUARD-rb_inspect-o.patch Magnifier (4.06 KB) Eric Wong, 08/09/2011 08:46 AM


#1 Updated by Kenta Murata over 3 years ago

  • Assignee set to Kenta Murata

#2 Updated by Eric Wong over 3 years ago

Eric Wong normalperson@yhbt.net wrote:

Bug #5172: [PATCH] bigdecimal: RB_GC_GUARD rb_inspect() output

If you prefer: git pull git://bogomips.org/ruby bigdecimal-gc-guard

Also, I noticed the following in ext/tk/tkutil/tkutil.c:

 rb_warning("fail to convert '%s' to string for Tk",
                RSTRING_PTR(rb_funcall(obj, rb_intern("inspect"), 0,

 id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str)));

I don't use or know the Tk ext at all, but the above examples do not
appear safe from a GC perspective.

Eric Wong

#3 Updated by Kenta Murata over 3 years ago

Would you please a new ticket for the issue of tk.

#4 Updated by Kenta Murata over 3 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32997.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Merge commit r32996 from trunk:
* ext/bigdecimal/bigdecimal.c (cannot_be_coerced_into_BigDecimal):
add a new function for raising error when an object cannot coerce
into BigDecimal. [Bug #5172]
* ext/bigdecimal/bigdecimal.c (BigDecimalValueWithPrec): use
cannot_be_coerced_into_BigDecimal function.
* ext/bigdecimal/bigdecimal.c (BigMath_s_exp): ditto.
* ext/bigdecimal/bigdecimal.c (BigMath_s_log): ditto.
* test/bigdecimal/test_bigdecimal.rb: test for the avobe changes.
* test/bigdecimal/testbase.rb (under_gc_stress): add a new utility
method to run tests under the condition of GC.stress = true.

Also available in: Atom PDF