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

ruby-changes:38592

From: nobu <ko1@a...>
Date: Fri, 29 May 2015 14:55:20 +0900 (JST)
Subject: [ruby-changes:38592] nobu:r50673 (trunk): openssl: wrapper object before alloc

nobu	2015-05-29 14:55:02 +0900 (Fri, 29 May 2015)

  New Revision: 50673

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

  Log:
    openssl: wrapper object before alloc
    
    * ext/openssl: make wrapper objects before allocating structs to
      get rid of potential memory leaks.

  Modified files:
    trunk/ext/openssl/ossl_bn.c
    trunk/ext/openssl/ossl_cipher.c
    trunk/ext/openssl/ossl_digest.c
    trunk/ext/openssl/ossl_engine.c
    trunk/ext/openssl/ossl_ns_spki.c
    trunk/ext/openssl/ossl_ocsp.c
    trunk/ext/openssl/ossl_pkcs12.c
    trunk/ext/openssl/ossl_pkcs7.c
    trunk/ext/openssl/ossl_pkey.c
    trunk/ext/openssl/ossl_pkey.h
    trunk/ext/openssl/ossl_pkey_dh.c
    trunk/ext/openssl/ossl_pkey_dsa.c
    trunk/ext/openssl/ossl_pkey_ec.c
    trunk/ext/openssl/ossl_pkey_rsa.c
    trunk/ext/openssl/ossl_ssl.c
    trunk/ext/openssl/ossl_x509attr.c
    trunk/ext/openssl/ossl_x509cert.c
    trunk/ext/openssl/ossl_x509crl.c
    trunk/ext/openssl/ossl_x509ext.c
    trunk/ext/openssl/ossl_x509name.c
    trunk/ext/openssl/ossl_x509req.c
    trunk/ext/openssl/ossl_x509revoked.c
    trunk/ext/openssl/ossl_x509store.c
Index: ext/openssl/ossl_pkey_dsa.c
===================================================================
--- ext/openssl/ossl_pkey_dsa.c	(revision 50672)
+++ ext/openssl/ossl_pkey_dsa.c	(revision 50673)
@@ -40,6 +40,7 @@ dsa_instance(VALUE klass, DSA *dsa) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_dsa.c#L40
     if (!dsa) {
 	return Qfalse;
     }
+    obj = NewPKey(klass);
     if (!(pkey = EVP_PKEY_new())) {
 	return Qfalse;
     }
@@ -47,7 +48,7 @@ dsa_instance(VALUE klass, DSA *dsa) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_dsa.c#L48
 	EVP_PKEY_free(pkey);
 	return Qfalse;
     }
-    WrapPKey(klass, obj, pkey);
+    SetPKey(obj, pkey);
 
     return obj;
 }
@@ -60,10 +61,11 @@ ossl_dsa_new(EVP_PKEY *pkey) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_dsa.c#L61
     if (!pkey) {
 	obj = dsa_instance(cDSA, DSA_new());
     } else {
+	obj = NewPKey(cDSA);
 	if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DSA) {
 	    ossl_raise(rb_eTypeError, "Not a DSA key!");
 	}
-	WrapPKey(cDSA, obj, pkey);
+	SetPKey(obj, pkey);
     }
     if (obj == Qfalse) {
 	ossl_raise(eDSAError, NULL);
Index: ext/openssl/ossl_x509attr.c
===================================================================
--- ext/openssl/ossl_x509attr.c	(revision 50672)
+++ ext/openssl/ossl_x509attr.c	(revision 50673)
@@ -10,11 +10,13 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509attr.c#L10
  */
 #include "ossl.h"
 
-#define WrapX509Attr(klass, obj, attr) do { \
+#define NewX509Attr(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_x509attr_type, 0)
+#define SetX509Attr(obj, attr) do { \
     if (!(attr)) { \
 	ossl_raise(rb_eRuntimeError, "ATTR wasn't initialized!"); \
     } \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_x509attr_type, (attr)); \
+    RTYPEDDATA_DATA(obj) = (attr); \
 } while (0)
 #define GetX509Attr(obj, attr) do { \
     TypedData_Get_Struct((obj), X509_ATTRIBUTE, &ossl_x509attr_type, (attr)); \
@@ -56,6 +58,7 @@ ossl_x509attr_new(X509_ATTRIBUTE *attr) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509attr.c#L58
     X509_ATTRIBUTE *new;
     VALUE obj;
 
+    obj = NewX509Attr(cX509Attr);
     if (!attr) {
 	new = X509_ATTRIBUTE_new();
     } else {
@@ -64,7 +67,7 @@ ossl_x509attr_new(X509_ATTRIBUTE *attr) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509attr.c#L67
     if (!new) {
 	ossl_raise(eX509AttrError, NULL);
     }
-    WrapX509Attr(cX509Attr, obj, new);
+    SetX509Attr(obj, new);
 
     return obj;
 }
@@ -91,9 +94,10 @@ ossl_x509attr_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509attr.c#L94
     X509_ATTRIBUTE *attr;
     VALUE obj;
 
+    obj = NewX509Attr(klass);
     if (!(attr = X509_ATTRIBUTE_new()))
 	ossl_raise(eX509AttrError, NULL);
-    WrapX509Attr(klass, obj, attr);
+    SetX509Attr(obj, attr);
 
     return obj;
 }
Index: ext/openssl/ossl_ssl.c
===================================================================
--- ext/openssl/ossl_ssl.c	(revision 50672)
+++ ext/openssl/ossl_ssl.c	(revision 50673)
@@ -175,17 +175,20 @@ ossl_sslctx_s_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L175
 {
     SSL_CTX *ctx;
     long mode = SSL_MODE_ENABLE_PARTIAL_WRITE;
+    VALUE obj;
 
 #ifdef SSL_MODE_RELEASE_BUFFERS
     mode |= SSL_MODE_RELEASE_BUFFERS;
 #endif
 
+    obj = TypedData_Wrap_Struct(klass, &ossl_sslctx_type, 0);
     ctx = SSL_CTX_new(SSLv23_method());
     if (!ctx) {
         ossl_raise(eSSLError, "SSL_CTX_new");
     }
     SSL_CTX_set_mode(ctx, mode);
-    return TypedData_Wrap_Struct(klass, &ossl_sslctx_type, ctx);
+    RTYPEDDATA_DATA(obj) = ctx;
+    return obj;
 }
 
 /*
Index: ext/openssl/ossl_ocsp.c
===================================================================
--- ext/openssl/ossl_ocsp.c	(revision 50672)
+++ ext/openssl/ossl_ocsp.c	(revision 50673)
@@ -13,9 +13,11 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L13
 
 #if defined(OSSL_OCSP_ENABLED)
 
-#define WrapOCSPReq(klass, obj, req) do { \
+#define NewOCSPReq(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_ocsp_request_type, 0)
+#define SetOCSPReq(obj, req) do { \
     if(!(req)) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_ocsp_request_type, (req)); \
+    RTYPEDDATA_DATA(obj) = (req); \
 } while (0)
 #define GetOCSPReq(obj, req) do { \
     TypedData_Get_Struct((obj), OCSP_REQUEST, &ossl_ocsp_request_type, (req)); \
@@ -26,9 +28,11 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L28
     GetOCSPReq((obj), (req)); \
 } while (0)
 
-#define WrapOCSPRes(klass, obj, res) do { \
+#define NewOCSPRes(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_ocsp_response_type, 0)
+#define SetOCSPRes(obj, res) do { \
     if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_ocsp_response_type, (res)); \
+    RTYPEDDATA_DATA(obj) = (res); \
 } while (0)
 #define GetOCSPRes(obj, res) do { \
     TypedData_Get_Struct((obj), OCSP_RESPONSE, &ossl_ocsp_response_type, (res)); \
@@ -39,9 +43,11 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L43
     GetOCSPRes((obj), (res)); \
 } while (0)
 
-#define WrapOCSPBasicRes(klass, obj, res) do { \
+#define NewOCSPBasicRes(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_ocsp_basicresp_type, 0)
+#define SetOCSPBasicRes(obj, res) do { \
     if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_ocsp_basicresp_type, (res)); \
+    RTYPEDDATA_DATA(obj) = (res); \
 } while (0)
 #define GetOCSPBasicRes(obj, res) do { \
     TypedData_Get_Struct((obj), OCSP_BASICRESP, &ossl_ocsp_basicresp_type, (res)); \
@@ -52,9 +58,11 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L58
     GetOCSPBasicRes((obj), (res)); \
 } while (0)
 
-#define WrapOCSPCertId(klass, obj, cid) do { \
+#define NewOCSPCertId(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_ocsp_certid_type, 0)
+#define SetOCSPCertId(obj, cid) do { \
     if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_ocsp_certid_type, (cid)); \
+    RTYPEDDATA_DATA(obj) = (cid); \
 } while (0)
 #define GetOCSPCertId(obj, cid) do { \
     TypedData_Get_Struct((obj), OCSP_CERTID, &ossl_ocsp_certid_type, (cid)); \
@@ -134,8 +142,8 @@ static const rb_data_type_t ossl_ocsp_ce https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L142
 static VALUE
 ossl_ocspcertid_new(OCSP_CERTID *cid)
 {
-    VALUE obj;
-    WrapOCSPCertId(cOCSPCertId, obj, cid);
+    VALUE obj = NewOCSPCertId(cOCSPCertId);
+    SetOCSPCertId(obj, cid);
     return obj;
 }
 
@@ -148,9 +156,10 @@ ossl_ocspreq_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L156
     OCSP_REQUEST *req;
     VALUE obj;
 
+    obj = NewOCSPReq(klass);
     if (!(req = OCSP_REQUEST_new()))
 	ossl_raise(eOCSPError, NULL);
-    WrapOCSPReq(klass, obj, req);
+    SetOCSPReq(obj, req);
 
     return obj;
 }
@@ -294,9 +303,10 @@ ossl_ocspreq_get_certid(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L303
     ary = (count > 0) ? rb_ary_new() : Qnil;
     for(i = 0; i < count; i++){
 	one = OCSP_request_onereq_get0(req, i);
+	tmp = NewOCSPCertId(cOCSPCertId);
 	if(!(id = OCSP_CERTID_dup(OCSP_onereq_get0_id(one))))
 	    ossl_raise(eOCSPError, NULL);
-	WrapOCSPCertId(cOCSPCertId, tmp, id);
+	SetOCSPCertId(tmp, id);
 	rb_ary_push(ary, tmp);
     }
 
@@ -415,9 +425,10 @@ ossl_ocspres_s_create(VALUE klass, VALUE https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L425
 
     if(NIL_P(basic_resp)) bs = NULL;
     else GetOCSPBasicRes(basic_resp, bs); /* NO NEED TO DUP */
+    obj = NewOCSPRes(klass);
     if(!(res = OCSP_response_create(st, bs)))
 	ossl_raise(eOCSPError, NULL);
-    WrapOCSPRes(klass, obj, res);
+    SetOCSPRes(obj, res);
 
     return obj;
 }
@@ -428,9 +439,10 @@ ossl_ocspres_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L439
     OCSP_RESPONSE *res;
     VALUE obj;
 
+    obj = NewOCSPRes(klass);
     if(!(res = OCSP_RESPONSE_new()))
 	ossl_raise(eOCSPError, NULL);
-    WrapOCSPRes(klass, obj, res);
+    SetOCSPRes(obj, res);
 
     return obj;
 }
@@ -519,9 +531,10 @@ ossl_ocspres_get_basic(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L531
     VALUE ret;
 
     GetOCSPRes(self, res);
+    ret = NewOCSPBasicRes(cOCSPBasicRes);
     if(!(bs = OCSP_response_get1_basic(res)))
 	return Qnil;
-    WrapOCSPBasicRes(cOCSPBasicRes, ret, bs);
+    SetOCSPBasicRes(ret, bs);
 
     return ret;
 }
@@ -562,9 +575,10 @@ ossl_ocspbres_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L575
     OCSP_BASICRESP *bs;
     VALUE obj;
 
+    obj = NewOCSPBasicRes(klass);
     if(!(bs = OCSP_BASICRESP_new()))
 	ossl_raise(eOCSPError, NULL);
-    WrapOCSPBasicRes(klass, obj, bs);
+    SetOCSPBasicRes(obj, bs);
 
     return obj;
 }
@@ -851,9 +865,10 @@ ossl_ocspcid_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ocsp.c#L865
     OCSP_CERTID *id;
     VALUE obj;
 
+    obj = NewOCSPCertId(klass);
     if(!(id = OCSP_CERTID_new()))
 	ossl_raise(eOCSPError, NULL);
-    WrapOCSPCertId(klass, obj, id);
+    SetOCSPCertId(obj, id);
 
     return obj;
 }
Index: ext/openssl/ossl_engine.c
===================================================================
--- ext/openssl/ossl_engine.c	(revision 50672)
+++ ext/openssl/ossl_engine.c	(revision 50673)
@@ -12,11 +12,13 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_engine.c#L12
 
 #if defined(OSSL_ENGINE_ENABLED)
 
-#define WrapEngine(klass, obj, engine) do { \
+#define NewEngine(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_engine_type, 0)
+#define SetEngine(obj, engine) do { \
     if (!(engine)) { \
 	ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
     } \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_engine_type, (engine)); \
+    RTYPEDDATA_DATA(obj) = (engine); \
 } while(0)
 #define GetEngine(obj, engine) do { \
     TypedData_Get_Struct((obj), ENGINE, &ossl_engine_type, (engine)); \
@@ -182,11 +184,12 @@ ossl_engine_s_engines(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_engine.c#L184
 
     ary = rb_ary_new();
     for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){
+	obj = NewEngine(klass);
 	/* Need a ref count of two here because of ENGINE_free being
 	 * called internally by OpenSSL when moving to the next ENGINE
 	 * and by us when releasing the ENGINE reference */
 	ENGINE_up_ref(e);
-	WrapEngine(klass, obj, e);
+	SetEngine(obj, e);
         rb_ary_push(ary, obj);
     }
 
@@ -213,9 +216,10 @@ ossl_engine_s_by_id(VALUE klass, VALUE i https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_engine.c#L216
 
     StringValue(id);
     ossl_engine_s_load(1, &id, klass);
+    obj = NewEngine(klass);
     if(!(e = ENGINE_by_id(RSTRING_PTR(id))))
 	ossl_raise(eEngineError, NULL);
-    WrapEngine(klass, obj, e);
+    SetEngine(obj, e);
     if(rb_block_given_p()) rb_yield(obj);
     if(!ENGINE_init(e))
 	ossl_raise(eEngineError, NULL);
@@ -232,10 +236,11 @@ ossl_engine_s_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_engine.c#L236
     ENGINE *e;
     VALUE obj;
 
+    obj = NewEngine(klass);
     if (!(e = ENGINE_new())) {
        ossl_raise(eEngineError, NULL);
     }
-    WrapEngine(klass, obj, e);
+    SetEngine(obj, e);
 
     return obj;
 }
Index: ext/openssl/ossl_cipher.c
===================================================================
--- ext/openssl/ossl_cipher.c	(revision 50672)
+++ ext/openssl/ossl_cipher.c	(revision 50673)
@@ -10,8 +10,8 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_cipher.c#L10
  */
 #include "ossl.h"
 
-#define WrapCipher(obj, klass, ctx) \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_cipher_type, (ctx))
+#define NewCipher(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_cipher_type, 0)
 #define MakeCipher(obj, klass, ctx) \
     (obj) = TypedData_Make_Struct((klass), EVP_CIPHER_CTX, &ossl_cipher_type, (ctx))
 #define AllocCipher(obj, ctx) \
@@ -98,11 +98,7 @@ ossl_cipher_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_cipher.c#L98
 static VALUE
 ossl_cipher_alloc(VALUE klass)
 {
-    VALUE obj;
-
-    WrapCipher(obj, klass, 0);
-
-    return obj;
+    return NewCipher(klass);
 }
 
 /*
Index: ext/openssl/ossl_pkey_rsa.c
===================================================================
--- ext/openssl/ossl_pkey_rsa.c	(revision 50672)
+++ ext/openssl/ossl_pkey_rsa.c	(revision 50673)
@@ -40,6 +40,7 @@ rsa_instance(VALUE klass, RSA *rsa) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_rsa.c#L40
     if (!rsa) {
 	return Qfalse;
     }
+    obj = NewPKey(klass);
     if (!(pkey = EVP_PKEY_new())) {
 	return Qfalse;
     }
@@ -47,7 +48,7 @@ rsa_instance(VALUE klass, RSA *rsa) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_rsa.c#L48
 	EVP_PKEY_free(pkey);
 	return Qfalse;
     }
-    WrapPKey(klass, obj, pkey);
+    SetPKey(obj, pkey);
 
     return obj;
 }
@@ -61,10 +62,11 @@ ossl_rsa_new(EVP_PKEY *pkey) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_rsa.c#L62
 	obj = rsa_instance(cRSA, RSA_new());
     }
     else {
+	obj = NewPKey(cRSA);
 	if (EVP_PKEY_type(pkey->type) != EVP_PKEY_RSA) {
 	    ossl_raise(rb_eTypeError, "Not a RSA key!");
 	}
-	WrapPKey(cRSA, obj, pkey);
+	SetPKey(obj, pkey);
     }
     if (obj == Qfalse) {
 	ossl_raise(eRSAError, NULL);
Index: ext/openssl/ossl_x509req.c
===================================================================
--- ext/openssl/ossl_x509req.c	(revision 50672)
+++ ext/openssl/ossl_x509req.c	(revision 50673)
@@ -10,11 +10,13 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509req.c#L10
  */
 #include "ossl.h"
 
-#define WrapX509Req(klass, obj, req) do { \
+#define NewX509Req(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_x509req_type, 0)
+#define SetX509Req(obj, req) do { \
     if (!(req)) { \
 	ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \
     } \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_x509req_type, (req)); \
+    RTYPEDDATA_DATA(obj) = (req); \
 } while (0)
 #define GetX509Req(obj, req) do { \
     TypedData_Get_Struct((obj), X509_REQ, &ossl_x509req_type, (req)); \
@@ -56,6 +58,7 @@ ossl_x509req_new(X509_REQ *req) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509req.c#L58
     X509_REQ *new;
     VALUE obj;
 
+    obj = NewX509Req(cX509Req);
     if (!req) {
 	new = X509_REQ_new();
     } else {
@@ -64,7 +67,7 @@ ossl_x509req_new(X509_REQ *req) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509req.c#L67
     if (!new) {
 	ossl_raise(eX509ReqError, NULL);
     }
-    WrapX509Req(cX509Req, obj, new);
+    SetX509Req(obj, new);
 
     return obj;
 }
@@ -101,10 +104,11 @@ ossl_x509req_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509req.c#L104
     X509_REQ *req;
     VALUE obj;
 
+    obj = NewX509Req(klass);
     if (!(req = X509_REQ_new())) {
 	ossl_raise(eX509ReqError, NULL);
     }
-    WrapX509Req(klass, obj, req);
+    SetX509Req(obj, req);
 
     return obj;
 }
Index: ext/openssl/ossl_pkey_ec.c
===================================================================
--- ext/openssl/ossl_pkey_ec.c	(revision 50672)
+++ ext/openssl/ossl_pkey_ec.c	(revision 50673)
@@ -116,6 +116,7 @@ static VALUE ec_instance(VALUE klass, EC https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_ec.c#L116
     if (!ec) {
 	return Qfalse;
     }
+    obj = NewPKey(klass);
     if (!(pkey = EVP_PKEY_new())) {
 	return Qfalse;
     }
@@ -123,7 +124,7 @@ static VALUE ec_instance(VALUE klass, EC https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_ec.c#L124
 	EVP_PKEY_free(pkey);
 	return Qfalse;
     }
-    WrapPKey(klass, obj, pkey);
+    SetPKey(obj, pkey);
 
     return obj;
 }
@@ -135,10 +136,11 @@ VALUE ossl_ec_new(EVP_PKEY *pkey) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_ec.c#L136
     if (!pkey) {
 	obj = ec_instance(cEC, EC_KEY_new());
     } else {
+	obj = NewPKey(cEC);
 	if (EVP_PKEY_type(pkey->type) != EVP_PKEY_EC) {
 	    ossl_raise(rb_eTypeError, "Not a EC key!");
 	}
-	WrapPKey(cEC, obj, pkey);
+	SetPKey(obj, pkey);
     }
     if (obj == Qfalse) {
 	ossl_raise(eECError, NULL);
Index: ext/openssl/ossl_digest.c
===================================================================
--- ext/openssl/ossl_digest.c	(revision 50672)
+++ ext/openssl/ossl_digest.c	(revision 50673)
@@ -95,13 +95,11 @@ ossl_digest_new(const EVP_MD *md) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_digest.c#L95
 static VALUE
 ossl_digest_alloc(VALUE klass)
 {
-    EVP_MD_CTX *ctx;
-    VALUE obj;
-
-    ctx = EVP_MD_CTX_create();
+    VALUE obj = TypedData_Wrap_Struct(klass, &ossl_digest_type, 0);
+    EVP_MD_CTX *ctx = EVP_MD_CTX_create();
     if (ctx == NULL)
 	ossl_raise(rb_eRuntimeError, "EVP_MD_CTX_create() failed");
-    obj = TypedData_Wrap_Struct(klass, &ossl_digest_type, ctx);
+    RTYPEDDATA_DATA(obj) = ctx;
 
     return obj;
 }
Index: ext/openssl/ossl_x509store.c
===================================================================
--- ext/openssl/ossl_x509store.c	(revision 50672)
+++ ext/openssl/ossl_x509store.c	(revision 50673)
@@ -10,11 +10,13 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L10
  */
 #include "ossl.h"
 
-#define WrapX509Store(klass, obj, st) do { \
+#define NewX509Store(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_x509store_type, 0)
+#define SetX509Store(obj, st) do { \
     if (!(st)) { \
 	ossl_raise(rb_eRuntimeError, "STORE wasn't initialized!"); \
     } \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_x509store_type, (st)); \
+    RTYPEDDATA_DATA(obj) = (st); \
 } while (0)
 #define GetX509Store(obj, st) do { \
     TypedData_Get_Struct((obj), X509_STORE, &ossl_x509store_type, (st)); \
@@ -27,11 +29,13 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L29
     GetX509Store((obj), (st)); \
 } while (0)
 
-#define WrapX509StCtx(klass, obj, ctx) do { \
+#define NewX509StCtx(klass) \
+    TypedData_Wrap_Struct((klass), &ossl_x509stctx_type, 0)
+#define SetX509StCtx(obj, ctx) do { \
     if (!(ctx)) { \
 	ossl_raise(rb_eRuntimeError, "STORE_CTX wasn't initialized!"); \
     } \
-    (obj) = TypedData_Wrap_Struct((klass), &ossl_x509stctx_type, (ctx)); \
+    RTYPEDDATA_DATA(obj) = (ctx); \
 } while (0)
 #define GetX509StCtx(obj, ctx) do { \
     TypedData_Get_Struct((obj), X509_STORE_CTX, &ossl_x509stctx_type, (ctx)); \
@@ -73,7 +77,8 @@ ossl_x509store_new(X509_STORE *store) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L77
 {
     VALUE obj;
 
-    WrapX509Store(cX509Store, obj, store);
+    obj = NewX509Store(cX509Store);
+    SetX509Store(obj, store);
 
     return obj;
 }
@@ -108,10 +113,11 @@ ossl_x509store_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L113
     X509_STORE *store;
     VALUE obj;
 
+    obj = NewX509Store(klass);
     if((store = X509_STORE_new()) == NULL){
         ossl_raise(eX509StoreError, NULL);
     }
-    WrapX509Store(klass, obj, store);
+    SetX509Store(obj, store);
 
     return obj;
 }
@@ -373,7 +379,8 @@ ossl_x509stctx_new(X509_STORE_CTX *ctx) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L379
 {
     VALUE obj;
 
-    WrapX509StCtx(cX509StoreContext, obj, ctx);
+    obj = NewX509StCtx(cX509StoreContext);
+    SetX509StCtx(obj, ctx);
 
     return obj;
 }
@@ -407,10 +414,11 @@ ossl_x509stctx_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L414
     X509_STORE_CTX *ctx;
     VALUE obj; (... truncated)

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

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