mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Get rid of warnings/exceptions at cleanup
After the encoding index instance variable is removed when all instance variables are removed in `obj_free`, then `rb_str_free` causes uninitialized instance variable warning and nil-to-integer conversion exception. Both cases result in object allocation during GC, and crashes.
This commit is contained in:
parent
b1b155ff03
commit
fce667ed08
3 changed files with 14 additions and 0 deletions
10
encoding.c
10
encoding.c
|
@ -779,8 +779,18 @@ enc_get_index_str(VALUE str)
|
|||
if (i == ENCODING_INLINE_MAX) {
|
||||
VALUE iv;
|
||||
|
||||
#if 0
|
||||
iv = rb_ivar_get(str, rb_id_encoding());
|
||||
i = NUM2INT(iv);
|
||||
#else
|
||||
/*
|
||||
* Tentatively, assume ASCII-8BIT, if encoding index instance
|
||||
* variable is not found. This can happen when freeing after
|
||||
* all instance variables are removed in `obj_free`.
|
||||
*/
|
||||
iv = rb_attr_get(str, rb_id_encoding());
|
||||
i = NIL_P(iv) ? ENCINDEX_ASCII : NUM2INT(iv);
|
||||
#endif
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
|
1
string.c
1
string.c
|
@ -181,6 +181,7 @@ VALUE rb_cSymbol;
|
|||
|
||||
#define STR_HEAP_PTR(str) (RSTRING(str)->as.heap.ptr)
|
||||
#define STR_HEAP_SIZE(str) ((size_t)RSTRING(str)->as.heap.aux.capa + TERM_LEN(str))
|
||||
/* TODO: include the terminator size in capa. */
|
||||
|
||||
#define STR_ENC_GET(str) get_encoding(str)
|
||||
|
||||
|
|
|
@ -76,6 +76,9 @@ class TestEncoding < Test::Unit::TestCase
|
|||
assert_equal("0", format % 0)
|
||||
assert_equal(e, format.dup.encoding)
|
||||
assert_equal(e, (format*1).encoding)
|
||||
|
||||
assert_equal(e, (("x"*30).force_encoding(e)*1).encoding)
|
||||
GC.start
|
||||
end;
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue