[macruby-changes] [4352] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 13 15:37:06 PDT 2010


Revision: 4352
          http://trac.macosforge.org/projects/ruby/changeset/4352
Author:   ernest.prabhakar at gmail.com
Date:     2010-07-13 15:37:05 -0700 (Tue, 13 Jul 2010)
Log Message:
-----------
Raise error on incorrect zero-argument initializers in gcd.c

Modified Paths:
--------------
    MacRuby/trunk/gcd.c
    MacRuby/trunk/spec/macruby/core/gcd/semaphore_spec.rb
    MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/queue_tags.txt
    MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/semaphore_tags.txt

Modified: MacRuby/trunk/gcd.c
===================================================================
--- MacRuby/trunk/gcd.c	2010-07-13 22:37:02 UTC (rev 4351)
+++ MacRuby/trunk/gcd.c	2010-07-13 22:37:05 UTC (rev 4352)
@@ -129,6 +129,14 @@
     }
 }
 
+static VALUE 
+rb_raise_init(VALUE self, SEL sel)
+{
+	rb_raise(rb_eArgError, "initializer called without any arguments");
+    return self;
+}
+
+
 #define SEC2NSEC_UINT64(sec) (uint64_t)(sec * NSEC_PER_SEC)
 #define SEC2NSEC_INT64(sec) (int64_t)(sec * NSEC_PER_SEC)
 #define TIMEOUT_MAX (1.0 * INT64_MAX / NSEC_PER_SEC)
@@ -1234,6 +1242,7 @@
     rb_objc_define_method(*(VALUE *)cQueue, "current", rb_queue_get_current, 0);
     rb_objc_define_method(*(VALUE *)cQueue, "main", rb_queue_get_main, 0);
     rb_objc_define_method(cQueue, "initialize", rb_queue_init, 1);
+    rb_objc_define_method(cQueue, "initialize", rb_raise_init, 0);
     rb_objc_define_method(cQueue, "apply", rb_queue_apply, 1);
     rb_objc_define_method(cQueue, "async", rb_queue_dispatch_async, -1);
     rb_objc_define_method(cQueue, "sync", rb_queue_dispatch_sync, 0);
@@ -1268,7 +1277,7 @@
     rb_objc_define_method(*(VALUE *)cGroup, "alloc", rb_group_alloc, 0);
     rb_objc_define_method(cGroup, "initialize", rb_group_init, 0);
     rb_objc_define_method(cGroup, "notify", rb_group_notify, 1);
-    rb_objc_define_method(cGroup, "on_completion", rb_group_notify, 1);
+    rb_objc_define_method(cGroup, "on_completion", rb_group_notify, 1); // deprecated
     rb_objc_define_method(cGroup, "wait", rb_group_wait, -1);
     
     rb_group_finalize_super = rb_objc_install_method2((Class)cGroup,
@@ -1318,6 +1327,7 @@
     rb_objc_define_method(*(VALUE *)cSource, "alloc", rb_source_alloc, 0);
     rb_objc_define_method(*(VALUE *)cSource, "timer", rb_source_timer, 4);
     rb_objc_define_method(cSource, "initialize", rb_source_init, 4);
+    rb_objc_define_method(cSource, "initialize", rb_raise_init, 0);
     rb_objc_define_method(cSource, "cancelled?", rb_source_cancelled_p, 0);
     rb_objc_define_method(cSource, "cancel!", rb_source_cancel, 0);
     rb_objc_define_method(cSource, "resume!", rb_dispatch_resume, 0);
@@ -1338,6 +1348,7 @@
     cSemaphore = rb_define_class_under(mDispatch, "Semaphore", rb_cObject);
     rb_objc_define_method(*(VALUE *)cSemaphore, "alloc", rb_semaphore_alloc, 0);
     rb_objc_define_method(cSemaphore, "initialize", rb_semaphore_init, 1);
+    rb_objc_define_method(cSemaphore, "initialize", rb_raise_init, 0);
     rb_objc_define_method(cSemaphore, "wait", rb_semaphore_wait, -1);
     rb_objc_define_method(cSemaphore, "signal", rb_semaphore_signal, 0);
     rb_semaphore_finalize_super = rb_objc_install_method2((Class)cSemaphore,

Modified: MacRuby/trunk/spec/macruby/core/gcd/semaphore_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd/semaphore_spec.rb	2010-07-13 22:37:02 UTC (rev 4351)
+++ MacRuby/trunk/spec/macruby/core/gcd/semaphore_spec.rb	2010-07-13 22:37:05 UTC (rev 4352)
@@ -10,26 +10,27 @@
       @sema1 = Dispatch::Semaphore.new 1
       @q = Dispatch::Queue.new('org.macruby.gcd_spec.semaphore')
     end
+    describe :new do
+      it "returns an instance of Semaphore for non-negative counts" do
+        @sema0.should be_kind_of(Dispatch::Semaphore)
+        @sema1.should be_kind_of(Dispatch::Semaphore)
+      end
 
-    it "returns an instance of Semaphore for non-negative counts" do
-      @sema0.should be_kind_of(Dispatch::Semaphore)
-      @sema1.should be_kind_of(Dispatch::Semaphore)
-    end
+      it "raises an ArgumentError if the count isn't specified" do
+        lambda { Dispatch::Semaphore.new }.should raise_error(ArgumentError)
+      end
 
-    it "raises an ArgumentError if the count isn't specified" do
-      lambda { Dispatch::Semaphore.new }.should raise_error(ArgumentError)
-    end
+      it "raises a TypeError if a non-numeric count is provided" do
+        lambda { Dispatch::Semaphore.new :foo }.should raise_error(TypeError)
+        lambda { Dispatch::Semaphore.new 3.5 }.should_not raise_error(TypeError)
+        lambda { Dispatch::Semaphore.new "3" }.should raise_error(TypeError)
+      end
 
-    it "raises a TypeError if a non-numeric count is provided" do
-      lambda { Dispatch::Semaphore.new :foo }.should raise_error(TypeError)
-      lambda { Dispatch::Semaphore.new 3.5 }.should_not raise_error(TypeError)
-      lambda { Dispatch::Semaphore.new "3" }.should raise_error(TypeError)
+      it "raises an ArgumentError if the specified count is less than zero" do
+        lambda { Dispatch::Semaphore.new -1 }.should raise_error(ArgumentError)
+      end
     end
 
-    it "raises an ArgumentError if the specified count is less than zero" do
-      lambda { Dispatch::Semaphore.new -1 }.should raise_error(ArgumentError)
-    end
-
     describe :wait do
       it "always returns true with default timeout FOREVER" do
         @sema1.wait.should == true

Modified: MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/queue_tags.txt
===================================================================
--- MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/queue_tags.txt	2010-07-13 22:37:02 UTC (rev 4351)
+++ MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/queue_tags.txt	2010-07-13 22:37:05 UTC (rev 4352)
@@ -1,4 +1,3 @@
-critical:Dispatch::Queue new raises an ArgumentError if not passed a string
 fails:Dispatch::Queue == should be true if the underlying dispatch_queues are equal
 fails:to_s returns the name of the queue
 fails:suspend! suspends the queue which can be resumed by calling #resume!

Modified: MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/semaphore_tags.txt
===================================================================
--- MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/semaphore_tags.txt	2010-07-13 22:37:02 UTC (rev 4351)
+++ MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/semaphore_tags.txt	2010-07-13 22:37:05 UTC (rev 4352)
@@ -1 +0,0 @@
-critical:Dispatch::Semaphore raises an ArgumentError if the count isn't specified
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100713/1e67ee28/attachment-0001.html>


More information about the macruby-changes mailing list