[前][次][番号順一覧][スレッド一覧]

ruby-changes:30089

From: naruse <ko1@a...>
Date: Tue, 23 Jul 2013 23:20:02 +0900 (JST)
Subject: [ruby-changes:30089] naruse:r42141 (trunk): * ext/openssl/extconf.rb (CRYPTO_THREADID): check exist or not.

naruse	2013-07-23 23:19:51 +0900 (Tue, 23 Jul 2013)

  New Revision: 42141

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42141

  Log:
    * ext/openssl/extconf.rb (CRYPTO_THREADID): check exist or not.
    
    * ext/openssl/ossl.c (ossl_thread_id): use rb_nativethread_self()
      implemented at r42137 to allow threads which doesn't associated with
      Ruby thread to use openssl functions.
    
    * ext/openssl/ossl.c (Init_ossl_locks): If CRYPTO_THREADID is defined
      (OpenSSL 1.0.0 or later has it) use CRYPTO_THREADID_set_callback()
      instead of CRYPTO_set_id_callback() because its argument is
      unsigned long; it may cause id collision on mswin64
      whose sizeof(unsigned long) < sizeof(void*).
      http://www.openssl.org/docs/crypto/threads.html
    
    * ext/openssl/ossl.c (ossl_threadid_func): defined for above.

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/extconf.rb
    trunk/ext/openssl/ossl.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42140)
+++ ChangeLog	(revision 42141)
@@ -1,3 +1,20 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jul 23 23:19:24 2013  NARUSE, Yui  <naruse@r...>
+
+	* ext/openssl/extconf.rb (CRYPTO_THREADID): check exist or not.
+
+	* ext/openssl/ossl.c (ossl_thread_id): use rb_nativethread_self()
+	  implemented at r42137 to allow threads which doesn't associated with
+	  Ruby thread to use openssl functions.
+
+	* ext/openssl/ossl.c (Init_ossl_locks): If CRYPTO_THREADID is defined
+	  (OpenSSL 1.0.0 or later has it) use CRYPTO_THREADID_set_callback()
+	  instead of CRYPTO_set_id_callback() because its argument is
+	  unsigned long; it may cause id collision on mswin64
+	  whose sizeof(unsigned long) < sizeof(void*).
+	  http://www.openssl.org/docs/crypto/threads.html
+
+	* ext/openssl/ossl.c (ossl_threadid_func): defined for above.
+
 Tue Jul 23 20:47:36 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c: Move functions.
Index: ext/openssl/ossl.c
===================================================================
--- ext/openssl/ossl.c	(revision 42140)
+++ ext/openssl/ossl.c	(revision 42141)
@@ -473,10 +473,19 @@ static void ossl_lock_callback(int mode, https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L473
     }
 }
 
+#ifdef HAVE_CRYPTO_THREADID_PTR
+static void ossl_threadid_func(CRYPTO_THREADID *id)
+{
+    /* register native thread id */
+    CRYPTO_THREADID_set_pointer(id, (void *)rb_nativethread_self());
+}
+#else
 static unsigned long ossl_thread_id(void)
 {
-    return NUM2ULONG(rb_obj_id(rb_thread_current()));
+    /* before OpenSSL 1.0, this is 'unsigned long' */
+    return (unsigned long)rb_nativethread_self();
 }
+#endif
 
 static void Init_ossl_locks(void)
 {
@@ -494,7 +503,11 @@ static void Init_ossl_locks(void) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L503
 	rb_nativethread_lock_initialize(&ossl_locks[i]);
     }
 
+#ifdef HAVE_CRYPTO_THREADID_PTR
+    CRYPTO_THREADID_set_callback(ossl_threadid_func);
+#else
     CRYPTO_set_id_callback(ossl_thread_id);
+#endif
     CRYPTO_set_locking_callback(ossl_lock_callback);
 }
 
Index: ext/openssl/extconf.rb
===================================================================
--- ext/openssl/extconf.rb	(revision 42140)
+++ ext/openssl/extconf.rb	(revision 42141)
@@ -144,6 +144,7 @@ if checking_for('OpenSSL version is 0.9. https://github.com/ruby/ruby/blob/trunk/ext/openssl/extconf.rb#L144
   }
   have_header("openssl/ocsp.h")
 end
+have_struct_member("CRYPTO_THREADID", "ptr", "openssl/crypto.h")
 have_struct_member("EVP_CIPHER_CTX", "flags", "openssl/evp.h")
 have_struct_member("EVP_CIPHER_CTX", "engine", "openssl/evp.h")
 have_struct_member("X509_ATTRIBUTE", "single", "openssl/x509.h")

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]