summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-08 03:15:28 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-08 03:15:28 +0000
commit703fb3d9becd0626c57f343ce16635c0434f19c6 (patch)
tree87cde4963e024d99d58a9d38c847b38db52214ce
parent0042ccef2cea6fafecf2edbfee90dd160cee7ba7 (diff)
* 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
-rw-r--r--ChangeLog7
-rw-r--r--ext/gdbm/gdbm.c13
-rw-r--r--ext/sdbm/init.c2
-rw-r--r--test/dbm/test_dbm.rb6
-rw-r--r--test/gdbm/test_gdbm.rb6
5 files changed, 25 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index e600efd..d5949ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Nov 8 12:10:15 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * 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 <matz@ruby-lang.org>
* configure.in: detect stdio buffer pointers for uClibc. a patch
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index e6a6e0d..1e83608 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 b697ca7..2e4f75c 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 5cf8acb..1845a6d 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 8c86d45..7e28d51 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])