summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-09 06:08:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-09 06:08:24 +0000
commit115eb4595cea72226ec8acd357e7c403e2c4b04a (patch)
treec050f1ee16f730fc7dbc89586e09b33a23196485 /string.c
parent9b64dfe3b8f0343ebf97ae80d3a4ec3f4bd115b3 (diff)
990209
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/string.c b/string.c
index 7ded9e3..18c876d 100644
--- a/string.c
+++ b/string.c
@@ -22,6 +22,10 @@
#include <unistd.h>
#endif
+#ifndef atof
+double strtod();
+#endif
+
VALUE rb_cString;
#define STR_FREEZE FL_USER1
@@ -60,14 +64,20 @@ rb_tainted_str_new(ptr, len)
char *ptr;
int len;
{
- return rb_obj_taint(rb_str_new(ptr, len));
+ VALUE str = rb_str_new(ptr, len);
+
+ FL_SET(str, FL_TAINT);
+ return str;
}
VALUE
rb_tainted_str_new2(ptr)
char *ptr;
{
- return rb_obj_taint(rb_str_new2(ptr));
+ VALUE str = rb_str_new2(ptr);
+
+ FL_SET(str, FL_TAINT);
+ return str;
}
VALUE
@@ -102,7 +112,7 @@ rb_str_new4(orig)
str->ptr = RSTRING(orig)->ptr;
RSTRING(orig)->orig = (VALUE)str;
str->orig = 0;
- if (rb_safe_level() >= 3) {
+ if (FL_TEST(str, FL_TAINT)) {
FL_SET(str, FL_TAINT);
}
return (VALUE)str;
@@ -1028,7 +1038,10 @@ rb_str_sub_bang(argc, argv, str)
regs = RMATCH(match)->regs;
if (iter) {
+ rb_match_busy(match, Qtrue);
repl = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
+ rb_match_busy(match, Qfalse);
+ rb_backref_set(match);
}
else {
repl = rb_reg_regsub(repl, str, regs);
@@ -1102,7 +1115,10 @@ rb_str_gsub_bang(argc, argv, str)
match = rb_backref_get();
regs = RMATCH(match)->regs;
if (iter) {
+ rb_match_busy(match, Qtrue);
val = rb_obj_as_string(rb_yield(rb_reg_nth_match(0, match)));
+ rb_match_busy(match, Qfalse);
+ rb_backref_set(match);
}
else {
val = rb_reg_regsub(repl, str, regs);
@@ -1313,7 +1329,7 @@ static VALUE
rb_str_to_f(str)
VALUE str;
{
- double f = atof(RSTRING(str)->ptr);
+ double f = strtod(RSTRING(str)->ptr, 0);
return rb_float_new(f);
}