[ruby/json] Use RB_TYPE_P
[ruby.git] / weakmap.c
index a48179a..2ebf7d2 100644 (file)
--- a/weakmap.c
+++ b/weakmap.c
@@ -439,18 +439,6 @@ wmap_values(VALUE self)
     return ary;
 }
 
-static VALUE
-nonspecial_obj_id(VALUE obj)
-{
-#if SIZEOF_LONG == SIZEOF_VOIDP
-    return (VALUE)((SIGNED_VALUE)(obj)|FIXNUM_FLAG);
-#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
-    return LL2NUM((SIGNED_VALUE)(obj) / 2);
-#else
-# error not supported
-#endif
-}
-
 static int
 wmap_aset_replace(st_data_t *key, st_data_t *val, st_data_t new_key_ptr, int existing)
 {
@@ -495,7 +483,7 @@ wmap_aset(VALUE self, VALUE key, VALUE val)
     RB_OBJ_WRITTEN(self, Qundef, key);
     RB_OBJ_WRITTEN(self, Qundef, val);
 
-    return nonspecial_obj_id(val);
+    return Qnil;
 }
 
 /* Retrieves a weakly referenced object with the given key */
@@ -648,10 +636,8 @@ static int
 wkmap_mark_table_i(st_data_t key, st_data_t val_obj, st_data_t data)
 {
     VALUE **dead_entry = (VALUE **)data;
-    if (dead_entry != NULL) {
-        ruby_sized_xfree(*dead_entry, sizeof(VALUE));
-        *dead_entry = NULL;
-    }
+    ruby_sized_xfree(*dead_entry, sizeof(VALUE));
+    *dead_entry = NULL;
 
     VALUE *key_ptr = (VALUE *)key;
 
@@ -714,10 +700,8 @@ static int
 wkmap_compact_table_i(st_data_t key, st_data_t val_obj, st_data_t data, int _error)
 {
     VALUE **dead_entry = (VALUE **)data;
-    if (dead_entry != NULL) {
-        ruby_sized_xfree(*dead_entry, sizeof(VALUE));
-        *dead_entry = NULL;
-    }
+    ruby_sized_xfree(*dead_entry, sizeof(VALUE));
+    *dead_entry = NULL;
 
     VALUE *key_ptr = (VALUE *)key;
 
@@ -875,7 +859,7 @@ wkmap_aset(VALUE self, VALUE key, VALUE val)
     TypedData_Get_Struct(self, struct weakkeymap, &weakkeymap_type, w);
 
     if (!FL_ABLE(key) || SYMBOL_P(key) || RB_BIGNUM_TYPE_P(key) || RB_TYPE_P(key, T_FLOAT)) {
-        rb_raise(rb_eArgError, "WeakKeyMap must be garbage collectable");
+        rb_raise(rb_eArgError, "WeakKeyMap keys must be garbage collectable");
         UNREACHABLE_RETURN(Qnil);
     }