summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-06 06:51:31 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-06 06:51:31 +0000
commit7752fb4205ecf5de2021a7924c213516c8a8d858 (patch)
tree112f7e4154e500bf48240f8b4cfaab09e351fd6e /ext
parent6154ce97a7915ac70326c007ee04a22fe5742e04 (diff)
* object.c (rb_obj_methods): list singleton methods if recur
argument is false; list all methods otherwise. * numeric.c (num_step): double epsilon to make "1.1.step(1.5,0.1)" to work. * ext/gdbm/gdbm.c (fgdbm_values_at): new method to replace select(index..). * ext/sdbm/init.c (fsdbm_values_at): ditto. * ext/dbm/dbm.c (fdbm_values_at): ditto. * ext/dbm/dbm.c (DBM::VERSION): defined. * ext/gdbm/testgdbm.rb: replace select with values_at. * ext/sdbm/testsdbm.rb: ditto. * ext/dbm/testdbm.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/dbm/dbm.c23
-rw-r--r--ext/dbm/testdbm.rb13
-rw-r--r--ext/gdbm/gdbm.c19
-rw-r--r--ext/gdbm/testgdbm.rb4
-rw-r--r--ext/sdbm/init.c19
-rw-r--r--ext/sdbm/testsdbm.rb6
6 files changed, 74 insertions, 10 deletions
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index 6eb7cfcd20..c422394405 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -254,6 +254,8 @@ fdbm_select(argc, argv, obj)
}
}
else {
+ rb_warn("DBM#select(index..) is deprecated; use DBM#values_at");
+
for (i=0; i<argc; i++) {
rb_ary_push(new, fdbm_fetch(obj, argv[i], Qnil));
}
@@ -263,6 +265,22 @@ fdbm_select(argc, argv, obj)
}
static VALUE
+fdbm_values_at(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ VALUE new = rb_ary_new2(argc);
+ int i;
+
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new, fdbm_fetch(obj, argv[i], Qnil));
+ }
+
+ return new;
+}
+
+static VALUE
fdbm_delete(obj, keystr)
VALUE obj, keystr;
{
@@ -731,6 +749,7 @@ Init_dbm()
rb_define_method(rb_cDBM, "indexes", fdbm_indexes, -1);
rb_define_method(rb_cDBM, "indices", fdbm_indexes, -1);
rb_define_method(rb_cDBM, "select", fdbm_select, -1);
+ rb_define_method(rb_cDBM, "values_at", fdbm_values_at, -1);
rb_define_method(rb_cDBM, "length", fdbm_length, 0);
rb_define_method(rb_cDBM, "size", fdbm_length, 0);
rb_define_method(rb_cDBM, "empty?", fdbm_empty_p, 0);
@@ -759,4 +778,8 @@ Init_dbm()
rb_define_method(rb_cDBM, "to_a", fdbm_to_a, 0);
rb_define_method(rb_cDBM, "to_hash", fdbm_to_hash, 0);
+
+#ifdef DB_VERSION_STRING
+ rb_define_const(rb_cDBM, "VERSION", rb_str_new2(DB_VERSION_STRING));
+#endif
}
diff --git a/ext/dbm/testdbm.rb b/ext/dbm/testdbm.rb
index 0be627d346..7ccb3d7b23 100644
--- a/ext/dbm/testdbm.rb
+++ b/ext/dbm/testdbm.rb
@@ -32,9 +32,12 @@ class TestDBM < RUNIT::TestCase
assert_instance_of(DBM, @dbm = DBM.new(@path))
# prepare to make readonly DBM file
- DBM.open("tmptest_dbm_rdonly", 0400) {|dbm|
+ DBM.open("tmptest_dbm_rdonly") {|dbm|
dbm['foo'] = 'FOO'
}
+
+ File.chmod(0400, *Dir.glob("tmptest_dbm_rdonly.*"))
+
assert_instance_of(DBM, @dbm_rdonly = DBM.new("tmptest_dbm_rdonly", nil))
end
def teardown
@@ -83,7 +86,7 @@ class TestDBM < RUNIT::TestCase
}
begin
sleep 1
- assert_exception(Errno::EWOULDBLOCK) {
+ assert_exception(Errno::EWOULDBLOCK, "NEVER MIND IF YOU USE Berkeley DB3") {
begin
assert_instance_of(DBM, dbm2 = DBM.open("tmptest_dbm", 0644))
rescue Errno::EAGAIN, Errno::EACCES, Errno::EINVAL
@@ -154,7 +157,7 @@ class TestDBM < RUNIT::TestCase
def test_s_open_error
assert_instance_of(DBM, dbm = DBM.open("tmptest_dbm", 0))
- assert_exception(Errno::EACCES) {
+ assert_exception(Errno::EACCES, "NEVER MIND IF YOU USE Berkeley DB3") {
DBM.open("tmptest_dbm", 0)
}
dbm.close
@@ -245,11 +248,11 @@ class TestDBM < RUNIT::TestCase
assert_equals(values.reverse, @dbm.indexes(*keys.reverse))
end
- def test_select
+ def test_values_at
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@dbm[keys[0]], @dbm[keys[1]], @dbm[keys[2]] = values
- assert_equals(values.reverse, @dbm.select(*keys.reverse))
+ assert_equals(values.reverse, @dbm.values_at(*keys.reverse))
end
def test_select_with_block
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index edbd976231..84996896ab 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -352,6 +352,8 @@ fgdbm_select(argc, argv, obj)
}
}
else {
+ rb_warn("GDBM#select(index..) is deprecated; use GDBM#values_at");
+
for (i=0; i<argc; i++) {
rb_ary_push(new, rb_gdbm_fetch3(obj, argv[i]));
}
@@ -361,6 +363,22 @@ fgdbm_select(argc, argv, obj)
}
static VALUE
+fgdbm_values_at(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ VALUE new = rb_ary_new2(argc);
+ int i;
+
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new, rb_gdbm_fetch3(obj, argv[i]));
+ }
+
+ return new;
+}
+
+static VALUE
rb_gdbm_delete(obj, keystr)
VALUE obj, keystr;
{
@@ -938,6 +956,7 @@ Init_gdbm()
rb_define_method(rb_cGDBM, "indexes", fgdbm_indexes, -1);
rb_define_method(rb_cGDBM, "indices", fgdbm_indexes, -1);
rb_define_method(rb_cGDBM, "select", fgdbm_select, -1);
+ rb_define_method(rb_cGDBM, "values_at", fgdbm_values_at, -1);
rb_define_method(rb_cGDBM, "length", fgdbm_length, 0);
rb_define_method(rb_cGDBM, "size", fgdbm_length, 0);
rb_define_method(rb_cGDBM, "empty?", fgdbm_empty_p, 0);
diff --git a/ext/gdbm/testgdbm.rb b/ext/gdbm/testgdbm.rb
index 524d3f8ca3..529b0010a2 100644
--- a/ext/gdbm/testgdbm.rb
+++ b/ext/gdbm/testgdbm.rb
@@ -279,11 +279,11 @@ class TestGDBM < RUNIT::TestCase
assert_equals(values.reverse, @gdbm.indexes(*keys.reverse))
end
- def test_select
+ def test_values_at
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@gdbm[keys[0]], @gdbm[keys[1]], @gdbm[keys[2]] = values
- assert_equals(values.reverse, @gdbm.select(*keys.reverse))
+ assert_equals(values.reverse, @gdbm.values_at(*keys.reverse))
end
def test_select_with_block
diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c
index f20e3cfa58..f473555840 100644
--- a/ext/sdbm/init.c
+++ b/ext/sdbm/init.c
@@ -242,6 +242,8 @@ fsdbm_select(argc, argv, obj)
}
}
else {
+ rb_warn("SDBM#select(index..) is deprecated; use SDBM#values_at");
+
for (i=0; i<argc; i++) {
rb_ary_push(new, fsdbm_fetch(obj, argv[i], Qnil));
}
@@ -251,6 +253,22 @@ fsdbm_select(argc, argv, obj)
}
static VALUE
+fsdbm_values_at(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ VALUE new = rb_ary_new2(argc);
+ int i;
+
+ for (i=0; i<argc; i++) {
+ rb_ary_push(new, fsdbm_fetch(obj, argv[i], Qnil));
+ }
+
+ return new;
+}
+
+static VALUE
fsdbm_delete(obj, keystr)
VALUE obj, keystr;
{
@@ -728,6 +746,7 @@ Init_sdbm()
rb_define_method(rb_cDBM, "indexes", fsdbm_indexes, -1);
rb_define_method(rb_cDBM, "indices", fsdbm_indexes, -1);
rb_define_method(rb_cDBM, "select", fsdbm_select, -1);
+ rb_define_method(rb_cDBM, "values_at", fsdbm_values_at, -1);
rb_define_method(rb_cDBM, "length", fsdbm_length, 0);
rb_define_method(rb_cDBM, "size", fsdbm_length, 0);
rb_define_method(rb_cDBM, "empty?", fsdbm_empty_p, 0);
diff --git a/ext/sdbm/testsdbm.rb b/ext/sdbm/testsdbm.rb
index 550b47a008..3577d3606c 100644
--- a/ext/sdbm/testsdbm.rb
+++ b/ext/sdbm/testsdbm.rb
@@ -51,7 +51,7 @@ class TestSDBM < RUNIT::TestCase
end
def test_version
- STDERR.print SDBM::VERSION
+ assert(! SDBM.const_defined?(:VERSION))
end
def test_s_new_has_no_block
@@ -219,11 +219,11 @@ class TestSDBM < RUNIT::TestCase
assert_equals(values.reverse, @sdbm.indexes(*keys.reverse))
end
- def test_select
+ def test_values_at
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@sdbm[keys[0]], @sdbm[keys[1]], @sdbm[keys[2]] = values
- assert_equals(values.reverse, @sdbm.select(*keys.reverse))
+ assert_equals(values.reverse, @sdbm.values_at(*keys.reverse))
end
def test_select_with_block