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

ruby-changes:64315

From: Nobuyoshi <ko1@a...>
Date: Sat, 19 Dec 2020 15:10:00 +0900 (JST)
Subject: [ruby-changes:64315] feacae193c (master): [digest] Added rb_digest_make_metadata to wrap metadata

https://git.ruby-lang.org/ruby.git/commit/?id=feacae193c

From feacae193ca3856b1d326697835357791a6df12b Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 17 Dec 2020 11:02:31 +0900
Subject: [digest] Added rb_digest_make_metadata to wrap metadata

https://github.com/ruby/digest/commit/7046fe6005

diff --git a/ext/digest/digest.h b/ext/digest/digest.h
index 4b69540..0d4f0e7 100644
--- a/ext/digest/digest.h
+++ b/ext/digest/digest.h
@@ -62,3 +62,11 @@ rb_id_metadata(void) https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.h#L62
 {
     return rb_intern_const("metadata");
 }
+
+static inline VALUE
+rb_digest_make_metadata(const rb_digest_metadata_t *meta)
+{
+#undef RUBY_UNTYPED_DATA_WARNING
+#define RUBY_UNTYPED_DATA_WARNING 0
+    return rb_obj_freeze(Data_Wrap_Struct(0, 0, 0, (void *)meta));
+}
diff --git a/ext/digest/md5/md5init.c b/ext/digest/md5/md5init.c
index 688a955..52cba78 100644
--- a/ext/digest/md5/md5init.c
+++ b/ext/digest/md5/md5init.c
@@ -57,8 +57,5 @@ Init_md5(void) https://github.com/ruby/ruby/blob/trunk/ext/digest/md5/md5init.c#L57
 
     cDigest_MD5 = rb_define_class_under(mDigest, "MD5", cDigest_Base);
 
-#undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
-    rb_iv_set(cDigest_MD5, "metadata",
-	      Data_Wrap_Struct(0, 0, 0, (void *)&md5));
+    rb_iv_set(cDigest_MD5, "metadata", rb_digest_make_metadata(&md5));
 }
diff --git a/ext/digest/rmd160/rmd160init.c b/ext/digest/rmd160/rmd160init.c
index 2c44d83..2ae81ec 100644
--- a/ext/digest/rmd160/rmd160init.c
+++ b/ext/digest/rmd160/rmd160init.c
@@ -53,8 +53,5 @@ Init_rmd160(void) https://github.com/ruby/ruby/blob/trunk/ext/digest/rmd160/rmd160init.c#L53
 
     cDigest_RMD160 = rb_define_class_under(mDigest, "RMD160", cDigest_Base);
 
-#undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
-    rb_iv_set(cDigest_RMD160, "metadata",
-	      Data_Wrap_Struct(0, 0, 0, (void *)&rmd160));
+    rb_iv_set(cDigest_RMD160, "metadata", rb_digest_make_metadata(&rmd160));
 }
diff --git a/ext/digest/sha1/sha1init.c b/ext/digest/sha1/sha1init.c
index 1d201c5..f7047bc 100644
--- a/ext/digest/sha1/sha1init.c
+++ b/ext/digest/sha1/sha1init.c
@@ -59,8 +59,5 @@ Init_sha1(void) https://github.com/ruby/ruby/blob/trunk/ext/digest/sha1/sha1init.c#L59
 
     cDigest_SHA1 = rb_define_class_under(mDigest, "SHA1", cDigest_Base);
 
-#undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
-    rb_iv_set(cDigest_SHA1, "metadata",
-	      Data_Wrap_Struct(0, 0, 0, (void *)&sha1));
+    rb_iv_set(cDigest_SHA1, "metadata", rb_digest_make_metadata(&sha1));
 }
diff --git a/ext/digest/sha2/sha2init.c b/ext/digest/sha2/sha2init.c
index aad7b65..6ed275e 100644
--- a/ext/digest/sha2/sha2init.c
+++ b/ext/digest/sha2/sha2init.c
@@ -47,9 +47,7 @@ Init_sha2(void) https://github.com/ruby/ruby/blob/trunk/ext/digest/sha2/sha2init.c#L47
     cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
 \
     rb_ivar_set(cDigest_SHA##bitlen, id_metadata, \
-		Data_Wrap_Struct(0, 0, 0, (void *)&sha##bitlen));
+		rb_digest_make_metadata(&sha##bitlen));
 
-#undef RUBY_UNTYPED_DATA_WARNING
-#define RUBY_UNTYPED_DATA_WARNING 0
     FOREACH_BITLEN(DEFINE_ALGO_CLASS)
 }
-- 
cgit v0.10.2


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

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