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

ruby-changes:58082

From: Alan <ko1@a...>
Date: Wed, 2 Oct 2019 16:06:00 +0900 (JST)
Subject: [ruby-changes:58082] 99d3043bd8 (master): Iseq#to_binary: dump flag for **nil (#2508)

https://git.ruby-lang.org/ruby.git/commit/?id=99d3043bd8

From 99d3043bd8e7705cb5ec1772080667981bd07a36 Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Wed, 2 Oct 2019 03:05:40 -0400
Subject: Iseq#to_binary: dump flag for **nil (#2508)

RUBY_ISEQ_DUMP_DEBUG=to_binary and the attached test case was failing.
Dump the flag to make sure `**nil` can round-trip properly.

diff --git a/compile.c b/compile.c
index 5bd2315..78d2fd4 100644
--- a/compile.c
+++ b/compile.c
@@ -9276,7 +9276,7 @@ typedef unsigned int ibf_offset_t; https://github.com/ruby/ruby/blob/trunk/compile.c#L9276
 
 #define IBF_MAJOR_VERSION ISEQ_MAJOR_VERSION
 #if RUBY_DEVEL
-#define IBF_DEVEL_VERSION 1
+#define IBF_DEVEL_VERSION 2
 #define IBF_MINOR_VERSION (ISEQ_MINOR_VERSION * 10000 + IBF_DEVEL_VERSION)
 #else
 #define IBF_MINOR_VERSION ISEQ_MINOR_VERSION
@@ -10129,7 +10129,7 @@ ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L10129
     ibf_offset_t body_offset = ibf_dump_pos(dump);
 
     /* dump the constant body */
-    unsigned char param_flags =
+    unsigned int param_flags =
         (body->param.flags.has_lead         << 0) |
         (body->param.flags.has_opt          << 1) |
         (body->param.flags.has_rest         << 2) |
@@ -10137,7 +10137,8 @@ ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L10137
         (body->param.flags.has_kw           << 4) |
         (body->param.flags.has_kwrest       << 5) |
         (body->param.flags.has_block        << 6) |
-        (body->param.flags.ambiguous_param0 << 7);
+        (body->param.flags.ambiguous_param0 << 7) |
+        (body->param.flags.accepts_no_kwarg << 8);
 
 #if IBF_ISEQ_ENABLE_LOCAL_BUFFER
 #  define IBF_BODY_OFFSET(x) (x)
@@ -10149,7 +10150,7 @@ ibf_dump_iseq_each(struct ibf_dump *dump, const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L10150
     ibf_dump_write_small_value(dump, body->iseq_size);
     ibf_dump_write_small_value(dump, IBF_BODY_OFFSET(bytecode_offset));
     ibf_dump_write_small_value(dump, bytecode_size);
-    ibf_dump_write_byte(dump, param_flags);
+    ibf_dump_write_small_value(dump, param_flags);
     ibf_dump_write_small_value(dump, body->param.size);
     ibf_dump_write_small_value(dump, body->param.lead_num);
     ibf_dump_write_small_value(dump, body->param.opt_num);
@@ -10254,7 +10255,7 @@ ibf_load_iseq_each(struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t offset) https://github.com/ruby/ruby/blob/trunk/compile.c#L10255
     const unsigned int iseq_size = (unsigned int)ibf_load_small_value(load, &reading_pos);
     const ibf_offset_t bytecode_offset = (ibf_offset_t)IBF_BODY_OFFSET(ibf_load_small_value(load, &reading_pos));
     const ibf_offset_t bytecode_size = (ibf_offset_t)ibf_load_small_value(load, &reading_pos);
-    const unsigned char param_flags = (unsigned char)ibf_load_byte(load, &reading_pos);
+    const unsigned int param_flags = (unsigned int)ibf_load_small_value(load, &reading_pos);
     const unsigned int param_size = (unsigned int)ibf_load_small_value(load, &reading_pos);
     const int param_lead_num = (int)ibf_load_small_value(load, &reading_pos);
     const int param_opt_num = (int)ibf_load_small_value(load, &reading_pos);
@@ -10302,6 +10303,7 @@ ibf_load_iseq_each(struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t offset) https://github.com/ruby/ruby/blob/trunk/compile.c#L10303
     load_body->param.flags.has_kwrest = (param_flags >> 5) & 1;
     load_body->param.flags.has_block = (param_flags >> 6) & 1;
     load_body->param.flags.ambiguous_param0 = (param_flags >> 7) & 1;
+    load_body->param.flags.accepts_no_kwarg = (param_flags >> 8) & 1;
     load_body->param.size = param_size;
     load_body->param.lead_num = param_lead_num;
     load_body->param.opt_num = param_opt_num;
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 2aa6966..30c4c28 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -443,6 +443,17 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L443
     end
   end
 
+  def test_to_binary_dumps_nokey
+    iseq = assert_iseq_to_binary(<<-RUBY)
+      o = Object.new
+      class << o
+        def foo(**nil); end
+      end
+      o
+    RUBY
+    assert_equal([[:nokey]], iseq.eval.singleton_method(:foo).parameters)
+  end
+
   def test_to_binary_line_info
     assert_iseq_to_binary("#{<<~"begin;"}\n#{<<~'end;'}", '[Bug #14660]').eval
     begin;
-- 
cgit v0.10.2


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

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