[macruby-changes] [3276] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Jan 14 15:32:17 PST 2010


Revision: 3276
          http://trac.macosforge.org/projects/ruby/changeset/3276
Author:   ernest.prabhakar at gmail.com
Date:     2010-01-14 15:32:15 -0800 (Thu, 14 Jan 2010)
Log Message:
-----------
Fixer Timer, commented-out crashing File close

Modified Paths:
--------------
    MacRuby/trunk/gcd.c
    MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb
    MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt

Modified: MacRuby/trunk/gcd.c
===================================================================
--- MacRuby/trunk/gcd.c	2010-01-14 23:32:13 UTC (rev 3275)
+++ MacRuby/trunk/gcd.c	2010-01-14 23:32:15 UTC (rev 3276)
@@ -759,21 +759,9 @@
     assert(sourceptr != NULL);
     rb_source_t *src = RSource(sourceptr);
     VALUE io = src->rb_context;
-    printf("Closing IO object %s\n", object_getClassName((id)io));
-    switch(src->source_enum)
-    {
-        case SOURCE_TYPE_READ:
-            rb_vm_call(io, selCloseRead, 0, NULL, false);
-            break;
-        case SOURCE_TYPE_WRITE:
-            rb_vm_call(io, selCloseWrite, 0, NULL, false);
-            break;
-        case SOURCE_TYPE_VNODE:
-            rb_vm_call(io, selClose, 0, NULL, false);
-            break;
-        default: rb_raise(rb_eArgError, "Unknown source type enum `%d'",
-            src->source_enum);
-    }
+    printf("\nClosing IO object of type %s\n", object_getClassName((id)io));
+//    rb_io_close(io);
+//    rb_vm_call(io, selClose, 0, NULL, false);
 }
 
 
@@ -809,7 +797,6 @@
     BOOL handle_is_file = rb_source_is_file(src) &&
         rb_obj_is_kind_of(handle, cIO);
     if (handle_is_file) {
-        printf("Extracting handler from IO object\n");
         GC_WB(&src->rb_context, handle);
         handle = rb_vm_call(handle, selFileNo, 0, NULL, false);
     }
@@ -828,7 +815,6 @@
     dispatch_source_set_event_handler_f(src->source, rb_source_event_handler);
 
     if (handle_is_file) {
-        printf("Initializing cancel handler\n");
         dispatch_source_set_cancel_handler_f(src->source, rb_source_close_handler);
     }
     rb_dispatch_resume(self, 0);
@@ -855,16 +841,15 @@
  */
 
 static VALUE
-rb_source_timer(VALUE self, SEL sel,
- VALUE delay, VALUE interval, VALUE leeway, VALUE queue)
+rb_source_timer(VALUE klass, VALUE sel, VALUE delay, VALUE interval, VALUE leeway, VALUE queue)
 {
+    Check_Queue(queue);
     dispatch_time_t start_time;
-    rb_source_t *src = RSource(self);
     VALUE argv[4] = {INT2FIX(SOURCE_TYPE_TIMER),
         INT2FIX(0), INT2FIX(0), queue};
-    Check_Queue(queue);
     
-    rb_class_new_instance(4, argv, cSource);
+    VALUE self = rb_class_new_instance(4, argv, cSource);
+    rb_source_t *src = RSource(self);
 
     if (NIL_P(leeway)) {
         leeway = INT2FIX(0);
@@ -876,6 +861,7 @@
         start_time = rb_num2timeout(delay);
     }
 
+    rb_dispatch_suspend(self, 0);
     dispatch_source_set_timer(src->source, start_time,
 	    rb_num2nsec(interval), rb_num2nsec(leeway));
     rb_dispatch_resume(self, 0);

Modified: MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb	2010-01-14 23:32:13 UTC (rev 3275)
+++ MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb	2010-01-14 23:32:15 UTC (rev 3276)
@@ -267,7 +267,7 @@
           it "does close file when cancelled given IO" do
             @src = Dispatch::Source.new(@type, @file, 0, @q) { }
             @file.closed?.should == false
-            src.cancel!
+            @src.cancel!
             @q.sync { }
             @file.closed?.should == true
           end
@@ -309,7 +309,7 @@
           it "does close file when cancelled given IO" do
             @src = Dispatch::Source.new(@type, @file, 0, @q) { }
             @file.closed?.should == false
-            src.cancel!
+            @src.cancel!
             @q.sync { }
             @file.closed?.should == true
           end
@@ -342,15 +342,15 @@
             @fired.should == true
             @flag.should == @mask
           end    
-        end
-        
-        it "does close file when cancelled given IO" do
-          @src = Dispatch::Source.new(@type, @file, 0, @q) { }
-          @file.closed?.should == false
-          src.cancel!
-          @q.sync { }
-          @file.closed?.should == true
-        end   
+
+          it "does close file when cancelled given IO" do
+            @src = Dispatch::Source.new(@type, @file, 0, @q) { }
+            @file.closed?.should == false
+            @src.cancel!
+            @q.sync { }
+            @file.closed?.should == true
+          end   
+        end      
       end
     end # file
     
@@ -369,7 +369,6 @@
       it "returns an instance of Dispatch::Source" do
         @src = Dispatch::Source.timer(0, @interval, 0, @q) { }
         @src.should be_kind_of(Dispatch::Source)
-        @src.should be_kind_of(Dispatch::Timer)
       end
 
       it "should not be suspended" do

Modified: MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt
===================================================================
--- MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt	2010-01-14 23:32:13 UTC (rev 3275)
+++ MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt	2010-01-14 23:32:15 UTC (rev 3276)
@@ -0,0 +1,3 @@
+fails:Dispatch::Source of type file: READ does close file when cancelled given IO
+fails:Dispatch::Source of type file: WRITE does close file when cancelled given IO
+fails:Dispatch::Source of type file: VNODE does close file when cancelled given IO
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100114/8697cec3/attachment-0001.html>


More information about the macruby-changes mailing list