From 4fe51cb33042375a11356900d8e618ce3b15cc3f Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 7 Sep 2011 22:33:14 +0000 Subject: [PATCH] * gc.c (id2ref): unmarked object is already dead while lazy sweeping, and to it cannot come back since other objects referred from it might have been freed already. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ gc.c | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ff648d1a66..8e96ed81b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Sep 8 07:33:12 2011 Nobuyoshi Nakada + + * gc.c (id2ref): unmarked object is already dead while lazy + sweeping, and to it cannot come back since other objects + referred from it might have been freed already. + Wed Sep 8 03:48:00 2011 Ayumu AIZAWA * ext/readline/README.ja: diff --git a/gc.c b/gc.c index e6784624a4..e2e3625635 100644 --- a/gc.c +++ b/gc.c @@ -390,6 +390,8 @@ int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress; #define global_List objspace->global_list #define ruby_gc_stress objspace->gc_stress +#define is_lazy_sweeping(objspace) ((objspace)->heap.sweep_slots != 0) + static void rb_objspace_call_finalizer(rb_objspace_t *objspace); #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE @@ -3130,7 +3132,8 @@ id2ref(VALUE obj, VALUE objid) BUILTIN_TYPE(ptr) > T_FIXNUM || BUILTIN_TYPE(ptr) == T_ICLASS) { rb_raise(rb_eRangeError, "%p is not id value", p0); } - if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) { + if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0 || + (is_lazy_sweeping(objspace) && !(RBASIC(ptr)->flags & FL_MARK))) { rb_raise(rb_eRangeError, "%p is recycled object", p0); } return (VALUE)ptr;