summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2021-12-17 14:22:14 +0900
committerKoichi Sasada <ko1@atdot.net>2021-12-17 15:46:50 +0900
commit37bd795cf8bc9681fccaf9b2d42292b14610a310 (patch)
tree9fcf88eb81175594565290442d6292b4ad0cb527 /hash.c
parentd524b9dec9859ce307f6f913be46144557e8edbd (diff)
downloadruby-37bd795cf8bc9681fccaf9b2d42292b14610a310.tar.gz
`ENV` ivars should not be accessible from ractors
The `ENV` object can have instance variables like other objects, but they should be accessed only on the main ractor. fix https://github.com/ruby/ruby/pull/5263#issuecomment-995585766
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index deb5e77872..da9af425c1 100644
--- a/hash.c
+++ b/hash.c
@@ -6653,6 +6653,17 @@ env_dup(VALUE obj)
rb_raise(rb_eTypeError, "Cannot dup ENV, use ENV.to_h to get a copy of ENV as a hash");
}
+const rb_data_type_t env_data_type = {
+ "ENV",
+ {
+ NULL,
+ RUBY_DEFAULT_FREE,
+ NULL,
+ NULL,
+ },
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
+};
+
/*
* A \Hash maps each of its unique keys to a specific value.
*
@@ -7308,7 +7319,7 @@ Init_Hash(void)
* envtbl = rb_define_class("ENV", rb_cObject);
*/
origenviron = environ;
- envtbl = rb_obj_alloc(rb_cObject);
+ envtbl = TypedData_Wrap_Struct(rb_cObject, &env_data_type, NULL);
rb_extend_object(envtbl, rb_mEnumerable);
FL_SET_RAW(envtbl, RUBY_FL_SHAREABLE);