ruby-changes:64454
From: Marc-Andre <ko1@a...>
Date: Tue, 22 Dec 2020 17:13:15 +0900 (JST)
Subject: [ruby-changes:64454] ee102de6d7 (master): [ruby/date] Deep-freeze internal constants.
https://git.ruby-lang.org/ruby.git/commit/?id=ee102de6d7 From ee102de6d7ec2454dc5da223483737478eb7bcc7 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune <github@m...> Date: Sat, 19 Dec 2020 22:28:20 -0500 Subject: [ruby/date] Deep-freeze internal constants. Probably not strictly necessary, but good principle anyways. diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 28d032e..c6bceb1 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -53,6 +53,8 @@ static double positive_inf, negative_inf; https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L53 #define f_add3(x,y,z) f_add(f_add(x, y), z) #define f_sub3(x,y,z) f_sub(f_sub(x, y), z) +#define f_frozen_ary(...) rb_obj_freeze(rb_ary_new3(__VA_ARGS__)) + static VALUE date_initialize(int argc, VALUE *argv, VALUE self); static VALUE datetime_initialize(int argc, VALUE *argv, VALUE self); @@ -3767,89 +3769,89 @@ rt_complete_frags(VALUE klass, VALUE hash) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L3769 VALUE k, a, d; if (NIL_P(tab)) { - tab = rb_ary_new3(11, - rb_ary_new3(2, + tab = f_frozen_ary(11, + f_frozen_ary(2, sym("time"), - rb_ary_new3(3, + f_frozen_ary(3, sym("hour"), sym("min"), sym("sec"))), - rb_ary_new3(2, + f_frozen_ary(2, Qnil, - rb_ary_new3(1, + f_frozen_ary(1, sym("jd"))), - rb_ary_new3(2, + f_frozen_ary(2, sym("ordinal"), - rb_ary_new3(5, + f_frozen_ary(5, sym("year"), sym("yday"), sym("hour"), sym("min"), sym("sec"))), - rb_ary_new3(2, + f_frozen_ary(2, sym("civil"), - rb_ary_new3(6, + f_frozen_ary(6, sym("year"), sym("mon"), sym("mday"), sym("hour"), sym("min"), sym("sec"))), - rb_ary_new3(2, + f_frozen_ary(2, sym("commercial"), - rb_ary_new3(6, + f_frozen_ary(6, sym("cwyear"), sym("cweek"), sym("cwday"), sym("hour"), sym("min"), sym("sec"))), - rb_ary_new3(2, + f_frozen_ary(2, sym("wday"), - rb_ary_new3(4, + f_frozen_ary(4, sym("wday"), sym("hour"), sym("min"), sym("sec"))), - rb_ary_new3(2, + f_frozen_ary(2, sym("wnum0"), - rb_ary_new3(6, + f_frozen_ary(6, sym("year"), sym("wnum0"), sym("wday"), sym("hour"), sym("min"), sym("sec"))), - rb_ary_new3(2, + f_frozen_ary(2, sym("wnum1"), - rb_ary_new3(6, + f_frozen_ary(6, sym("year"), sym("wnum1"), sym("wday"), sym("hour"), sym("min"), sym("sec"))), - rb_ary_new3(2, + f_frozen_ary(2, Qnil, - rb_ary_new3(6, + f_frozen_ary(6, sym("cwyear"), sym("cweek"), sym("wday"), sym("hour"), sym("min"), sym("sec"))), - rb_ary_new3(2, + f_frozen_ary(2, Qnil, - rb_ary_new3(6, + f_frozen_ary(6, sym("year"), sym("wnum0"), sym("cwday"), sym("hour"), sym("min"), sym("sec"))), - rb_ary_new3(2, + f_frozen_ary(2, Qnil, - rb_ary_new3(6, + f_frozen_ary(6, sym("year"), sym("wnum1"), sym("cwday"), diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c index 0378e50..5fa036e 100644 --- a/ext/date/date_parse.c +++ b/ext/date/date_parse.c @@ -276,6 +276,7 @@ regcomp(const char *source, long len, int opt) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L276 VALUE pat; pat = rb_reg_new(source, len, opt); + rb_obj_freeze(pat); rb_gc_register_mark_object(pat); return pat; } diff --git a/ext/date/date_strptime.c b/ext/date/date_strptime.c index 26d9fd1..7b06a31 100644 --- a/ext/date/date_strptime.c +++ b/ext/date/date_strptime.c @@ -581,6 +581,7 @@ date__strptime_internal(const char *str, size_t slen, https://github.com/ruby/ruby/blob/trunk/ext/date/date_strptime.c#L581 if (NIL_P(pat)) { pat = rb_reg_new(pat_source, sizeof pat_source - 1, ONIG_OPTION_IGNORECASE); + rb_obj_freeze(pat); rb_gc_register_mark_object(pat); } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/