pack.c: hide associated objects
* marshal.c (to_be_skipped_id): ignore anonymous attributes. * pack.c (Init_pack): use anonymous ID so that associated objects do not appear in the packed result. * parse.y (rb_make_internal_id): return an anonymous ID for internal use. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5ba39a12d9
commit
b2b5a5db09
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Wed Feb 5 20:56:32 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* marshal.c (to_be_skipped_id): ignore anonymous attributes.
|
||||||
|
|
||||||
|
* pack.c (Init_pack): use anonymous ID so that associated objects
|
||||||
|
do not appear in the packed result.
|
||||||
|
|
||||||
|
* parse.y (rb_make_internal_id): return an anonymous ID for
|
||||||
|
internal use.
|
||||||
|
|
||||||
Wed Feb 5 14:41:56 2014 Koichi Sasada <ko1@atdot.net>
|
Wed Feb 5 14:41:56 2014 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* vsnprintf.c: remove duplicated def of `UNINITIALIZED_VAR()'.
|
* vsnprintf.c: remove duplicated def of `UNINITIALIZED_VAR()'.
|
||||||
|
@ -642,6 +642,7 @@ int rb_is_method_name(VALUE name);
|
|||||||
int rb_is_junk_name(VALUE name);
|
int rb_is_junk_name(VALUE name);
|
||||||
void rb_gc_mark_parser(void);
|
void rb_gc_mark_parser(void);
|
||||||
void rb_gc_mark_symbols(int full_mark);
|
void rb_gc_mark_symbols(int full_mark);
|
||||||
|
ID rb_make_internal_id(void);
|
||||||
|
|
||||||
/* proc.c */
|
/* proc.c */
|
||||||
VALUE rb_proc_location(VALUE self);
|
VALUE rb_proc_location(VALUE self);
|
||||||
|
@ -513,7 +513,7 @@ w_uclass(VALUE obj, VALUE super, struct dump_arg *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define to_be_skipped_id(id) (id == rb_id_encoding() || id == rb_intern("E"))
|
#define to_be_skipped_id(id) (id == rb_id_encoding() || id == rb_intern("E") || !rb_id2str(id))
|
||||||
|
|
||||||
static int
|
static int
|
||||||
w_obj_each(st_data_t key, st_data_t val, st_data_t a)
|
w_obj_each(st_data_t key, st_data_t val, st_data_t a)
|
||||||
|
2
pack.c
2
pack.c
@ -2046,5 +2046,5 @@ Init_pack(void)
|
|||||||
rb_define_method(rb_cArray, "pack", pack_pack, 1);
|
rb_define_method(rb_cArray, "pack", pack_pack, 1);
|
||||||
rb_define_method(rb_cString, "unpack", pack_unpack, 1);
|
rb_define_method(rb_cString, "unpack", pack_unpack, 1);
|
||||||
|
|
||||||
id_associated = rb_intern_const("__pack_associated__");
|
id_associated = rb_make_internal_id();
|
||||||
}
|
}
|
||||||
|
20
parse.y
20
parse.y
@ -10407,6 +10407,15 @@ rb_intern3(const char *name, long len, rb_encoding *enc)
|
|||||||
return intern_str(str);
|
return intern_str(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ID
|
||||||
|
next_id_base(void)
|
||||||
|
{
|
||||||
|
if (global_symbols.last_id >= ~(ID)0 >> (ID_SCOPE_SHIFT+RUBY_SPECIAL_SHIFT)) {
|
||||||
|
return (ID)-1;
|
||||||
|
}
|
||||||
|
return ++global_symbols.last_id << ID_SCOPE_SHIFT;
|
||||||
|
}
|
||||||
|
|
||||||
static ID
|
static ID
|
||||||
intern_str(VALUE str)
|
intern_str(VALUE str)
|
||||||
{
|
{
|
||||||
@ -10415,6 +10424,7 @@ intern_str(VALUE str)
|
|||||||
rb_encoding *enc, *symenc;
|
rb_encoding *enc, *symenc;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
ID id;
|
ID id;
|
||||||
|
ID nid;
|
||||||
int mb;
|
int mb;
|
||||||
|
|
||||||
RSTRING_GETMEM(str, name, len);
|
RSTRING_GETMEM(str, name, len);
|
||||||
@ -10505,7 +10515,7 @@ intern_str(VALUE str)
|
|||||||
if (sym_check_asciionly(str)) symenc = rb_usascii_encoding();
|
if (sym_check_asciionly(str)) symenc = rb_usascii_encoding();
|
||||||
new_id:
|
new_id:
|
||||||
if (symenc != enc) rb_enc_associate(str, symenc);
|
if (symenc != enc) rb_enc_associate(str, symenc);
|
||||||
if (global_symbols.last_id >= ~(ID)0 >> (ID_SCOPE_SHIFT+RUBY_SPECIAL_SHIFT)) {
|
if ((nid = next_id_base()) == (ID)-1) {
|
||||||
if (len > 20) {
|
if (len > 20) {
|
||||||
rb_raise(rb_eRuntimeError, "symbol table overflow (symbol %.20s...)",
|
rb_raise(rb_eRuntimeError, "symbol table overflow (symbol %.20s...)",
|
||||||
name);
|
name);
|
||||||
@ -10515,7 +10525,7 @@ intern_str(VALUE str)
|
|||||||
(int)len, name);
|
(int)len, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
id |= ++global_symbols.last_id << ID_SCOPE_SHIFT;
|
id |= nid;
|
||||||
id_register:
|
id_register:
|
||||||
return register_symid_str(id, str);
|
return register_symid_str(id, str);
|
||||||
}
|
}
|
||||||
@ -10622,6 +10632,12 @@ rb_id2name(ID id)
|
|||||||
return RSTRING_PTR(str);
|
return RSTRING_PTR(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ID
|
||||||
|
rb_make_internal_id(void)
|
||||||
|
{
|
||||||
|
return next_id_base() | ID_INTERNAL;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
symbols_i(VALUE sym, ID value, VALUE ary)
|
symbols_i(VALUE sym, ID value, VALUE ary)
|
||||||
{
|
{
|
||||||
|
@ -595,4 +595,9 @@ class TestMarshal < Test::Unit::TestCase
|
|||||||
Marshal.dump(TestForRespondToFalse.new)
|
Marshal.dump(TestForRespondToFalse.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_packed_string
|
||||||
|
packed = ["foo"].pack("p")
|
||||||
|
assert_equal(Marshal.dump(""+packed), Marshal.dump(packed))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user