mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	error.c: preserve encoding
* error.c (rb_error_frozen_object): preserve encoding of class name in error message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									d9a597408f
								
							
						
					
					
						commit
						8b9afe6520
					
				
					 3 changed files with 20 additions and 1 deletions
				
			
		
							
								
								
									
										7
									
								
								error.c
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								error.c
									
										
									
									
									
								
							|  | @ -2129,6 +2129,13 @@ rb_error_frozen(const char *what) | |||
|     rb_raise(rb_eRuntimeError, "can't modify frozen %s", what); | ||||
| } | ||||
| 
 | ||||
| void | ||||
| rb_error_frozen_object(VALUE frozen_obj) | ||||
| { | ||||
|     rb_raise(rb_eRuntimeError, "can't modify frozen %"PRIsVALUE, | ||||
| 	     CLASS_OF(frozen_obj)); | ||||
| } | ||||
| 
 | ||||
| #undef rb_check_frozen | ||||
| void | ||||
| rb_check_frozen(VALUE obj) | ||||
|  |  | |||
|  | @ -255,13 +255,14 @@ PRINTF_ARGS(void rb_compile_error(const char*, int, const char*, ...), 3, 4); | |||
| PRINTF_ARGS(void rb_compile_error_with_enc(const char*, int, void *, const char*, ...), 4, 5); | ||||
| PRINTF_ARGS(void rb_compile_error_append(const char*, ...), 1, 2); | ||||
| NORETURN(void rb_error_frozen(const char*)); | ||||
| NORETURN(void rb_error_frozen_object(VALUE)); | ||||
| void rb_error_untrusted(VALUE); | ||||
| void rb_check_frozen(VALUE); | ||||
| void rb_check_trusted(VALUE); | ||||
| #define rb_check_frozen_internal(obj) do { \ | ||||
| 	VALUE frozen_obj = (obj); \ | ||||
| 	if (OBJ_FROZEN(frozen_obj)) { \ | ||||
| 	    rb_error_frozen(rb_obj_classname(frozen_obj)); \ | ||||
| 	    rb_error_frozen_object(frozen_obj); \ | ||||
| 	} \ | ||||
|     } while (0) | ||||
| #define rb_check_trusted_internal(obj) ((void) 0) | ||||
|  |  | |||
|  | @ -68,6 +68,17 @@ class TestObject < Test::Unit::TestCase | |||
|     assert_equal(true, nil.frozen?) | ||||
|   end | ||||
| 
 | ||||
|   def test_frozen_error_message | ||||
|     name = "C\u{30c6 30b9 30c8}" | ||||
|     klass = EnvUtil.labeled_class(name) { | ||||
|       attr_accessor :foo | ||||
|     } | ||||
|     obj = klass.new.freeze | ||||
|     assert_raise_with_message(RuntimeError, /#{name}/) { | ||||
|       obj.foo = 1 | ||||
|     } | ||||
|   end | ||||
| 
 | ||||
|   def test_nil_to_f | ||||
|     assert_equal(0.0, nil.to_f) | ||||
|   end | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 nobu
						nobu