Skip to content

Commit cc4fd69

Browse files
make bn shareable when frozen
1 parent 8367b16 commit cc4fd69

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

ext/openssl/ossl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
#include <errno.h>
1818
#include <ruby/io.h>
1919
#include <ruby/thread.h>
20+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
21+
#include <ruby/ractor.h>
22+
#else
23+
#define RUBY_TYPED_FROZEN_SHAREABLE 0
24+
#endif
25+
2026
#include <openssl/opensslv.h>
2127

2228
#include <openssl/err.h>

ext/openssl/ossl_bn.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
/* modified by Michal Rokos <[email protected]> */
1111
#include "ossl.h"
1212

13-
#ifdef HAVE_RB_EXT_RACTOR_SAFE
14-
#include <ruby/ractor.h>
15-
#endif
16-
1713
#define NewBN(klass) \
1814
TypedData_Wrap_Struct((klass), &ossl_bn_type, 0)
1915
#define SetBN(obj, bn) do { \
@@ -41,7 +37,7 @@ static const rb_data_type_t ossl_bn_type = {
4137
{
4238
0, ossl_bn_free,
4339
},
44-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
40+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE,
4541
};
4642

4743
/*
@@ -693,6 +689,7 @@ BIGNUM_3c(mod_exp)
693689
ossl_bn_##func(VALUE self, VALUE bit) \
694690
{ \
695691
BIGNUM *bn; \
692+
rb_check_frozen(self); \
696693
GetBN(self, bn); \
697694
if (BN_##func(bn, NUM2INT(bit)) <= 0) { \
698695
ossl_raise(eBNError, NULL); \
@@ -748,6 +745,7 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
748745
BIGNUM *bn, *result; \
749746
int b; \
750747
VALUE obj; \
748+
rb_check_frozen(self); \
751749
b = NUM2INT(bits); \
752750
GetBN(self, bn); \
753751
obj = NewBN(rb_obj_class(self)); \
@@ -782,6 +780,7 @@ BIGNUM_SHIFT(rshift)
782780
{ \
783781
BIGNUM *bn; \
784782
int b; \
783+
rb_check_frozen(self); \
785784
b = NUM2INT(bits); \
786785
GetBN(self, bn); \
787786
if (BN_##func(bn, bn, b) <= 0) \
@@ -1191,6 +1190,7 @@ ossl_bn_set_flags(VALUE self, VALUE arg)
11911190
BIGNUM *bn;
11921191
GetBN(self, bn);
11931192

1193+
rb_check_frozen(self);
11941194
BN_set_flags(bn, NUM2INT(arg));
11951195
return Qnil;
11961196
}

0 commit comments

Comments
 (0)