diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 736a12fd26..9a15f09989 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -264,7 +264,7 @@ module TkComm end def uninstall_cmd(id) id = $1 if /rb_out (c\d+)/ =~ id - Tk_CMDTBL[id] = nil + Tk_CMDTBL.delete(id) end private :install_cmd, :uninstall_cmd @@ -282,7 +282,7 @@ module TkComm end def uninstall_win() - Tk_WINDOWS[@path] = nil + Tk_WINDOWS.delete(@path) end class Event @@ -2188,7 +2188,7 @@ module TkOption METHOD_TBL = {} ADD_METHOD = #{add} SAFE_MODE = #{safe} - %w(#{func_str}).each{|f| METHOD_TBL[f.intern] = nil } + %w(#{func_str}).each{|f| METHOD_TBL.delete(f.intern) } end EOD diff --git a/ext/tk/lib/tkafter.rb b/ext/tk/lib/tkafter.rb index ec39d9957f..b7c21e7529 100644 --- a/ext/tk/lib/tkafter.rb +++ b/ext/tk/lib/tkafter.rb @@ -64,7 +64,7 @@ class TkAfter def set_next_callback(args) if @running == false || @proc_max == 0 || @do_loop == 0 - Tk_CBTBL[@id] = nil ;# for GC + Tk_CBTBL.delete(@id) ;# for GC @running = false return end @@ -72,7 +72,7 @@ class TkAfter if @do_loop < 0 || (@do_loop -= 1) > 0 @current_pos = 0 else - Tk_CBTBL[@id] = nil ;# for GC + Tk_CBTBL.delete(@id) ;# for GC @running = false return end @@ -272,7 +272,7 @@ class TkAfter @running = false tk_call 'after', 'cancel', @after_id if @after_id @after_id = nil - Tk_CBTBL[@id] = nil ;# for GC + Tk_CBTBL.delete(@id) ;# for GC self end alias stop cancel diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb index 18febd2f13..4a5e4b45bb 100644 --- a/ext/tk/lib/tkcanvas.rb +++ b/ext/tk/lib/tkcanvas.rb @@ -504,7 +504,7 @@ class TkcTag") - TkVirtualEventTBL[@id] = nil + TkVirtualEventTBL.delete(@id) else tk_call('event', 'delete', "<#{@id}>", *(sequences.collect{|seq| "<#{tk_event_sequence(seq)}>"}) ) - TkVirtualEventTBL[@id] = nil if info == [] + TkVirtualEventTBL.delete(@id) if info == [] end self end diff --git a/gc.c b/gc.c index 3ecac66aba..72cbfb626e 100644 --- a/gc.c +++ b/gc.c @@ -848,12 +848,12 @@ gc_sweep() { RVALUE *p, *pend, *final_list; int freed = 0; - int i, used = heaps_used; + int i, j; if (ruby_in_compile && ruby_parser_stack_on_heap()) { /* should not reclaim nodes during compilation if yacc's semantic stack is not allocated on machine stack */ - for (i = 0; i < used; i++) { + for (i = 0; i < heaps_used; i++) { p = heaps[i]; pend = p + heaps_limits[i]; while (p < pend) { if (!(p->as.basic.flags&FL_MARK) && BUILTIN_TYPE(p) == T_NODE) @@ -869,8 +869,10 @@ gc_sweep() freelist = 0; final_list = deferred_final_list; deferred_final_list = 0; - for (i = 0; i < used; i++) { + for (i = 0; i < heaps_used; i++) { int n = 0; + RVALUE *free = freelist; + RVALUE *final = final_list; p = heaps[i]; pend = p + heaps_limits[i]; while (p < pend) { @@ -899,7 +901,18 @@ gc_sweep() } p++; } - freed += n; + if (n == heaps_limits[i] && freed + n > FREE_MIN) { + RVALUE *pp; + + heaps_limits[i] = 0; + for (pp = final_list; pp != final; pp = pp->as.free.next) { + p->as.free.flags |= FL_SINGLETON; /* freeing page mark */ + } + freelist = free; /* cancel this page from freelist */ + } + else { + freed += n; + } } if (freed < FREE_MIN) { add_heap(); @@ -918,9 +931,23 @@ gc_sweep() for (p = final_list; p; p = tmp) { tmp = p->as.free.next; run_final((VALUE)p); - p->as.free.flags = 0; - p->as.free.next = freelist; - freelist = p; + if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */ + p->as.free.flags = 0; + p->as.free.next = freelist; + freelist = p; + } + } + } + for (i = j = 0; j < heaps_used; i++) { + if (heaps_limits[i] == 0) { + free(heaps[i]); + heaps_used--; + } + else { + if (i != j) { + heaps[j] = heaps[i]; + } + j++; } } } diff --git a/object.c b/object.c index 71f5e99bdc..455d353b39 100644 --- a/object.c +++ b/object.c @@ -83,6 +83,14 @@ rb_class_real(cl) return cl; } +VALUE +rb_obj_type(obj) + VALUE obj; +{ + rb_warn("`type' is deprecated; use `class'"); + return rb_class_real(CLASS_OF(obj)); +} + VALUE rb_obj_class(obj) VALUE obj; @@ -1292,7 +1300,7 @@ Init_Object() rb_define_method(rb_mKernel, "hash", rb_obj_id, 0); rb_define_method(rb_mKernel, "id", rb_obj_id, 0); rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0); - rb_define_method(rb_mKernel, "type", rb_obj_class, 0); + rb_define_method(rb_mKernel, "type", rb_obj_type, 0); rb_define_method(rb_mKernel, "class", rb_obj_class, 0); rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);