* gc.c (define_final): document fix: finalizers never get called

before target object is destroyed.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2005-06-19 17:16:14 +00:00
parent 5cea368b61
commit 7946d2357a
2 changed files with 44 additions and 39 deletions

View File

@ -1,3 +1,8 @@
Mon Jun 20 02:15:35 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (define_final): document fix: finalizers never get called
before target object is destroyed.
Mon Jun 20 01:26:49 2005 GOTOU Yuuzou <gotoyuzo@notwork.org> Mon Jun 20 01:26:49 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/openssl_missing.c, ext/openssl/ossl.h, * ext/openssl/openssl_missing.c, ext/openssl/ossl.h,
@ -8,8 +13,8 @@ Mon Jun 20 01:26:49 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
Sun Jun 19 17:22:02 CEST 2005 Michael Neumann <mneumann@ruby-lang.org> Sun Jun 19 17:22:02 CEST 2005 Michael Neumann <mneumann@ruby-lang.org>
* lib/xmlrpc/utils.rb: Patch by Nobuhiro IMAI fixes the following * lib/xmlrpc/utils.rb: Patch by Nobuhiro IMAI fixes the following
problem: Default value modification on problem: Default value modification on
Module#public_instance_methods (false -> true) breaks Module#public_instance_methods (false -> true) breaks
s.add_handler(XMLRPC::iPIMethods("sample"), MyHandler.new) style s.add_handler(XMLRPC::iPIMethods("sample"), MyHandler.new) style
security protection. security protection.

74
gc.c
View File

@ -187,14 +187,14 @@ static st_table *finalizer_table = 0;
/* /*
* call-seq: * call-seq:
* GC.enable => true or false * GC.enable => true or false
* *
* Enables garbage collection, returning <code>true</code> if garbage * Enables garbage collection, returning <code>true</code> if garbage
* collection was previously disabled. * collection was previously disabled.
* *
* GC.disable #=> false * GC.disable #=> false
* GC.enable #=> true * GC.enable #=> true
* GC.enable #=> false * GC.enable #=> false
* *
*/ */
VALUE VALUE
@ -209,13 +209,13 @@ rb_gc_enable()
/* /*
* call-seq: * call-seq:
* GC.disable => true or false * GC.disable => true or false
* *
* Disables garbage collection, returning <code>true</code> if garbage * Disables garbage collection, returning <code>true</code> if garbage
* collection was already disabled. * collection was already disabled.
* *
* GC.disable #=> false * GC.disable #=> false
* GC.disable #=> true * GC.disable #=> true
* *
*/ */
VALUE VALUE
@ -298,7 +298,7 @@ typedef struct RVALUE {
struct RFile file; struct RFile file;
struct RNode node; struct RNode node;
struct RMatch match; struct RMatch match;
struct RVarmap varmap; struct RVarmap varmap;
struct SCOPE scope; struct SCOPE scope;
} as; } as;
#ifdef GC_DEBUG #ifdef GC_DEBUG
@ -697,7 +697,7 @@ rb_gc_mark_maybe(obj)
#define GC_LEVEL_MAX 250 #define GC_LEVEL_MAX 250
void static void
gc_mark(ptr, lev) gc_mark(ptr, lev)
VALUE ptr; VALUE ptr;
int lev; int lev;
@ -707,7 +707,7 @@ gc_mark(ptr, lev)
obj = RANY(ptr); obj = RANY(ptr);
if (rb_special_const_p(ptr)) return; /* special const not marked */ if (rb_special_const_p(ptr)) return; /* special const not marked */
if (obj->as.basic.flags == 0) return; /* free cell */ if (obj->as.basic.flags == 0) return; /* free cell */
if (obj->as.basic.flags & FL_MARK) return; /* already marked */ if (obj->as.basic.flags & FL_MARK) return; /* already marked */
obj->as.basic.flags |= FL_MARK; obj->as.basic.flags |= FL_MARK;
if (lev > GC_LEVEL_MAX || (lev == 0 && ruby_stack_check())) { if (lev > GC_LEVEL_MAX || (lev == 0 && ruby_stack_check())) {
@ -745,7 +745,7 @@ gc_mark_children(ptr, lev)
obj = RANY(ptr); obj = RANY(ptr);
if (rb_special_const_p(ptr)) return; /* special const not marked */ if (rb_special_const_p(ptr)) return; /* special const not marked */
if (obj->as.basic.flags == 0) return; /* free cell */ if (obj->as.basic.flags == 0) return; /* free cell */
if (obj->as.basic.flags & FL_MARK) return; /* already marked */ if (obj->as.basic.flags & FL_MARK) return; /* already marked */
obj->as.basic.flags |= FL_MARK; obj->as.basic.flags |= FL_MARK;
marking: marking:
@ -1309,10 +1309,10 @@ garbage_collect()
during_gc++; during_gc++;
init_mark_stack(); init_mark_stack();
/* mark frame stack */ /* mark frame stack */
for (frame = ruby_frame; frame; frame = frame->prev) { for (frame = ruby_frame; frame; frame = frame->prev) {
rb_gc_mark_frame(frame); rb_gc_mark_frame(frame);
if (frame->tmp) { if (frame->tmp) {
struct FRAME *tmp = frame->tmp; struct FRAME *tmp = frame->tmp;
while (tmp) { while (tmp) {
@ -1386,7 +1386,7 @@ garbage_collect()
rb_mark_generic_ivar_tbl(); rb_mark_generic_ivar_tbl();
rb_gc_mark_parser(); rb_gc_mark_parser();
/* gc_mark objects whose marking are not completed*/ /* gc_mark objects whose marking are not completed*/
while (!MARK_STACK_EMPTY){ while (!MARK_STACK_EMPTY){
if (mark_stack_overflow){ if (mark_stack_overflow){
@ -1413,7 +1413,7 @@ rb_gc()
* ObjectSpace.garbage_collect => nil * ObjectSpace.garbage_collect => nil
* *
* Initiates garbage collection, unless manually disabled. * Initiates garbage collection, unless manually disabled.
* *
*/ */
VALUE VALUE
@ -1479,29 +1479,29 @@ Init_stack(addr)
* The <code>ObjectSpace</code> module contains a number of routines * The <code>ObjectSpace</code> module contains a number of routines
* that interact with the garbage collection facility and allow you to * that interact with the garbage collection facility and allow you to
* traverse all living objects with an iterator. * traverse all living objects with an iterator.
* *
* <code>ObjectSpace</code> also provides support for object * <code>ObjectSpace</code> also provides support for object
* finalizers, procs that will be called when a specific object is * finalizers, procs that will be called when a specific object is
* about to be destroyed by garbage collection. * about to be destroyed by garbage collection.
* *
* include ObjectSpace * include ObjectSpace
* *
* *
* a = "A" * a = "A"
* b = "B" * b = "B"
* c = "C" * c = "C"
* *
* *
* define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" }) * define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
* define_finalizer(a, proc {|id| puts "Finalizer two on #{id}" }) * define_finalizer(a, proc {|id| puts "Finalizer two on #{id}" })
* define_finalizer(b, proc {|id| puts "Finalizer three on #{id}" }) * define_finalizer(b, proc {|id| puts "Finalizer three on #{id}" })
* *
* <em>produces:</em> * <em>produces:</em>
* *
* Finalizer three on 537763470 * Finalizer three on 537763470
* Finalizer one on 537763480 * Finalizer one on 537763480
* Finalizer two on 537763480 * Finalizer two on 537763480
* *
*/ */
void void
@ -1583,7 +1583,7 @@ os_obj_of(of)
/* /*
* call-seq: * call-seq:
* ObjectSpace.each_object([module]) {|obj| ... } => fixnum * ObjectSpace.each_object([module]) {|obj| ... } => fixnum
* *
* Calls the block once for each living, nonimmediate object in this * Calls the block once for each living, nonimmediate object in this
* Ruby process. If <i>module</i> is specified, calls the block * Ruby process. If <i>module</i> is specified, calls the block
* for only those classes or modules that match (or are a subclass of) * for only those classes or modules that match (or are a subclass of)
@ -1593,15 +1593,15 @@ os_obj_of(of)
* never returned. In the example below, <code>each_object</code> * never returned. In the example below, <code>each_object</code>
* returns both the numbers we defined and several constants defined in * returns both the numbers we defined and several constants defined in
* the <code>Math</code> module. * the <code>Math</code> module.
* *
* a = 102.7 * a = 102.7
* b = 95 # Won't be returned * b = 95 # Won't be returned
* c = 12345678987654321 * c = 12345678987654321
* count = ObjectSpace.each_object(Numeric) {|x| p x } * count = ObjectSpace.each_object(Numeric) {|x| p x }
* puts "Total count: #{count}" * puts "Total count: #{count}"
* *
* <em>produces:</em> * <em>produces:</em>
* *
* 12345678987654321 * 12345678987654321
* 102.7 * 102.7
* 2.71828182845905 * 2.71828182845905
@ -1610,7 +1610,7 @@ os_obj_of(of)
* 1.7976931348623157e+308 * 1.7976931348623157e+308
* 2.2250738585072e-308 * 2.2250738585072e-308
* Total count: 7 * Total count: 7
* *
*/ */
static VALUE static VALUE
@ -1686,9 +1686,9 @@ call_final(os, obj)
/* /*
* call-seq: * call-seq:
* ObjectSpace.undefine_finalizer(obj) * ObjectSpace.undefine_finalizer(obj)
* *
* Removes all finalizers for <i>obj</i>. * Removes all finalizers for <i>obj</i>.
* *
*/ */
static VALUE static VALUE
@ -1704,10 +1704,10 @@ undefine_final(os, obj)
/* /*
* call-seq: * call-seq:
* ObjectSpace.define_finalizer(obj, aProc=proc()) * ObjectSpace.define_finalizer(obj, aProc=proc())
* *
* Adds <i>aProc</i> as a finalizer, to be called when <i>obj</i> * Adds <i>aProc</i> as a finalizer, to be called after <i>obj</i>
* is about to be destroyed. * was destroyed.
* *
*/ */
static VALUE static VALUE
@ -1857,14 +1857,14 @@ rb_gc_call_finalizer_at_exit()
/* /*
* call-seq: * call-seq:
* ObjectSpace._id2ref(object_id) -> an_object * ObjectSpace._id2ref(object_id) -> an_object
* *
* Converts an object id to a reference to the object. May not be * Converts an object id to a reference to the object. May not be
* called on an object id passed as a parameter to a finalizer. * called on an object id passed as a parameter to a finalizer.
* *
* s = "I am a string" #=> "I am a string" * s = "I am a string" #=> "I am a string"
* r = ObjectSpace._id2ref(s.object_id) #=> "I am a string" * r = ObjectSpace._id2ref(s.object_id) #=> "I am a string"
* r == s #=> true * r == s #=> true
* *
*/ */
static VALUE static VALUE