summaryrefslogtreecommitdiff
path: root/ext/sdbm/init.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-20 08:05:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-20 08:05:44 +0000
commit6259c87d02fce0a77ac90b6786ed1f2bc5baea32 (patch)
tree941121f72d4e32b756acdc1c2a1c4f7a0cb849a3 /ext/sdbm/init.c
parent52b3e3b97f42498c1f30984cb1e174422c235c80 (diff)
* include/ruby/ruby.h (ExportStringValue): new macro to convert
string in internal encoding to external to export. * string.c (rb_str_export): new function to do conversion to external encoding. * ext/sdbm/init.c: encoding conversion support. * ext/dbm/dbm.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/sdbm/init.c')
-rw-r--r--ext/sdbm/init.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c
index 70480f4..ecedd63 100644
--- a/ext/sdbm/init.c
+++ b/ext/sdbm/init.c
@@ -96,7 +96,7 @@ fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
else {
mode = NUM2INT(vmode);
}
- SafeStringValue(file);
+ FilePathValue(file);
dbm = 0;
if (mode >= 0)
@@ -142,7 +142,7 @@ fsdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
struct dbmdata *dbmp;
DBM *dbm;
- StringValue(keystr);
+ ExportStringValue(keystr);
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);
@@ -150,10 +150,10 @@ fsdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
value = sdbm_fetch(dbm, key);
if (value.dptr == 0) {
if (ifnone == Qnil && rb_block_given_p())
- return rb_yield(rb_tainted_str_new(key.dptr, key.dsize));
+ return rb_yield(rb_external_str_new(key.dptr, key.dsize));
return ifnone;
}
- return rb_tainted_str_new(value.dptr, value.dsize);
+ return rb_external_str_new(value.dptr, value.dsize);
}
static VALUE
@@ -182,7 +182,7 @@ fsdbm_index(VALUE obj, VALUE valstr)
struct dbmdata *dbmp;
DBM *dbm;
- StringValue(valstr);
+ ExportStringValue(valstr);
val.dptr = RSTRING_PTR(valstr);
val.dsize = RSTRING_LEN(valstr);
@@ -191,7 +191,7 @@ fsdbm_index(VALUE obj, VALUE valstr)
val = sdbm_fetch(dbm, key);
if (val.dsize == RSTRING_LEN(valstr) &&
memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0)
- return rb_tainted_str_new(key.dptr, key.dsize);
+ return rb_external_str_new(key.dptr, key.dsize);
}
return Qnil;
}
@@ -208,8 +208,8 @@ fsdbm_select(VALUE obj)
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
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));
+ assoc = rb_assoc_new(rb_external_str_new(key.dptr, key.dsize),
+ rb_external_str_new(val.dptr, val.dsize));
v = rb_yield(assoc);
if (RTEST(v)) {
rb_ary_push(new, assoc);
@@ -249,7 +249,7 @@ fsdbm_delete(VALUE obj, VALUE keystr)
VALUE valstr;
fdbm_modify(obj);
- StringValue(keystr);
+ ExportStringValue(keystr);
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);
@@ -263,7 +263,7 @@ fsdbm_delete(VALUE obj, VALUE keystr)
}
/* need to save value before sdbm_delete() */
- valstr = rb_tainted_str_new(value.dptr, value.dsize);
+ valstr = rb_external_str_new(value.dptr, value.dsize);
if (sdbm_delete(dbm, key)) {
dbmp->di_size = -1;
@@ -288,8 +288,8 @@ fsdbm_shift(VALUE obj)
key = sdbm_firstkey(dbm);
if (!key.dptr) return Qnil;
val = sdbm_fetch(dbm, key);
- keystr = rb_tainted_str_new(key.dptr, key.dsize);
- valstr = rb_tainted_str_new(val.dptr, val.dsize);
+ keystr = rb_external_str_new(key.dptr, key.dsize);
+ valstr = rb_external_str_new(val.dptr, val.dsize);
sdbm_delete(dbm, key);
if (dbmp->di_size >= 0) {
dbmp->di_size--;
@@ -314,8 +314,8 @@ fsdbm_delete_if(VALUE obj)
dbmp->di_size = -1;
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);
+ keystr = rb_external_str_new(key.dptr, key.dsize);
+ valstr = rb_external_str_new(val.dptr, val.dsize);
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);
@@ -324,7 +324,7 @@ fsdbm_delete_if(VALUE obj)
for (i = 0; i < RARRAY_LEN(ary); i++) {
keystr = RARRAY_PTR(ary)[i];
- StringValue(keystr);
+ ExportStringValue(keystr);
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);
if (sdbm_delete(dbm, key)) {
@@ -369,8 +369,8 @@ fsdbm_invert(VALUE obj)
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);
+ keystr = rb_external_str_new(key.dptr, key.dsize);
+ valstr = rb_external_str_new(val.dptr, val.dsize);
rb_hash_aset(hash, valstr, keystr);
}
return hash;
@@ -389,8 +389,8 @@ fsdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
}
fdbm_modify(obj);
- StringValue(keystr);
- StringValue(valstr);
+ ExportStringValue(keystr);
+ ExportStringValue(valstr);
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);
@@ -491,7 +491,7 @@ fsdbm_each_value(VALUE obj)
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));
+ rb_yield(rb_external_str_new(val.dptr, val.dsize));
GetDBM2(obj, dbmp, dbm);
}
return obj;
@@ -508,7 +508,7 @@ fsdbm_each_key(VALUE obj)
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));
+ rb_yield(rb_external_str_new(key.dptr, key.dsize));
GetDBM2(obj, dbmp, dbm);
}
return obj;
@@ -527,8 +527,8 @@ fsdbm_each_pair(VALUE obj)
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);
+ keystr = rb_external_str_new(key.dptr, key.dsize);
+ valstr = rb_external_str_new(val.dptr, val.dsize);
rb_yield(rb_assoc_new(keystr, valstr));
GetDBM2(obj, dbmp, dbm);
}
@@ -547,7 +547,7 @@ fsdbm_keys(VALUE obj)
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));
+ rb_ary_push(ary, rb_external_str_new(key.dptr, key.dsize));
}
return ary;
@@ -565,7 +565,7 @@ fsdbm_values(VALUE obj)
ary = rb_ary_new();
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
- rb_ary_push(ary, rb_tainted_str_new(val.dptr, val.dsize));
+ rb_ary_push(ary, rb_external_str_new(val.dptr, val.dsize));
}
return ary;
@@ -578,7 +578,7 @@ fsdbm_has_key(VALUE obj, VALUE keystr)
struct dbmdata *dbmp;
DBM *dbm;
- StringValue(keystr);
+ ExportStringValue(keystr);
key.dptr = RSTRING_PTR(keystr);
key.dsize = RSTRING_LEN(keystr);
@@ -595,7 +595,7 @@ fsdbm_has_value(VALUE obj, VALUE valstr)
struct dbmdata *dbmp;
DBM *dbm;
- StringValue(valstr);
+ ExportStringValue(valstr);
val.dptr = RSTRING_PTR(valstr);
val.dsize = RSTRING_LEN(valstr);
@@ -621,8 +621,8 @@ fsdbm_to_a(VALUE obj)
ary = rb_ary_new();
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_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_ary_push(ary, rb_assoc_new(rb_external_str_new(key.dptr, key.dsize),
+ rb_external_str_new(val.dptr, val.dsize)));
}
return ary;
@@ -640,8 +640,8 @@ fsdbm_to_hash(VALUE obj)
hash = rb_hash_new();
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_fetch(dbm, key);
- rb_hash_aset(hash, rb_tainted_str_new(key.dptr, key.dsize),
- rb_tainted_str_new(val.dptr, val.dsize));
+ rb_hash_aset(hash, rb_external_str_new(key.dptr, key.dsize),
+ rb_external_str_new(val.dptr, val.dsize));
}
return hash;