зеркало из https://github.com/github/ruby.git
* array.c: remove #indexes, #indices.
* hash.c: ditto. * ext/dbm/dbm.c: remove #indexes, #indices, "values_at" warning from #select. * ext/gdbm/gdbm.c: ditto. * ext/sdbm/init.c: ditto. * ext/dbm/dbm.c (Init_dbm): set VERSION constant as "unknown" when DB_VERSION_STRING is not available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
6ea8b50946
Коммит
21606c6ec5
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
Fri Jun 11 22:08:50 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* array.c: remove #indexes, #indices.
|
||||
|
||||
* hash.c: ditto.
|
||||
|
||||
* ext/dbm/dbm.c: remove #indexes, #indices, "values_at" warning
|
||||
from #select.
|
||||
|
||||
* ext/gdbm/gdbm.c: ditto.
|
||||
|
||||
* ext/sdbm/init.c: ditto.
|
||||
|
||||
* ext/dbm/dbm.c (Init_dbm): set VERSION constant as "unknown" when
|
||||
DB_VERSION_STRING is not available.
|
||||
|
||||
Thu Jun 10 19:19:41 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* ext/sdbm/init.c (fsdbm_store): sdbm should use StringValue().
|
||||
|
|
27
array.c
27
array.c
|
@ -951,31 +951,6 @@ rb_ary_rindex(ary, val)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* array.indexes( i1, i2, ... iN ) => an_array
|
||||
* array.indices( i1, i2, ... iN ) => an_array
|
||||
*
|
||||
* Deprecated; use <code>Array#select</code>.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
rb_ary_indexes(argc, argv, ary)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE ary;
|
||||
{
|
||||
VALUE new_ary;
|
||||
long i;
|
||||
|
||||
new_ary = rb_ary_new2(argc);
|
||||
for (i=0; i<argc; i++) {
|
||||
rb_ary_push(new_ary, rb_ary_aref(1, argv+i, ary));
|
||||
}
|
||||
|
||||
return new_ary;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_ary_to_ary(obj)
|
||||
VALUE obj;
|
||||
|
@ -3029,8 +3004,6 @@ Init_Array()
|
|||
rb_define_method(rb_cArray, "empty?", rb_ary_empty_p, 0);
|
||||
rb_define_method(rb_cArray, "index", rb_ary_index, 1);
|
||||
rb_define_method(rb_cArray, "rindex", rb_ary_rindex, 1);
|
||||
rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
|
||||
rb_define_method(rb_cArray, "indices", rb_ary_indexes, -1);
|
||||
rb_define_method(rb_cArray, "join", rb_ary_join_m, -1);
|
||||
rb_define_method(rb_cArray, "reverse", rb_ary_reverse_m, 0);
|
||||
rb_define_method(rb_cArray, "reverse!", rb_ary_reverse_bang, 0);
|
||||
|
|
|
@ -220,57 +220,25 @@ fdbm_index(obj, valstr)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
fdbm_indexes(argc, argv, obj)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
fdbm_select(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE new;
|
||||
VALUE new = rb_ary_new();
|
||||
int i;
|
||||
datum key, val;
|
||||
DBM *dbm;
|
||||
struct dbmdata *dbmp;
|
||||
|
||||
new = rb_ary_new2(argc);
|
||||
for (i=0; i<argc; i++) {
|
||||
rb_ary_push(new, fdbm_fetch(obj, argv[i], Qnil));
|
||||
}
|
||||
GetDBM(obj, dbmp);
|
||||
dbm = dbmp->di_dbm;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
fdbm_select(argc, argv, obj)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE new = rb_ary_new2(argc);
|
||||
int i;
|
||||
|
||||
if (rb_block_given_p()) {
|
||||
datum key, val;
|
||||
DBM *dbm;
|
||||
struct dbmdata *dbmp;
|
||||
|
||||
if (argc > 0) {
|
||||
rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
|
||||
}
|
||||
GetDBM(obj, dbmp);
|
||||
dbm = dbmp->di_dbm;
|
||||
|
||||
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
|
||||
VALUE assoc;
|
||||
val = dbm_fetch(dbm, key);
|
||||
assoc = rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
|
||||
rb_tainted_str_new(val.dptr, val.dsize));
|
||||
if (RTEST(rb_yield(assoc)))
|
||||
rb_ary_push(new, assoc);
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
|
||||
VALUE assoc;
|
||||
val = dbm_fetch(dbm, key);
|
||||
assoc = rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
|
||||
rb_tainted_str_new(val.dptr, val.dsize));
|
||||
if (RTEST(rb_yield(assoc)))
|
||||
rb_ary_push(new, assoc);
|
||||
}
|
||||
|
||||
return new;
|
||||
|
@ -766,8 +734,6 @@ Init_dbm()
|
|||
rb_define_method(rb_cDBM, "[]=", fdbm_store, 2);
|
||||
rb_define_method(rb_cDBM, "store", fdbm_store, 2);
|
||||
rb_define_method(rb_cDBM, "index", fdbm_index, 1);
|
||||
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);
|
||||
|
@ -807,5 +773,7 @@ Init_dbm()
|
|||
|
||||
#ifdef DB_VERSION_STRING
|
||||
rb_define_const(rb_cDBM, "VERSION", rb_str_new2(DB_VERSION_STRING));
|
||||
#else
|
||||
rb_define_const(rb_cDBM, "VERSION", rb_str_new2("unknown"));
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -316,56 +316,24 @@ fgdbm_index(obj, valstr)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
fgdbm_indexes(argc, argv, obj)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
fgdbm_select(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE new;
|
||||
VALUE new = rb_ary_new();
|
||||
int i;
|
||||
GDBM_FILE dbm;
|
||||
struct dbmdata *dbmp;
|
||||
VALUE keystr;
|
||||
|
||||
new = rb_ary_new2(argc);
|
||||
for (i=0; i<argc; i++) {
|
||||
rb_ary_push(new, rb_gdbm_fetch3(obj, argv[i]));
|
||||
}
|
||||
GetDBM(obj, dbmp);
|
||||
dbm = dbmp->di_dbm;
|
||||
|
||||
return new;
|
||||
}
|
||||
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
|
||||
keystr = rb_gdbm_nextkey(dbm, keystr)) {
|
||||
VALUE assoc = rb_assoc_new(keystr, rb_gdbm_fetch2(dbm, keystr));
|
||||
|
||||
static VALUE
|
||||
fgdbm_select(argc, argv, obj)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE new = rb_ary_new2(argc);
|
||||
int i;
|
||||
|
||||
if (rb_block_given_p()) {
|
||||
GDBM_FILE dbm;
|
||||
struct dbmdata *dbmp;
|
||||
VALUE keystr;
|
||||
|
||||
if (argc > 0) {
|
||||
rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
|
||||
}
|
||||
GetDBM(obj, dbmp);
|
||||
dbm = dbmp->di_dbm;
|
||||
|
||||
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
|
||||
keystr = rb_gdbm_nextkey(dbm, keystr)) {
|
||||
VALUE assoc = rb_assoc_new(keystr, rb_gdbm_fetch2(dbm, keystr));
|
||||
|
||||
if (RTEST(rb_yield(assoc)))
|
||||
rb_ary_push(new, assoc);
|
||||
}
|
||||
}
|
||||
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]));
|
||||
}
|
||||
if (RTEST(rb_yield(assoc)))
|
||||
rb_ary_push(new, assoc);
|
||||
}
|
||||
|
||||
return new;
|
||||
|
@ -970,9 +938,7 @@ Init_gdbm()
|
|||
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, "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, "select", fgdbm_select, 0);
|
||||
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);
|
||||
|
|
|
@ -196,57 +196,25 @@ fsdbm_index(obj, valstr)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
fsdbm_indexes(argc, argv, obj)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
fsdbm_select(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE new;
|
||||
VALUE new = rb_ary_new();
|
||||
int i;
|
||||
datum key, val;
|
||||
DBM *dbm;
|
||||
struct dbmdata *dbmp;
|
||||
|
||||
new = rb_ary_new2(argc);
|
||||
for (i=0; i<argc; i++) {
|
||||
rb_ary_push(new, fsdbm_fetch(obj, argv[i], Qnil));
|
||||
}
|
||||
GetDBM(obj, dbmp);
|
||||
dbm = dbmp->di_dbm;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
fsdbm_select(argc, argv, obj)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE new = rb_ary_new2(argc);
|
||||
int i;
|
||||
|
||||
if (rb_block_given_p()) {
|
||||
datum key, val;
|
||||
DBM *dbm;
|
||||
struct dbmdata *dbmp;
|
||||
|
||||
if (argc > 0) {
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
|
||||
}
|
||||
GetDBM(obj, dbmp);
|
||||
dbm = dbmp->di_dbm;
|
||||
|
||||
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
||||
VALUE assoc;
|
||||
val = sdbm_fetch(dbm, key);
|
||||
assoc = rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
|
||||
rb_tainted_str_new(val.dptr, val.dsize));
|
||||
if (RTEST(rb_yield(assoc)))
|
||||
rb_ary_push(new, assoc);
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
||||
VALUE assoc;
|
||||
val = sdbm_fetch(dbm, key);
|
||||
assoc = rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
|
||||
rb_tainted_str_new(val.dptr, val.dsize));
|
||||
if (RTEST(rb_yield(assoc)))
|
||||
rb_ary_push(new, assoc);
|
||||
}
|
||||
|
||||
return new;
|
||||
|
@ -749,9 +717,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, "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, "select", fsdbm_select, 0);
|
||||
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);
|
||||
|
|
72
hash.c
72
hash.c
|
@ -558,32 +558,6 @@ rb_hash_index(hash, value)
|
|||
return args[1];
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* hsh.indexes(key, ...) => array
|
||||
* hsh.indices(key, ...) => array
|
||||
*
|
||||
* Deprecated in favor of <code>Hash#select</code>.
|
||||
*
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
rb_hash_indexes(argc, argv, hash)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE hash;
|
||||
{
|
||||
VALUE indexes;
|
||||
int i;
|
||||
|
||||
indexes = rb_ary_new2(argc);
|
||||
for (i=0; i<argc; i++) {
|
||||
RARRAY(indexes)->ptr[i] = rb_hash_aref(hash, argv[i]);
|
||||
RARRAY(indexes)->len++;
|
||||
}
|
||||
return indexes;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* hsh.delete(key) => value
|
||||
|
@ -770,7 +744,7 @@ rb_hash_values_at(argc, argv, hash)
|
|||
VALUE *argv;
|
||||
VALUE hash;
|
||||
{
|
||||
VALUE result = rb_ary_new();
|
||||
VALUE result = rb_ary_new2(argc);
|
||||
long i;
|
||||
|
||||
for (i=0; i<argc; i++) {
|
||||
|
@ -793,16 +767,11 @@ rb_hash_values_at(argc, argv, hash)
|
|||
*/
|
||||
|
||||
VALUE
|
||||
rb_hash_select(argc, argv, hash)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
rb_hash_select(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
VALUE result;
|
||||
|
||||
if (argc > 0) {
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
|
||||
}
|
||||
result = rb_ary_new();
|
||||
rb_hash_foreach(hash, select_i, result);
|
||||
return result;
|
||||
|
@ -2035,16 +2004,11 @@ env_values_at(argc, argv)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
env_select(argc, argv)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
env_select()
|
||||
{
|
||||
VALUE result;
|
||||
char **env;
|
||||
|
||||
if (argc > 0) {
|
||||
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
|
||||
}
|
||||
result = rb_ary_new();
|
||||
env = GET_ENVIRON(environ);
|
||||
while (*env) {
|
||||
|
@ -2230,28 +2194,6 @@ env_index(dmy, value)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
env_indexes(argc, argv)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
{
|
||||
int i;
|
||||
VALUE indexes = rb_ary_new2(argc);
|
||||
|
||||
for (i=0;i<argc;i++) {
|
||||
VALUE tmp = rb_check_string_type(argv[i]);
|
||||
if (NIL_P(tmp)) {
|
||||
RARRAY(indexes)->ptr[i] = Qnil;
|
||||
}
|
||||
else {
|
||||
RARRAY(indexes)->ptr[i] = env_str_new2(getenv(RSTRING(tmp)->ptr));
|
||||
}
|
||||
RARRAY(indexes)->len = i+1;
|
||||
}
|
||||
|
||||
return indexes;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
env_to_hash()
|
||||
{
|
||||
|
@ -2400,8 +2342,6 @@ Init_Hash()
|
|||
rb_define_method(rb_cHash,"default=", rb_hash_set_default, 1);
|
||||
rb_define_method(rb_cHash,"default_proc", rb_hash_default_proc, 0);
|
||||
rb_define_method(rb_cHash,"index", rb_hash_index, 1);
|
||||
rb_define_method(rb_cHash,"indexes", rb_hash_indexes, -1);
|
||||
rb_define_method(rb_cHash,"indices", rb_hash_indexes, -1);
|
||||
rb_define_method(rb_cHash,"size", rb_hash_size, 0);
|
||||
rb_define_method(rb_cHash,"length", rb_hash_size, 0);
|
||||
rb_define_method(rb_cHash,"empty?", rb_hash_empty_p, 0);
|
||||
|
@ -2419,7 +2359,7 @@ Init_Hash()
|
|||
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_if", rb_hash_delete_if, 0);
|
||||
rb_define_method(rb_cHash,"select", rb_hash_select, -1);
|
||||
rb_define_method(rb_cHash,"select", rb_hash_select, 0);
|
||||
rb_define_method(rb_cHash,"reject", rb_hash_reject, 0);
|
||||
rb_define_method(rb_cHash,"reject!", rb_hash_reject_bang, 0);
|
||||
rb_define_method(rb_cHash,"clear", rb_hash_clear, 0);
|
||||
|
@ -2454,7 +2394,7 @@ Init_Hash()
|
|||
rb_define_singleton_method(envtbl,"clear", env_clear, 0);
|
||||
rb_define_singleton_method(envtbl,"reject", env_reject, 0);
|
||||
rb_define_singleton_method(envtbl,"reject!", env_reject_bang, 0);
|
||||
rb_define_singleton_method(envtbl,"select", env_select, -1);
|
||||
rb_define_singleton_method(envtbl,"select", env_select, 0);
|
||||
rb_define_singleton_method(envtbl,"shift", env_shift, 0);
|
||||
rb_define_singleton_method(envtbl,"invert", env_invert, 0);
|
||||
rb_define_singleton_method(envtbl,"replace", env_replace, 1);
|
||||
|
@ -2464,8 +2404,6 @@ Init_Hash()
|
|||
rb_define_singleton_method(envtbl,"to_a", env_to_a, 0);
|
||||
rb_define_singleton_method(envtbl,"to_s", env_to_s, 0);
|
||||
rb_define_singleton_method(envtbl,"index", env_index, 1);
|
||||
rb_define_singleton_method(envtbl,"indexes", env_indexes, -1);
|
||||
rb_define_singleton_method(envtbl,"indices", env_indexes, -1);
|
||||
rb_define_singleton_method(envtbl,"size", env_size, 0);
|
||||
rb_define_singleton_method(envtbl,"length", env_size, 0);
|
||||
rb_define_singleton_method(envtbl,"empty?", env_empty_p, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче