String for string literal is not resizable
This commit is contained in:
parent
9877f3ada8
commit
1910bd4247
@ -1196,6 +1196,7 @@ fstring.o: $(hdrdir)/ruby/backward.h
|
|||||||
fstring.o: $(hdrdir)/ruby/backward/2/assume.h
|
fstring.o: $(hdrdir)/ruby/backward/2/assume.h
|
||||||
fstring.o: $(hdrdir)/ruby/backward/2/attributes.h
|
fstring.o: $(hdrdir)/ruby/backward/2/attributes.h
|
||||||
fstring.o: $(hdrdir)/ruby/backward/2/bool.h
|
fstring.o: $(hdrdir)/ruby/backward/2/bool.h
|
||||||
|
fstring.o: $(hdrdir)/ruby/backward/2/gcc_version_since.h
|
||||||
fstring.o: $(hdrdir)/ruby/backward/2/inttypes.h
|
fstring.o: $(hdrdir)/ruby/backward/2/inttypes.h
|
||||||
fstring.o: $(hdrdir)/ruby/backward/2/limits.h
|
fstring.o: $(hdrdir)/ruby/backward/2/limits.h
|
||||||
fstring.o: $(hdrdir)/ruby/backward/2/long_long.h
|
fstring.o: $(hdrdir)/ruby/backward/2/long_long.h
|
||||||
@ -1358,6 +1359,8 @@ fstring.o: $(hdrdir)/ruby/oniguruma.h
|
|||||||
fstring.o: $(hdrdir)/ruby/ruby.h
|
fstring.o: $(hdrdir)/ruby/ruby.h
|
||||||
fstring.o: $(hdrdir)/ruby/st.h
|
fstring.o: $(hdrdir)/ruby/st.h
|
||||||
fstring.o: $(hdrdir)/ruby/subst.h
|
fstring.o: $(hdrdir)/ruby/subst.h
|
||||||
|
fstring.o: $(top_srcdir)/internal/compilers.h
|
||||||
|
fstring.o: $(top_srcdir)/internal/string.h
|
||||||
fstring.o: fstring.c
|
fstring.o: fstring.c
|
||||||
init.o: $(RUBY_EXTCONF_H)
|
init.o: $(RUBY_EXTCONF_H)
|
||||||
init.o: $(arch_hdrdir)/ruby/config.h
|
init.o: $(arch_hdrdir)/ruby/config.h
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
#include "ruby/encoding.h"
|
#include "ruby/encoding.h"
|
||||||
|
#include "internal/string.h"
|
||||||
|
|
||||||
VALUE rb_fstring(VALUE str);
|
VALUE rb_fstring(VALUE str);
|
||||||
|
|
||||||
@ -9,6 +10,14 @@ bug_s_fstring(VALUE self, VALUE str)
|
|||||||
return rb_fstring(str);
|
return rb_fstring(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
bug_s_fstring_fake_str(VALUE self)
|
||||||
|
{
|
||||||
|
static const char literal[] = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
struct RString fake_str;
|
||||||
|
return rb_fstring(rb_setup_fake_str(&fake_str, literal, sizeof(literal) - 1, 0));
|
||||||
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
bug_s_rb_enc_interned_str(VALUE self, VALUE encoding)
|
bug_s_rb_enc_interned_str(VALUE self, VALUE encoding)
|
||||||
{
|
{
|
||||||
@ -25,6 +34,7 @@ void
|
|||||||
Init_string_fstring(VALUE klass)
|
Init_string_fstring(VALUE klass)
|
||||||
{
|
{
|
||||||
rb_define_singleton_method(klass, "fstring", bug_s_fstring, 1);
|
rb_define_singleton_method(klass, "fstring", bug_s_fstring, 1);
|
||||||
|
rb_define_singleton_method(klass, "fstring_fake_str", bug_s_fstring_fake_str, 0);
|
||||||
rb_define_singleton_method(klass, "rb_enc_interned_str", bug_s_rb_enc_interned_str, 1);
|
rb_define_singleton_method(klass, "rb_enc_interned_str", bug_s_rb_enc_interned_str, 1);
|
||||||
rb_define_singleton_method(klass, "rb_enc_str_new", bug_s_rb_enc_str_new, 1);
|
rb_define_singleton_method(klass, "rb_enc_str_new", bug_s_rb_enc_str_new, 1);
|
||||||
}
|
}
|
||||||
|
2
string.c
2
string.c
@ -428,7 +428,7 @@ rb_fstring(VALUE str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OBJ_FROZEN(str))
|
if (!FL_TEST_RAW(str, FL_FREEZE | STR_NOFREE))
|
||||||
rb_str_resize(str, RSTRING_LEN(str));
|
rb_str_resize(str, RSTRING_LEN(str));
|
||||||
|
|
||||||
fstr = register_fstring(str, FALSE);
|
fstr = register_fstring(str, FALSE);
|
||||||
|
@ -49,6 +49,10 @@ class Test_String_Fstring < Test::Unit::TestCase
|
|||||||
assert_raise(TypeError) {fstr.singleton_class}
|
assert_raise(TypeError) {fstr.singleton_class}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_fake_str
|
||||||
|
assert_equal([*"a".."z"].join(""), Bug::String.fstring_fake_str)
|
||||||
|
end
|
||||||
|
|
||||||
class S < String
|
class S < String
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user