[macruby-changes] [3112] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Dec 14 15:32:27 PST 2009
Revision: 3112
http://trac.macosforge.org/projects/ruby/changeset/3112
Author: ernest.prabhakar at gmail.com
Date: 2009-12-14 15:32:25 -0800 (Mon, 14 Dec 2009)
Log Message:
-----------
Changed 'parenthesis' to 'brace' in HACKING to match common English meaning
Modified Paths:
--------------
MacRuby/trunk/HACKING.rdoc
MacRuby/trunk/gcd.c
Modified: MacRuby/trunk/HACKING.rdoc
===================================================================
--- MacRuby/trunk/HACKING.rdoc 2009-12-14 19:30:09 UTC (rev 3111)
+++ MacRuby/trunk/HACKING.rdoc 2009-12-14 23:32:25 UTC (rev 3112)
@@ -17,7 +17,7 @@
code, so we are preserving it.
* Insert a new line between the type and the name of a function during its
- definition and start the opening parenthesis on a new line too.
+ definition and start the opening brace on a new line too.
static void
do_something(void)
@@ -26,7 +26,7 @@
}
* A space must be inserted between keywords and their operand and branches must
- be written so that an ending parenthesis is always at the end of a line.
+ be written so that an ending brace is always at the end of a line.
if (some_boolean) {
...
@@ -35,7 +35,7 @@
...
}
-* Branches with only one expression must still be covered by parenthesis, even
+* Branches with only one expression must still be covered by braces, even
if it's not mandatory in the C language. Also, do not write one-liner
branches.
@@ -55,7 +55,7 @@
...
}
-* Do not insert a space between a function call and its first parenthesis.
+* Do not insert a space between a function call and its first brace.
do_something();
Modified: MacRuby/trunk/gcd.c
===================================================================
--- MacRuby/trunk/gcd.c 2009-12-14 19:30:09 UTC (rev 3111)
+++ MacRuby/trunk/gcd.c 2009-12-14 23:32:25 UTC (rev 3112)
@@ -134,16 +134,36 @@
}
}
+#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)
+
static inline uint64_t
-number_to_nanoseconds(VALUE num)
+rb_num2nsec(VALUE num)
{
const double sec = rb_num2dbl(num);
+ fprintf(stderr, "rb_num2nsec: %lf/%lf\n", sec, TIMEOUT_MAX);
if (sec < 0.0) {
rb_raise(rb_eArgError, "negative delay specified");
}
- return (uint64_t)(((uint64_t)sec) * NSEC_PER_SEC);
+ return SEC2NSEC_UINT64(sec);
}
+static inline dispatch_time_t
+rb_num2timeout(VALUE num)
+{
+ dispatch_time_t dispatch_timeout = DISPATCH_TIME_FOREVER;
+ if (!NIL_P(num)) {
+ const double sec = rb_num2dbl(num);
+ if (sec < TIMEOUT_MAX) {
+ fprintf(stderr, "rb_num2timeout< %lf\n", sec);
+ dispatch_timeout = dispatch_walltime(NULL, SEC2NSEC_INT64(sec));
+ }
+ }
+ fprintf(stderr, "rb_num2timeout> %llu\n", dispatch_timeout);
+ return dispatch_timeout;
+}
+
static VALUE
rb_queue_alloc(VALUE klass, SEL sel)
{
@@ -414,15 +434,10 @@
* gcdq.after(0.5) { puts 'wait is over :)' }
*
*/
-// TODO: there is a max value that can be passed (int64_max / NSEC_PER_SEC);
-// adjust for this.
static VALUE
rb_queue_dispatch_after(VALUE self, SEL sel, VALUE sec)
{
- sec = rb_Float(sec);
- dispatch_time_t offset = dispatch_walltime(NULL,
- (int64_t)(RFLOAT_VALUE(sec) * NSEC_PER_SEC));
-
+ dispatch_time_t offset = rb_num2timeout(sec);
rb_vm_block_t *block = given_block();
block = rb_dispatch_prepare_block(block);
@@ -641,17 +656,10 @@
static VALUE
rb_group_wait(VALUE self, SEL sel, int argc, VALUE *argv)
{
- dispatch_time_t timeout = DISPATCH_TIME_FOREVER;
- VALUE float_timeout;
- rb_scan_args(argc, argv, "01", &float_timeout);
- if (!NIL_P(float_timeout)) {
- // TODO: watch out for overflow here, too
- double d = NUM2DBL(float_timeout);
- int64_t to = (int64_t)(d * NSEC_PER_SEC);
- timeout = dispatch_walltime(NULL, to);
- }
- return dispatch_group_wait(RGroup(self)->group, timeout) == 0
- ? Qtrue : Qfalse;
+ VALUE num;
+ rb_scan_args(argc, argv, "01", &num);
+ return dispatch_group_wait(RGroup(self)->group, rb_num2timeout(num))
+ == 0 ? Qtrue : Qfalse;
}
static VALUE rb_source_on_event(VALUE self, SEL sel);
@@ -735,10 +743,10 @@
start_time = DISPATCH_TIME_NOW;
}
else {
- start_time = dispatch_walltime(NULL, number_to_nanoseconds(delay));
+ start_time = rb_num2timeout(delay);
}
- const uint64_t dispatch_interval = number_to_nanoseconds(interval);
- const uint64_t dispatch_leeway = number_to_nanoseconds(leeway);
+ const uint64_t dispatch_interval = rb_num2nsec(interval);
+ const uint64_t dispatch_leeway = rb_num2nsec(leeway);
VALUE src = rb_source_alloc(klass, sel);
RSource(src)->source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,
@@ -844,16 +852,19 @@
}
static VALUE
-rb_semaphore_wait(VALUE self, SEL sel, VALUE time)
+rb_semaphore_wait(VALUE self, SEL sel, int argc, VALUE *argv)
{
- return LONG2NUM(dispatch_semaphore_wait(RSemaphore(self)->sem,
- NUM2LL(time)));
+ VALUE num;
+ rb_scan_args(argc, argv, "01", &num);
+ return dispatch_semaphore_wait(RSemaphore(self)->sem, rb_num2timeout(num))
+ == 0 ? Qtrue : Qfalse;
}
static VALUE
rb_semaphore_signal(VALUE self, SEL sel)
{
- return LONG2NUM(dispatch_semaphore_signal(RSemaphore(self)->sem));
+ return dispatch_semaphore_signal(RSemaphore(self)->sem)
+ == 0 ? Qtrue : Qfalse;
}
static IMP rb_semaphore_finalize_super;
@@ -971,7 +982,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, "wait", rb_semaphore_wait, 1);
+ rb_objc_define_method(cSemaphore, "wait", rb_semaphore_wait, -1);
rb_objc_define_method(cSemaphore, "signal", rb_semaphore_signal, 0);
rb_queue_finalize_super = rb_objc_install_method2((Class)cSemaphore,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091214/c99f65e2/attachment-0001.html>
More information about the macruby-changes
mailing list