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

ruby-changes:36033

From: nobu <ko1@a...>
Date: Thu, 23 Oct 2014 21:43:10 +0900 (JST)
Subject: [ruby-changes:36033] nobu:r48114 (trunk): hash.c: rb_hash_delete does not call the block

nobu	2014-10-23 21:42:57 +0900 (Thu, 23 Oct 2014)

  New Revision: 48114

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

  Log:
    hash.c: rb_hash_delete does not call the block
    
    * hash.c (rb_hash_delete): now does not call the block given to
      the current method.  [ruby-core:65861] [Bug #10413]

  Added directories:
    trunk/ext/-test-/hash/
    trunk/test/-ext-/hash/
  Added files:
    trunk/ext/-test-/hash/delete.c
    trunk/ext/-test-/hash/extconf.rb
    trunk/ext/-test-/hash/init.c
    trunk/test/-ext-/hash/test_delete.rb
  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/hash.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48113)
+++ ChangeLog	(revision 48114)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Oct 23 21:42:54 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (rb_hash_delete): now does not call the block given to
+	  the current method.  [ruby-core:65861] [Bug #10413]
+
 Thu Oct 23 19:13:26 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_method.c (rb_method_entry_make): warn redefinition only for
Index: ext/-test-/hash/delete.c
===================================================================
--- ext/-test-/hash/delete.c	(revision 0)
+++ ext/-test-/hash/delete.c	(revision 48114)
@@ -0,0 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/hash/delete.c#L1
+#include "ruby.h"
+
+static VALUE
+hash_delete(VALUE hash, VALUE key)
+{
+    VALUE ret = rb_hash_delete(hash, key);
+    return ret == Qundef ? Qfalse : Qtrue;
+}
+
+void
+Init_delete(VALUE klass)
+{
+    rb_define_method(klass, "delete", hash_delete, 1);
+}

Property changes on: ext/-test-/hash/delete.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ext/-test-/hash/init.c
===================================================================
--- ext/-test-/hash/init.c	(revision 0)
+++ ext/-test-/hash/init.c	(revision 48114)
@@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/hash/init.c#L1
+#include "ruby.h"
+
+#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);}
+
+void
+Init_hash(void)
+{
+    VALUE mBug = rb_define_module("Bug");
+    VALUE klass = rb_define_class_under(mBug, "Hash", rb_cHash);
+    TEST_INIT_FUNCS(init);
+}

Property changes on: ext/-test-/hash/init.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ext/-test-/hash/extconf.rb
===================================================================
--- ext/-test-/hash/extconf.rb	(revision 0)
+++ ext/-test-/hash/extconf.rb	(revision 48114)
@@ -0,0 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/hash/extconf.rb#L1
+$INCFLAGS << " -I$(topdir) -I$(top_srcdir)"
+$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
+inits = $srcs.map {|s| File.basename(s, ".*")}
+inits.delete("init")
+inits.map! {|s|"X(#{s})"}
+$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\""
+create_makefile("-test-/hash")

Property changes on: ext/-test-/hash/extconf.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: hash.c
===================================================================
--- hash.c	(revision 48113)
+++ hash.c	(revision 48114)
@@ -972,8 +972,8 @@ rb_hash_index(VALUE hash, VALUE value) https://github.com/ruby/ruby/blob/trunk/hash.c#L972
     return rb_hash_key(hash, value);
 }
 
-static VALUE
-rb_hash_delete_key(VALUE hash, VALUE key)
+VALUE
+rb_hash_delete(VALUE hash, VALUE key)
 {
     st_data_t ktmp = (st_data_t)key, val;
 
@@ -1008,13 +1008,13 @@ rb_hash_delete_key(VALUE hash, VALUE key https://github.com/ruby/ruby/blob/trunk/hash.c#L1008
  *
  */
 
-VALUE
-rb_hash_delete(VALUE hash, VALUE key)
+static VALUE
+rb_hash_delete_m(VALUE hash, VALUE key)
 {
     VALUE val;
 
     rb_hash_modify_check(hash);
-    val = rb_hash_delete_key(hash, key);
+    val = rb_hash_delete(hash, key);
     if (val != Qundef) return val;
     if (rb_block_given_p()) {
 	return rb_yield(key);
@@ -1066,7 +1066,7 @@ rb_hash_shift(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1066
 	else {
 	    rb_hash_foreach(hash, shift_i_safe, (VALUE)&var);
 	    if (var.key != Qundef) {
-		rb_hash_delete_key(hash, var.key);
+		rb_hash_delete(hash, var.key);
 		return rb_assoc_new(var.key, var.val);
 	    }
 	}
@@ -3881,7 +3881,7 @@ Init_Hash(void) https://github.com/ruby/ruby/blob/trunk/hash.c#L3881
     rb_define_method(rb_cHash,"values_at", rb_hash_values_at, -1);
 
     rb_define_method(rb_cHash,"shift", rb_hash_shift, 0);
-    rb_define_method(rb_cHash,"delete", rb_hash_delete, 1);
+    rb_define_method(rb_cHash,"delete", rb_hash_delete_m, 1);
     rb_define_method(rb_cHash,"delete_if", rb_hash_delete_if, 0);
     rb_define_method(rb_cHash,"keep_if", rb_hash_keep_if, 0);
     rb_define_method(rb_cHash,"select", rb_hash_select, 0);
Index: NEWS
===================================================================
--- NEWS	(revision 48113)
+++ NEWS	(revision 48114)
@@ -289,6 +289,8 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L289
   * RUBY_INTERNAL_EVENT_GC_EXIT
     r47528
 
+* rb_hash_delete() now does not call the block given to the current method.
+
 === Build system updates
 
 * jemalloc is optionally supported via `./configure --with-jemalloc`
Index: test/-ext-/hash/test_delete.rb
===================================================================
--- test/-ext-/hash/test_delete.rb	(revision 0)
+++ test/-ext-/hash/test_delete.rb	(revision 48114)
@@ -0,0 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/hash/test_delete.rb#L1
+require 'test/unit'
+require '-test-/hash'
+
+class TestHash < Test::Unit::TestCase
+  class TestDelete < Test::Unit::TestCase
+    def test_delete
+      hash = Bug::Hash.new
+      hash[1] = 2
+      called = false
+      assert_equal 1, hash.size
+      assert_equal true, hash.delete(1) {called = true}
+      assert_equal false, called, "block called"
+      assert_equal 0, hash.size
+      assert_equal false, hash.delete(1) {called = true}
+      assert_equal false, called, "block called"
+      assert_equal 0, hash.size
+    end
+  end
+end

Property changes on: test/-ext-/hash/test_delete.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


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

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