diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-08-14 14:45:23 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-08-15 12:09:26 +0900 |
commit | ff30358d13d24d8202f2717c43700be70bdd49d3 (patch) | |
tree | 32757f4895a67fefcfb4830e40e2206a7ac388f7 /include | |
parent | 72d0f2f0e0546a4c7c3b9ec85d3f67a36e9c5038 (diff) |
RARRAY_AREF: convert into an inline function
RARRAY_AREF has been a macro for reasons. We might not be able to
change that for public APIs, but why not relax the situation internally
to make it an inline function.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3419
Diffstat (limited to 'include')
-rw-r--r-- | include/ruby/internal/core/rarray.h | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/include/ruby/internal/core/rarray.h b/include/ruby/internal/core/rarray.h index a21500e1d2..938e2dc897 100644 --- a/include/ruby/internal/core/rarray.h +++ b/include/ruby/internal/core/rarray.h @@ -256,20 +256,15 @@ RARRAY_ASET(VALUE ary, long i, VALUE v) RB_OBJ_WRITE(ary, &ptr[i], v)); } -/* RARRAY_AREF is used as a lvalue. Cannot be a function. */ -#if 0 -RBIMPL_ATTR_PURE_UNLESS_DEBUG() -RBIMPL_ATTR_ARTIFICIAL() -static inline VALUE -RARRAY_AREF(VALUE ary, long i) -{ - RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY); - - return RARRAY_CONST_PTR_TRANSIENT(ary)[i]; -} -#else -# undef RARRAY_AREF -# define RARRAY_AREF(a, i) RARRAY_CONST_PTR_TRANSIENT(a)[i] -#endif +/* + * :FIXME: we want to convert RARRAY_AREF into an inline function (to add rooms + * for more sanity checks). However there were situations where the address of + * this macro is taken i.e. &RARRAY_AREF(...). They cannot be possible if this + * is not a macro. Such usages are abuse, and we eliminated them internally. + * However we are afraid of similar things to remain in the wild. This macro + * remains as it is due to that. If we could warn such usages we can set a + * transition path, but currently no way is found to do so. + */ +#define RARRAY_AREF(a, i) RARRAY_CONST_PTR_TRANSIENT(a)[i] #endif /* RBIMPL_RARRAY_H */ |