1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/date] Deep-freeze internal constants.

Probably not strictly necessary, but good principle anyways.
This commit is contained in:
Marc-Andre Lafortune 2020-12-19 22:28:20 -05:00 committed by Marc-André Lafortune
parent 7fbad92241
commit ee102de6d7
Notes: git 2020-12-22 17:13:19 +09:00
3 changed files with 27 additions and 23 deletions

View file

@ -53,6 +53,8 @@ static double positive_inf, negative_inf;
#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)
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"),

View file

@ -276,6 +276,7 @@ regcomp(const char *source, long len, int opt)
VALUE pat;
pat = rb_reg_new(source, len, opt);
rb_obj_freeze(pat);
rb_gc_register_mark_object(pat);
return pat;
}

View file

@ -581,6 +581,7 @@ date__strptime_internal(const char *str, size_t slen,
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);
}