ruby-changes:53801
From: nobu <ko1@a...>
Date: Tue, 27 Nov 2018 12:19:12 +0900 (JST)
Subject: [ruby-changes:53801] nobu:r66019 (trunk): Add rb_typeddata_is_instance_of
nobu 2018-11-27 12:19:06 +0900 (Tue, 27 Nov 2018) New Revision: 66019 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66019 Log: Add rb_typeddata_is_instance_of Similar to rb_typeddata_is_kind_of, except for that inherited type is not an instance. Modified files: trunk/error.c trunk/internal.h trunk/iseq.c Index: iseq.c =================================================================== --- iseq.c (revision 66018) +++ iseq.c (revision 66019) @@ -2329,9 +2329,7 @@ iseqw_s_of(VALUE klass, VALUE body) https://github.com/ruby/ruby/blob/trunk/iseq.c#L2329 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; } Index: error.c =================================================================== --- error.c (revision 66018) +++ error.c (revision 66019) @@ -830,6 +830,13 @@ rb_typeddata_is_kind_of(VALUE obj, const https://github.com/ruby/ruby/blob/trunk/error.c#L830 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) { Index: internal.h =================================================================== --- internal.h (revision 66018) +++ internal.h (revision 66019) @@ -2266,6 +2266,13 @@ NORETURN(void rb_unexpected_type(VALUE,i https://github.com/ruby/ruby/blob/trunk/internal.h#L2266 ((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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/