[macruby-changes] [2160] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 3 10:45:29 PDT 2009


Revision: 2160
          http://trac.macosforge.org/projects/ruby/changeset/2160
Author:   pthomson at apple.com
Date:     2009-08-03 10:45:29 -0700 (Mon, 03 Aug 2009)
Log Message:
-----------
Removed the negative-index feature of Readline::HISTORY.

Modified Paths:
--------------
    MacRuby/branches/experimental/ext/readline/readline.c
    MacRuby/branches/experimental/spec/frozen/library/readline/history/element_reference_spec.rb

Modified: MacRuby/branches/experimental/ext/readline/readline.c
===================================================================
--- MacRuby/branches/experimental/ext/readline/readline.c	2009-08-03 17:34:25 UTC (rev 2159)
+++ MacRuby/branches/experimental/ext/readline/readline.c	2009-08-03 17:45:29 UTC (rev 2160)
@@ -81,6 +81,17 @@
 }
 #endif
 
+static HIST_ENTRY*
+readline_history_get(int idx)
+{
+	int readline_idx = history_base + idx - 1;
+	if (readline_idx < 0)
+	{
+		rb_raise(rb_eIndexError, "invalid index");
+	}
+	return history_get(readline_idx);
+}
+
 static VALUE
 readline_readline(VALUE self, SEL sel, int argc, VALUE *argv)
 {
@@ -532,7 +543,7 @@
     if (i < 0) {
         i += history_length;
     }
-    entry = history_get(history_base + i - 1);
+    entry = readline_history_get(i);
     if (entry == NULL) {
 	rb_raise(rb_eIndexError, "invalid index");
     }
@@ -640,7 +651,7 @@
 
     rb_secure(4);
     for (i = 0; i < history_length; i++) {
-        entry = history_get(history_base + i - 1);
+        entry = readline_history_get(i);
         if (entry == NULL)
             break;
 	rb_yield(rb_tainted_str_new2(entry->line));

Modified: MacRuby/branches/experimental/spec/frozen/library/readline/history/element_reference_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/readline/history/element_reference_spec.rb	2009-08-03 17:34:25 UTC (rev 2159)
+++ MacRuby/branches/experimental/spec/frozen/library/readline/history/element_reference_spec.rb	2009-08-03 17:45:29 UTC (rev 2160)
@@ -31,14 +31,9 @@
       end
 
       it "raises an IndexError when there is no item at the passed index" do
-        # When asking for negative indices from readline's history on
-        # libedit (which MacRuby uses), readline behaves more like a Ruby array
-        # and returns indices counting from the end.
-        not_compliant_on :macruby do
-          lambda { Readline::HISTORY[-10] }.should raise_error(IndexError)
-          lambda { Readline::HISTORY[-9] }.should raise_error(IndexError)
-          lambda { Readline::HISTORY[-8] }.should raise_error(IndexError)
-        end
+        lambda { Readline::HISTORY[-10] }.should raise_error(IndexError)
+        lambda { Readline::HISTORY[-9] }.should raise_error(IndexError)
+        lambda { Readline::HISTORY[-8] }.should raise_error(IndexError)
 
         lambda { Readline::HISTORY[8] }.should raise_error(IndexError)
         lambda { Readline::HISTORY[9] }.should raise_error(IndexError)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090803/552350bd/attachment.html>


More information about the macruby-changes mailing list