Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit b2b5a5db0925f94220897813a552aa7d4ec2fd11 1 parent 5ba39a1
@nobu nobu authored
View
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>
* vsnprintf.c: remove duplicated def of `UNINITIALIZED_VAR()'.
View
1  internal.h
@@ -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);
View
2  marshal.c
@@ -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)
View
2  pack.c
@@ -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();
}
View
20 parse.y
@@ -10408,6 +10408,15 @@ rb_intern3(const char *name, long len, rb_encoding *enc)
}
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)
{
const char *name, *m, *e;
@@ -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);
@@ -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);
@@ -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);
}
@@ -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)
{
View
5 test/ruby/test_marshal.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.