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

ruby-changes:36709

From: nobu <ko1@a...>
Date: Sat, 13 Dec 2014 06:57:54 +0900 (JST)
Subject: [ruby-changes:36709] nobu:r48791 (trunk): ossl_digest.c: typed data

nobu	2014-12-13 06:57:44 +0900 (Sat, 13 Dec 2014)

  New Revision: 48791

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

  Log:
    ossl_digest.c: typed data
    
    * ext/openssl/ossl_digest.c (ossl_digest_type): use typed data.

  Modified files:
    trunk/ext/openssl/ossl_digest.c
Index: ext/openssl/ossl_digest.c
===================================================================
--- ext/openssl/ossl_digest.c	(revision 48790)
+++ ext/openssl/ossl_digest.c	(revision 48791)
@@ -11,7 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_digest.c#L11
 #include "ossl.h"
 
 #define GetDigest(obj, ctx) do { \
-    Data_Get_Struct((obj), EVP_MD_CTX, (ctx)); \
+    TypedData_Get_Struct((obj), EVP_MD_CTX, &ossl_digest_type, (ctx)); \
     if (!(ctx)) { \
 	ossl_raise(rb_eRuntimeError, "Digest CTX wasn't initialized!"); \
     } \
@@ -29,6 +29,20 @@ VALUE eDigestError; https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_digest.c#L29
 
 static VALUE ossl_digest_alloc(VALUE klass);
 
+static void
+ossl_digest_free(void *ctx)
+{
+    EVP_MD_CTX_destroy(ctx);
+}
+
+static const rb_data_type_t ossl_digest_type = {
+    "OpenSSL/Digest",
+    {
+	0, ossl_digest_free,
+    },
+    0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
 /*
  * Public
  */
@@ -87,7 +101,7 @@ ossl_digest_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_digest.c#L101
     ctx = EVP_MD_CTX_create();
     if (ctx == NULL)
 	ossl_raise(rb_eRuntimeError, "EVP_MD_CTX_create() failed");
-    obj = Data_Wrap_Struct(klass, 0, EVP_MD_CTX_destroy, ctx);
+    obj = TypedData_Wrap_Struct(klass, &ossl_digest_type, ctx);
 
     return obj;
 }

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

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