From b4bb59354a957d88942dd6ae51e11bafe661fa13 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 28 Jun 2018 08:35:48 +0000 Subject: check enc_capable. * encoding.c (rb_enc_capable): make it extern to check enc_capable. enc_index can be set to limited types such as T_STRING, T_REGEX and so on. This function check an object is this kind of types. * include/ruby/encoding.h: ditto. * encoding.c (enc_set_index): check a given object is enc_capable. * include/ruby/encoding.h (PUREFUNC): * marshal.c (encoding_name): check `rb_enc_capable` first. * marshal.c (r_ivar): ditto. If it is not enc_capable, it should be malformed data. * spec/ruby/optional/capi/encoding_spec.rb: remove tests depending on the wrong feature: all objects can set enc_index. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- encoding.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'encoding.c') diff --git a/encoding.c b/encoding.c index 9744c1d692..8d1894aa91 100644 --- a/encoding.c +++ b/encoding.c @@ -756,6 +756,12 @@ enc_capable(VALUE obj) } } +int +rb_enc_capable(VALUE obj) +{ + return enc_capable(obj); +} + ID rb_id_encoding(void) { @@ -813,6 +819,8 @@ rb_enc_get_index(VALUE obj) static void enc_set_index(VALUE obj, int idx) { + if (!enc_capable(obj)) rb_bug("enc_set_index: not capable object"); + if (idx < ENCODING_INLINE_MAX) { ENCODING_SET_INLINED(obj, idx); return; -- cgit v1.2.3