[macruby-changes] [5255] MacRuby/trunk/array.c

source_changes at macosforge.org source_changes at macosforge.org
Sun Mar 6 00:34:40 PST 2011


Revision: 5255
          http://trac.macosforge.org/projects/ruby/changeset/5255
Author:   watson1978 at gmail.com
Date:     2011-03-06 00:34:38 -0800 (Sun, 06 Mar 2011)
Log Message:
-----------
Array#reverse will not raise a SecurityError when $SAFE is 4.

Test Script:
{{{
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

ary = [ "a", "b", "c" ]
ret = nil
Thread.start {
  $SAFE=4
  ret = ["c", "b", "a"] == ary.reverse

  begin
    ary.reverse!
  rescue SecurityError => err
  else
    raise "error"
  end
}.join

assert_equal(true, ret)
assert_equal(["a", "b", "c"], ary)

puts :ok
}}}

Modified Paths:
--------------
    MacRuby/trunk/array.c

Modified: MacRuby/trunk/array.c
===================================================================
--- MacRuby/trunk/array.c	2011-03-05 14:09:55 UTC (rev 5254)
+++ MacRuby/trunk/array.c	2011-03-06 08:34:38 UTC (rev 5255)
@@ -1319,7 +1319,17 @@
 static VALUE
 rary_reverse(VALUE ary, SEL sel)
 {
-    return rary_reverse_bang(rary_dup(ary, 0), 0);
+    VALUE dup = rary_dup(ary, 0);
+
+    if (RARY(dup)->len > 1) {
+	for (size_t i = 0; i < RARY(dup)->len / 2; i++) {
+	    const size_t j = RARY(dup)->len - i - 1;
+	    VALUE elem = rary_elt(dup, i);
+	    rary_elt_set(dup, i, rary_elt(dup, j));
+	    rary_elt_set(dup, j, elem);
+	}
+    }
+    return dup;
 }
 
 static inline long
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110306/f4738d06/attachment.html>


More information about the macruby-changes mailing list