[macruby-changes] [2744] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Oct 6 17:27:38 PDT 2009


Revision: 2744
          http://trac.macosforge.org/projects/ruby/changeset/2744
Author:   lsansonetti at apple.com
Date:     2009-10-06 17:27:35 -0700 (Tue, 06 Oct 2009)
Log Message:
-----------
fix for <rdar://problem/7281043> Adding frameworks after requiring a library that uses at_exit causes a bus error

Modified Paths:
--------------
    MacRuby/trunk/eval_jump.c
    MacRuby/trunk/include/ruby/intern.h
    MacRuby/trunk/proc.c

Modified: MacRuby/trunk/eval_jump.c
===================================================================
--- MacRuby/trunk/eval_jump.c	2009-10-06 23:56:31 UTC (rev 2743)
+++ MacRuby/trunk/eval_jump.c	2009-10-07 00:27:35 UTC (rev 2744)
@@ -5,11 +5,8 @@
 
 /* exit */
 
-void
-rb_call_end_proc(VALUE data)
-{
-    rb_proc_call(data, rb_ary_new());
-}
+// TODO: move & lock me into RoxorCore
+static VALUE at_exit_procs = Qnil;
 
 /*
  *  call-seq:
@@ -35,63 +32,34 @@
 static VALUE
 rb_f_at_exit(VALUE self, SEL sel)
 {
-    VALUE proc;
-
     if (!rb_block_given_p()) {
 	rb_raise(rb_eArgError, "called without a block");
     }
-    proc = rb_block_proc();
-    rb_set_end_proc(rb_call_end_proc, proc);
+    VALUE proc = rb_block_proc();
+    rb_ary_push(at_exit_procs, proc);
     return proc;
 }
 
-struct end_proc_data {
-    void (*func) ();
-    VALUE data;
-    int safe;
-    struct end_proc_data *next;
-};
-
-static struct end_proc_data *end_procs = NULL;
-static struct end_proc_data *tmp_end_procs = NULL;
-
 void
-rb_set_end_proc(void (*func)(VALUE), VALUE data)
-{
-    struct end_proc_data *link = ALLOC(struct end_proc_data);
-    struct end_proc_data **list;
-
-    list = &end_procs;
-    GC_WB(&link->next, *list);
-    link->func = func;
-    link->data = data;
-    link->safe = rb_safe_level();
-    *list = link;
-}
-
-void
 rb_exec_end_proc(void)
 {
-    struct end_proc_data *link, *tmp;
-    int safe = rb_safe_level();
-
-    if (end_procs != NULL) {
-	tmp_end_procs = link = end_procs;
-	end_procs = 0;
-	while (link != NULL) {
-	    rb_set_safe_level_force(link->safe);
-	    (*link->func) (link->data);
-	    tmp = link;
-	    tmp_end_procs = link = link->next;
-	    xfree(tmp);
+    while (true) {
+	const int count = RARRAY_LEN(at_exit_procs);
+	if (count > 0) {
+	    VALUE proc = RARRAY_AT(at_exit_procs, count - 1);
+	    rb_ary_delete_at(at_exit_procs, count - 1);	
+	    rb_proc_call2(proc, 0, NULL);
+	    continue;
 	}
+	break;
     }
-    rb_set_safe_level_force(safe);
 }
 
 void
 Init_jump(void)
 {
     rb_objc_define_module_function(rb_mKernel, "at_exit", rb_f_at_exit, 0);
-    GC_ROOT(&end_procs);
+
+    at_exit_procs = rb_ary_new();
+    GC_RETAIN(at_exit_procs);
 }

Modified: MacRuby/trunk/include/ruby/intern.h
===================================================================
--- MacRuby/trunk/include/ruby/intern.h	2009-10-06 23:56:31 UTC (rev 2743)
+++ MacRuby/trunk/include/ruby/intern.h	2009-10-07 00:27:35 UTC (rev 2744)
@@ -278,13 +278,13 @@
 VALUE rb_block_proc(void);
 VALUE rb_f_lambda(void);
 VALUE rb_proc_call(VALUE, VALUE);
+VALUE rb_proc_call2(VALUE self, int argc, VALUE *argv);
 int rb_proc_arity(VALUE);
 VALUE rb_binding_new(void);
 VALUE rb_method_call(VALUE, SEL, int, VALUE*);
 int rb_mod_method_arity(VALUE, ID);
 int rb_obj_method_arity(VALUE, ID);
 VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*);
-void rb_set_end_proc(void (*)(VALUE), VALUE);
 void rb_mark_end_proc(void);
 void rb_exec_end_proc(void);
 void Init_jump(void);

Modified: MacRuby/trunk/proc.c
===================================================================
--- MacRuby/trunk/proc.c	2009-10-06 23:56:31 UTC (rev 2743)
+++ MacRuby/trunk/proc.c	2009-10-07 00:27:35 UTC (rev 2744)
@@ -450,6 +450,12 @@
     return proc_call(self, 0, RARRAY_LEN(args), RARRAY_PTR(args));
 }
 
+VALUE
+rb_proc_call2(VALUE self, int argc, VALUE *argv)
+{
+    return proc_call(self, 0, argc, argv);
+}
+
 /*
  *  call-seq:
  *     prc.arity -> fixnum
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091006/ba49bd5d/attachment.html>


More information about the macruby-changes mailing list