Bug #5012

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

Added by Kazuki Tsujimoto almost 3 years ago. Updated almost 3 years ago.

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

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 @@ timeinitcopy(VALUE copy, VALUE time)
static VALUE
timedup(VALUE time)
{
- VALUE dup = time
salloc(CLASSOF(time));
+ VALUE dup = timesalloc(rbobjclass(time));
timeinitcopy(dup, time);
return dup;
}
=end

Associated revisions

Revision 32554
Added by Motohiro KOSAKI almost 3 years ago

  • time.c (timedup): used rbobjclass() instead of CLASSOF().
    The patch is made by Kazuki Tsujimoto. [Bug #5012]

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

History

#1 Updated by Motohiro KOSAKI almost 3 years ago

  • Target version set to 1.9.3

#2 Updated by Nobuyoshi Nakada almost 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to Motohiro KOSAKI

#3 Updated by Motohiro KOSAKI almost 3 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 (timedup): used rbobjclass() instead of CLASSOF().
    The patch is made by Kazuki Tsujimoto. [Bug #5012]

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

#4 Updated by Motohiro KOSAKI almost 3 years ago

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

Also available in: Atom PDF