Skip to content

Commit 695126f

Browse files
committed
Freeze more constants for Ractor compatibility
1 parent 42effce commit 695126f

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

ext/openssl/ossl.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,12 +1010,17 @@ Init_openssl(void)
10101010
/*
10111011
* Version of OpenSSL the ruby OpenSSL extension was built with
10121012
*/
1013-
rb_define_const(mOSSL, "OPENSSL_VERSION", rb_str_new2(OPENSSL_VERSION_TEXT));
1013+
rb_define_const(mOSSL, "OPENSSL_VERSION",
1014+
rb_obj_freeze(rb_str_new_cstr(OPENSSL_VERSION_TEXT)));
10141015

10151016
/*
10161017
* Version of OpenSSL the ruby OpenSSL extension is running with
10171018
*/
1018-
rb_define_const(mOSSL, "OPENSSL_LIBRARY_VERSION", rb_str_new2(OpenSSL_version(OPENSSL_VERSION)));
1019+
rb_define_const(
1020+
mOSSL,
1021+
"OPENSSL_LIBRARY_VERSION",
1022+
rb_obj_freeze(rb_str_new_cstr(OpenSSL_version(OPENSSL_VERSION)))
1023+
);
10191024

10201025
/*
10211026
* Version number of OpenSSL the ruby OpenSSL extension was built with

ext/openssl/ossl_asn1.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,6 @@ void
13971397
Init_ossl_asn1(void)
13981398
{
13991399
#undef rb_intern
1400-
VALUE ary;
1401-
int i;
14021400

14031401
sym_UNIVERSAL = ID2SYM(rb_intern_const("UNIVERSAL"));
14041402
sym_CONTEXT_SPECIFIC = ID2SYM(rb_intern_const("CONTEXT_SPECIFIC"));
@@ -1548,17 +1546,20 @@ Init_ossl_asn1(void)
15481546
rb_define_module_function(mASN1, "traverse", ossl_asn1_traverse, 1);
15491547
rb_define_module_function(mASN1, "decode", ossl_asn1_decode, 1);
15501548
rb_define_module_function(mASN1, "decode_all", ossl_asn1_decode_all, 1);
1551-
ary = rb_ary_new();
15521549

1550+
VALUE ary = rb_ary_new_capa(ossl_asn1_info_size);
1551+
for (int i = 0; i < ossl_asn1_info_size; i++) {
1552+
const char *name = ossl_asn1_info[i].name;
1553+
if (name[0] == '[')
1554+
continue;
1555+
rb_define_const(mASN1, name, INT2NUM(i));
1556+
rb_ary_store(ary, i, rb_obj_freeze(rb_str_new_cstr(name)));
1557+
}
1558+
rb_obj_freeze(ary);
15531559
/*
15541560
* Array storing tag names at the tag's index.
15551561
*/
15561562
rb_define_const(mASN1, "UNIVERSAL_TAG_NAME", ary);
1557-
for(i = 0; i < ossl_asn1_info_size; i++){
1558-
if(ossl_asn1_info[i].name[0] == '[') continue;
1559-
rb_define_const(mASN1, ossl_asn1_info[i].name, INT2NUM(i));
1560-
rb_ary_store(ary, i, rb_str_new2(ossl_asn1_info[i].name));
1561-
}
15621563

15631564
/* Document-class: OpenSSL::ASN1::ASN1Data
15641565
*
@@ -1880,6 +1881,7 @@ do{\
18801881
rb_hash_aset(class_tag_map, cASN1GeneralString, INT2NUM(V_ASN1_GENERALSTRING));
18811882
rb_hash_aset(class_tag_map, cASN1UniversalString, INT2NUM(V_ASN1_UNIVERSALSTRING));
18821883
rb_hash_aset(class_tag_map, cASN1BMPString, INT2NUM(V_ASN1_BMPSTRING));
1884+
rb_obj_freeze(class_tag_map);
18831885

18841886
id_each = rb_intern_const("each");
18851887
}

ext/openssl/ossl_x509.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ VALUE mX509;
1313

1414
#define DefX509Const(x) rb_define_const(mX509, #x, INT2NUM(X509_##x))
1515
#define DefX509Default(x,i) \
16-
rb_define_const(mX509, "DEFAULT_" #x, rb_str_new2(X509_get_default_##i()))
16+
rb_define_const(mX509, "DEFAULT_" #x, \
17+
rb_obj_freeze(rb_str_new_cstr(X509_get_default_##i())))
1718

1819
ASN1_TIME *
1920
ossl_x509_time_adjust(ASN1_TIME *s, VALUE time)

ext/openssl/ossl_x509name.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ Init_ossl_x509name(void)
534534
rb_hash_aset(hash, rb_str_new2("DC"), ia5str);
535535
rb_hash_aset(hash, rb_str_new2("domainComponent"), ia5str);
536536
rb_hash_aset(hash, rb_str_new2("emailAddress"), ia5str);
537+
rb_obj_freeze(hash);
537538

538539
/*
539540
* The default object type template for name entries.

0 commit comments

Comments
 (0)