summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-18 08:47:06 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-18 08:47:06 +0000
commit35f851bcfe7e42ddf1b44606d2df4d4be9de9976 (patch)
tree22b6a55b921d76a6d432f0a2156496ccb827be73 /string.c
parentcd956b3114c1b59de6660e1c70be192c6ee29235 (diff)
* string.c (rb_str_replace): swap arguments of OBJ_INFECT.
* eval.c (rb_thread_schedule): should not select a thread which is not yet initialized. * time.c (time_plus): wrong boundary check. * time.c (time_minus): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c79
1 files changed, 43 insertions, 36 deletions
diff --git a/string.c b/string.c
index 640cf7f..59f9776 100644
--- a/string.c
+++ b/string.c
@@ -195,13 +195,6 @@ rb_str_to_str(str)
return rb_convert_type(str, T_STRING, "String", "to_str");
}
-VALUE
-rb_string_value(ptr)
- volatile VALUE *ptr;
-{
- return *ptr = rb_str_to_str(*ptr);
-}
-
static void
rb_str_become(str, str2)
VALUE str, str2;
@@ -428,6 +421,48 @@ rb_str_format(str, arg)
return rb_f_sprintf(2, argv);
}
+static int
+str_independent(str)
+ VALUE str;
+{
+ if (OBJ_FROZEN(str)) rb_error_frozen("string");
+ if (!OBJ_TAINTED(str) && rb_safe_level() >= 4)
+ rb_raise(rb_eSecurityError, "Insecure: can't modify string");
+ if (!FL_TEST(str, ELTS_SHARED)) return 1;
+ return 0;
+}
+
+static void
+str_make_independent(str)
+ VALUE str;
+{
+ char *ptr;
+
+ ptr = ALLOC_N(char, RSTRING(str)->len+1);
+ if (RSTRING(str)->ptr) {
+ memcpy(ptr, RSTRING(str)->ptr, RSTRING(str)->len);
+ }
+ ptr[RSTRING(str)->len] = 0;
+ RSTRING(str)->ptr = ptr;
+ RSTRING(str)->aux.capa = RSTRING(str)->len;
+ FL_UNSET(str, ELTS_SHARED|STR_ASSOC);
+}
+
+void
+rb_str_modify(str)
+ VALUE str;
+{
+ if (str_independent(str)) return;
+ str_make_independent(str);
+}
+
+VALUE
+rb_string_value(ptr)
+ volatile VALUE *ptr;
+{
+ return *ptr = rb_str_to_str(*ptr);
+}
+
VALUE
rb_str_substr(str, beg, len)
VALUE str;
@@ -455,34 +490,6 @@ rb_str_substr(str, beg, len)
return str2;
}
-static int
-str_independent(str)
- VALUE str;
-{
- if (OBJ_FROZEN(str)) rb_error_frozen("string");
- if (!OBJ_TAINTED(str) && rb_safe_level() >= 4)
- rb_raise(rb_eSecurityError, "Insecure: can't modify string");
- if (!FL_TEST(str, ELTS_SHARED)) return 1;
- return 0;
-}
-
-void
-rb_str_modify(str)
- VALUE str;
-{
- char *ptr;
-
- if (str_independent(str)) return;
- ptr = ALLOC_N(char, RSTRING(str)->len+1);
- if (RSTRING(str)->ptr) {
- memcpy(ptr, RSTRING(str)->ptr, RSTRING(str)->len);
- }
- ptr[RSTRING(str)->len] = 0;
- RSTRING(str)->ptr = ptr;
- RSTRING(str)->aux.capa = RSTRING(str)->len;
- FL_UNSET(str, ELTS_SHARED|STR_ASSOC);
-}
-
VALUE
rb_str_freeze(str)
VALUE str;
@@ -1610,7 +1617,7 @@ rb_str_replace(str, str2)
memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len);
}
- OBJ_INFECT(str2, str);
+ OBJ_INFECT(str, str2);
return str;
}