ruby-changes:57272
From: usa <ko1@a...>
Date: Mon, 26 Aug 2019 23:54:20 +0900 (JST)
Subject: [ruby-changes:57272] usa: 401da79188 (ruby_2_5): merge revision(s) d0ba4abf1a00339ebbb5d405db3240a8bdb7b68b,54eac83b2ad77ddea84fa6d66c09e0bb014cf61e: [Backport #15786]
https://git.ruby-lang.org/ruby.git/commit/?id=401da79188 From 401da7918827a75a737c023ee11631792bc908ca Mon Sep 17 00:00:00 2001 From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Mon, 26 Aug 2019 14:54:04 +0000 Subject: merge revision(s) d0ba4abf1a00339ebbb5d405db3240a8bdb7b68b,54eac83b2ad77ddea84fa6d66c09e0bb014cf61e: [Backport #15786] Add RB_ID_SERIAL_MAX Hide internal IDs * parse.y (internal_id): number the ID serial for internal use by counting down from the neary maximum value, not to accidentally match permanent IDs. [Bug #15768] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e diff --git a/parse.y b/parse.y index 682fc28..62428c9 100644 --- a/parse.y +++ b/parse.y @@ -11583,8 +11583,9 @@ rb_init_parse(void) https://github.com/ruby/ruby/blob/trunk/parse.y#L11583 static ID internal_id_gen(struct parser_params *parser) { + const ID max_id = RB_ID_SERIAL_MAX & ~0xffff; ID id = (ID)vtable_size(lvtbl->args) + (ID)vtable_size(lvtbl->vars); - id += ((tLAST_TOKEN - ID_INTERNAL) >> ID_SCOPE_SHIFT) + 1; + id = max_id - id; return ID_STATIC_SYM | ID_INTERNAL | (id << ID_SCOPE_SHIFT); } diff --git a/symbol.c b/symbol.c index 147c11f..d200e9e 100644 --- a/symbol.c +++ b/symbol.c @@ -18,6 +18,9 @@ https://github.com/ruby/ruby/blob/trunk/symbol.c#L18 #ifndef SYMBOL_DEBUG # define SYMBOL_DEBUG 0 #endif +#ifndef CHECK_ID_SERIAL +# define CHECK_ID_SERIAL SYMBOL_DEBUG +#endif #define SYMBOL_PINNED_P(sym) (RSYMBOL(sym)->id&~ID_SCOPE_MASK) @@ -338,20 +341,41 @@ set_id_entry(rb_id_serial_t num, VALUE str, VALUE sym) https://github.com/ruby/ruby/blob/trunk/symbol.c#L341 } static VALUE -get_id_entry(rb_id_serial_t num, const enum id_entry_type t) +get_id_serial_entry(rb_id_serial_t num, ID id, const enum id_entry_type t) { if (num && num <= global_symbols.last_id) { size_t idx = num / ID_ENTRY_UNIT; VALUE ids = global_symbols.ids; VALUE ary; if (idx < (size_t)RARRAY_LEN(ids) && !NIL_P(ary = rb_ary_entry(ids, (long)idx))) { - VALUE result = rb_ary_entry(ary, (long)(num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE + t); - if (!NIL_P(result)) return result; + long pos = (long)(num % ID_ENTRY_UNIT) * ID_ENTRY_SIZE; + VALUE result = rb_ary_entry(ary, pos + t); + if (NIL_P(result)) return 0; +#if CHECK_ID_SERIAL + if (id) { + VALUE sym = result; + if (t != ID_ENTRY_SYM) + sym = rb_ary_entry(ary, pos + ID_ENTRY_SYM); + if (STATIC_SYM_P(sym)) { + if (STATIC_SYM2ID(sym) != id) return 0; + } + else { + if (RSYMBOL(sym)->id != id) return 0; + } + } +#endif + return result; } } return 0; } +static VALUE +get_id_entry(ID id, const enum id_entry_type t) +{ + return get_id_serial_entry(rb_id_to_serial(id), id, t); +} + static inline ID #ifdef __GNUC__ __attribute__((unused)) @@ -359,7 +383,7 @@ __attribute__((unused)) https://github.com/ruby/ruby/blob/trunk/symbol.c#L383 rb_id_serial_to_id(rb_id_serial_t num) { if (is_notop_id((ID)num)) { - VALUE sym = get_id_entry(num, ID_ENTRY_SYM); + VALUE sym = get_id_serial_entry(num, 0, ID_ENTRY_SYM); return SYM2ID(sym); } else { @@ -547,7 +571,7 @@ lookup_str_sym(const VALUE str) https://github.com/ruby/ruby/blob/trunk/symbol.c#L571 static VALUE lookup_id_str(ID id) { - return get_id_entry(rb_id_to_serial(id), ID_ENTRY_STR); + return get_id_entry(id, ID_ENTRY_STR); } ID @@ -726,7 +750,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/symbol.c#L750 rb_id2sym(ID x) { if (!DYNAMIC_ID_P(x)) return STATIC_ID2SYM(x); - return get_id_entry(rb_id_to_serial(x), ID_ENTRY_SYM); + return get_id_entry(x, ID_ENTRY_SYM); } diff --git a/symbol.h b/symbol.h index 1f0b139..cc7f156 100644 --- a/symbol.h +++ b/symbol.h @@ -53,6 +53,10 @@ id_type(ID id) https://github.com/ruby/ruby/blob/trunk/symbol.h#L53 } typedef uint32_t rb_id_serial_t; +static const uint32_t RB_ID_SERIAL_MAX = /* 256M on LP32 */ + UINT32_MAX >> + ((sizeof(ID)-sizeof(rb_id_serial_t))*CHAR_BIT < RUBY_ID_SCOPE_SHIFT ? + RUBY_ID_SCOPE_SHIFT : 0); static inline rb_id_serial_t rb_id_to_serial(ID id) diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index cb68b2e..77273da 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -599,6 +599,11 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L599 assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:keyrest, :o]], self.class.instance_method(:pmk7).parameters) end + def test_hidden_parameters + instance_eval("def m((_)"+",(_)"*256+");end") + assert_empty(method(:m).parameters.map{|_,n|n}.compact) + end + def test_public_method_with_zsuper_method c = Class.new c.class_eval do diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index e661874..df9bb5f 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -1120,6 +1120,9 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L1120 assert_equal([[:req]], method(:putc).parameters) assert_equal([[:rest]], method(:p).parameters) + + pr = eval("proc{|"+"(_),"*30+"|}") + assert_empty(pr.parameters.map{|_,n|n}.compact) end def pm0() end diff --git a/version.h b/version.h index bd7813a..220de0f 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1 #define RUBY_VERSION "2.5.6" #define RUBY_RELEASE_DATE "2019-08-26" -#define RUBY_PATCHLEVEL 177 +#define RUBY_PATCHLEVEL 178 #define RUBY_RELEASE_YEAR 2019 #define RUBY_RELEASE_MONTH 8 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/