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

ruby-changes:62371

From: nagachika <ko1@a...>
Date: Thu, 23 Jul 2020 13:51:13 +0900 (JST)
Subject: [ruby-changes:62371] 9da6470d7b (ruby_2_7): merge revision(s) a2be428c5fec31b8adbd5ac087e7637ddf7e54d0: [Backport #16826]

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

From 9da6470d7b3aa136b4b92469c8bbc522beb1ac31 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Thu, 23 Jul 2020 13:50:56 +0900
Subject: merge revision(s) a2be428c5fec31b8adbd5ac087e7637ddf7e54d0: [Backport
 #16826]

	Fix ObjectSpace::WeakMap#key? to work if the value is nil

	* Fixes [Bug #16826]

diff --git a/gc.c b/gc.c
index a08793f..73faf46 100644
--- a/gc.c
+++ b/gc.c
@@ -10707,7 +10707,7 @@ wmap_aset(VALUE self, VALUE wmap, VALUE orig) https://github.com/ruby/ruby/blob/trunk/gc.c#L10707
 
 /* Retrieves a weakly referenced object with the given key */
 static VALUE
-wmap_aref(VALUE self, VALUE wmap)
+wmap_lookup(VALUE self, VALUE key)
 {
     st_data_t data;
     VALUE obj;
@@ -10715,17 +10715,25 @@ wmap_aref(VALUE self, VALUE wmap) https://github.com/ruby/ruby/blob/trunk/gc.c#L10715
     rb_objspace_t *objspace = &rb_objspace;
 
     TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
-    if (!st_lookup(w->wmap2obj, (st_data_t)wmap, &data)) return Qnil;
+    if (!st_lookup(w->wmap2obj, (st_data_t)key, &data)) return Qundef;
     obj = (VALUE)data;
-    if (!wmap_live_p(objspace, obj)) return Qnil;
+    if (!wmap_live_p(objspace, obj)) return Qundef;
     return obj;
 }
 
+/* Retrieves a weakly referenced object with the given key */
+static VALUE
+wmap_aref(VALUE self, VALUE key)
+{
+    VALUE obj = wmap_lookup(self, key);
+    return obj != Qundef ? obj : Qnil;
+}
+
 /* Returns +true+ if +key+ is registered */
 static VALUE
 wmap_has_key(VALUE self, VALUE key)
 {
-    return NIL_P(wmap_aref(self, key)) ? Qfalse : Qtrue;
+    return wmap_lookup(self, key) == Qundef ? Qfalse : Qtrue;
 }
 
 /* Returns the number of referenced objects */
diff --git a/version.h b/version.h
index bc61b57..e1a6dfd 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L2
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 1
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 101
+#define RUBY_PATCHLEVEL 102
 
 #define RUBY_RELEASE_YEAR 2020
 #define RUBY_RELEASE_MONTH 7
-- 
cgit v0.10.2


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

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