mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	support Ruby 2.x for openssl
This commit is contained in:
		
							parent
							
								
									ad76c8fb6b
								
							
						
					
					
						commit
						e76b56f58e
					
				
					 2 changed files with 35 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -497,8 +497,11 @@ print_mem_leaks(VALUE self)
 | 
			
		|||
    int ret;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    BN_CTX_free(ossl_bn_ctx);
 | 
			
		||||
    ossl_bn_ctx = NULL;
 | 
			
		||||
#ifndef HAVE_RB_EXT_RACTOR_SAFE
 | 
			
		||||
    // for Ruby 2.x
 | 
			
		||||
    void ossl_bn_ctx_free(void); // ossl_bn.c
 | 
			
		||||
    ossl_bn_ctx_free();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000
 | 
			
		||||
    ret = CRYPTO_mem_leaks_fp(stderr);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,7 +9,10 @@
 | 
			
		|||
 */
 | 
			
		||||
/* modified by Michal Rokos <m.rokos@sh.cvut.cz> */
 | 
			
		||||
#include "ossl.h"
 | 
			
		||||
 | 
			
		||||
#if HAVE_RB_EXT_RACTOR_SAFE
 | 
			
		||||
#include <ruby/ractor.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define NewBN(klass) \
 | 
			
		||||
  TypedData_Wrap_Struct((klass), &ossl_bn_type, 0)
 | 
			
		||||
| 
						 | 
				
			
			@ -152,6 +155,7 @@ ossl_bn_value_ptr(volatile VALUE *ptr)
 | 
			
		|||
 * Private
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#if HAVE_RB_EXT_RACTOR_SAFE
 | 
			
		||||
void
 | 
			
		||||
ossl_bn_ctx_free(void *ptr)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -180,6 +184,28 @@ ossl_bn_ctx_get(void)
 | 
			
		|||
    }
 | 
			
		||||
    return ctx;
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
// for ruby 2.x
 | 
			
		||||
static BN_CTX *gv_ossl_bn_ctx;
 | 
			
		||||
 | 
			
		||||
BN_CTX *
 | 
			
		||||
ossl_bn_ctx_get(void)
 | 
			
		||||
{
 | 
			
		||||
    if (gv_ossl_bn_ctx == NULL) {
 | 
			
		||||
        if (!(gv_ossl_bn_ctx = BN_CTX_new())) {
 | 
			
		||||
            ossl_raise(rb_eRuntimeError, "Cannot init BN_CTX");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return gv_ossl_bn_ctx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
ossl_bn_ctx_free(void)
 | 
			
		||||
{
 | 
			
		||||
    BN_CTX_free(gv_ossl_bn_ctx);
 | 
			
		||||
    gv_ossl_bn_ctx = NULL;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static VALUE
 | 
			
		||||
ossl_bn_alloc(VALUE klass)
 | 
			
		||||
| 
						 | 
				
			
			@ -1116,7 +1142,11 @@ Init_ossl_bn(void)
 | 
			
		|||
    eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_RB_EXT_RACTOR_SAFE
 | 
			
		||||
    ossl_bn_ctx_key = rb_ractor_local_storage_ptr_newkey(&ossl_bn_ctx_key_type);
 | 
			
		||||
#else
 | 
			
		||||
    ossl_bn_ctx_get();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    eBNError = rb_define_class_under(mOSSL, "BNError", eOSSLError);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue