Bug #5012
closedTimeオブジェクト間で特異オブジェクトが共有される
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
Updated by kosaki (Motohiro KOSAKI) over 13 years ago
- Target version set to 1.9.3
Updated by nobu (Nobuyoshi Nakada) over 13 years ago
- Status changed from Open to Assigned
- Assignee set to kosaki (Motohiro KOSAKI)
Updated by kosaki (Motohiro KOSAKI) over 13 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] [ruby-dev:44071] -
test/ruby/test_time.rb (TestTime#test_getlocal_dont_share_eigenclass):
added a new test for eigenclass of time object.
Updated by kosaki (Motohiro KOSAKI) over 13 years ago
ありがとうございます。よさげに見えたので1.9.3ブランチにも入れてしまいました。