Skip to content

Commit 3f7b722

Browse files
authored
Merge pull request #809 from HoneyryderChuck/issue-521-3
ossl config: shareable when frozen
2 parents f8937a6 + 654cb22 commit 3f7b722

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

ext/openssl/ossl_config.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static const rb_data_type_t ossl_config_type = {
2222
{
2323
0, nconf_free,
2424
},
25-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
25+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE,
2626
};
2727

2828
CONF *
@@ -87,6 +87,7 @@ config_s_parse(VALUE klass, VALUE str)
8787

8888
bio = ossl_obj2bio(&str);
8989
config_load_bio(conf, bio); /* Consumes BIO */
90+
rb_obj_freeze(obj);
9091
return obj;
9192
}
9293

@@ -144,6 +145,7 @@ config_initialize(int argc, VALUE *argv, VALUE self)
144145
ossl_raise(eConfigError, "BIO_new_file");
145146
config_load_bio(conf, bio); /* Consumes BIO */
146147
}
148+
rb_obj_freeze(self);
147149
return self;
148150
}
149151

@@ -158,6 +160,7 @@ config_initialize_copy(VALUE self, VALUE other)
158160
rb_check_frozen(self);
159161
bio = ossl_obj2bio(&str);
160162
config_load_bio(conf, bio); /* Consumes BIO */
163+
rb_obj_freeze(self);
161164
return self;
162165
}
163166

@@ -453,6 +456,6 @@ Init_ossl_config(void)
453456
* The default system configuration file for OpenSSL.
454457
*/
455458
path = CONF_get1_default_config_file();
456-
path_str = ossl_buf2str(path, rb_long2int(strlen(path)));
459+
path_str = rb_obj_freeze(ossl_buf2str(path, rb_long2int(strlen(path))));
457460
rb_define_const(cConfig, "DEFAULT_CONFIG_FILE", path_str);
458461
}

test/openssl/test_config.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def test_s_parse
3939
assert_equal("[ default ]\n\n", c.to_s)
4040
c = OpenSSL::Config.parse(@it.to_s)
4141
assert_equal(['CA_default', 'ca', 'default'], c.sections.sort)
42+
assert_predicate(c, :frozen?)
4243
end
4344

4445
def test_s_parse_format
@@ -188,6 +189,7 @@ def test_initialize
188189
c = OpenSSL::Config.new
189190
assert_equal("", c.to_s)
190191
assert_equal([], c.sections)
192+
assert_predicate(c, :frozen?)
191193
end
192194

193195
def test_initialize_with_empty_file
@@ -268,11 +270,22 @@ def test_inspect
268270
def test_dup
269271
assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
270272
c1 = @it.dup
273+
assert_predicate(c1, :frozen?)
271274
assert_equal(@it.sections.sort, c1.sections.sort)
272275
c2 = @it.clone
276+
assert_predicate(c2, :frozen?)
273277
assert_equal(@it.sections.sort, c2.sections.sort)
274278
end
275279

280+
if respond_to?(:ractor)
281+
ractor
282+
def test_ractor
283+
assert(Ractor.shareable?(@it))
284+
assert(Ractor.shareable?(OpenSSL::Config.parse("[empty]\n")))
285+
assert(Ractor.shareable?(OpenSSL::Config::DEFAULT_CONFIG_FILE))
286+
end
287+
end
288+
276289
private
277290

278291
def in_tmpdir(*args)

0 commit comments

Comments
 (0)