* ext/dbm/dbm.c (fdbm_select): [ruby-dev:25132]

* ext/sdbm/init.c: ditto.

* ext/gdbm/gdbm.c: ditto.

* eval.c (proc_invoke): merge Guy Decoux's argument preserve
  patch in [ruby-core:03874].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-12-09 02:19:50 +00:00
Родитель 32481c4126
Коммит 3d66cc4c6b
5 изменённых файлов: 140 добавлений и 160 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Thu Dec 9 10:54:36 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/dbm/dbm.c (fdbm_select): [ruby-dev:25132]
* ext/sdbm/init.c: ditto.
* ext/gdbm/gdbm.c: ditto.
Thu Dec 9 10:19:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/socket/test_socket.rb (test_setsockopt): use SO_LINGER instead
@ -71,6 +79,11 @@ Wed Dec 8 20:13:06 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* lib/mkmf.rb (VPATH): specify the implicit path separator for DJGPP.
Wed Dec 8 17:48:22 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (proc_invoke): merge Guy Decoux's argument preserve
patch in [ruby-core:03874].
Wed Dec 8 17:37:33 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_pipe_exec): need to close original socket

26
eval.c
Просмотреть файл

@ -3237,11 +3237,19 @@ rb_eval(self, n)
}
}
if (nd_type(node) == NODE_ZSUPER) {
if (ruby_frame->prev && (ruby_frame->prev->flags & FRAME_DMETH)) {
rb_raise(rb_eRuntimeError, "super: specify arguments explicitly");
}
argc = ruby_frame->argc;
argv = ruby_scope->local_vars + 2;
if (argc && ruby_frame->prev &&
(ruby_frame->prev->flags & FRAME_DMETH)) {
if (TYPE(RBASIC(ruby_scope)->klass) != T_ARRAY ||
RARRAY(RBASIC(ruby_scope)->klass)->len != argc) {
rb_raise(rb_eRuntimeError,
"super: specify arguments explicitly");
}
argv = RARRAY(RBASIC(ruby_scope)->klass)->ptr;
}
else {
argv = ruby_scope->local_vars + 2;
}
}
else {
BEGIN_CALLARGS;
@ -8194,7 +8202,7 @@ proc_invoke(proc, args, self, klass)
volatile int safe = ruby_safe_level;
volatile VALUE old_wrapper = ruby_wrapper;
volatile int pcall, avalue = Qtrue;
VALUE bvar = Qnil;
VALUE bvar = Qnil, tmp = args;
Data_Get_Struct(proc, struct BLOCK, data);
pcall = (data->flags & BLOCK_LAMBDA) ? YIELD_LAMBDA_CALL : 0;
@ -8217,6 +8225,14 @@ proc_invoke(proc, args, self, klass)
_block.block_obj = bvar;
if (self != Qundef) _block.frame.self = self;
if (klass) _block.frame.last_class = klass;
_block.frame.argc = RARRAY(tmp)->len;
if (_block.frame.argc && (ruby_frame->flags & FRAME_DMETH)) {
NEWOBJ(scope, struct SCOPE);
OBJSETUP(scope, tmp, T_SCOPE);
scope->local_tbl = _block.scope->local_tbl;
scope->local_vars = _block.scope->local_vars;
_block.scope = scope;
}
ruby_block = &_block;
PUSH_ITER(ITER_CUR);

Просмотреть файл

@ -43,6 +43,11 @@ closed_dbm()
if (dbmp->di_dbm == 0) closed_dbm();\
}
#define GetDBM2(obj, data, dbm) {\
GetDBM(obj, data);\
(dbm) = dbmp->di_dbm;\
}
static void
free_dbm(dbmp)
struct dbmdata *dbmp;
@ -161,8 +166,7 @@ fdbm_fetch(obj, keystr, ifnone)
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
value = dbm_fetch(dbm, key);
if (value.dptr == 0) {
if (ifnone == Qnil && rb_block_given_p())
@ -207,8 +211,7 @@ fdbm_index(obj, valstr)
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
@ -229,16 +232,17 @@ fdbm_select(obj)
DBM *dbm;
struct dbmdata *dbmp;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
VALUE assoc;
VALUE assoc, v;
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)))
v = rb_yield(assoc);
if (RTEST(v)) {
rb_ary_push(new, assoc);
}
GetDBM2(obj, dbmp, dbm);
}
return new;
@ -282,8 +286,7 @@ fdbm_delete(obj, keystr)
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
value = dbm_fetch(dbm, key);
if (value.dptr == 0) {
@ -314,8 +317,7 @@ fdbm_shift(obj)
VALUE keystr, valstr;
fdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
key = dbm_firstkey(dbm);
@ -340,8 +342,7 @@ fdbm_delete_if(obj)
int i, status = 0, n;
fdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
n = dbmp->di_size;
dbmp->di_size = -1;
@ -352,6 +353,7 @@ fdbm_delete_if(obj)
ret = rb_protect(rb_yield, rb_assoc_new(rb_str_dup(keystr), valstr), &status);
if (status != 0) break;
if (RTEST(ret)) rb_ary_push(ary, keystr);
GetDBM2(obj, dbmp, dbm);
}
for (i = 0; i < RARRAY(ary)->len; i++) {
@ -378,8 +380,7 @@ fdbm_clear(obj)
DBM *dbm;
fdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
while (key = dbm_firstkey(dbm), key.dptr) {
if (dbm_delete(dbm, key)) {
@ -401,8 +402,7 @@ fdbm_invert(obj)
VALUE keystr, valstr;
VALUE hash = rb_hash_new();
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
keystr = rb_tainted_str_new(key.dptr, key.dsize);
@ -470,9 +470,8 @@ fdbm_store(obj, keystr, valstr)
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
GetDBM(obj, dbmp);
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
dbm = dbmp->di_dbm;
if (dbm_store(dbm, key, val, DBM_REPLACE)) {
#ifdef HAVE_DBM_CLEARERR
dbm_clearerr(dbm);
@ -493,9 +492,8 @@ fdbm_length(obj)
DBM *dbm;
int i = 0;
GetDBM(obj, dbmp);
GetDBM2(obj, dbmp, dbm);
if (dbmp->di_size > 0) return INT2FIX(dbmp->di_size);
dbm = dbmp->di_dbm;
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
i++;
@ -514,7 +512,7 @@ fdbm_empty_p(obj)
DBM *dbm;
int i = 0;
GetDBM(obj, dbmp);
GetDBM2(obj, dbmp, dbm);
if (dbmp->di_size < 0) {
dbm = dbmp->di_dbm;
@ -537,11 +535,11 @@ fdbm_each_value(obj)
struct dbmdata *dbmp;
DBM *dbm;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
rb_yield(rb_tainted_str_new(val.dptr, val.dsize));
GetDBM2(obj, dbmp, dbm);
}
return obj;
}
@ -554,10 +552,10 @@ fdbm_each_key(obj)
struct dbmdata *dbmp;
DBM *dbm;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
rb_yield(rb_tainted_str_new(key.dptr, key.dsize));
GetDBM2(obj, dbmp, dbm);
}
return obj;
}
@ -571,14 +569,14 @@ fdbm_each_pair(obj)
struct dbmdata *dbmp;
VALUE keystr, valstr;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
keystr = rb_tainted_str_new(key.dptr, key.dsize);
valstr = rb_tainted_str_new(val.dptr, val.dsize);
rb_yield(rb_assoc_new(keystr, valstr));
GetDBM2(obj, dbmp, dbm);
}
return obj;
@ -593,8 +591,7 @@ fdbm_keys(obj)
DBM *dbm;
VALUE ary;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
ary = rb_ary_new();
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
@ -613,9 +610,7 @@ fdbm_values(obj)
DBM *dbm;
VALUE ary;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
ary = rb_ary_new();
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
@ -637,8 +632,7 @@ fdbm_has_key(obj, keystr)
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
val = dbm_fetch(dbm, key);
if (val.dptr) return Qtrue;
return Qfalse;
@ -656,8 +650,7 @@ fdbm_has_value(obj, valstr)
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
@ -676,14 +669,12 @@ fdbm_to_a(obj)
DBM *dbm;
VALUE ary;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
ary = rb_ary_new();
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);
rb_ary_push(ary, rb_assoc_new(rb_tainted_str_new(key.dptr, key.dsize),
rb_tainted_str_new(val.dptr, val.dsize)));
rb_tainted_str_new(val.dptr, val.dsize)));
}
return ary;
@ -698,9 +689,7 @@ fdbm_to_hash(obj)
DBM *dbm;
VALUE hash;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
hash = rb_hash_new();
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
val = dbm_fetch(dbm, key);

Просмотреть файл

@ -44,6 +44,11 @@ closed_dbm()
if (dbmp->di_dbm == 0) closed_dbm();\
} while (0)
#define GetDBM2(obj, data, dbm) {\
GetDBM(obj, data);\
(dbm) = dbmp->di_dbm;\
}
static void
free_dbm(dbmp)
struct dbmdata *dbmp;
@ -202,8 +207,7 @@ rb_gdbm_fetch3(obj, keystr)
struct dbmdata *dbmp;
GDBM_FILE dbm;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
return rb_gdbm_fetch2(dbm, keystr);
}
@ -299,8 +303,7 @@ fgdbm_index(obj, valstr)
VALUE keystr, valstr2;
StringValue(valstr);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
@ -325,15 +328,16 @@ fgdbm_select(obj)
struct dbmdata *dbmp;
VALUE keystr;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, 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));
VALUE v = rb_yield(assoc);
if (RTEST(rb_yield(assoc)))
if (RTEST(v)) {
rb_ary_push(new, assoc);
}
GetDBM2(obj, dbmp, dbm);
}
return new;
@ -376,9 +380,7 @@ rb_gdbm_delete(obj, keystr)
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
if (!gdbm_exists(dbm, key)) {
return Qnil;
}
@ -413,9 +415,7 @@ fgdbm_shift(obj)
VALUE keystr, valstr;
rb_gdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
keystr = rb_gdbm_firstkey(dbm);
if (NIL_P(keystr)) return Qnil;
valstr = rb_gdbm_fetch2(dbm, keystr);
@ -435,8 +435,7 @@ fgdbm_delete_if(obj)
int i, status = 0, n;
rb_gdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
n = dbmp->di_size;
dbmp->di_size = -1;
@ -447,6 +446,7 @@ fgdbm_delete_if(obj)
ret = rb_protect(rb_yield, rb_assoc_new(keystr, valstr), &status);
if (status != 0) break;
if (RTEST(ret)) rb_ary_push(ary, keystr);
GetDBM2(obj, dbmp, dbm);
}
for (i = 0; i < RARRAY(ary)->len; i++)
@ -466,8 +466,7 @@ fgdbm_clear(obj)
GDBM_FILE dbm;
rb_gdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
#if 0
@ -505,8 +504,7 @@ fgdbm_invert(obj)
VALUE keystr, valstr;
VALUE hash = rb_hash_new();
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
valstr = rb_gdbm_fetch2(dbm, keystr);
@ -574,9 +572,8 @@ fgdbm_store(obj, keystr, valstr)
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
GetDBM(obj, dbmp);
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
dbm = dbmp->di_dbm;
if (gdbm_store(dbm, key, val, GDBM_REPLACE)) {
if (errno == EPERM) rb_sys_fail(0);
rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
@ -594,9 +591,8 @@ fgdbm_length(obj)
GDBM_FILE dbm;
int i = 0;
GetDBM(obj, dbmp);
GetDBM2(obj, dbmp, dbm);
if (dbmp->di_size > 0) return INT2FIX(dbmp->di_size);
dbm = dbmp->di_dbm;
for (key = gdbm_firstkey(dbm); key.dptr; key = nextkey) {
nextkey = gdbm_nextkey(dbm, key);
@ -640,13 +636,12 @@ fgdbm_each_value(obj)
GDBM_FILE dbm;
VALUE keystr;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
rb_yield(rb_gdbm_fetch2(dbm, keystr));
GetDBM2(obj, dbmp, dbm);
}
return obj;
}
@ -659,13 +654,12 @@ fgdbm_each_key(obj)
GDBM_FILE dbm;
VALUE keystr;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
rb_yield(keystr);
GetDBM2(obj, dbmp, dbm);
}
return obj;
}
@ -678,13 +672,12 @@ fgdbm_each_pair(obj)
struct dbmdata *dbmp;
VALUE keystr;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
rb_yield(rb_assoc_new(keystr, rb_gdbm_fetch2(dbm, keystr)));
GetDBM2(obj, dbmp, dbm);
}
return obj;
@ -698,9 +691,7 @@ fgdbm_keys(obj)
GDBM_FILE dbm;
VALUE keystr, ary;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
ary = rb_ary_new();
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
@ -720,9 +711,7 @@ fgdbm_values(obj)
GDBM_FILE dbm;
VALUE valstr, ary;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
ary = rb_ary_new();
for (key = gdbm_firstkey(dbm); key.dptr; key = nextkey) {
nextkey = gdbm_nextkey(dbm, key);
@ -746,8 +735,7 @@ fgdbm_has_key(obj, keystr)
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
if (gdbm_exists(dbm, key))
return Qtrue;
return Qfalse;
@ -762,8 +750,7 @@ fgdbm_has_value(obj, valstr)
VALUE keystr, valstr2;
StringValue(valstr);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
@ -787,9 +774,7 @@ fgdbm_to_a(obj)
GDBM_FILE dbm;
VALUE keystr, ary;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
ary = rb_ary_new();
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
@ -808,8 +793,7 @@ fgdbm_reorganize(obj)
GDBM_FILE dbm;
rb_gdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
gdbm_reorganize(dbm);
return obj;
}
@ -822,8 +806,7 @@ fgdbm_sync(obj)
GDBM_FILE dbm;
rb_gdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
gdbm_sync(dbm);
return obj;
}
@ -836,9 +819,7 @@ fgdbm_set_cachesize(obj, val)
GDBM_FILE dbm;
int optval;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
optval = FIX2INT(val);
if (gdbm_setopt(dbm, GDBM_CACHESIZE, &optval, sizeof(optval)) == -1) {
rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
@ -854,9 +835,7 @@ fgdbm_set_fastmode(obj, val)
GDBM_FILE dbm;
int optval;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
optval = 0;
if (RTEST(val))
optval = 1;
@ -879,9 +858,7 @@ fgdbm_set_syncmode(obj, val)
GDBM_FILE dbm;
int optval;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
optval = 0;
if (RTEST(val))
optval = 1;
@ -901,9 +878,7 @@ fgdbm_to_hash(obj)
GDBM_FILE dbm;
VALUE keystr, hash;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
hash = rb_hash_new();
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {

Просмотреть файл

@ -31,9 +31,15 @@ closed_sdbm()
#define GetDBM(obj, dbmp) {\
Data_Get_Struct(obj, struct dbmdata, dbmp);\
if (dbmp == 0) closed_dbm();\
if (dbmp->di_dbm == 0) closed_sdbm();\
}
#define GetDBM2(obj, data, dbm) {\
GetDBM(obj, data);\
(dbm) = dbmp->di_dbm;\
}
static void
free_sdbm(dbmp)
struct dbmdata *dbmp;
@ -138,8 +144,7 @@ fsdbm_fetch(obj, keystr, ifnone)
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
value = sdbm_fetch(dbm, key);
if (value.dptr == 0) {
if (ifnone == Qnil && rb_block_given_p())
@ -184,8 +189,7 @@ fsdbm_index(obj, valstr)
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
@ -205,16 +209,17 @@ fsdbm_select(obj)
DBM *dbm;
struct dbmdata *dbmp;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
VALUE assoc;
VALUE assoc, v;
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)))
v = rb_yield(assoc);
if (RTEST(v)) {
rb_ary_push(new, assoc);
}
GetDBM2(obj, dbmp, dbm);
}
return new;
@ -258,8 +263,7 @@ fsdbm_delete(obj, keystr)
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
value = sdbm_fetch(dbm, key);
@ -291,9 +295,7 @@ fsdbm_shift(obj)
VALUE keystr, valstr;
fdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
key = sdbm_firstkey(dbm);
if (!key.dptr) return Qnil;
val = sdbm_fetch(dbm, key);
@ -319,8 +321,7 @@ fsdbm_delete_if(obj)
int i, status = 0, n;
fdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
n = dbmp->di_size;
dbmp->di_size = -1;
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
@ -330,6 +331,7 @@ fsdbm_delete_if(obj)
ret = rb_protect(rb_yield, rb_assoc_new(rb_str_dup(keystr), valstr), &status);
if (status != 0) break;
if (RTEST(ret)) rb_ary_push(ary, keystr);
GetDBM2(obj, dbmp, dbm);
}
for (i = 0; i < RARRAY(ary)->len; i++) {
@ -356,8 +358,7 @@ fsdbm_clear(obj)
DBM *dbm;
fdbm_modify(obj);
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
while (key = sdbm_firstkey(dbm), key.dptr) {
if (sdbm_delete(dbm, key)) {
@ -379,8 +380,7 @@ fsdbm_invert(obj)
VALUE keystr, valstr;
VALUE hash = rb_hash_new();
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
keystr = rb_tainted_str_new(key.dptr, key.dsize);
@ -453,9 +453,8 @@ fsdbm_store(obj, keystr, valstr)
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
GetDBM(obj, dbmp);
GetDBM2(obj, dbmp, dbm);
dbmp->di_size = -1;
dbm = dbmp->di_dbm;
if (sdbm_store(dbm, key, val, DBM_REPLACE)) {
#ifdef HAVE_DBM_CLAERERR
sdbm_clearerr(dbm);
@ -476,9 +475,8 @@ fsdbm_length(obj)
DBM *dbm;
int i = 0;
GetDBM(obj, dbmp);
GetDBM2(obj, dbmp, dbm);
if (dbmp->di_size > 0) return INT2FIX(dbmp->di_size);
dbm = dbmp->di_dbm;
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
i++;
@ -520,11 +518,11 @@ fsdbm_each_value(obj)
struct dbmdata *dbmp;
DBM *dbm;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
rb_yield(rb_tainted_str_new(val.dptr, val.dsize));
GetDBM2(obj, dbmp, dbm);
}
return obj;
}
@ -537,10 +535,10 @@ fsdbm_each_key(obj)
struct dbmdata *dbmp;
DBM *dbm;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
rb_yield(rb_tainted_str_new(key.dptr, key.dsize));
GetDBM2(obj, dbmp, dbm);
}
return obj;
}
@ -554,14 +552,13 @@ fsdbm_each_pair(obj)
struct dbmdata *dbmp;
VALUE keystr, valstr;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
keystr = rb_tainted_str_new(key.dptr, key.dsize);
valstr = rb_tainted_str_new(val.dptr, val.dsize);
rb_yield(rb_assoc_new(keystr, valstr));
GetDBM2(obj, dbmp, dbm);
}
return obj;
@ -576,9 +573,7 @@ fsdbm_keys(obj)
DBM *dbm;
VALUE ary;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
ary = rb_ary_new();
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
rb_ary_push(ary, rb_tainted_str_new(key.dptr, key.dsize));
@ -596,9 +591,7 @@ fsdbm_values(obj)
DBM *dbm;
VALUE ary;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
ary = rb_ary_new();
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
@ -620,8 +613,7 @@ fsdbm_has_key(obj, keystr)
key.dptr = RSTRING(keystr)->ptr;
key.dsize = RSTRING(keystr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
val = sdbm_fetch(dbm, key);
if (val.dptr) return Qtrue;
return Qfalse;
@ -639,8 +631,7 @@ fsdbm_has_value(obj, valstr)
val.dptr = RSTRING(valstr)->ptr;
val.dsize = RSTRING(valstr)->len;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
if (val.dsize == RSTRING(valstr)->len &&
@ -659,9 +650,7 @@ fsdbm_to_a(obj)
DBM *dbm;
VALUE ary;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
ary = rb_ary_new();
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
@ -681,9 +670,7 @@ fsdbm_to_hash(obj)
DBM *dbm;
VALUE hash;
GetDBM(obj, dbmp);
dbm = dbmp->di_dbm;
GetDBM2(obj, dbmp, dbm);
hash = rb_hash_new();
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);