Rb_get_interned

e$B$J$+$@$G$9!#e(B

e$B0JA0DI2C$5$l$?e(Brb_sym_interned_p()e$B$O7k6I!"e(Bintern.he$B$K@k8@$@$1;D$7e(B
e$B$F>C$5$l$F$7$^$C$?$h$&$G$9$,!"JQ?t$dDj?t$,Dj5A$5$l$F$$$k$+$rD4e(B
e$B$Y$h$&$H$9$k$@$1$G?7$7$$L>A0$,EPO?$5$l$F$7$^$&$N$OL5BL$N$h$&$Je(B
e$B5$$,$7$^$9!#e(B

ID rb_get_interned(const char *name, long len);

e$B$N$h$&$J7A$G4{B8$NL>A0$@$1$rC5$9$H$$$&$N$O$I$&$G$7$g$&$+!#e(B
e$B$H$j$"$($:e(Bvariable.c:rb_path2class()e$B$rNc$K!#e(B

Index: parse.y

— parse.y (revision 12575)
+++ parse.y (working copy)
@@ -8418,17 +8418,57 @@ rb_symname_p(const char *name)
}

+static ID
+id_register(VALUE str, ID id)
+{

  • OBJ_FREEZE(str);
  • st_add_direct(global_symbols.sym_id, (st_data_t)str, id);
  • st_add_direct(global_symbols.id_str, id, (st_data_t)str);
  • return id;
    +}

+static ID
+get_interned(VALUE str)
+{

  • st_data_t id;
  • if (st_lookup(global_symbols.sym_id, (st_data_t)str, &id))
  • return (ID)id;
  • if (RSTRING_LEN(str) > 0) {
  • const char *name = RSTRING_PTR(str);
  • char c = *name;
  • if (c != ‘_’ && c != ‘$’ && c != ‘@’ && ISASCII© && !ISALNUM©) {
  •  /* operators */
    
  •  int i;
    
  •  for (i = 0; op_tbl[i].token; i++) {
    
  • if (*op_tbl[i].name == *name &&
  •    strcmp(op_tbl[i].name, name) == 0) {
    
  •    return id_register(str, op_tbl[i].token);
    
  • }
  •  }
    
  • }
  • }
  • return 0;
    +}

+ID
+rb_get_interned(const char *name, long len)
+{

  • return get_interned(rb_str_new(name, len));
    +}

ID
rb_intern2(const char *name, long len)
{
const char *m = name;

  • VALUE str = rb_str_new(name, len);
  • ID id;
    int last;
  • VALUE str = rb_str_new(name, len);
  • ID id = get_interned(str);
  • if (st_lookup(global_symbols.sym_id, (st_data_t)str, (st_data_t
    *)&id))
  • return id;
  • if (id) return id;
    last = len-1;
  • id = 0;
    switch (*name) {
    case ‘$’:
    @@ -8447,23 +8487,9 @@ rb_intern2(const char *name, long len)
    break;
    default:
  • if (name[0] != ‘_’ && ISASCII(name[0]) && !ISALNUM(name[0])) {
  •  /* operators */
    
  •  int i;
    
  •  for (i=0; op_tbl[i].token; i++) {
    
  • if (*op_tbl[i].name == *name &&
  •    strcmp(op_tbl[i].name, name) == 0) {
    
  •    id = op_tbl[i].token;
    
  •    goto id_register;
    
  • }
  •  }
    
  • }
  • if (name[last] == ‘=’) {
  • if (name[last] == ‘=’ && last > 1 && name[last-1] != ‘=’) {
    /* attribute assignment */
    id = rb_intern2(name, last);
    if (id > tLAST_TOKEN && !is_attrset_id(id)) {
  • id = rb_id_attrset(id);
  • goto id_register;
  • return id_register(str, rb_id_attrset(id));
    }
    id = ID_ATTRSET;
    @@ -8485,9 +8511,5 @@ rb_intern2(const char *name, long len)
    new_id:
    id |= ++global_symbols.last_id << ID_SCOPE_SHIFT;
  • id_register:
  • OBJ_FREEZE(str);
  • st_add_direct(global_symbols.sym_id, (st_data_t)str, id);
  • st_add_direct(global_symbols.id_str, id, (st_data_t)str);
  • return id;
  • return id_register(str, id);
    }

Index: variable.c

— variable.c (revision 12575)
+++ variable.c (working copy)
@@ -237,5 +237,6 @@ rb_path2class(const char *path)
while (*p) {
while (*p && *p != ‘:’) p++;

  • id = rb_intern2(pbeg, p-pbeg);
  • id = rb_get_interned(pbeg, p-pbeg);
  • if (!id) goto undefined_class;
    if (p[0] == ‘:’) {
    if (p[1] != ‘:’) goto undefined_class;
    Index: include/ruby/intern.h
    ===================================================================
    — include/ruby/intern.h (revision 12575)
    +++ include/ruby/intern.h (working copy)
    @@ -408,5 +409,4 @@ int rb_is_local_id(ID);
    int rb_is_junk_id(ID);
    int rb_symname_p(const char*);
    -int rb_sym_interned_p(VALUE);
    void rb_gc_mark_symbols(void);
    VALUE rb_backref_get(void);
    Index: include/ruby/ruby.h
    ===================================================================
    — include/ruby/ruby.h (revision 12575)
    +++ include/ruby/ruby.h (working copy)
    @@ -614,4 +614,5 @@ void rb_gc_unregister_address(VALUE*);
    ID rb_intern(const char*);
    ID rb_intern2(const char*, long);
    +ID rb_get_interned(const char*, long);
    const char *rb_id2name(ID);
    ID rb_to_id(VALUE);

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31028] rb_get_interned”
on Wed, 20 Jun 2007 14:44:57 +0900, Nobuyoshi N.
[email protected] writes:

|e$B0JA0DI2C$5$l$?e(Brb_sym_interned_p()e$B$O7k6I!"e(Bintern.he$B$K@k8@$@$1;D$7e(B
|e$B$F>C$5$l$F$7$^$C$?$h$&$G$9$,!"JQ?t$dDj?t$,Dj5A$5$l$F$$$k$+$rD4e(B
|e$B$Y$h$&$H$9$k$@$1$G?7$7$$L>A0$,EPO?$5$l$F$7$^$&$N$OL5BL$N$h$&$Je(B
|e$B5$$,$7$^$9!#e(B

e$B5$;}$A$O$o$+$j$^$9!)e(B

| ID rb_get_interned(const char *name, long len);
|
|e$B$N$h$&$J7A$G4{B8$NL>A0$@$1$rC5$9$H$$$&$N$O$I$&$G$7$g$&$+!#e(B
|e$B$H$j$"$($:e(Bvariable.c:rb_path2class()e$B$rNc$K!#e(B

e$BL>A0$,5$$KF~$i$J$$!#e(B

e$B$J$+$@$G$9!#e(B

At Wed, 20 Jun 2007 15:36:20 +0900,
Yukihiro M. wrote in [ruby-dev:31029]:

| ID rb_get_interned(const char *name, long len);
|
|e$B$N$h$&$J7A$G4{B8$NL>A0$@$1$rC5$9$H$$$&$N$O$I$&$G$7$g$&$+!#e(B

e$BL>A0$,5$$KF~$i$J$$!#e(B

e$B0z?t$Oe(BOK?

rb_registered_id()
rb_interned_p()
e$B$H$+!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31030] Re: rb_get_interned”
on Wed, 20 Jun 2007 16:31:39 +0900, Nobuyoshi N.
[email protected] writes:

|> | ID rb_get_interned(const char *name, long len);
|> |
|> |e$B$N$h$&$J7A$G4{B8$NL>A0$@$1$rC5$9$H$$$&$N$O$I$&$G$7$g$&$+!#e(B
|>
|> e$BL>A0$,5$$KF~$i$J$$!#e(B
|
|e$B0z?t$Oe(BOK?
|
|rb_registered_id()
|rb_interned_p()
|e$B$H$+!#e(B

e$B$&!<$s!“$=$l$@$C$?$i=c?h$K85!9$Ne(Brb_sym_interned_p()e$B$rI|3h$5$;e(B
e$B$k$N$,$h$$$h$&$K;W$$$^$9!#0z?t$K$D$$$F$O!“e(BM17Ne$B2=$7$?;~$K%(%se(B
e$B%3!<%G%#%s%0>pJs$rF@$k$3$H$,$G$-$k$h$&$Ke(BVALUEe$B$G$”$kJ}$,$”$j$,e(B
e$B$?$$$G$9!#e(B

e$B$J$+$@$G$9!#e(B

At Thu, 21 Jun 2007 01:41:25 +0900,
Yukihiro M. wrote in [ruby-dev:31032]:

|e$B$H$+!#e(B

e$B$&!<$s!"$=$l$@$C$?$i=c?h$K85!9$Ne(Brb_sym_interned_p()e$B$rI|3h$5$;e(B
e$B$k$N$,$h$$$h$&$K;W$$$^$9!#0z?t$K$D$$$F$O!“e(BM17Ne$B2=$7$?;~$K%(%se(B
e$B%3!<%G%#%s%0>pJs$rF@$k$3$H$,$G$-$k$h$&$Ke(BVALUEe$B$G$”$kJ}$,$"$j$,e(B
e$B$?$$$G$9!#e(B

e$B$H$J$k$He(Brb_intern2()e$B$O$I$&$J$k$s$G$7$g$&!#e(Brb_str_intern()e$B$rBeBXe(B
e$B$Ke(B?

e$B$b$&$R$H$D!"e(Brb_sym_interned_p()e$B$NI|3h$bH?BP$G$O$J$$$s$G$9$,!"e(BID
e$B$rJV$94X?t$H$7$F$O$A$g$C$HL>A0$K0cOB46$J$$$G$9$+!#e(B