mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
call rb_str_modify to make a copy unshared
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d1417ff8fa
commit
d25a27abba
3 changed files with 14 additions and 1 deletions
|
@ -572,6 +572,7 @@
|
||||||
#define HAVE_RB_STRING 1
|
#define HAVE_RB_STRING 1
|
||||||
#define HAVE_SAFE_STRING_VALUE 1
|
#define HAVE_SAFE_STRING_VALUE 1
|
||||||
#define HAVE_RB_STRING_VALUE_CSTR 1
|
#define HAVE_RB_STRING_VALUE_CSTR 1
|
||||||
|
#define HAVE_RB_STR_MODIFY 1
|
||||||
|
|
||||||
/* Struct */
|
/* Struct */
|
||||||
#define HAVE_RB_STRUCT_AREF 1
|
#define HAVE_RB_STRUCT_AREF 1
|
||||||
|
|
|
@ -504,6 +504,13 @@ static VALUE string_spec_rb_string_value_cstr(VALUE self, VALUE str) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_RB_STR_MODIFY
|
||||||
|
static VALUE string_spec_rb_str_modify(VALUE self, VALUE str) {
|
||||||
|
rb_str_modify(str);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void Init_string_spec(void) {
|
void Init_string_spec(void) {
|
||||||
VALUE cls;
|
VALUE cls;
|
||||||
cls = rb_define_class("CApiStringSpecs", rb_cObject);
|
cls = rb_define_class("CApiStringSpecs", rb_cObject);
|
||||||
|
@ -744,6 +751,10 @@ void Init_string_spec(void) {
|
||||||
#ifdef HAVE_RB_STRING_VALUE_CSTR
|
#ifdef HAVE_RB_STRING_VALUE_CSTR
|
||||||
rb_define_method(cls, "rb_string_value_cstr", string_spec_rb_string_value_cstr, 1);
|
rb_define_method(cls, "rb_string_value_cstr", string_spec_rb_string_value_cstr, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_RB_STR_MODIFY
|
||||||
|
rb_define_method(cls, "rb_str_modify", string_spec_rb_str_modify, 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,8 @@ describe "C-API String function" do
|
||||||
before :each do
|
before :each do
|
||||||
# Make a completely new copy of the string
|
# Make a completely new copy of the string
|
||||||
# for every example (#dup doesn't cut it).
|
# for every example (#dup doesn't cut it).
|
||||||
@str = "abcdefghij"[0..-1]
|
@str = "abcdefghij"
|
||||||
|
@s.rb_str_modify(@str)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reduces the size of the string" do
|
it "reduces the size of the string" do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue