Skip to content

Commit fd3b246

Browse files
ossl config: shareable when frozen
should proobably be initialized as frozen, given no state modifications
1 parent bd647c3 commit fd3b246

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

ext/openssl/ossl_config.c

Lines changed: 3 additions & 3 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 *
@@ -47,6 +47,7 @@ config_s_alloc(VALUE klass)
4747
if (!conf)
4848
ossl_raise(eConfigError, "NCONF_new");
4949
RTYPEDDATA_DATA(obj) = conf;
50+
rb_obj_freeze(obj);
5051
return obj;
5152
}
5253

@@ -137,7 +138,6 @@ config_initialize(int argc, VALUE *argv, VALUE self)
137138

138139
/* 0-arguments call has no use-case, but is kept for compatibility */
139140
rb_scan_args(argc, argv, "01", &filename);
140-
rb_check_frozen(self);
141141
if (!NIL_P(filename)) {
142142
BIO *bio = BIO_new_file(StringValueCStr(filename), "rb");
143143
if (!bio)
@@ -453,6 +453,6 @@ Init_ossl_config(void)
453453
* The default system configuration file for OpenSSL.
454454
*/
455455
path = CONF_get1_default_config_file();
456-
path_str = ossl_buf2str(path, rb_long2int(strlen(path)));
456+
path_str = rb_obj_freeze(ossl_buf2str(path, rb_long2int(strlen(path))));
457457
rb_define_const(cConfig, "DEFAULT_CONFIG_FILE", path_str);
458458
}

test/openssl/test_config.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ def test_dup
273273
assert_equal(@it.sections.sort, c2.sections.sort)
274274
end
275275

276+
if respond_to?(:ractor)
277+
ractor
278+
def test_ractor
279+
assert Ractor.shareable?(OpenSSL::Config.parse("[empty]\n"))
280+
assert Ractor.shareable?(OpenSSL::Config::DEFAULT_CONFIG_FILE)
281+
end
282+
end
283+
276284
private
277285

278286
def in_tmpdir(*args)

0 commit comments

Comments
 (0)