From 703fb3d9becd0626c57f343ce16635c0434f19c6 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 8 Nov 2008 03:15:28 +0000 Subject: [PATCH] * ext/gdbm/gdbm.c (fgdbm_index): make #index warn like Hash. [ruby-dev:37039] * ext/sdbm/init.c (Init_sdbm): typo fixed. [ruby-dev:37039] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ ext/gdbm/gdbm.c | 13 +++++++++++-- ext/sdbm/init.c | 2 +- test/dbm/test_dbm.rb | 6 +++--- test/gdbm/test_gdbm.rb | 6 +++--- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e600efdb91..d5949aef3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Nov 8 12:10:15 2008 Yukihiro Matsumoto + + * ext/gdbm/gdbm.c (fgdbm_index): make #index warn like Hash. + [ruby-dev:37039] + + * ext/sdbm/init.c (Init_sdbm): typo fixed. [ruby-dev:37039] + Sat Nov 8 07:07:48 2008 Yukihiro Matsumoto * configure.in: detect stdio buffer pointers for uClibc. a patch diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c index e6a6e0d039..1e83608132 100644 --- a/ext/gdbm/gdbm.c +++ b/ext/gdbm/gdbm.c @@ -396,13 +396,13 @@ fgdbm_fetch_m(int argc, VALUE *argv, VALUE obj) /* * call-seq: - * gdbm.index(value) -> key + * gdbm.key(value) -> key * * Returns the _key_ for a given _value_. If several keys may map to the * same value, the key that is found first will be returned. */ static VALUE -fgdbm_index(VALUE obj, VALUE valstr) +fgdbm_key(VALUE obj, VALUE valstr) { struct dbmdata *dbmp; GDBM_FILE dbm; @@ -424,6 +424,14 @@ fgdbm_index(VALUE obj, VALUE valstr) return Qnil; } +/* :nodoc: */ +static VALUE +fgdbm_index(VALUE obj, VALUE value) +{ + rb_warn("GDBM#index is deprecated; use GDBM#key"); + return fgdbm_key(obj, value); +} + /* * call-seq: * gdbm.select { |value| block } -> array @@ -1180,6 +1188,7 @@ Init_gdbm(void) rb_define_method(rb_cGDBM, "[]=", fgdbm_store, 2); rb_define_method(rb_cGDBM, "store", fgdbm_store, 2); rb_define_method(rb_cGDBM, "index", fgdbm_index, 1); + rb_define_method(rb_cGDBM, "key", fgdbm_key, 1); rb_define_method(rb_cGDBM, "select", fgdbm_select, 0); rb_define_method(rb_cGDBM, "values_at", fgdbm_values_at, -1); rb_define_method(rb_cGDBM, "length", fgdbm_length, 0); diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c index b697ca7380..2e4f75cfbf 100644 --- a/ext/sdbm/init.c +++ b/ext/sdbm/init.c @@ -678,7 +678,7 @@ Init_sdbm() rb_define_method(rb_cDBM, "[]=", fsdbm_store, 2); rb_define_method(rb_cDBM, "store", fsdbm_store, 2); rb_define_method(rb_cDBM, "index", fsdbm_index, 1); - rb_define_method(rb_cDBM, "index", fsdbm_key, 1); + rb_define_method(rb_cDBM, "key", fsdbm_key, 1); rb_define_method(rb_cDBM, "select", fsdbm_select, 0); rb_define_method(rb_cDBM, "values_at", fsdbm_values_at, -1); rb_define_method(rb_cDBM, "length", fsdbm_length, 0); diff --git a/test/dbm/test_dbm.rb b/test/dbm/test_dbm.rb index 5cf8acb68c..1845a6db55 100644 --- a/test/dbm/test_dbm.rb +++ b/test/dbm/test_dbm.rb @@ -217,7 +217,7 @@ if defined? DBM n = 0 ret = @dbm.each_pair {|key, val| - assert_not_nil(i = keys.key(key)) + assert_not_nil(i = keys.index(key)) assert_equal(val, values[i]) n += 1 @@ -239,7 +239,7 @@ if defined? DBM n = 0 ret = @dbm.each_value {|val| assert_not_nil(key = @dbm.key(val)) - assert_not_nil(i = keys.key(key)) + assert_not_nil(i = keys.index(key)) assert_equal(val, values[i]) n += 1 @@ -260,7 +260,7 @@ if defined? DBM n = 0 ret = @dbm.each_key {|key| - assert_not_nil(i = keys.key(key)) + assert_not_nil(i = keys.index(key)) assert_equal(@dbm[key], values[i]) n += 1 diff --git a/test/gdbm/test_gdbm.rb b/test/gdbm/test_gdbm.rb index 8c86d4510d..7e28d5121d 100644 --- a/test/gdbm/test_gdbm.rb +++ b/test/gdbm/test_gdbm.rb @@ -276,9 +276,9 @@ if defined? GDBM } end - def test_index + def test_key assert_equal('bar', @gdbm['foo'] = 'bar') - assert_equal('foo', @gdbm.index('bar')) + assert_equal('foo', @gdbm.key('bar')) assert_nil(@gdbm['bar']) end @@ -354,7 +354,7 @@ if defined? GDBM n = 0 ret = @gdbm.each_value {|val| - assert_not_nil(key = @gdbm.index(val)) + assert_not_nil(key = @gdbm.key(val)) assert_not_nil(i = keys.index(key)) assert_equal(val, values[i])