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

ruby-changes:12449

From: nobu <ko1@a...>
Date: Thu, 16 Jul 2009 18:30:43 +0900 (JST)
Subject: [ruby-changes:12449] Ruby:r24149 (trunk): * hash.c (rb_hash_aset, recursive_hash): rejects recursive hash.

nobu	2009-07-16 18:30:23 +0900 (Thu, 16 Jul 2009)

  New Revision: 24149

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

  Log:
    * hash.c (rb_hash_aset, recursive_hash): rejects recursive hash.
      [ruby-core:22921]

  Modified files:
    trunk/ChangeLog
    trunk/hash.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24148)
+++ ChangeLog	(revision 24149)
@@ -1,3 +1,8 @@
+Thu Jul 16 18:30:20 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (rb_hash_aset, recursive_hash): rejects recursive hash.
+	  [ruby-core:22921]
+
 Thu Jul 16 18:28:09 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* id.c (Init_id), vm.c (vm_exec): @#__ThrowState__ is no longer
Index: hash.c
===================================================================
--- hash.c	(revision 24148)
+++ hash.c	(revision 24149)
@@ -1016,6 +1016,9 @@
 rb_hash_aset(VALUE hash, VALUE key, VALUE val)
 {
     rb_hash_modify(hash);
+    if (hash == key) {
+	rb_raise(rb_eArgError, "recursive key for hash");
+    }
     if (RHASH(hash)->ntbl->type == &identhash || rb_obj_class(key) != rb_cString) {
 	st_insert(RHASH(hash)->ntbl, key, val);
     }
@@ -1546,7 +1549,7 @@
     VALUE hval;
 
     if (recur) {
-	return LONG2FIX(0);
+	rb_raise(rb_eArgError, "recursive key for hash");
     }
     if (!RHASH(hash)->ntbl)
         return LONG2FIX(0);

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

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