summaryrefslogtreecommitdiff
path: root/ext/gdbm
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-09 02:19:50 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-09 02:19:50 +0000
commit3d66cc4c6b9585227b6489497d66dbc065c6f6a6 (patch)
treec92c837c765644f1ba35a315090fbfb6cc90369d /ext/gdbm
parent32481c4126c09a659dd240a44fe27a2af513dd52 (diff)
* 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
Diffstat (limited to 'ext/gdbm')
-rw-r--r--ext/gdbm/gdbm.c99
1 files changed, 37 insertions, 62 deletions
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index e905dad..d55b04c 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -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)) {