Skip to content

Commit 74d0cde

Browse files
MSNexploderrhenium
authored andcommitted
Don't redefine #rb_intern over and over again
[ This is a backport to the 2.2 branch. ] (cherry picked from commit 0330483)
1 parent 5443723 commit 74d0cde

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,8 +2503,6 @@ ossl_ssl_tmp_key(VALUE self)
25032503
# endif /* defined(HAVE_SSL_GET_SERVER_TMP_KEY) */
25042504
#endif /* !defined(OPENSSL_NO_SOCK) */
25052505

2506-
#undef rb_intern
2507-
#define rb_intern(s) rb_intern_const(s)
25082506
void
25092507
Init_ossl_ssl(void)
25102508
{
@@ -2515,8 +2513,8 @@ Init_ossl_ssl(void)
25152513
rb_mWaitWritable = rb_define_module_under(rb_cIO, "WaitWritable");
25162514
#endif
25172515

2518-
id_call = rb_intern("call");
2519-
ID_callback_state = rb_intern("callback_state");
2516+
id_call = rb_intern_const("call");
2517+
ID_callback_state = rb_intern_const("callback_state");
25202518

25212519
ossl_ssl_ex_vcb_idx = SSL_get_ex_new_index(0, (void *)"ossl_ssl_ex_vcb_idx", 0, 0, 0);
25222520
if (ossl_ssl_ex_vcb_idx < 0)
@@ -2583,37 +2581,37 @@ Init_ossl_ssl(void)
25832581
* The _cert_, _key_, and _extra_chain_cert_ attributes are deprecated.
25842582
* It is recommended to use #add_certificate instead.
25852583
*/
2586-
rb_attr(cSSLContext, rb_intern("cert"), 1, 1, Qfalse);
2584+
rb_attr(cSSLContext, rb_intern_const("cert"), 1, 1, Qfalse);
25872585

25882586
/*
25892587
* Context private key
25902588
*
25912589
* The _cert_, _key_, and _extra_chain_cert_ attributes are deprecated.
25922590
* It is recommended to use #add_certificate instead.
25932591
*/
2594-
rb_attr(cSSLContext, rb_intern("key"), 1, 1, Qfalse);
2592+
rb_attr(cSSLContext, rb_intern_const("key"), 1, 1, Qfalse);
25952593

25962594
/*
25972595
* A certificate or Array of certificates that will be sent to the client.
25982596
*/
2599-
rb_attr(cSSLContext, rb_intern("client_ca"), 1, 1, Qfalse);
2597+
rb_attr(cSSLContext, rb_intern_const("client_ca"), 1, 1, Qfalse);
26002598

26012599
/*
26022600
* The path to a file containing a PEM-format CA certificate
26032601
*/
2604-
rb_attr(cSSLContext, rb_intern("ca_file"), 1, 1, Qfalse);
2602+
rb_attr(cSSLContext, rb_intern_const("ca_file"), 1, 1, Qfalse);
26052603

26062604
/*
26072605
* The path to a directory containing CA certificates in PEM format.
26082606
*
26092607
* Files are looked up by subject's X509 name's hash value.
26102608
*/
2611-
rb_attr(cSSLContext, rb_intern("ca_path"), 1, 1, Qfalse);
2609+
rb_attr(cSSLContext, rb_intern_const("ca_path"), 1, 1, Qfalse);
26122610

26132611
/*
26142612
* Maximum session lifetime in seconds.
26152613
*/
2616-
rb_attr(cSSLContext, rb_intern("timeout"), 1, 1, Qfalse);
2614+
rb_attr(cSSLContext, rb_intern_const("timeout"), 1, 1, Qfalse);
26172615

26182616
/*
26192617
* Session verification mode.
@@ -2626,12 +2624,12 @@ Init_ossl_ssl(void)
26262624
*
26272625
* See SSL_CTX_set_verify(3) for details.
26282626
*/
2629-
rb_attr(cSSLContext, rb_intern("verify_mode"), 1, 1, Qfalse);
2627+
rb_attr(cSSLContext, rb_intern_const("verify_mode"), 1, 1, Qfalse);
26302628

26312629
/*
26322630
* Number of CA certificates to walk when verifying a certificate chain.
26332631
*/
2634-
rb_attr(cSSLContext, rb_intern("verify_depth"), 1, 1, Qfalse);
2632+
rb_attr(cSSLContext, rb_intern_const("verify_depth"), 1, 1, Qfalse);
26352633

26362634
/*
26372635
* A callback for additional certificate verification. The callback is
@@ -2645,20 +2643,20 @@ Init_ossl_ssl(void)
26452643
* If the callback returns +false+, the chain verification is immediately
26462644
* stopped and a bad_certificate alert is then sent.
26472645
*/
2648-
rb_attr(cSSLContext, rb_intern("verify_callback"), 1, 1, Qfalse);
2646+
rb_attr(cSSLContext, rb_intern_const("verify_callback"), 1, 1, Qfalse);
26492647

26502648
/*
26512649
* Whether to check the server certificate is valid for the hostname.
26522650
*
26532651
* In order to make this work, verify_mode must be set to VERIFY_PEER and
26542652
* the server hostname must be given by OpenSSL::SSL::SSLSocket#hostname=.
26552653
*/
2656-
rb_attr(cSSLContext, rb_intern("verify_hostname"), 1, 1, Qfalse);
2654+
rb_attr(cSSLContext, rb_intern_const("verify_hostname"), 1, 1, Qfalse);
26572655

26582656
/*
26592657
* An OpenSSL::X509::Store used for certificate verification.
26602658
*/
2661-
rb_attr(cSSLContext, rb_intern("cert_store"), 1, 1, Qfalse);
2659+
rb_attr(cSSLContext, rb_intern_const("cert_store"), 1, 1, Qfalse);
26622660

26632661
/*
26642662
* An Array of extra X509 certificates to be added to the certificate
@@ -2667,7 +2665,7 @@ Init_ossl_ssl(void)
26672665
* The _cert_, _key_, and _extra_chain_cert_ attributes are deprecated.
26682666
* It is recommended to use #add_certificate instead.
26692667
*/
2670-
rb_attr(cSSLContext, rb_intern("extra_chain_cert"), 1, 1, Qfalse);
2668+
rb_attr(cSSLContext, rb_intern_const("extra_chain_cert"), 1, 1, Qfalse);
26712669

26722670
/*
26732671
* A callback invoked when a client certificate is requested by a server
@@ -2677,7 +2675,7 @@ Init_ossl_ssl(void)
26772675
* containing an OpenSSL::X509::Certificate and an OpenSSL::PKey. If any
26782676
* other value is returned the handshake is suspended.
26792677
*/
2680-
rb_attr(cSSLContext, rb_intern("client_cert_cb"), 1, 1, Qfalse);
2678+
rb_attr(cSSLContext, rb_intern_const("client_cert_cb"), 1, 1, Qfalse);
26812679

26822680
#if !defined(OPENSSL_NO_EC) && defined(HAVE_SSL_CTX_SET_TMP_ECDH_CALLBACK)
26832681
/*
@@ -2690,15 +2688,15 @@ Init_ossl_ssl(void)
26902688
* The callback is deprecated. This does not work with recent versions of
26912689
* OpenSSL. Use OpenSSL::SSL::SSLContext#ecdh_curves= instead.
26922690
*/
2693-
rb_attr(cSSLContext, rb_intern("tmp_ecdh_callback"), 1, 1, Qfalse);
2691+
rb_attr(cSSLContext, rb_intern_const("tmp_ecdh_callback"), 1, 1, Qfalse);
26942692
#endif
26952693

26962694
/*
26972695
* Sets the context in which a session can be reused. This allows
26982696
* sessions for multiple applications to be distinguished, for example, by
26992697
* name.
27002698
*/
2701-
rb_attr(cSSLContext, rb_intern("session_id_context"), 1, 1, Qfalse);
2699+
rb_attr(cSSLContext, rb_intern_const("session_id_context"), 1, 1, Qfalse);
27022700

27032701
/*
27042702
* A callback invoked on a server when a session is proposed by the client
@@ -2707,15 +2705,15 @@ Init_ossl_ssl(void)
27072705
* The callback is invoked with the SSLSocket and session id. The
27082706
* callback may return a Session from an external cache.
27092707
*/
2710-
rb_attr(cSSLContext, rb_intern("session_get_cb"), 1, 1, Qfalse);
2708+
rb_attr(cSSLContext, rb_intern_const("session_get_cb"), 1, 1, Qfalse);
27112709

27122710
/*
27132711
* A callback invoked when a new session was negotiated.
27142712
*
27152713
* The callback is invoked with an SSLSocket. If +false+ is returned the
27162714
* session will be removed from the internal cache.
27172715
*/
2718-
rb_attr(cSSLContext, rb_intern("session_new_cb"), 1, 1, Qfalse);
2716+
rb_attr(cSSLContext, rb_intern_const("session_new_cb"), 1, 1, Qfalse);
27192717

27202718
/*
27212719
* A callback invoked when a session is removed from the internal cache.
@@ -2726,7 +2724,7 @@ Init_ossl_ssl(void)
27262724
* multi-threaded application. The callback is called inside a global lock
27272725
* and it can randomly cause deadlock on Ruby thread switching.
27282726
*/
2729-
rb_attr(cSSLContext, rb_intern("session_remove_cb"), 1, 1, Qfalse);
2727+
rb_attr(cSSLContext, rb_intern_const("session_remove_cb"), 1, 1, Qfalse);
27302728

27312729
rb_define_const(mSSLExtConfig, "HAVE_TLSEXT_HOST_NAME", Qtrue);
27322730

@@ -2749,7 +2747,7 @@ Init_ossl_ssl(void)
27492747
* raise RuntimeError, "Client renegotiation disabled"
27502748
* end
27512749
*/
2752-
rb_attr(cSSLContext, rb_intern("renegotiation_cb"), 1, 1, Qfalse);
2750+
rb_attr(cSSLContext, rb_intern_const("renegotiation_cb"), 1, 1, Qfalse);
27532751
#ifndef OPENSSL_NO_NEXTPROTONEG
27542752
/*
27552753
* An Enumerable of Strings. Each String represents a protocol to be
@@ -2762,7 +2760,7 @@ Init_ossl_ssl(void)
27622760
*
27632761
* ctx.npn_protocols = ["http/1.1", "spdy/2"]
27642762
*/
2765-
rb_attr(cSSLContext, rb_intern("npn_protocols"), 1, 1, Qfalse);
2763+
rb_attr(cSSLContext, rb_intern_const("npn_protocols"), 1, 1, Qfalse);
27662764
/*
27672765
* A callback invoked on the client side when the client needs to select
27682766
* a protocol from the list sent by the server. Supported in OpenSSL 1.0.1
@@ -2779,7 +2777,7 @@ Init_ossl_ssl(void)
27792777
* protocols.first
27802778
* end
27812779
*/
2782-
rb_attr(cSSLContext, rb_intern("npn_select_cb"), 1, 1, Qfalse);
2780+
rb_attr(cSSLContext, rb_intern_const("npn_select_cb"), 1, 1, Qfalse);
27832781
#endif
27842782

27852783
#ifdef HAVE_SSL_CTX_SET_ALPN_SELECT_CB
@@ -2794,7 +2792,7 @@ Init_ossl_ssl(void)
27942792
*
27952793
* ctx.alpn_protocols = ["http/1.1", "spdy/2", "h2"]
27962794
*/
2797-
rb_attr(cSSLContext, rb_intern("alpn_protocols"), 1, 1, Qfalse);
2795+
rb_attr(cSSLContext, rb_intern_const("alpn_protocols"), 1, 1, Qfalse);
27982796
/*
27992797
* A callback invoked on the server side when the server needs to select
28002798
* a protocol from the list sent by the client. Supported in OpenSSL 1.0.2
@@ -2811,7 +2809,7 @@ Init_ossl_ssl(void)
28112809
* protocols.first
28122810
* end
28132811
*/
2814-
rb_attr(cSSLContext, rb_intern("alpn_select_cb"), 1, 1, Qfalse);
2812+
rb_attr(cSSLContext, rb_intern_const("alpn_select_cb"), 1, 1, Qfalse);
28152813
#endif
28162814

28172815
rb_define_alias(cSSLContext, "ssl_timeout", "timeout");
@@ -3039,17 +3037,17 @@ Init_ossl_ssl(void)
30393037
#endif
30403038

30413039

3042-
sym_exception = ID2SYM(rb_intern("exception"));
3043-
sym_wait_readable = ID2SYM(rb_intern("wait_readable"));
3044-
sym_wait_writable = ID2SYM(rb_intern("wait_writable"));
3040+
sym_exception = ID2SYM(rb_intern_const("exception"));
3041+
sym_wait_readable = ID2SYM(rb_intern_const("wait_readable"));
3042+
sym_wait_writable = ID2SYM(rb_intern_const("wait_writable"));
30453043

3046-
id_tmp_dh_callback = rb_intern("tmp_dh_callback");
3047-
id_tmp_ecdh_callback = rb_intern("tmp_ecdh_callback");
3048-
id_npn_protocols_encoded = rb_intern("npn_protocols_encoded");
3044+
id_tmp_dh_callback = rb_intern_const("tmp_dh_callback");
3045+
id_tmp_ecdh_callback = rb_intern_const("tmp_ecdh_callback");
3046+
id_npn_protocols_encoded = rb_intern_const("npn_protocols_encoded");
30493047
id_each = rb_intern_const("each");
30503048

30513049
#define DefIVarID(name) do \
3052-
id_i_##name = rb_intern("@"#name); while (0)
3050+
id_i_##name = rb_intern_const("@"#name); while (0)
30533051

30543052
DefIVarID(cert_store);
30553053
DefIVarID(ca_file);

0 commit comments

Comments
 (0)