From b549d14c00784b45e7248cac7e1274f8a15f9883 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 27 Nov 2018 03:19:06 +0000 Subject: Add rb_typeddata_is_instance_of Similar to rb_typeddata_is_kind_of, except for that inherited type is not an instance. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- error.c | 7 +++++++ internal.h | 7 +++++++ iseq.c | 4 +--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/error.c b/error.c index fc3022f854..8e97f4919d 100644 --- a/error.c +++ b/error.c @@ -830,6 +830,13 @@ rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type) return 1; } +#undef rb_typeddata_is_instance_of +int +rb_typeddata_is_instance_of(VALUE obj, const rb_data_type_t *data_type) +{ + return rb_typeddata_is_instance_of_inline(obj, data_type); +} + void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type) { diff --git a/internal.h b/internal.h index b49939c61f..8f69c6f1da 100644 --- a/internal.h +++ b/internal.h @@ -2266,6 +2266,13 @@ NORETURN(void rb_unexpected_type(VALUE,int)); ((t) == RUBY_T_DATA && RTYPEDDATA_P(v)) ? \ rb_unexpected_type((VALUE)(v), (t)) : (void)0) +static inline int +rb_typeddata_is_instance_of_inline(VALUE obj, const rb_data_type_t *data_type) +{ + return RB_TYPE_P(obj, T_DATA) && RTYPEDDATA_P(obj) && (RTYPEDDATA_TYPE(obj) == data_type); +} +#define rb_typeddata_is_instance_of rb_typeddata_is_instance_of_inline + /* file.c (export) */ #if defined HAVE_READLINK && defined RUBY_ENCODING_H VALUE rb_readlink(VALUE path, rb_encoding *enc); diff --git a/iseq.c b/iseq.c index 888f7f5061..0b5f7c14e4 100644 --- a/iseq.c +++ b/iseq.c @@ -2329,9 +2329,7 @@ iseqw_s_of(VALUE klass, VALUE body) else if (rb_obj_is_method(body)) { iseq = rb_method_iseq(body); } - else if (RB_TYPE_P(body, T_DATA) && - RTYPEDDATA_P(body) && - RTYPEDDATA_TYPE(body) == &iseqw_data_type) { + else if (rb_typeddata_is_instance_of(body, &iseqw_data_type)) { return body; } -- cgit v1.2.3