summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-29 09:08:18 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-29 09:08:18 +0000
commit40bc4f5ae4ffe325c36a49e0d3280dbee2a39cee (patch)
tree834cc2146161802fb97d89f0a747ae794048169b /string.c
parent3bf972993f689965c857540ec1ccc729477e8e66 (diff)
* array.c (rb_ary_become): should not free ptr if it's shared.
* eval.c (rb_alias): prohibit making an alias named "allocate" if klass is a metaclass. * string.c (rb_string_value_ptr): StringValuePtr() should never return NULL pointer. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/string.c b/string.c
index 2ef8de5..b036cb5 100644
--- a/string.c
+++ b/string.c
@@ -440,6 +440,21 @@ rb_string_value(ptr)
return *ptr = rb_str_to_str(*ptr);
}
+char *
+rb_string_value_ptr(ptr)
+ volatile VALUE *ptr;
+{
+ VALUE s = *ptr;
+ if (TYPE(s) != T_STRING) {
+ s = rb_str_to_str(s);
+ *ptr = s;
+ }
+ if (!RSTRING(s)->ptr) {
+ str_make_independent(s);
+ }
+ return RSTRING(s)->ptr;
+}
+
VALUE
rb_str_substr(str, beg, len)
VALUE str;
@@ -1609,18 +1624,17 @@ rb_str_replace(str, str2)
}
RSTRING(str)->len = RSTRING(str2)->len;
RSTRING(str)->ptr = RSTRING(str2)->ptr;
- if (FL_TEST(str2, ELTS_SHARED|STR_ASSOC)) {
- FL_SET(str, RBASIC(str2)->flags & (ELTS_SHARED|STR_ASSOC));
- RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
- }
- else {
- RSTRING(str)->aux.capa = RSTRING(str2)->aux.capa;
- }
+ FL_SET(str, RBASIC(str2)->flags & (ELTS_SHARED|STR_ASSOC));
+ RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
}
else {
rb_str_modify(str);
rb_str_resize(str, RSTRING(str2)->len);
memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len);
+ if (FL_TEST(str2, STR_ASSOC)) {
+ FL_SET(str, RBASIC(str2)->flags & (ELTS_SHARED|STR_ASSOC));
+ RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
+ }
}
OBJ_INFECT(str, str2);