Skip to content

Commit

Permalink
pack.c: hide associated objects
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Feb 5, 2014
1 parent 5ba39a1 commit b2b5a5d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
10 changes: 10 additions & 0 deletions 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>

* vsnprintf.c: remove duplicated def of `UNINITIALIZED_VAR()'.
Expand Down
1 change: 1 addition & 0 deletions internal.h
Expand Up @@ -642,6 +642,7 @@ int rb_is_method_name(VALUE name);
int rb_is_junk_name(VALUE name);
void rb_gc_mark_parser(void);
void rb_gc_mark_symbols(int full_mark);
ID rb_make_internal_id(void);

/* proc.c */
VALUE rb_proc_location(VALUE self);
Expand Down
2 changes: 1 addition & 1 deletion marshal.c
Expand Up @@ -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
w_obj_each(st_data_t key, st_data_t val, st_data_t a)
Expand Down
2 changes: 1 addition & 1 deletion pack.c
Expand Up @@ -2046,5 +2046,5 @@ Init_pack(void)
rb_define_method(rb_cArray, "pack", pack_pack, 1);
rb_define_method(rb_cString, "unpack", pack_unpack, 1);

id_associated = rb_intern_const("__pack_associated__");
id_associated = rb_make_internal_id();
}
20 changes: 18 additions & 2 deletions parse.y
Expand Up @@ -10407,6 +10407,15 @@ rb_intern3(const char *name, long len, rb_encoding *enc)
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
intern_str(VALUE str)
{
Expand All @@ -10415,6 +10424,7 @@ intern_str(VALUE str)
rb_encoding *enc, *symenc;
unsigned char c;
ID id;
ID nid;
int mb;

RSTRING_GETMEM(str, name, len);
Expand Down Expand Up @@ -10505,7 +10515,7 @@ intern_str(VALUE str)
if (sym_check_asciionly(str)) symenc = rb_usascii_encoding();
new_id:
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) {
rb_raise(rb_eRuntimeError, "symbol table overflow (symbol %.20s...)",
name);
Expand All @@ -10515,7 +10525,7 @@ intern_str(VALUE str)
(int)len, name);
}
}
id |= ++global_symbols.last_id << ID_SCOPE_SHIFT;
id |= nid;
id_register:
return register_symid_str(id, str);
}
Expand Down Expand Up @@ -10622,6 +10632,12 @@ rb_id2name(ID id)
return RSTRING_PTR(str);
}

ID
rb_make_internal_id(void)
{
return next_id_base() | ID_INTERNAL;
}

static int
symbols_i(VALUE sym, ID value, VALUE ary)
{
Expand Down
5 changes: 5 additions & 0 deletions test/ruby/test_marshal.rb
Expand Up @@ -595,4 +595,9 @@ def test_marshal_respond_to_arity
Marshal.dump(TestForRespondToFalse.new)
end
end

def test_packed_string
packed = ["foo"].pack("p")
assert_equal(Marshal.dump(""+packed), Marshal.dump(packed))
end
end

0 comments on commit b2b5a5d

Please sign in to comment.