diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-28 08:15:42 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-28 08:15:42 +0000 |
commit | 95d1b61a146f9e88564d3df7e648b78881741a61 (patch) | |
tree | 80a5e7736295617b89cdd4c1b16d631b00daa759 /iseq.c | |
parent | e4c92f24fe23fbadc1a92f4e545b2a594ea56cba (diff) | |
download | ruby-95d1b61a146f9e88564d3df7e648b78881741a61.tar.gz |
symbols instead of IDs
* encoding.c (rb_enc_get_index): deal with symbols instead of IDs
to get rid of inadvertent pin-downs.
* enum.c (chunk_ii): ditto.
* enumerator.c (append_method): ditto.
* iseq.c (iseq_load): ditto.
* marshal.c (w_symbol, r_symlink, r_symreal, r_symbol): ditto.
* signal.c (trap_handler): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'iseq.c')
-rw-r--r-- | iseq.c | 50 |
1 files changed, 26 insertions, 24 deletions
@@ -475,17 +475,29 @@ rb_iseq_new_with_bopt(NODE *node, VALUE name, VALUE path, VALUE absolute_path, V static inline VALUE CHECK_INTEGER(VALUE v) {(void)NUM2LONG(v); return v;} static enum iseq_type -iseq_type_from_id(const ID typeid) -{ - if (typeid == rb_intern("top")) return ISEQ_TYPE_TOP; - if (typeid == rb_intern("method")) return ISEQ_TYPE_METHOD; - if (typeid == rb_intern("block")) return ISEQ_TYPE_BLOCK; - if (typeid == rb_intern("class")) return ISEQ_TYPE_CLASS; - if (typeid == rb_intern("rescue")) return ISEQ_TYPE_RESCUE; - if (typeid == rb_intern("ensure")) return ISEQ_TYPE_ENSURE; - if (typeid == rb_intern("eval")) return ISEQ_TYPE_EVAL; - if (typeid == rb_intern("main")) return ISEQ_TYPE_MAIN; - if (typeid == rb_intern("defined_guard")) return ISEQ_TYPE_DEFINED_GUARD; +iseq_type_from_sym(VALUE type) +{ + const ID id_top = rb_intern("top"); + const ID id_method = rb_intern("method"); + const ID id_block = rb_intern("block"); + const ID id_class = rb_intern("class"); + const ID id_rescue = rb_intern("rescue"); + const ID id_ensure = rb_intern("ensure"); + const ID id_eval = rb_intern("eval"); + const ID id_main = rb_intern("main"); + const ID id_defined_guard = rb_intern("defined_guard"); + /* ensure all symbols are static or pinned down before + * conversion */ + const ID typeid = rb_check_id(&type); + if (typeid == id_top) return ISEQ_TYPE_TOP; + if (typeid == id_method) return ISEQ_TYPE_METHOD; + if (typeid == id_block) return ISEQ_TYPE_BLOCK; + if (typeid == id_class) return ISEQ_TYPE_CLASS; + if (typeid == id_rescue) return ISEQ_TYPE_RESCUE; + if (typeid == id_ensure) return ISEQ_TYPE_ENSURE; + if (typeid == id_eval) return ISEQ_TYPE_EVAL; + if (typeid == id_main) return ISEQ_TYPE_MAIN; + if (typeid == id_defined_guard) return ISEQ_TYPE_DEFINED_GUARD; return (enum iseq_type)-1; } @@ -499,7 +511,6 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt) VALUE type, body, locals, args, exception; st_data_t iseq_type; - ID typeid; rb_iseq_t *iseq; rb_compile_option_t option; int i = 0; @@ -539,14 +550,9 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt) iseq->self = iseqval; iseq->local_iseq = iseq; - typeid = SYM2ID(type); - iseq_type = iseq_type_from_id(typeid); + iseq_type = iseq_type_from_sym(type); if (iseq_type == (enum iseq_type)-1) { - VALUE typename = rb_id2str(typeid); - if (typename) - rb_raise(rb_eTypeError, "unsupport type: :%"PRIsVALUE, typename); - else - rb_raise(rb_eTypeError, "unsupport type: %p", (void *)typeid); + rb_raise(rb_eTypeError, "unsupport type: :%"PRIsVALUE, rb_sym2str(type)); } if (parent == Qnil) { @@ -1615,11 +1621,7 @@ ruby_node_name(int node) static VALUE register_label(struct st_table *table, unsigned long idx) { - VALUE sym; - char buff[7 + DECIMAL_SIZE_OF_BITS(sizeof(idx) * CHAR_BIT)]; - - snprintf(buff, sizeof(buff), "label_%lu", idx); - sym = ID2SYM(rb_intern(buff)); + VALUE sym = rb_str_dynamic_intern(rb_sprintf("label_%lu", idx)); st_insert(table, idx, sym); return sym; } |