ruby-changes:36714
From: nobu <ko1@a...>
Date: Sat, 13 Dec 2014 06:58:37 +0900 (JST)
Subject: [ruby-changes:36714] nobu:r48799 (trunk): ossl_ssl_session.c: typed data
nobu 2014-12-13 06:58:25 +0900 (Sat, 13 Dec 2014) New Revision: 48799 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48799 Log: ossl_ssl_session.c: typed data * ext/openssl/ossl_ssl_session.c (ossl_ssl_session_type): use typed data. Modified files: trunk/ext/openssl/ossl_ssl.h trunk/ext/openssl/ossl_ssl_session.c Index: ext/openssl/ossl_ssl.h =================================================================== --- ext/openssl/ossl_ssl.h (revision 48798) +++ ext/openssl/ossl_ssl.h (revision 48799) @@ -16,7 +16,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.h#L16 } while (0) #define GetSSLSession(obj, sess) do { \ - Data_Get_Struct((obj), SSL_SESSION, (sess)); \ + TypedData_Get_Struct((obj), SSL_SESSION, &ossl_ssl_session_type, (sess)); \ if (!(sess)) { \ ossl_raise(rb_eRuntimeError, "SSL Session wasn't initialized."); \ } \ @@ -27,6 +27,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.h#L27 GetSSLSession((obj), (sess)); \ } while (0) +extern const rb_data_type_t ossl_ssl_session_type; extern VALUE mSSL; extern VALUE eSSLError; extern VALUE cSSLSocket; Index: ext/openssl/ossl_ssl_session.c =================================================================== --- ext/openssl/ossl_ssl_session.c (revision 48798) +++ ext/openssl/ossl_ssl_session.c (revision 48799) @@ -4,25 +4,26 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl_session.c#L4 #include "ossl.h" -#define GetSSLSession(obj, sess) do { \ - Data_Get_Struct((obj), SSL_SESSION, (sess)); \ - if (!(sess)) { \ - ossl_raise(rb_eRuntimeError, "SSL Session wasn't initialized."); \ - } \ -} while (0) - -#define SafeGetSSLSession(obj, sess) do { \ - OSSL_Check_Kind((obj), cSSLSession); \ - GetSSLSession((obj), (sess)); \ -} while (0) - - VALUE cSSLSession; static VALUE eSSLSession; +static void +ossl_ssl_session_free(void *ptr) +{ + SSL_SESSION_free(ptr); +} + +const rb_data_type_t ossl_ssl_session_type = { + "OpenSSL/SSL/Session", + { + 0, ossl_ssl_session_free, + }, + 0, 0, RUBY_TYPED_FREE_IMMEDIATELY, +}; + static VALUE ossl_ssl_session_alloc(VALUE klass) { - return Data_Wrap_Struct(klass, 0, SSL_SESSION_free, NULL); + return TypedData_Wrap_Struct(klass, &ossl_ssl_session_type, NULL); } /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/