aboutsummaryrefslogtreecommitdiffstats
path: root/encoding.c
diff options
context:
space:
mode:
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/encoding.c b/encoding.c
index f2e67ff508..e713b0a922 100644
--- a/encoding.c
+++ b/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;
}