Project

General

Profile

Bug #5199

ext/tk: RB_GC_GUARD seems to be needed in several places

Added by normalperson (Eric Wong) over 8 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.4dev (2011-08-11 trunk 32931) [x86_64-linux]
Backport:
[ruby-core:39000]

Description

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,
               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. Compilers can optimize the original
VALUE away entirely so GC can collect.

RSTRING_PTR (being a macro,) may also evaluate its arguments multiple
times.


Files

bug-5199-tkutil.diff (3.83 KB) bug-5199-tkutil.diff nobu (Nobuyoshi Nakada), 02/20/2013 12:54 PM

Associated revisions

Revision c2b7ae98
Added by nobu (Nobuyoshi Nakada) over 6 years ago

tkutil.c: prevent temporary objects from GC

  • ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and rb_intern_str() instead of rb_intern() and RSTRING_PTR() with RB_GC_GUARD(), to prevent temporary objects from GC. [ruby-core:39000] [Bug #5199]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 41351
Added by nobu (Nobuyoshi Nakada) over 6 years ago

tkutil.c: prevent temporary objects from GC

  • ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and rb_intern_str() instead of rb_intern() and RSTRING_PTR() with RB_GC_GUARD(), to prevent temporary objects from GC. [ruby-core:39000] [Bug #5199]

Revision 41351
Added by nobu (Nobuyoshi Nakada) over 6 years ago

tkutil.c: prevent temporary objects from GC

  • ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and rb_intern_str() instead of rb_intern() and RSTRING_PTR() with RB_GC_GUARD(), to prevent temporary objects from GC. [ruby-core:39000] [Bug #5199]

Revision 41351
Added by nobu (Nobuyoshi Nakada) over 6 years ago

tkutil.c: prevent temporary objects from GC

  • ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and rb_intern_str() instead of rb_intern() and RSTRING_PTR() with RB_GC_GUARD(), to prevent temporary objects from GC. [ruby-core:39000] [Bug #5199]

Revision 41351
Added by nobu (Nobuyoshi Nakada) over 6 years ago

tkutil.c: prevent temporary objects from GC

  • ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and rb_intern_str() instead of rb_intern() and RSTRING_PTR() with RB_GC_GUARD(), to prevent temporary objects from GC. [ruby-core:39000] [Bug #5199]

Revision 41351
Added by nobu (Nobuyoshi Nakada) over 6 years ago

tkutil.c: prevent temporary objects from GC

  • ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and rb_intern_str() instead of rb_intern() and RSTRING_PTR() with RB_GC_GUARD(), to prevent temporary objects from GC. [ruby-core:39000] [Bug #5199]

Revision 41351
Added by nobu (Nobuyoshi Nakada) over 6 years ago

tkutil.c: prevent temporary objects from GC

  • ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and rb_intern_str() instead of rb_intern() and RSTRING_PTR() with RB_GC_GUARD(), to prevent temporary objects from GC. [ruby-core:39000] [Bug #5199]

Revision 9a1728a1
Added by nagachika (Tomoyuki Chikanaga) almost 6 years ago

merge revision(s) 41351: [Backport #9199]

    * ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and
      rb_intern_str() instead of rb_intern() and RSTRING_PTR() with
      RB_GC_GUARD(), to prevent temporary objects from GC.
      [ruby-core:39000] [Bug #5199]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@44564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

Updated by mrkn (Kenta Murata) over 8 years ago

  • Assignee set to nagai (Hidetoshi Nagai)
#2

Updated by shyouhei (Shyouhei Urabe) over 7 years ago

  • Status changed from Open to Assigned

Updated by ko1 (Koichi Sasada) almost 7 years ago

  • Target version changed from 2.0.0 to 2.1.0

Time up for 2.0.0.

Nagai-san, how about it?

Updated by nagai (Hidetoshi Nagai) almost 7 years ago

From: "ko1 (Koichi Sasada)" redmine@ruby-lang.org
Subject: [ruby-core:52367] [ruby-trunk - Bug #5199] ext/tk: RB_GC_GUARD seems to be needed in several places
Date: Sun, 17 Feb 2013 19:06:43 +0900
Message-ID: redmine.journal-36417.20130217190643@ruby-lang.org

Issue #5199 has been updated by ko1 (Koichi Sasada).

Target version changed from 2.0.0 to 2.1.0

Time up for 2.0.0.

Nagai-san, how about it?

I'm very sorry. I didn't check the tickets about Ruby/Tk.
Last half year (and now), I was busy on my primary works.
So I couldn't follow up many changes for 2.0.0.
I'll fix them on 2.1.0 as soon as possible.
Although I'm sorry, it's not now. Maybe, it is one month or more after.
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
Department of Artificial Intelligence, Kyushu Institute of Technology

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

Quick patch.

2.0 has GC safe functions, rb_sprintf() with PRIsVALUE, rb_intern_str(), and so on.

Updated by jonforums (Jon Forums) over 6 years ago

nobu (Nobuyoshi Nakada) wrote:

Quick patch.

2.0 has GC safe functions, rb_sprintf() with PRIsVALUE, rb_intern_str(), and so on.

Does a list of these new 2.0 GC-safe functions exist anywhere?

If the 2.0 GC-safe functions aren't currently enumerated in a single, accessible place, should they be listed in a new section to README.EXT, and a short note added to mame-san's draft 2.0.0-p0 ANN? Perhaps under "Built-in libraries" as "New GC-safe API for more robust extensions."

Updated by nagai (Hidetoshi Nagai) over 6 years ago

nobu (Nobuyoshi Nakada) wrote:

Quick patch.

2.0 has GC safe functions, rb_sprintf() with PRIsVALUE, rb_intern_str(), and so on.

Nakada-san, please commit the patch.

#8

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

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

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


tkutil.c: prevent temporary objects from GC

  • ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and rb_intern_str() instead of rb_intern() and RSTRING_PTR() with RB_GC_GUARD(), to prevent temporary objects from GC. [ruby-core:39000] [Bug #5199]

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Backport set to 2.0.0: REQUIRED
#10

Updated by nagachika (Tomoyuki Chikanaga) almost 6 years ago

  • Backport changed from 2.0.0: REQUIRED to 2.0.0: DONE

r41351 was backported to ruby_2_0_0 at r44564.

Also available in: Atom PDF