summaryrefslogtreecommitdiff
path: root/marshal.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-22 17:03:31 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-22 17:03:31 (GMT)
commitffcb7abe0b057cb5460cde83f411a2d9c55f5699 (patch)
treeeae498e4619b916471f56924d6a0e4d1f2c37025 /marshal.c
parent74768415d8d9eff2c02e0bfc04f2b325ec579e63 (diff)
marshal.c: register symbol strings first
* marshal.c (r_symreal): register symbol names as strings first so that r_symlink always returns valid names. [ruby-core:68587] [Bug #10991] * marshal.c (r_ivar, r_object0): now need to intern symbol names. * marshal.c (r_object0): compare with symbol names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'marshal.c')
-rw-r--r--marshal.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/marshal.c b/marshal.c
index 931c349..1fae545 100644
--- a/marshal.c
+++ b/marshal.c
@@ -1295,11 +1295,18 @@ r_bytes0(long len, struct load_arg *arg)
static int
sym2encidx(VALUE sym, VALUE val)
{
- if (sym == ID2SYM(rb_id_encoding())) {
+ static const char name_encoding[8] = "encoding";
+ const char *p;
+ long l;
+ if (rb_enc_get_index(sym) != ENCINDEX_US_ASCII) return -1;
+ RSTRING_GETMEM(sym, p, l);
+ if (l <= 0) return -1;
+ if (l == sizeof(name_encoding) &&
+ memcmp(p, name_encoding, sizeof(name_encoding)) == 0) {
int idx = rb_enc_find_index(StringValueCStr(val));
return idx;
}
- else if (sym == ID2SYM(rb_intern("E"))) {
+ else if (l == 1 && *p == 'E') {
if (val == Qfalse) return rb_usascii_encindex();
else if (val == Qtrue) return rb_utf8_encindex();
/* bogus ignore */
@@ -1327,7 +1334,8 @@ r_symreal(struct load_arg *arg, int ivar)
int idx = -1;
st_index_t n = arg->symbols->num_entries;
- st_insert(arg->symbols, (st_data_t)n, (st_data_t)0);
+ if (rb_enc_str_asciionly_p(s)) rb_enc_associate_index(s, ENCINDEX_US_ASCII);
+ st_insert(arg->symbols, (st_data_t)n, (st_data_t)s);
if (ivar) {
long num = r_long(arg);
while (num-- > 0) {
@@ -1336,10 +1344,8 @@ r_symreal(struct load_arg *arg, int ivar)
}
}
if (idx > 0) rb_enc_associate_index(s, idx);
- sym = rb_str_intern(s);
- st_insert(arg->symbols, (st_data_t)n, (st_data_t)sym);
- return sym;
+ return s;
}
static VALUE
@@ -1367,7 +1373,7 @@ r_symbol(struct load_arg *arg)
static VALUE
r_unique(struct load_arg *arg)
{
- return rb_sym2str(r_symbol(arg));
+ return r_symbol(arg);
}
static VALUE
@@ -1465,7 +1471,7 @@ r_ivar(VALUE obj, int *has_encoding, struct load_arg *arg)
if (has_encoding) *has_encoding = TRUE;
}
else {
- rb_ivar_set(obj, SYM2ID(sym), val);
+ rb_ivar_set(obj, rb_intern_str(sym), val);
}
} while (--len > 0);
}
@@ -1790,13 +1796,13 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
v = r_entry0(v, idx, arg);
values = rb_ary_new2(len);
for (i=0; i<len; i++) {
+ VALUE n = rb_sym2str(RARRAY_AREF(mem, i));
slot = r_symbol(arg);
- if (RARRAY_AREF(mem, i) != slot) {
+ if (!rb_str_equal(n, slot)) {
rb_raise(rb_eTypeError, "struct %"PRIsVALUE" not compatible (:%"PRIsVALUE" for :%"PRIsVALUE")",
rb_class_name(klass),
- rb_sym2str(slot),
- rb_sym2str(RARRAY_AREF(mem, i)));
+ slot, n);
}
rb_ary_push(values, r_object(arg));
arg->readable -= 2;
@@ -1934,11 +1940,12 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
else {
v = r_symreal(arg, 0);
}
+ v = rb_str_intern(v);
v = r_leave(v, arg);
break;
case TYPE_SYMLINK:
- v = r_symlink(arg);
+ v = rb_str_intern(r_symlink(arg));
break;
default: