[前][次][番号順一覧][スレッド一覧]

ruby-changes:32761

From: nobu <ko1@a...>
Date: Wed, 5 Feb 2014 20:56:41 +0900 (JST)
Subject: [ruby-changes:32761] nobu:r44840 (trunk): pack.c: hide associated objects

nobu	2014-02-05 20:56:35 +0900 (Wed, 05 Feb 2014)

  New Revision: 44840

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44840

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/internal.h
    trunk/marshal.c
    trunk/pack.c
    trunk/parse.y
    trunk/test/ruby/test_marshal.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44839)
+++ ChangeLog	(revision 44840)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Feb  5 20:56:32 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@a...>
 
 	* vsnprintf.c: remove duplicated def of `UNINITIALIZED_VAR()'.
Index: pack.c
===================================================================
--- pack.c	(revision 44839)
+++ pack.c	(revision 44840)
@@ -2046,5 +2046,5 @@ Init_pack(void) https://github.com/ruby/ruby/blob/trunk/pack.c#L2046
     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();
 }
Index: parse.y
===================================================================
--- parse.y	(revision 44839)
+++ parse.y	(revision 44840)
@@ -10408,6 +10408,15 @@ rb_intern3(const char *name, long len, r https://github.com/ruby/ruby/blob/trunk/parse.y#L10408
 }
 
 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) https://github.com/ruby/ruby/blob/trunk/parse.y#L10424
     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) https://github.com/ruby/ruby/blob/trunk/parse.y#L10515
     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) https://github.com/ruby/ruby/blob/trunk/parse.y#L10525
 		     (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) https://github.com/ruby/ruby/blob/trunk/parse.y#L10632
     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)
 {
Index: internal.h
===================================================================
--- internal.h	(revision 44839)
+++ internal.h	(revision 44840)
@@ -642,6 +642,7 @@ int rb_is_method_name(VALUE name); https://github.com/ruby/ruby/blob/trunk/internal.h#L642
 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);
Index: marshal.c
===================================================================
--- marshal.c	(revision 44839)
+++ marshal.c	(revision 44840)
@@ -513,7 +513,7 @@ w_uclass(VALUE obj, VALUE super, struct https://github.com/ruby/ruby/blob/trunk/marshal.c#L513
     }
 }
 
-#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)
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 44839)
+++ test/ruby/test_marshal.rb	(revision 44840)
@@ -595,4 +595,9 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L595
       Marshal.dump(TestForRespondToFalse.new)
     end
   end
+
+  def test_packed_string
+    packed = ["foo"].pack("p")
+    assert_equal(Marshal.dump(""+packed), Marshal.dump(packed))
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]