[macruby-changes] [849] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun Mar 8 17:41:28 PDT 2009


Revision: 849
          http://trac.macosforge.org/projects/ruby/changeset/849
Author:   lsansonetti at apple.com
Date:     2009-03-08 17:41:28 -0700 (Sun, 08 Mar 2009)
Log Message:
-----------
fixed GC leaks + added some temporary rdoc tweaks

Modified Paths:
--------------
    MacRuby/trunk/insns.def
    MacRuby/trunk/io.c
    MacRuby/trunk/lib/rdoc/markup/attribute_manager.rb
    MacRuby/trunk/lib/rdoc/markup/lines.rb
    MacRuby/trunk/lib/rdoc/parser.rb
    MacRuby/trunk/lib/rdoc/ri/paths.rb
    MacRuby/trunk/re.c
    MacRuby/trunk/regcomp.c
    MacRuby/trunk/regenc.c
    MacRuby/trunk/regexec.c
    MacRuby/trunk/regint.h
    MacRuby/trunk/regparse.c
    MacRuby/trunk/string.c

Modified: MacRuby/trunk/insns.def
===================================================================
--- MacRuby/trunk/insns.def	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/insns.def	2009-03-09 00:41:28 UTC (rev 849)
@@ -1980,6 +1980,12 @@
 {
     if (!SPECIAL_CONST_P(recv) &&
 	BASIC_OP_UNREDEFINED_P(BOP_LENGTH)) {
+#if 0
+	if (HEAP_CLASS_OF(recv) == rb_cCFString) {
+	    val = rb_str_length(recv);
+	}
+	else
+#endif
 	if (HEAP_CLASS_OF(recv) == rb_cCFArray) {
 	    val = LONG2NUM(RARRAY_LEN(recv));
 	}

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/io.c	2009-03-09 00:41:28 UTC (rev 849)
@@ -6280,7 +6280,7 @@
     arg->argv = argv + 1;
     if (argc == 1) {
       no_key:
-	arg->io = rb_io_open(RSTRING_PTR(argv[0]), "r");
+	GC_WB(&arg->io, rb_io_open(RSTRING_PTR(argv[0]), "r"));
 	return;
     }
     opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
@@ -6306,7 +6306,7 @@
 	values[0] = argv[0];
 	for (i = 0; i < v_len; i++)
 	    values[i + 1] = RARRAY_AT(v, i);
-	arg->io = rb_io_open_with_args(v_len + 1, values);
+	GC_WB(&arg->io, rb_io_open_with_args(v_len + 1, values));
 #else
 	VALUE args;
 	args = rb_ary_new2(RARRAY_LEN(v)+1);
@@ -6319,10 +6319,10 @@
     }
     v = rb_hash_aref(opt, mode);
     if (!NIL_P(v)) {
-	arg->io = rb_io_open(RSTRING_PTR(argv[0]), StringValueCStr(v));
+	GC_WB(&arg->io, rb_io_open(RSTRING_PTR(argv[0]), StringValueCStr(v)));
     }
     else {
-	arg->io = rb_io_open(RSTRING_PTR(argv[0]), "r");
+	GC_WB(&arg->io, rb_io_open(RSTRING_PTR(argv[0]), "r"));
     }
 
     v = rb_hash_aref(opt, encoding);
@@ -6370,13 +6370,13 @@
 static VALUE
 rb_io_s_foreach(int argc, VALUE *argv, VALUE self)
 {
-    struct foreach_arg arg;
+    struct foreach_arg *arg = xmalloc(sizeof(struct foreach_arg));
 
     rb_scan_args(argc, argv, "13", NULL, NULL, NULL, NULL);
     RETURN_ENUMERATOR(self, argc, argv);
-    open_key_args(argc, argv, &arg);
-    if (NIL_P(arg.io)) return Qnil;
-    return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, arg.io);
+    open_key_args(argc, argv, arg);
+    if (NIL_P(arg->io)) return Qnil;
+    return rb_ensure(io_s_foreach, (VALUE)arg, rb_io_close, arg->io);
 }
 
 static VALUE
@@ -6406,12 +6406,12 @@
 static VALUE
 rb_io_s_readlines(int argc, VALUE *argv, VALUE io)
 {
-    struct foreach_arg arg;
+    struct foreach_arg *arg = xmalloc(sizeof(struct foreach_arg));
 
     rb_scan_args(argc, argv, "13", NULL, NULL, NULL, NULL);
-    open_key_args(argc, argv, &arg);
-    if (NIL_P(arg.io)) return Qnil;
-    return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
+    open_key_args(argc, argv, arg);
+    if (NIL_P(arg->io)) return Qnil;
+    return rb_ensure(io_s_readlines, (VALUE)arg, rb_io_close, arg->io);
 }
 
 static VALUE
@@ -6456,17 +6456,17 @@
 rb_io_s_read(int argc, VALUE *argv, VALUE io)
 {
     VALUE offset;
-    struct foreach_arg arg;
+    struct foreach_arg *arg = xmalloc(sizeof(struct foreach_arg));
 
     rb_scan_args(argc, argv, "13", NULL, NULL, &offset, NULL);
-    open_key_args(argc, argv, &arg);
-    if (NIL_P(arg.io)) return Qnil;
+    open_key_args(argc, argv, arg);
+    if (NIL_P(arg->io)) return Qnil;
     if (!NIL_P(offset)) {
-	rb_io_binmode(arg.io);
-	rb_io_seek(arg.io, offset, SEEK_SET);
-	if (arg.argc == 2) arg.argc = 1;
+	rb_io_binmode(arg->io);
+	rb_io_seek(arg->io, offset, SEEK_SET);
+	if (arg->argc == 2) arg->argc = 1;
     }
-    return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io);
+    return rb_ensure(io_s_read, (VALUE)arg, rb_io_close, arg->io);
 }
 
 struct copy_stream_struct {

Modified: MacRuby/trunk/lib/rdoc/markup/attribute_manager.rb
===================================================================
--- MacRuby/trunk/lib/rdoc/markup/attribute_manager.rb	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/lib/rdoc/markup/attribute_manager.rb	2009-03-09 00:41:28 UTC (rev 849)
@@ -64,7 +64,8 @@
 
   def copy_string(start_pos, end_pos)
     res = @str[start_pos...end_pos]
-    res.gsub!(/\000/, '')
+    # XXX this doesn't work in MacRuby yet
+    #res.gsub!(/\000/, '')
     res
   end
 
@@ -131,7 +132,8 @@
   end
 
   def unmask_protected_sequences
-    @str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1\000")
+    #@str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1\000")
+    @str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1")
   end
 
   def initialize

Modified: MacRuby/trunk/lib/rdoc/markup/lines.rb
===================================================================
--- MacRuby/trunk/lib/rdoc/markup/lines.rb	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/lib/rdoc/markup/lines.rb	2009-03-09 00:41:28 UTC (rev 849)
@@ -44,7 +44,8 @@
       @deleted = false
 
       # expand tabs
-      1 while @text.gsub!(/\t+/) { ' ' * (8*$&.length - $`.length % 8)}  && $~ #`
+      #1 while @text.gsub!(/\t+/) { ' ' * (8*$&.length - $`.length % 8)}  && $~ #`
+      @text.gsub!(/\t+/) { ' ' * (8*$&.length - $`.length % 8)}
 
       # Strip trailing whitespace
       @text.sub!(/\s+$/, '')

Modified: MacRuby/trunk/lib/rdoc/parser.rb
===================================================================
--- MacRuby/trunk/lib/rdoc/parser.rb	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/lib/rdoc/parser.rb	2009-03-09 00:41:28 UTC (rev 849)
@@ -67,6 +67,8 @@
   # the gem).
 
   def self.binary?(file)
+=begin
+    # XXX: this currently doesn't work in MacRuby
     s = (File.read(file, File.stat(file).blksize, 0, :mode => "rb") || "").split(//)
 
     if s.size > 0 then
@@ -74,6 +76,8 @@
     else
       false
     end
+=end
+    false
   end
   private_class_method :binary?
 

Modified: MacRuby/trunk/lib/rdoc/ri/paths.rb
===================================================================
--- MacRuby/trunk/lib/rdoc/ri/paths.rb	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/lib/rdoc/ri/paths.rb	2009-03-09 00:41:28 UTC (rev 849)
@@ -40,7 +40,7 @@
   end
 
   begin
-    require 'rubygems' unless defined?(Gem)
+    require 'rubygems'# unless defined?(Gem)
 
     # HACK dup'd from Gem.latest_partials and friends
     all_paths = []

Modified: MacRuby/trunk/re.c
===================================================================
--- MacRuby/trunk/re.c	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/re.c	2009-03-09 00:41:28 UTC (rev 849)
@@ -1361,11 +1361,8 @@
     cstr = range = RSTRING_PTR(str);
     clen = RSTRING_LEN(str);
 #if WITH_OBJC
-    static struct re_registers *regs = NULL;
-    if (regs == NULL) {
-	regs = xmalloc(sizeof(struct re_registers));
-	rb_objc_root(&regs);
-    }
+    struct re_registers *regs = NULL;
+    regs = xmalloc(sizeof(struct re_registers));
     pregs = regs;
 #else
     static struct re_registers regs;
@@ -1397,7 +1394,7 @@
 	}
 	else {
 	    onig_free(reg0);
-	    RREGEXP(re)->ptr = reg;
+	    GC_WB(&RREGEXP(re)->ptr, reg);
 	}
     }
     if (!busy) FL_UNSET(re, REG_BUSY);

Modified: MacRuby/trunk/regcomp.c
===================================================================
--- MacRuby/trunk/regcomp.c	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/regcomp.c	2009-03-09 00:41:28 UTC (rev 849)
@@ -143,7 +143,7 @@
     buf->p = NULL;
   }
   else {
-    buf->p = (UChar* )xmalloc(size);
+    GC_WB(&buf->p, (UChar* )xmalloc(size));
     if (IS_NULL(buf->p)) return(ONIGERR_MEMORY);
   }
 
@@ -164,7 +164,7 @@
   CHECK_NULL_RETURN_MEMERR(p);
   uslist->num   = 0;
   uslist->alloc = size;
-  uslist->us    = p;
+  GC_WB(&uslist->us, p);
   return 0;
 }
 
@@ -186,7 +186,7 @@
     p = (UnsetAddr* )xrealloc(uslist->us, sizeof(UnsetAddr) * size);
     CHECK_NULL_RETURN_MEMERR(p);
     uslist->alloc = size;
-    uslist->us    = p;
+    GC_WB(&uslist->us, p);
   }
 
   uslist->us[uslist->num].offset = offset;
@@ -656,7 +656,7 @@
   if (reg->repeat_range_alloc == 0) {
     p = (OnigRepeatRange* )xmalloc(sizeof(OnigRepeatRange) * REPEAT_RANGE_ALLOC);
     CHECK_NULL_RETURN_MEMERR(p);
-    reg->repeat_range = p;
+    GC_WB(&reg->repeat_range, p);
     reg->repeat_range_alloc = REPEAT_RANGE_ALLOC;
   }
   else if (reg->repeat_range_alloc <= id) {
@@ -665,7 +665,7 @@
     p = (OnigRepeatRange* )xrealloc(reg->repeat_range,
                                     sizeof(OnigRepeatRange) * n);
     CHECK_NULL_RETURN_MEMERR(p);
-    reg->repeat_range = p;
+    GC_WB(&reg->repeat_range, p);
     reg->repeat_range_alloc = n;
   }
   else {
@@ -3914,7 +3914,7 @@
   }
   else {
     if (IS_NULL(*int_skip)) {
-      *int_skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
+      GC_WB(int_skip, (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE));
       if (IS_NULL(*int_skip)) return ONIGERR_MEMORY;
     }
     for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) (*int_skip)[i] = len;
@@ -4887,7 +4887,7 @@
   if (e->len == 0) return 0;
 
   if (e->ignore_case) {
-    reg->exact = (UChar* )xmalloc(e->len);
+    GC_WB(&reg->exact, (UChar* )xmalloc(e->len));
     CHECK_NULL_RETURN_MEMERR(reg->exact);
     xmemcpy(reg->exact, e->s, e->len);
     reg->exact_end = reg->exact + e->len;
@@ -4896,7 +4896,7 @@
   else {
     int allow_reverse;
 
-    reg->exact = str_dup(e->s, e->s + e->len);
+    GC_WB(&reg->exact, str_dup(e->s, e->s + e->len));
     CHECK_NULL_RETURN_MEMERR(reg->exact);
     reg->exact_end = reg->exact + e->len;
  
@@ -5343,10 +5343,7 @@
 
   int r, init_size;
   Node*  root;
-  ScanEnv  scan_env;
-#ifdef USE_SUBEXP_CALL
-  UnsetAddrList  uslist;
-#endif
+  ScanEnv  *scan_env;
 
   reg->state = ONIG_STATE_COMPILING;
 
@@ -5372,16 +5369,17 @@
   reg->num_comb_exp_check = 0;
 #endif
 
-  r = onig_parse_make_tree(&root, pattern, pattern_end, reg, &scan_env);
+  scan_env = xmalloc(sizeof(ScanEnv));
+  r = onig_parse_make_tree(&root, pattern, pattern_end, reg, scan_env);
   if (r != 0) goto err;
 
 #ifdef USE_NAMED_GROUP
   /* mixed use named group and no-named group */
-  if (scan_env.num_named > 0 &&
-      IS_SYNTAX_BV(scan_env.syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) &&
+  if (scan_env->num_named > 0 &&
+      IS_SYNTAX_BV(scan_env->syntax, ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP) &&
       !ONIG_IS_OPTION_ON(reg->options, ONIG_OPTION_CAPTURE_GROUP)) {
-    if (scan_env.num_named != scan_env.num_mem)
-      r = disable_noname_group_capture(&root, reg, &scan_env);
+    if (scan_env->num_named != scan_env->num_mem)
+      r = disable_noname_group_capture(&root, reg, scan_env);
     else
       r = numbered_ref_check(root);
 
@@ -5390,85 +5388,85 @@
 #endif
 
 #ifdef USE_SUBEXP_CALL
-  if (scan_env.num_call > 0) {
-    r = unset_addr_list_init(&uslist, scan_env.num_call);
+  if (scan_env->num_call > 0) {
+    GC_WB(&scan_env->unset_addr_list, xmalloc(sizeof(UnsetAddrList)));
+    r = unset_addr_list_init(scan_env->unset_addr_list, scan_env->num_call);
     if (r != 0) goto err;
-    scan_env.unset_addr_list = &uslist;
-    r = setup_subexp_call(root, &scan_env);
+    r = setup_subexp_call(root, scan_env);
     if (r != 0) goto err_unset;
-    r = subexp_recursive_check_trav(root, &scan_env);
+    r = subexp_recursive_check_trav(root, scan_env);
     if (r  < 0) goto err_unset;
-    r = subexp_inf_recursive_check_trav(root, &scan_env);
+    r = subexp_inf_recursive_check_trav(root, scan_env);
     if (r != 0) goto err_unset;
 
-    reg->num_call = scan_env.num_call;
+    reg->num_call = scan_env->num_call;
   }
   else
     reg->num_call = 0;
 #endif
 
-  r = setup_tree(root, reg, 0, &scan_env);
+  r = setup_tree(root, reg, 0, scan_env);
   if (r != 0) goto err_unset;
 
 #ifdef ONIG_DEBUG_PARSE_TREE
   print_tree(stderr, root);
 #endif
 
-  reg->capture_history  = scan_env.capture_history;
-  reg->bt_mem_start     = scan_env.bt_mem_start;
+  reg->capture_history  = scan_env->capture_history;
+  reg->bt_mem_start     = scan_env->bt_mem_start;
   reg->bt_mem_start    |= reg->capture_history;
   if (IS_FIND_CONDITION(reg->options))
     BIT_STATUS_ON_ALL(reg->bt_mem_end);
   else {
-    reg->bt_mem_end  = scan_env.bt_mem_end;
+    reg->bt_mem_end  = scan_env->bt_mem_end;
     reg->bt_mem_end |= reg->capture_history;
   }
 
 #ifdef USE_COMBINATION_EXPLOSION_CHECK
-  if (scan_env.backrefed_mem == 0
+  if (scan_env->backrefed_mem == 0
 #ifdef USE_SUBEXP_CALL
-      || scan_env.num_call == 0
+      || scan_env->num_call == 0
 #endif
       ) {
-    setup_comb_exp_check(root, 0, &scan_env);
+    setup_comb_exp_check(root, 0, scan_env);
 #ifdef USE_SUBEXP_CALL
-    if (scan_env.has_recursion != 0) {
-      scan_env.num_comb_exp_check = 0;
+    if (scan_env->has_recursion != 0) {
+      scan_env->num_comb_exp_check = 0;
     }
     else
 #endif
-    if (scan_env.comb_exp_max_regnum > 0) {
+    if (scan_env->comb_exp_max_regnum > 0) {
       int i;
-      for (i = 1; i <= scan_env.comb_exp_max_regnum; i++) {
-	if (BIT_STATUS_AT(scan_env.backrefed_mem, i) != 0) {
-	  scan_env.num_comb_exp_check = 0;
+      for (i = 1; i <= scan_env->comb_exp_max_regnum; i++) {
+	if (BIT_STATUS_AT(scan_env->backrefed_mem, i) != 0) {
+	  scan_env->num_comb_exp_check = 0;
 	  break;
 	}
       }
     }
   }
 
-  reg->num_comb_exp_check = scan_env.num_comb_exp_check;
+  reg->num_comb_exp_check = scan_env->num_comb_exp_check;
 #endif
 
   clear_optimize_info(reg);
 #ifndef ONIG_DONT_OPTIMIZE
-  r = set_optimize_info_from_tree(root, reg, &scan_env);
+  r = set_optimize_info_from_tree(root, reg, scan_env);
   if (r != 0) goto err_unset;
 #endif
 
-  if (IS_NOT_NULL(scan_env.mem_nodes_dynamic)) {
-    xfree(scan_env.mem_nodes_dynamic);
-    scan_env.mem_nodes_dynamic = (Node** )NULL;
+  if (IS_NOT_NULL(scan_env->mem_nodes_dynamic)) {
+    xfree(scan_env->mem_nodes_dynamic);
+    scan_env->mem_nodes_dynamic = (Node** )NULL;
   }
 
   r = compile_tree(root, reg);
   if (r == 0) {
     r = add_opcode(reg, OP_END);
 #ifdef USE_SUBEXP_CALL
-    if (scan_env.num_call > 0) {
-      r = unset_addr_list_fix(&uslist, reg);
-      unset_addr_list_end(&uslist);
+    if (scan_env->num_call > 0) {
+      r = unset_addr_list_fix(scan_env->unset_addr_list, reg);
+      unset_addr_list_end(scan_env->unset_addr_list);
       if (r) goto err;
     }
 #endif
@@ -5483,8 +5481,8 @@
     }
   }
 #ifdef USE_SUBEXP_CALL
-  else if (scan_env.num_call > 0) {
-    unset_addr_list_end(&uslist);
+  else if (scan_env->num_call > 0) {
+    unset_addr_list_end(scan_env->unset_addr_list);
   }
 #endif
   onig_node_free(root);
@@ -5502,22 +5500,22 @@
 
  err_unset:
 #ifdef USE_SUBEXP_CALL
-  if (scan_env.num_call > 0) {
-    unset_addr_list_end(&uslist);
+  if (scan_env->num_call > 0) {
+    unset_addr_list_end(scan_env->unset_addr_list);
   }
 #endif
  err:
-  if (IS_NOT_NULL(scan_env.error)) {
+  if (IS_NOT_NULL(scan_env->error)) {
     if (IS_NOT_NULL(einfo)) {
-      einfo->enc     = scan_env.enc;
-      einfo->par     = scan_env.error;
-      einfo->par_end = scan_env.error_end;
+      einfo->enc     = scan_env->enc;
+      einfo->par     = scan_env->error;
+      einfo->par_end = scan_env->error_end;
     }
   }
 
   onig_node_free(root);
-  if (IS_NOT_NULL(scan_env.mem_nodes_dynamic))
-      xfree(scan_env.mem_nodes_dynamic);
+  if (IS_NOT_NULL(scan_env->mem_nodes_dynamic))
+      xfree(scan_env->mem_nodes_dynamic);
   return r;
 }
 

Modified: MacRuby/trunk/regenc.c
===================================================================
--- MacRuby/trunk/regenc.c	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/regenc.c	2009-03-09 00:41:28 UTC (rev 849)
@@ -880,7 +880,7 @@
 
   if (IS_NULL(list)) return ONIGERR_MEMORY;
 
-  *plist = list;
+  GC_WB(plist, list);
   *psize = new_size;
 
   return 0;

Modified: MacRuby/trunk/regexec.c
===================================================================
--- MacRuby/trunk/regexec.c	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/regexec.c	2009-03-09 00:41:28 UTC (rev 849)
@@ -120,7 +120,7 @@
     parent->allocated = n;
   }
 
-  parent->childs[parent->num_childs] = child;
+  GC_WB(&parent->childs[parent->num_childs], child);
   parent->num_childs++;
   return 0;
 }
@@ -2975,7 +2975,7 @@
   int i, len;
 
   if (IS_NULL(*skip)) {
-    *skip = (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE);
+    GC_WB(skip, (int* )xmalloc(sizeof(int) * ONIG_CHAR_TABLE_SIZE));
     if (IS_NULL(*skip)) return ONIGERR_MEMORY;
   }
 

Modified: MacRuby/trunk/regint.h
===================================================================
--- MacRuby/trunk/regint.h	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/regint.h	2009-03-09 00:41:28 UTC (rev 849)
@@ -66,7 +66,7 @@
 /* !!! moved to regenc.h. */ /* #define USE_CRNL_AS_LINE_TERMINATOR */
 
 /* internal config */
-#define USE_PARSE_TREE_NODE_RECYCLE
+//#define USE_PARSE_TREE_NODE_RECYCLE
 #define USE_OP_PUSH_OR_JUMP_EXACT
 #define USE_QTFR_PEEK_NEXT
 #define USE_ST_LIBRARY

Modified: MacRuby/trunk/regparse.c
===================================================================
--- MacRuby/trunk/regparse.c	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/regparse.c	2009-03-09 00:41:28 UTC (rev 849)
@@ -111,7 +111,8 @@
   int r;
   BBuf *to;
 
-  *rto = to = (BBuf* )xmalloc(sizeof(BBuf));
+  to = (BBuf* )xmalloc(sizeof(BBuf));
+  GC_WB(rto, to);
   CHECK_NULL_RETURN_MEMERR(to);
   r = BBUF_INIT(to, from->alloc);
   if (r != 0) return r;
@@ -728,7 +729,7 @@
     e = (NameEntry* )xmalloc(sizeof(NameEntry));
     CHECK_NULL_RETURN_MEMERR(e);
 
-    e->name = strdup_with_null(reg->enc, name, name_end);
+    GC_WB(&e->name, strdup_with_null(reg->enc, name, name_end));
     if (IS_NULL(e->name)) return ONIGERR_MEMORY;
     onig_st_insert_strend(t, e->name, (e->name + (name_end - name)),
                           (HashDataType )e);
@@ -748,7 +749,7 @@
       t->alloc = 0;
       t->num   = 0;
 
-      t->e = (NameEntry* )xmalloc(sizeof(NameEntry) * alloc);
+      GC_WB(&t->e, (NameEntry* )xmalloc(sizeof(NameEntry) * alloc));
       if (IS_NULL(t->e)) {
 	xfree(t);
 	return ONIGERR_MEMORY;
@@ -776,7 +777,7 @@
     }
     e = &(t->e[t->num]);
     t->num++;
-    e->name = strdup_with_null(reg->enc, name, name_end);
+    GC_WB(&e->name, strdup_with_null(reg->enc, name, name_end));
     e->name_len = name_end - name;
 #endif
   }
@@ -795,7 +796,7 @@
   else {
     if (e->back_num == 2) {
       alloc = INIT_NAME_BACKREFS_ALLOC_NUM;
-      e->back_refs = (int* )xmalloc(sizeof(int) * alloc);
+      GC_WB(&e->back_refs, (int* )xmalloc(sizeof(int) * alloc));
       CHECK_NULL_RETURN_MEMERR(e->back_refs);
       e->back_alloc = alloc;
       e->back_refs[0] = e->back_ref1;
@@ -965,7 +966,7 @@
       for (i = env->num_mem + 1; i < alloc; i++)
 	p[i] = NULL_NODE;
 
-      env->mem_nodes_dynamic = p;
+      GC_WB(&env->mem_nodes_dynamic, p);
       env->mem_alloc = alloc;
     }
   }
@@ -1097,7 +1098,7 @@
     }
     FreeNodeList = FreeNodeList->next;
     rb_objc_retain(FreeNodeList);
-    xfree(n);
+//    xfree(n);
   }
   /* THREAD_ATOMIC_END; */
   return 0;
@@ -1113,10 +1114,10 @@
   THREAD_ATOMIC_START;
   if (IS_NOT_NULL(FreeNodeList)) {
     node = (Node* )FreeNodeList;
-    if (FreeNodeList != NULL) {
-	rb_objc_release(FreeNodeList);
+    FreeNodeList = FreeNodeList->next;
+    if (node != NULL) {
+	rb_objc_release(node);
     }
-    FreeNodeList = FreeNodeList->next;
     rb_objc_retain(FreeNodeList);
     THREAD_ATOMIC_END;
     return node;
@@ -1194,7 +1195,7 @@
     bbuf->used  = n + 1;
     bbuf->p     = (UChar* )((void* )ranges);
 
-    cc->mbuf = bbuf;
+    GC_WB(&cc->mbuf, bbuf);
   }
 
   return node;
@@ -1327,7 +1328,7 @@
       onig_node_free(node);
       return NULL;
     }
-    NBREF(node)->back_dynamic = p;
+    GC_WB(&NBREF(node)->back_dynamic, p);
     for (i = 0; i < back_num; i++)
       p[i] = backrefs[i];
   }
@@ -1446,7 +1447,7 @@
 	  p = strcat_capa(NSTR(node)->s, NSTR(node)->end, s, end, capa);
 
 	CHECK_NULL_RETURN_MEMERR(p);
-	NSTR(node)->s    = p;
+	GC_WB(&NSTR(node)->s, p);
 	NSTR(node)->capa = capa;
       }
     }

Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c	2009-03-07 20:15:12 UTC (rev 848)
+++ MacRuby/trunk/string.c	2009-03-09 00:41:28 UTC (rev 849)
@@ -835,8 +835,14 @@
 	    CFStringRef substr = CFStringCreateWithBytes(NULL, 
 		(const UInt8 *)ptr,
 		len, cfstring_encoding, false);
-	    CFStringAppend((CFMutableStringRef)str, substr);
-	    CFRelease(substr);
+	    if (substr == NULL) {
+		data = (CFMutableDataRef)rb_str_cfdata(str);
+		CFDataAppendBytes(data, (void *)ptr, len);
+	    }
+	    else {
+		CFStringAppend((CFMutableStringRef)str, substr);
+		CFRelease(substr);
+	    }
 	}
     }
 }
@@ -3726,9 +3732,17 @@
 	rb_ary_push(result, tmp);
     }
     if (NIL_P(limit) && lim == 0) {
-	while (RARRAY_LEN(result) > 0 &&
-	       RSTRING_LEN(RARRAY_AT(result, RARRAY_LEN(result)-1)) == 0)
-	    rb_ary_pop(result);
+	int count = RARRAY_LEN(result);
+	while (count > 0) {
+	    VALUE s = RARRAY_AT(result, count - 1);
+	    if (s == Qnil || RSTRING_LEN(s) == 0) {
+		rb_ary_pop(result);
+		count--;
+	    }
+	    else {
+		break;
+	    }
+	}
     }
 
     return result;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090308/357922d2/attachment-0001.html>


More information about the macruby-changes mailing list