1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* gc.c (run_finalizer): use object instead of object id.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2011-09-29 11:09:48 +00:00
parent 8e6e8e6288
commit b2658a7604
2 changed files with 13 additions and 7 deletions

View file

@ -1,3 +1,7 @@
Thu Sep 29 20:09:42 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (run_finalizer): use object instead of object id.
Thu Sep 29 20:07:36 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* use RB_TYPE_P which is optimized for constant types, instead of

16
gc.c
View file

@ -397,6 +397,8 @@ int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress;
#define is_lazy_sweeping(objspace) ((objspace)->heap.sweep_slots != 0)
#define nonspecial_obj_id(obj) (VALUE)((SIGNED_VALUE)(obj)|FIXNUM_FLAG)
static void rb_objspace_call_finalizer(rb_objspace_t *objspace);
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
@ -2903,11 +2905,12 @@ run_single_final(VALUE arg)
}
static void
run_finalizer(rb_objspace_t *objspace, VALUE objid, VALUE table)
run_finalizer(rb_objspace_t *objspace, VALUE obj, VALUE table)
{
long i;
int status;
VALUE args[3];
VALUE objid = nonspecial_obj_id(obj);
if (RARRAY_LEN(table) > 0) {
args[1] = rb_obj_freeze(rb_ary_new3(1, objid));
@ -2928,13 +2931,11 @@ run_finalizer(rb_objspace_t *objspace, VALUE objid, VALUE table)
static void
run_final(rb_objspace_t *objspace, VALUE obj)
{
VALUE objid;
RUBY_DATA_FUNC free_func = 0;
st_data_t key, table;
objspace->heap.final_num--;
objid = rb_obj_id(obj); /* make obj into id */
RBASIC(obj)->klass = 0;
if (RTYPEDDATA_P(obj)) {
@ -2949,7 +2950,7 @@ run_final(rb_objspace_t *objspace, VALUE obj)
key = (st_data_t)obj;
if (st_delete(finalizer_table, &key, &table)) {
run_finalizer(objspace, objid, (VALUE)table);
run_finalizer(objspace, obj, (VALUE)table);
}
}
@ -3033,8 +3034,9 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
st_foreach(finalizer_table, force_chain_object, (st_data_t)&list);
while (list) {
struct force_finalize_list *curr = list;
run_finalizer(objspace, rb_obj_id(curr->obj), curr->table);
st_delete(finalizer_table, (st_data_t*)&curr->obj, 0);
st_data_t obj = (st_data_t)curr->obj;
run_finalizer(objspace, curr->obj, curr->table);
st_delete(finalizer_table, &obj, 0);
list = curr->next;
xfree(curr);
}
@ -3222,7 +3224,7 @@ rb_obj_id(VALUE obj)
if (SPECIAL_CONST_P(obj)) {
return LONG2NUM((SIGNED_VALUE)obj);
}
return (VALUE)((SIGNED_VALUE)obj|FIXNUM_FLAG);
return nonspecial_obj_id(obj);
}
static int