зеркало из https://github.com/github/ruby.git
* gc.c (run_final): runs finalizers with the object terminated.
* gc.c (rb_gc_call_finalizer_at_exit): keeps finalized objects from linking to freelist. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
508b170dcd
Коммит
d8353d6b6e
|
@ -1,3 +1,10 @@
|
||||||
|
Thu Aug 7 05:06:03 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* gc.c (run_final): runs finalizers with the object terminated.
|
||||||
|
|
||||||
|
* gc.c (rb_gc_call_finalizer_at_exit): keeps finalized objects from
|
||||||
|
linking to freelist.
|
||||||
|
|
||||||
Thu Aug 7 04:43:14 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
Thu Aug 7 04:43:14 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* enc/depend: for build in other than srcdir.
|
* enc/depend: for build in other than srcdir.
|
||||||
|
|
27
gc.c
27
gc.c
|
@ -1509,6 +1509,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj)
|
||||||
|
|
||||||
if (FL_TEST(obj, FL_EXIVAR)) {
|
if (FL_TEST(obj, FL_EXIVAR)) {
|
||||||
rb_free_generic_ivar((VALUE)obj);
|
rb_free_generic_ivar((VALUE)obj);
|
||||||
|
FL_UNSET(obj, FL_EXIVAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (BUILTIN_TYPE(obj)) {
|
switch (BUILTIN_TYPE(obj)) {
|
||||||
|
@ -2042,6 +2043,7 @@ run_final(rb_objspace_t *objspace, VALUE obj)
|
||||||
VALUE args[3], table, objid;
|
VALUE args[3], table, objid;
|
||||||
|
|
||||||
objid = rb_obj_id(obj); /* make obj into id */
|
objid = rb_obj_id(obj); /* make obj into id */
|
||||||
|
RBASIC(obj)->klass = 0;
|
||||||
|
|
||||||
if (RDATA(obj)->dfree) {
|
if (RDATA(obj)->dfree) {
|
||||||
(*RDATA(obj)->dfree)(DATA_PTR(obj));
|
(*RDATA(obj)->dfree)(DATA_PTR(obj));
|
||||||
|
@ -2085,16 +2087,18 @@ static int
|
||||||
chain_finalized_object(st_data_t key, st_data_t val, st_data_t arg)
|
chain_finalized_object(st_data_t key, st_data_t val, st_data_t arg)
|
||||||
{
|
{
|
||||||
RVALUE *p = (RVALUE *)key, **final_list = (RVALUE **)arg;
|
RVALUE *p = (RVALUE *)key, **final_list = (RVALUE **)arg;
|
||||||
if ((p->as.basic.flags & (FL_FINALIZE|FL_MARK)) == FL_FINALIZE) {
|
if (p->as.basic.flags & FL_FINALIZE) {
|
||||||
if (BUILTIN_TYPE(p) != T_DEFERRED) {
|
if (BUILTIN_TYPE(p) != T_DEFERRED) {
|
||||||
p->as.free.flags = FL_MARK | T_DEFERRED; /* remain marked */
|
p->as.free.flags = FL_MARK | T_DEFERRED; /* remain marked */
|
||||||
RDATA(p)->dfree = 0;
|
RDATA(p)->dfree = 0;
|
||||||
}
|
}
|
||||||
p->as.free.next = *final_list;
|
p->as.free.next = *final_list;
|
||||||
*final_list = p;
|
*final_list = p;
|
||||||
|
return ST_CONTINUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
return ST_DELETE;
|
return ST_DELETE;
|
||||||
}
|
}
|
||||||
return ST_CONTINUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -2105,21 +2109,22 @@ rb_gc_call_finalizer_at_exit(void)
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* run finalizers */
|
/* run finalizers */
|
||||||
if (need_call_final) {
|
if (finalizer_table) {
|
||||||
do {
|
|
||||||
p = deferred_final_list;
|
p = deferred_final_list;
|
||||||
deferred_final_list = 0;
|
deferred_final_list = 0;
|
||||||
finalize_list(objspace, p);
|
finalize_list(objspace, p);
|
||||||
mark_tbl(objspace, finalizer_table, 0);
|
while (finalizer_table->num_entries > 0) {
|
||||||
|
RVALUE *final_list = 0;
|
||||||
st_foreach(finalizer_table, chain_finalized_object,
|
st_foreach(finalizer_table, chain_finalized_object,
|
||||||
(st_data_t)&deferred_final_list);
|
(st_data_t)&final_list);
|
||||||
} while (deferred_final_list);
|
if (!(p = final_list)) break;
|
||||||
if (finalizer_table->num_entries) {
|
do {
|
||||||
rb_warning("%d finalizer%s left not-invoked due to self-reference",
|
final_list = p->as.free.next;
|
||||||
finalizer_table->num_entries,
|
run_final(objspace, (VALUE)p);
|
||||||
finalizer_table->num_entries > 1 ? "s" : "");
|
} while ((p = final_list) != 0);
|
||||||
}
|
}
|
||||||
st_free_table(finalizer_table);
|
st_free_table(finalizer_table);
|
||||||
|
finalizer_table = 0;
|
||||||
}
|
}
|
||||||
/* finalizers are part of garbage collection */
|
/* finalizers are part of garbage collection */
|
||||||
during_gc++;
|
during_gc++;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче