Modified: MacRuby/trunk/gcd.c (2923 => 2924)
--- MacRuby/trunk/gcd.c 2009-10-30 04:10:23 UTC (rev 2923)
+++ MacRuby/trunk/gcd.c 2009-10-30 04:11:56 UTC (rev 2924)
@@ -317,22 +317,23 @@
static VALUE
rb_queue_dispatch(VALUE self, SEL sel, int argc, VALUE* argv)
{
- rb_vm_block_t *the_block = rb_vm_current_block();
- if (the_block == NULL) {
+ rb_vm_block_t *block = rb_vm_current_block();
+ if (block == NULL) {
rb_raise(rb_eArgError, "dispatch() requires a block argument");
}
VALUE synchronous;
rb_scan_args(argc, argv, "01", &synchronous);
+ rb_vm_block_make_detachable_proc(block);
rb_vm_set_multithreaded(true);
if (RTEST(synchronous)){
- dispatch_sync_f(RQueue(self)->queue, (void *)the_block,
+ dispatch_sync_f(RQueue(self)->queue, (void *)block,
rb_queue_dispatcher);
}
else {
- dispatch_async_f(RQueue(self)->queue, (void *)the_block,
+ dispatch_async_f(RQueue(self)->queue, (void *)block,
rb_queue_dispatcher);
}
@@ -356,14 +357,15 @@
sec = rb_Float(sec);
dispatch_time_t offset = dispatch_walltime(NULL,
(int64_t)(RFLOAT_VALUE(sec) * NSEC_PER_SEC));
- rb_vm_block_t *the_block = rb_vm_current_block();
- if (the_block == NULL) {
+ rb_vm_block_t *block = rb_vm_current_block();
+ if (block == NULL) {
rb_raise(rb_eArgError, "dispatch_after() requires a block argument");
}
+ rb_vm_block_make_detachable_proc(block);
rb_vm_set_multithreaded(true);
- dispatch_after_f(offset, RQueue(self)->queue, (void *)the_block,
+ dispatch_after_f(offset, RQueue(self)->queue, (void *)block,
rb_queue_dispatcher);
return Qnil;
@@ -394,14 +396,15 @@
static VALUE
rb_queue_apply(VALUE self, SEL sel, VALUE n)
{
- rb_vm_block_t *the_block = rb_vm_current_block();
- if (the_block == NULL) {
+ rb_vm_block_t *block = rb_vm_current_block();
+ if (block == NULL) {
rb_raise(rb_eArgError, "apply() requires a block argument");
}
+ rb_vm_block_make_detachable_proc(block);
rb_vm_set_multithreaded(true);
- dispatch_apply_f(NUM2SIZET(n), RQueue(self)->queue, (void*)the_block,
+ dispatch_apply_f(NUM2SIZET(n), RQueue(self)->queue, (void *)block,
rb_queue_applier);
return Qnil;
@@ -550,15 +553,16 @@
static VALUE
rb_group_dispatch(VALUE self, SEL sel, VALUE target)
{
- rb_vm_block_t *the_block = rb_vm_current_block();
- if (the_block == NULL) {
+ rb_vm_block_t *block = rb_vm_current_block();
+ if (block == NULL) {
rb_raise(rb_eArgError, "dispatch() requires a block argument");
}
+ rb_vm_block_make_detachable_proc(block);
rb_vm_set_multithreaded(true);
dispatch_group_async_f(RGroup(self)->group, RQueue(target)->queue,
- (void *)the_block, rb_queue_dispatcher);
+ (void *)block, rb_queue_dispatcher);
return Qnil;
}
@@ -581,15 +585,16 @@
static VALUE
rb_group_notify(VALUE self, SEL sel, VALUE target)
{
- rb_vm_block_t *the_block = rb_vm_current_block();
- if (the_block == NULL) {
+ rb_vm_block_t *block = rb_vm_current_block();
+ if (block == NULL) {
rb_raise(rb_eArgError, "notify() requires a block argument");
}
+ rb_vm_block_make_detachable_proc(block);
rb_vm_set_multithreaded(true);
dispatch_group_notify_f(RGroup(self)->group, RQueue(target)->queue,
- (void *)the_block, rb_queue_dispatcher);
+ (void *)block, rb_queue_dispatcher);
return Qnil;
}
Modified: MacRuby/trunk/proc.c (2923 => 2924)
--- MacRuby/trunk/proc.c 2009-10-30 04:10:23 UTC (rev 2923)
+++ MacRuby/trunk/proc.c 2009-10-30 04:11:56 UTC (rev 2924)
@@ -44,12 +44,7 @@
VALUE obj;
obj = Data_Wrap_Struct(klass, NULL, NULL, proc);
proc->proc = obj; // weak
- if (!(proc->flags & VM_BLOCK_PROC)) {
- proc->flags |= VM_BLOCK_PROC;
- if (!(proc->flags & VM_BLOCK_METHOD)) {
- rb_vm_add_block_lvar_use(proc);
- }
- }
+ rb_vm_block_make_detachable_proc(proc);
return obj;
}
Modified: MacRuby/trunk/vm.cpp (2923 => 2924)
--- MacRuby/trunk/vm.cpp 2009-10-30 04:10:23 UTC (rev 2923)
+++ MacRuby/trunk/vm.cpp 2009-10-30 04:11:56 UTC (rev 2924)
@@ -2543,7 +2543,8 @@
block_for_uses != NULL;
block_for_uses = block_for_uses->parent_block) {
- rb_vm_add_lvar_use(block_for_uses->parent_var_uses, block, VM_LVAR_USE_TYPE_BLOCK);
+ rb_vm_add_lvar_use(block_for_uses->parent_var_uses, block,
+ VM_LVAR_USE_TYPE_BLOCK);
}
}
@@ -2555,7 +2556,8 @@
block_for_uses != NULL;
block_for_uses = block_for_uses->parent_block) {
- rb_vm_add_lvar_use(block_for_uses->parent_var_uses, binding, VM_LVAR_USE_TYPE_BINDING);
+ rb_vm_add_lvar_use(block_for_uses->parent_var_uses, binding,
+ VM_LVAR_USE_TYPE_BINDING);
}
rb_vm_add_lvar_use(parent_var_uses, binding, VM_LVAR_USE_TYPE_BINDING);
}
@@ -3983,7 +3985,7 @@
if (body != NULL) {
GC_WB(&t->body, body);
- rb_vm_add_block_lvar_use(body);
+ rb_vm_block_make_detachable_proc(body);
}
else {
t->body = NULL;
@@ -3992,8 +3994,7 @@
if (argc > 0) {
t->argc = argc;
GC_WB(&t->argv, xmalloc(sizeof(VALUE) * argc));
- int i;
- for (i = 0; i < argc; i++) {
+ for (int i = 0; i < argc; i++) {
GC_WB(&t->argv[i], argv[i]);
}
}
Modified: MacRuby/trunk/vm.h (2923 => 2924)
--- MacRuby/trunk/vm.h 2009-10-30 04:10:23 UTC (rev 2923)
+++ MacRuby/trunk/vm.h 2009-10-30 04:11:56 UTC (rev 2924)
@@ -367,6 +367,17 @@
bool rb_vm_block_saved(void);
VALUE rb_vm_block_eval(rb_vm_block_t *block, int argc, const VALUE *argv);
+static inline void
+rb_vm_block_make_detachable_proc(rb_vm_block_t *b)
+{
+ if (!(b->flags & VM_BLOCK_PROC)) {
+ b->flags |= VM_BLOCK_PROC;
+ if (!(b->flags & VM_BLOCK_METHOD)) {
+ rb_vm_add_block_lvar_use(b);
+ }
+ }
+}
+
rb_vm_binding_t *rb_vm_current_binding(void);
void rb_vm_add_binding(rb_vm_binding_t *binding);
void rb_vm_pop_binding();