summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornari <nari@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-26 04:57:47 +0000
committernari <nari@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-26 04:57:47 +0000
commit90b70738427567dc065ad75b32fa932b280c304a (patch)
treec123b148394a08abcb0ecebcb407a251388af33b /string.c
parent2bf56dededed9d4c376893f783aa5b4300b08495 (diff)
* parse.y: support Symbol GC. [ruby-trunk Feature #9634]
See this ticket about Symbol GC. * include/ruby/ruby.h: Declare few functions. * rb_sym2id: almost same as old SYM2ID but support dynamic symbols. * rb_id2sym: almost same as old ID2SYM but support dynamic symbols. * rb_sym2str: almost same as `rb_id2str(SYM2ID(sym))` but not pin down a dynamic symbol. Declare a new struct. * struct RSymbol: represents a dynamic symbol as object in Ruby's heaps. Add few macros. * STATIC_SYM_P: check a static symbol. * DYNAMIC_SYM_P: check a dynamic symbol. * RSYMBOL: cast to RSymbol * gc.c: declare RSymbol. support T_SYMBOL. * internal.h: Declare few functions. * rb_gc_free_dsymbol: free up a dynamic symbol. GC call this function at a sweep phase. * rb_str_dynamic_intern: convert a string to a dynamic symbol. * rb_check_id_without_pindown: not pinning function. * rb_sym2id_without_pindown: ditto. * rb_check_id_cstr_without_pindown: ditto. * string.c (Init_String): String#intern and String#to_sym use rb_str_dynamic_intern. * template/id.h.tmpl: use LSB of ID as a flag for determining a static symbol, so we shift left other ruby_id_types. * string.c: use rb_sym2str instead `rb_id2str(SYM2ID(sym))` to avoid pinning. * load.c: use xx_without_pindown function at creating temporary ID to avoid pinning. * object.c: ditto. * sprintf.c: ditto. * struct.c: ditto. * thread.c: ditto. * variable.c: ditto. * vm_method.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/string.c b/string.c
index 3eda81ca3c..936cc18ac4 100644
--- a/string.c
+++ b/string.c
@@ -8345,10 +8345,9 @@ sym_inspect(VALUE sym)
VALUE str;
const char *ptr;
long len;
- ID id = SYM2ID(sym);
char *dest;
- sym = rb_id2str(id);
+ sym = rb_sym2str(sym);
if (!rb_str_symname_p(sym)) {
str = rb_str_inspect(sym);
len = RSTRING_LEN(str);
@@ -8384,9 +8383,7 @@ sym_inspect(VALUE sym)
VALUE
rb_sym_to_s(VALUE sym)
{
- ID id = SYM2ID(sym);
-
- return str_new_shared(rb_cString, rb_id2str(id));
+ return str_new_shared(rb_cString, rb_sym2str(sym));
}
@@ -8468,7 +8465,7 @@ sym_to_proc(VALUE sym)
static VALUE
sym_succ(VALUE sym)
{
- return rb_str_intern(rb_str_succ(rb_sym_to_s(sym)));
+ return rb_str_dynamic_intern(rb_str_succ(rb_sym_to_s(sym)));
}
/*
@@ -8552,7 +8549,7 @@ sym_aref(int argc, VALUE *argv, VALUE sym)
static VALUE
sym_length(VALUE sym)
{
- return rb_str_length(rb_id2str(SYM2ID(sym)));
+ return rb_str_length(rb_sym2str(sym));
}
/*
@@ -8565,7 +8562,7 @@ sym_length(VALUE sym)
static VALUE
sym_empty(VALUE sym)
{
- return rb_str_empty(rb_id2str(SYM2ID(sym)));
+ return rb_str_empty(rb_sym2str(sym));
}
/*
@@ -8578,7 +8575,7 @@ sym_empty(VALUE sym)
static VALUE
sym_upcase(VALUE sym)
{
- return rb_str_intern(rb_str_upcase(rb_id2str(SYM2ID(sym))));
+ return rb_str_dynamic_intern(rb_str_upcase(rb_sym2str(sym)));
}
/*
@@ -8591,7 +8588,7 @@ sym_upcase(VALUE sym)
static VALUE
sym_downcase(VALUE sym)
{
- return rb_str_intern(rb_str_downcase(rb_id2str(SYM2ID(sym))));
+ return rb_str_dynamic_intern(rb_str_downcase(rb_sym2str(sym)));
}
/*
@@ -8604,7 +8601,7 @@ sym_downcase(VALUE sym)
static VALUE
sym_capitalize(VALUE sym)
{
- return rb_str_intern(rb_str_capitalize(rb_id2str(SYM2ID(sym))));
+ return rb_str_dynamic_intern(rb_str_capitalize(rb_sym2str(sym)));
}
/*
@@ -8617,7 +8614,7 @@ sym_capitalize(VALUE sym)
static VALUE
sym_swapcase(VALUE sym)
{
- return rb_str_intern(rb_str_swapcase(rb_id2str(SYM2ID(sym))));
+ return rb_str_dynamic_intern(rb_str_swapcase(rb_sym2str(sym)));
}
/*
@@ -8630,7 +8627,7 @@ sym_swapcase(VALUE sym)
static VALUE
sym_encoding(VALUE sym)
{
- return rb_obj_encoding(rb_id2str(SYM2ID(sym)));
+ return rb_obj_encoding(rb_sym2str(sym));
}
ID
@@ -8742,8 +8739,8 @@ Init_String(void)
rb_define_method(rb_cString, "<<", rb_str_concat, 1);
rb_define_method(rb_cString, "prepend", rb_str_prepend, 1);
rb_define_method(rb_cString, "crypt", rb_str_crypt, 1);
- rb_define_method(rb_cString, "intern", rb_str_intern, 0);
- rb_define_method(rb_cString, "to_sym", rb_str_intern, 0);
+ rb_define_method(rb_cString, "intern", rb_str_dynamic_intern, 0); /* in parse.y */
+ rb_define_method(rb_cString, "to_sym", rb_str_dynamic_intern, 0); /* in parse.y */
rb_define_method(rb_cString, "ord", rb_str_ord, 0);
rb_define_method(rb_cString, "include?", rb_str_include, 1);