[前][次][番号順一覧][スレッド一覧]

ruby-changes:60396

From: Nobuyoshi <ko1@a...>
Date: Sat, 14 Mar 2020 20:28:05 +0900 (JST)
Subject: [ruby-changes:60396] 3e7e1b965b (ruby_2_7): Pass keyword arguments to IOs properly [Bug #16639]

https://git.ruby-lang.org/ruby.git/commit/?id=3e7e1b965b

From 3e7e1b965b06f3c843972d7e2f6e3d040374d67f Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 18 Feb 2020 14:34:26 +0900
Subject: Pass keyword arguments to IOs properly [Bug #16639]

(cherry picked from commit 041c2932e336b509b0ddc1fdbd9f160bce8d4893)

diff --git a/io.c b/io.c
index 42528c0..868756f 100644
--- a/io.c
+++ b/io.c
@@ -12399,10 +12399,14 @@ argf_block_call_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, argf)) https://github.com/ruby/ruby/blob/trunk/io.c#L12399
     return Qnil;
 }
 
+#define ARGF_block_call(mid, argc, argv, func, argf) \
+    rb_block_call_kw(ARGF.current_file, mid, argc, argv, \
+                     func, argf, rb_keyword_given_p())
+
 static void
 argf_block_call(ID mid, int argc, VALUE *argv, VALUE argf)
 {
-    VALUE ret = rb_block_call(ARGF.current_file, mid, argc, argv, argf_block_call_i, argf);
+    VALUE ret = ARGF_block_call(mid, argc, argv, argf_block_call_i, argf);
     if (ret != Qundef) ARGF.next_p = 1;
 }
 
@@ -12418,7 +12422,7 @@ argf_block_call_line_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, argf)) https://github.com/ruby/ruby/blob/trunk/io.c#L12422
 static void
 argf_block_call_line(ID mid, int argc, VALUE *argv, VALUE argf)
 {
-    VALUE ret = rb_block_call(ARGF.current_file, mid, argc, argv, argf_block_call_line_i, argf);
+    VALUE ret = ARGF_block_call(mid, argc, argv, argf_block_call_line_i, argf);
     if (ret != Qundef) ARGF.next_p = 1;
 }
 
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index a76bdcc..277fa36 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -725,6 +725,13 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L725
                       ["\"a\\n\\n\"", "\"b\\n\""], [])
   end
 
+  def test_each_line_chomp
+    assert_in_out_err(['-e', 'ARGF.each_line(chomp: false) {|para| p para}'], "a\nb\n",
+                      ["\"a\\n\"", "\"b\\n\""], [])
+    assert_in_out_err(['-e', 'ARGF.each_line(chomp: true) {|para| p para}'], "a\nb\n",
+                      ["\"a\"", "\"b\""], [])
+  end
+
   def test_each_byte
     ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
       {#
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]