mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* io.c (parse_mode_enc): set set_by_bom bit. [ruby-core:30641]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									dd4b718457
								
							
						
					
					
						commit
						6fa0b50416
					
				
					 4 changed files with 20 additions and 12 deletions
				
			
		|  | @ -1,3 +1,7 @@ | ||||||
|  | Tue Jun  8 06:04:49 2010  Nobuyoshi Nakada  <nobu@ruby-lang.org> | ||||||
|  | 
 | ||||||
|  | 	* io.c (parse_mode_enc): set set_by_bom bit.  [ruby-core:30641] | ||||||
|  | 
 | ||||||
| Sun Jun  6 23:35:12 2010  Masaya Tarui  <tarui@ruby-lnag.org> | Sun Jun  6 23:35:12 2010  Masaya Tarui  <tarui@ruby-lnag.org> | ||||||
| 
 | 
 | ||||||
| 	* gc.c (heaps_slot, assign_heap_slot, gc_sweep): skip sweep if | 	* gc.c (heaps_slot, assign_heap_slot, gc_sweep): skip sweep if | ||||||
|  |  | ||||||
							
								
								
									
										20
									
								
								io.c
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								io.c
									
										
									
									
									
								
							|  | @ -4216,7 +4216,7 @@ rb_io_ext_int_to_encs(rb_encoding *ext, rb_encoding *intern, rb_encoding **enc, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void | static void | ||||||
| parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p) | parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p) | ||||||
| { | { | ||||||
|     const char *p; |     const char *p; | ||||||
|     char encname[ENCODING_MAXNAMELEN+1]; |     char encname[ENCODING_MAXNAMELEN+1]; | ||||||
|  | @ -4232,6 +4232,7 @@ parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p) | ||||||
| 	    idx = -1; | 	    idx = -1; | ||||||
| 	else { | 	else { | ||||||
| 	    if (io_encname_bom_p(estr, len)) { | 	    if (io_encname_bom_p(estr, len)) { | ||||||
|  | 		if (fmode_p) *fmode_p |= FMODE_SETENC_BY_BOM; | ||||||
| 		estr += 4; | 		estr += 4; | ||||||
|                 len -= 4; |                 len -= 4; | ||||||
|             } |             } | ||||||
|  | @ -4244,6 +4245,7 @@ parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p) | ||||||
|     else { |     else { | ||||||
| 	long len = strlen(estr); | 	long len = strlen(estr); | ||||||
| 	if (io_encname_bom_p(estr, len)) { | 	if (io_encname_bom_p(estr, len)) { | ||||||
|  | 	    if (fmode_p) *fmode_p |= FMODE_SETENC_BY_BOM; | ||||||
| 	    estr += 4; | 	    estr += 4; | ||||||
|             len -= 4; |             len -= 4; | ||||||
| 	    memcpy(encname, estr, len); | 	    memcpy(encname, estr, len); | ||||||
|  | @ -4288,7 +4290,7 @@ mode_enc(rb_io_t *fptr, const char *estr) | ||||||
| { | { | ||||||
|     clear_codeconv(fptr); |     clear_codeconv(fptr); | ||||||
| 
 | 
 | ||||||
|     parse_mode_enc(estr, &fptr->encs.enc, &fptr->encs.enc2); |     parse_mode_enc(estr, &fptr->encs.enc, &fptr->encs.enc2, NULL); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void | static void | ||||||
|  | @ -4301,7 +4303,7 @@ rb_io_mode_enc(rb_io_t *fptr, const char *modestr) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int | int | ||||||
| rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p) | rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p) | ||||||
| { | { | ||||||
|     VALUE encoding=Qnil, extenc=Qundef, intenc=Qundef, tmp; |     VALUE encoding=Qnil, extenc=Qundef, intenc=Qundef, tmp; | ||||||
|     int extracted = 0; |     int extracted = 0; | ||||||
|  | @ -4351,7 +4353,7 @@ rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2 | ||||||
|     } |     } | ||||||
|     if (!NIL_P(encoding)) { |     if (!NIL_P(encoding)) { | ||||||
| 	extracted = 1; | 	extracted = 1; | ||||||
| 	parse_mode_enc(StringValueCStr(encoding), enc_p, enc2_p); | 	parse_mode_enc(StringValueCStr(encoding), enc_p, enc2_p, fmode_p); | ||||||
|     } |     } | ||||||
|     else if (extenc != Qundef || intenc != Qundef) { |     else if (extenc != Qundef || intenc != Qundef) { | ||||||
|         extracted = 1; |         extracted = 1; | ||||||
|  | @ -4426,9 +4428,7 @@ rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, | ||||||
|         p = strchr(p, ':'); |         p = strchr(p, ':'); | ||||||
|         if (p) { |         if (p) { | ||||||
|             has_enc = 1; |             has_enc = 1; | ||||||
|             parse_mode_enc(p+1, &enc, &enc2); |             parse_mode_enc(p+1, &enc, &enc2, &fmode); | ||||||
| 	    if (io_encname_bom_p(p+1, 0)) |  | ||||||
| 		fmode |= FMODE_SETENC_BY_BOM; |  | ||||||
|         } |         } | ||||||
| 	else { | 	else { | ||||||
| 	    rb_encoding *e; | 	    rb_encoding *e; | ||||||
|  | @ -4474,7 +4474,7 @@ rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, | ||||||
| 	} | 	} | ||||||
|         ecflags = rb_econv_prepare_opts(opthash, &ecopts); |         ecflags = rb_econv_prepare_opts(opthash, &ecopts); | ||||||
| 
 | 
 | ||||||
|         if (rb_io_extract_encoding_option(opthash, &enc, &enc2)) { |         if (rb_io_extract_encoding_option(opthash, &enc, &enc2, &fmode)) { | ||||||
|             if (has_enc) { |             if (has_enc) { | ||||||
|                 rb_raise(rb_eArgError, "encoding specified twice"); |                 rb_raise(rb_eArgError, "encoding specified twice"); | ||||||
|             } |             } | ||||||
|  | @ -4700,7 +4700,7 @@ rb_file_open_internal(VALUE io, VALUE filename, const char *modestr) | ||||||
|     convconfig_t convconfig; |     convconfig_t convconfig; | ||||||
| 
 | 
 | ||||||
|     if (p) { |     if (p) { | ||||||
|         parse_mode_enc(p+1, &convconfig.enc, &convconfig.enc2); |         parse_mode_enc(p+1, &convconfig.enc, &convconfig.enc2, &fmode); | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
| 	rb_encoding *e; | 	rb_encoding *e; | ||||||
|  | @ -7630,7 +7630,7 @@ io_encoding_set(rb_io_t *fptr, VALUE v1, VALUE v2, VALUE opt) | ||||||
| 	else { | 	else { | ||||||
| 	    tmp = rb_check_string_type(v1); | 	    tmp = rb_check_string_type(v1); | ||||||
| 	    if (!NIL_P(tmp) && rb_enc_asciicompat(rb_enc_get(tmp))) { | 	    if (!NIL_P(tmp) && rb_enc_asciicompat(rb_enc_get(tmp))) { | ||||||
|                 parse_mode_enc(RSTRING_PTR(tmp), &enc, &enc2); |                 parse_mode_enc(RSTRING_PTR(tmp), &enc, &enc2, NULL); | ||||||
|                 ecflags = rb_econv_prepare_opts(opt, &ecopts); |                 ecflags = rb_econv_prepare_opts(opt, &ecopts); | ||||||
| 	    } | 	    } | ||||||
| 	    else { | 	    else { | ||||||
|  |  | ||||||
|  | @ -1740,6 +1740,10 @@ EOT | ||||||
|         assert_equal(content[1].force_encoding("ascii-8bit"), |         assert_equal(content[1].force_encoding("ascii-8bit"), | ||||||
|                      result.force_encoding("ascii-8bit")) |                      result.force_encoding("ascii-8bit")) | ||||||
|       end |       end | ||||||
|  | 
 | ||||||
|  |       bug3407 = '[ruby-core:30641]' | ||||||
|  |       result = File.read('UTF-8-bom.txt', encoding: 'BOM|UTF-8') | ||||||
|  |       assert_equal("a", result.force_encoding("ascii-8bit"), bug3407) | ||||||
|     } |     } | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| #define RUBY_VERSION "1.9.2" | #define RUBY_VERSION "1.9.2" | ||||||
| #define RUBY_RELEASE_DATE "2010-06-06" | #define RUBY_RELEASE_DATE "2010-06-08" | ||||||
| #define RUBY_PATCHLEVEL -1 | #define RUBY_PATCHLEVEL -1 | ||||||
| 
 | 
 | ||||||
| #define RUBY_VERSION_MAJOR 1 | #define RUBY_VERSION_MAJOR 1 | ||||||
|  | @ -7,7 +7,7 @@ | ||||||
| #define RUBY_VERSION_TEENY 1 | #define RUBY_VERSION_TEENY 1 | ||||||
| #define RUBY_RELEASE_YEAR 2010 | #define RUBY_RELEASE_YEAR 2010 | ||||||
| #define RUBY_RELEASE_MONTH 6 | #define RUBY_RELEASE_MONTH 6 | ||||||
| #define RUBY_RELEASE_DAY 6 | #define RUBY_RELEASE_DAY 8 | ||||||
| 
 | 
 | ||||||
| #include "ruby/version.h" | #include "ruby/version.h" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 nobu
						nobu