Project

General

Profile

Bug #5012

Timeオブジェクト間で特異オブジェクトが共有される

Added by ktsj (Kazuki Tsujimoto) almost 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.3dev (2011-07-10 trunk 32482) [x86_64-linux]
[ruby-dev:44071]

Description

=begin
辻本です。

Time#getlocalなどによって返されるTimeオブジェクトが、
レシーバと特異オブジェクトを共有してしまっています。

t0 = Time.now
class <<t0; end

t1 = t0.getlocal

def t0.m
0
end

p t0.m # => 0
p t1.m # => 0

以下のパッチでどうでしょうか。

diff --git a/time.c b/time.c
index 5dbf9b2..eb49ef2 100644
--- a/time.c
+++ b/time.c
@@ -3426,7 +3426,7 @@ time_init_copy(VALUE copy, VALUE time)
static VALUE
time_dup(VALUE time)
{

  • VALUE dup = time_s_alloc(CLASS_OF(time));
  • VALUE dup = time_s_alloc(rb_obj_class(time)); time_init_copy(dup, time); return dup; } =end

Associated revisions

Revision 6270ce85
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (time_dup): used rb_obj_class() instead of CLASS_OF().
    The patch is made by Kazuki Tsujimoto. [Bug #5012]

  • test/ruby/test_time.rb (TestTime#test_getlocal_dont_share_eigenclass):
    added a new test for eigenclass of time object.

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

Revision 32554
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (time_dup): used rb_obj_class() instead of CLASS_OF().
    The patch is made by Kazuki Tsujimoto. [Bug #5012]

  • test/ruby/test_time.rb (TestTime#test_getlocal_dont_share_eigenclass):
    added a new test for eigenclass of time object.

Revision 32554
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (time_dup): used rb_obj_class() instead of CLASS_OF().
    The patch is made by Kazuki Tsujimoto. [Bug #5012]

  • test/ruby/test_time.rb (TestTime#test_getlocal_dont_share_eigenclass):
    added a new test for eigenclass of time object.

Revision 32554
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (time_dup): used rb_obj_class() instead of CLASS_OF().
    The patch is made by Kazuki Tsujimoto. [Bug #5012]

  • test/ruby/test_time.rb (TestTime#test_getlocal_dont_share_eigenclass):
    added a new test for eigenclass of time object.

Revision 32554
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (time_dup): used rb_obj_class() instead of CLASS_OF().
    The patch is made by Kazuki Tsujimoto. [Bug #5012]

  • test/ruby/test_time.rb (TestTime#test_getlocal_dont_share_eigenclass):
    added a new test for eigenclass of time object.

Revision 32554
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

  • time.c (time_dup): used rb_obj_class() instead of CLASS_OF().
    The patch is made by Kazuki Tsujimoto. [Bug #5012]

  • test/ruby/test_time.rb (TestTime#test_getlocal_dont_share_eigenclass):
    added a new test for eigenclass of time object.

Revision f11eb9bb
Added by kosaki (Motohiro KOSAKI) almost 7 years ago

merge revision(s) 32554:

* time.c (time_dup): used rb_obj_class() instead of CLASS_OF().
  The patch is made by Kazuki Tsujimoto. [Bug #5012] 

* test/ruby/test_time.rb (TestTime#test_getlocal_dont_share_eigenclass):
  added a new test for eigenclass of time object.

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

History

#1 [ruby-dev:44072] Updated by kosaki (Motohiro KOSAKI) almost 7 years ago

  • Target version set to 1.9.3

#2 [ruby-dev:44107] Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Status changed from Open to Assigned
  • Assignee set to kosaki (Motohiro KOSAKI)

#3 Updated by kosaki (Motohiro KOSAKI) almost 7 years ago

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

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


  • time.c (time_dup): used rb_obj_class() instead of CLASS_OF().
    The patch is made by Kazuki Tsujimoto. [Bug #5012]

  • test/ruby/test_time.rb (TestTime#test_getlocal_dont_share_eigenclass):
    added a new test for eigenclass of time object.

#4 [ruby-dev:44115] Updated by kosaki (Motohiro KOSAKI) almost 7 years ago

ありがとうございます。よさげに見えたので1.9.3ブランチにも入れてしまいました。

Also available in: Atom PDF