ruby-changes:73784
From: Nobuyoshi <ko1@a...>
Date: Thu, 29 Sep 2022 14:06:50 +0900 (JST)
Subject: [ruby-changes:73784] 5a8aaedaff (master): [ruby/date] Narrow ALLOCV region for shrunk words
https://git.ruby-lang.org/ruby.git/commit/?id=5a8aaedaff From 5a8aaedaff48fbf715eed67f29282f9464f118f0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 23 Apr 2022 00:24:17 +0900 Subject: [ruby/date] Narrow ALLOCV region for shrunk words https://github.com/ruby/date/commit/f51b038074 --- ext/date/date_parse.c | 26 ++++++++++++++++++-------- test/date/test_date_parse.rb | 2 ++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c index 4890401894..6155293bb9 100644 --- a/ext/date/date_parse.c +++ b/ext/date/date_parse.c @@ -413,7 +413,6 @@ VALUE https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L413 date_zone_to_diff(VALUE str) { VALUE offset = Qnil; - VALUE vbuf = 0; long l = RSTRING_LEN(str); const char *s = RSTRING_PTR(str); @@ -439,16 +438,27 @@ date_zone_to_diff(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L438 l -= w; dst = 1; } + { + const char *zn = s; long sl = shrunk_size(s, l); - if (sl > 0 && sl <= MAX_WORD_LENGTH) { + VALUE vbuf = 0; + const struct zone *z = 0; + + if (sl <= 0) { + sl = l; + } + else if (sl <= MAX_WORD_LENGTH) { char *d = ALLOCV_N(char, vbuf, sl); - l = shrink_space(d, s, l); - s = d; + sl = shrink_space(d, s, l); + zn = d; } - } - if (l > 0 && l <= MAX_WORD_LENGTH) { - const struct zone *z = zonetab(s, (unsigned int)l); + + if (sl > 0 && sl <= MAX_WORD_LENGTH) { + z = zonetab(zn, (unsigned int)sl); + } + ALLOCV_END(vbuf); + if (z) { int d = z->offset; if (dst) @@ -457,6 +467,7 @@ date_zone_to_diff(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L467 goto ok; } } + { char *p; int sign = 0; @@ -542,7 +553,6 @@ date_zone_to_diff(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L553 } RB_GC_GUARD(str); ok: - ALLOCV_END(vbuf); return offset; } diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb index d8dcf6e05e..0b7fc269d0 100644 --- a/test/date/test_date_parse.rb +++ b/test/date/test_date_parse.rb @@ -132,6 +132,7 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L132 [['19990523235521.123[-9]',false],[1999,5,23,23,55,21,'-9',-(9*3600),nil], __LINE__], [['19990523235521.123[+9]',false],[1999,5,23,23,55,21,'+9',+(9*3600),nil], __LINE__], [['19990523235521.123[9]',false],[1999,5,23,23,55,21,'9',+(9*3600),nil], __LINE__], + [['19990523235521.123[9 ]',false],[1999,5,23,23,55,21,'9 ',+(9*3600),nil], __LINE__], [['19990523235521.123[-9.50]',false],[1999,5,23,23,55,21,'-9.50',-(9*3600+30*60),nil], __LINE__], [['19990523235521.123[+9.50]',false],[1999,5,23,23,55,21,'+9.50',+(9*3600+30*60),nil], __LINE__], [['19990523235521.123[-5:EST]',false],[1999,5,23,23,55,21,'EST',-5*3600,nil], __LINE__], @@ -140,6 +141,7 @@ class TestDateParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date_parse.rb#L141 [['235521.123',false],[nil,nil,nil,23,55,21,nil,nil,nil], __LINE__], [['235521.123[-9]',false],[nil,nil,nil,23,55,21,'-9',-9*3600,nil], __LINE__], [['235521.123[+9]',false],[nil,nil,nil,23,55,21,'+9',+9*3600,nil], __LINE__], + [['235521.123[-9 ]',false],[nil,nil,nil,23,55,21,'-9 ',-9*3600,nil], __LINE__], [['235521.123[-5:EST]',false],[nil,nil,nil,23,55,21,'EST',-5*3600,nil], __LINE__], [['235521.123[+9:JST]',false],[nil,nil,nil,23,55,21,'JST',+9*3600,nil], __LINE__], -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/