mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	parse.y: non-local/const attrset
* parse.y (rb_id_attrset): allow other than ID_ATTRSET. * parse.y (intern_str): ditto. try stem ID for ID_INSTANCE, ID_GLOBAL, ID_CLASS, ID_JUNK too. [Bug #8756] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									90749b1f2a
								
							
						
					
					
						commit
						0dd8ec36c0
					
				
					 3 changed files with 42 additions and 21 deletions
				
			
		| 
						 | 
					@ -1,3 +1,10 @@
 | 
				
			||||||
 | 
					Sat Aug 10 13:53:22 2013  Nobuyoshi Nakada  <nobu@ruby-lang.org>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						* parse.y (rb_id_attrset): allow other than ID_ATTRSET.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						* parse.y (intern_str): ditto.  try stem ID for ID_INSTANCE,
 | 
				
			||||||
 | 
						  ID_GLOBAL, ID_CLASS, ID_JUNK too.  [Bug #8756]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Sat Aug 10 12:49:50 2013  Kouhei Sutou  <kou@cozmixng.org>
 | 
					Sat Aug 10 12:49:50 2013  Kouhei Sutou  <kou@cozmixng.org>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	* lib/rexml/parsers/baseparser.rb
 | 
						* lib/rexml/parsers/baseparser.rb
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										34
									
								
								parse.y
									
										
									
									
									
								
							
							
						
						
									
										34
									
								
								parse.y
									
										
									
									
									
								
							| 
						 | 
					@ -8785,7 +8785,11 @@ rb_id_attrset(ID id)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
	int scope = (int)(id & ID_SCOPE_MASK);
 | 
						int scope = (int)(id & ID_SCOPE_MASK);
 | 
				
			||||||
	if (scope != ID_LOCAL && scope != ID_CONST) {
 | 
						switch (scope) {
 | 
				
			||||||
 | 
						  case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL:
 | 
				
			||||||
 | 
						  case ID_CONST: case ID_CLASS: case ID_JUNK:
 | 
				
			||||||
 | 
						    break;
 | 
				
			||||||
 | 
						  default:
 | 
				
			||||||
	    rb_bug("rb_id_attrset: %s ID - %"PRIdVALUE, id_type_names[scope],
 | 
						    rb_bug("rb_id_attrset: %s ID - %"PRIdVALUE, id_type_names[scope],
 | 
				
			||||||
		   (VALUE)id);
 | 
							   (VALUE)id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10415,8 +10419,9 @@ intern_str(VALUE str)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						break;
 | 
				
			||||||
	if (m[last] == '=') {
 | 
					    }
 | 
				
			||||||
 | 
					    if (name[last] == '=') {
 | 
				
			||||||
	/* attribute assignment */
 | 
						/* attribute assignment */
 | 
				
			||||||
	id = rb_intern3(name, last, enc);
 | 
						id = rb_intern3(name, last, enc);
 | 
				
			||||||
	if (id > tLAST_OP_ID && !is_attrset_id(id)) {
 | 
						if (id > tLAST_OP_ID && !is_attrset_id(id)) {
 | 
				
			||||||
| 
						 | 
					@ -10426,13 +10431,13 @@ intern_str(VALUE str)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	id = ID_ATTRSET;
 | 
						id = ID_ATTRSET;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
	else if (rb_enc_isupper(m[0], enc)) {
 | 
					    else if (id == 0) {
 | 
				
			||||||
 | 
						if (rb_enc_isupper(m[0], enc)) {
 | 
				
			||||||
	    id = ID_CONST;
 | 
						    id = ID_CONST;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else {
 | 
						else {
 | 
				
			||||||
	    id = ID_LOCAL;
 | 
						    id = ID_LOCAL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	break;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!rb_enc_isdigit(*m, enc)) {
 | 
					    if (!rb_enc_isdigit(*m, enc)) {
 | 
				
			||||||
	while (m <= name + last && is_identchar(m, e, enc)) {
 | 
						while (m <= name + last && is_identchar(m, e, enc)) {
 | 
				
			||||||
| 
						 | 
					@ -10444,7 +10449,7 @@ intern_str(VALUE str)
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (m - name < len) id = ID_JUNK;
 | 
					    if (id != ID_ATTRSET && m - name < len) id = ID_JUNK;
 | 
				
			||||||
    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);
 | 
				
			||||||
| 
						 | 
					@ -10527,16 +10532,21 @@ rb_id2str(ID id)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (is_attrset_id(id)) {
 | 
					    if (is_attrset_id(id)) {
 | 
				
			||||||
	ID id2 = (id & ~ID_SCOPE_MASK) | ID_LOCAL;
 | 
						ID id_stem = (id & ~ID_SCOPE_MASK);
 | 
				
			||||||
	VALUE str;
 | 
						VALUE str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (!(str = rb_id2str(id2))) {
 | 
						do {
 | 
				
			||||||
	    if (!is_local_id(id2)) return 0;
 | 
						    if (!!(str = rb_id2str(id_stem | ID_LOCAL))) break;
 | 
				
			||||||
	    id2 = (id & ~ID_SCOPE_MASK) | ID_CONST;
 | 
						    if (!!(str = rb_id2str(id_stem | ID_CONST))) break;
 | 
				
			||||||
	}
 | 
						    if (!!(str = rb_id2str(id_stem | ID_INSTANCE))) break;
 | 
				
			||||||
 | 
						    if (!!(str = rb_id2str(id_stem | ID_GLOBAL))) break;
 | 
				
			||||||
 | 
						    if (!!(str = rb_id2str(id_stem | ID_CLASS))) break;
 | 
				
			||||||
 | 
						    if (!!(str = rb_id2str(id_stem | ID_JUNK))) break;
 | 
				
			||||||
 | 
						    return 0;
 | 
				
			||||||
 | 
						} while (0);
 | 
				
			||||||
	str = rb_str_dup(str);
 | 
						str = rb_str_dup(str);
 | 
				
			||||||
	rb_str_cat(str, "=", 1);
 | 
						rb_str_cat(str, "=", 1);
 | 
				
			||||||
	rb_intern_str(str);
 | 
						register_symid_str(id, str);
 | 
				
			||||||
	if (st_lookup(global_symbols.id_str, id, &data)) {
 | 
						if (st_lookup(global_symbols.id_str, id, &data)) {
 | 
				
			||||||
            VALUE str = (VALUE)data;
 | 
					            VALUE str = (VALUE)data;
 | 
				
			||||||
            if (RBASIC(str)->klass == 0)
 | 
					            if (RBASIC(str)->klass == 0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,6 +132,10 @@ class TestStruct < Test::Unit::TestCase
 | 
				
			||||||
    klass = Struct.new(:@a)
 | 
					    klass = Struct.new(:@a)
 | 
				
			||||||
    o = klass.new(1)
 | 
					    o = klass.new(1)
 | 
				
			||||||
    assert_equal("#<struct :@a=1>", o.inspect)
 | 
					    assert_equal("#<struct :@a=1>", o.inspect)
 | 
				
			||||||
 | 
					    methods = klass.instance_methods(false)
 | 
				
			||||||
 | 
					    assert_equal([:@a, :"@a="].inspect, methods.inspect, '[Bug #8756]')
 | 
				
			||||||
 | 
					    assert_include(methods, :@a)
 | 
				
			||||||
 | 
					    assert_include(methods, :"@a=")
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def test_init_copy
 | 
					  def test_init_copy
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue