diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-01-28 17:02:30 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-01-28 17:09:42 +0900 |
commit | 3c3eb418f9ce05740e5ca506b9cd5fe5cabc4bb6 (patch) | |
tree | def41d273b86918acf1c0d918f4080819d4dbaad /include | |
parent | 7cf5d547e422134d506d37a179f64be9e98b105c (diff) | |
download | ruby-3c3eb418f9ce05740e5ca506b9cd5fe5cabc4bb6.tar.gz |
improved support for rb_f_notimplement
rb_f_notimplement should be accepted for all possible arities.
Test provided for that.
Diffstat (limited to 'include')
-rw-r--r-- | include/ruby/backward/cxxanyargs.hpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/include/ruby/backward/cxxanyargs.hpp b/include/ruby/backward/cxxanyargs.hpp index 16529f8db2..31758c14e5 100644 --- a/include/ruby/backward/cxxanyargs.hpp +++ b/include/ruby/backward/cxxanyargs.hpp @@ -446,6 +446,9 @@ rb_ivar_foreach(VALUE q, int_type *w, VALUE e) /// types and provide warnings for other cases. This is such attempt. namespace define_method { +/// @brief type of rb_f_notimplement +typedef VALUE notimpl_type(int, const VALUE *, VALUE, VALUE); + /// @brief Template metaprogramming to generate function prototypes. /// @tparam T Type of method id (`ID` or `const char*` in practice). /// @tparam F Definition driver e.g. ::rb_define_method. @@ -490,6 +493,16 @@ struct driver { { F(klass, mid, reinterpret_cast<type *>(func), N); } + + /// @brief Defines klass#mid as func, whose arity is N. + /// @param[in] klass Where the method lives. + /// @param[in] mid Name of the method to define. + /// @param[in] func Function that implements klass#mid. + static inline void + define(VALUE klass, T mid, notimpl_type func) + { + F(klass, mid, reinterpret_cast<type *>(func), N); + } }; /// @cond INTERNAL_MACRO @@ -513,7 +526,6 @@ struct driver { template<bool b> struct specific<-1, b> : public engine<-1, VALUE(*)(int argc, VALUE *argv, VALUE self)> { using engine<-1, VALUE(*)(int argc, VALUE *argv, VALUE self)>::define; static inline void define(VALUE c, T m, VALUE(*f)(int argc, const VALUE *argv, VALUE self)) { F(c, m, reinterpret_cast<type *>(f), -1); } - static inline void define(VALUE c, T m, VALUE(*f)(int argc, const VALUE *argv, VALUE self, VALUE)) { F(c, m, reinterpret_cast<type *>(f), -1); } }; template<bool b> struct specific<-2, b> : public engine<-2, VALUE(*)(VALUE, VALUE)> {}; /// @endcond @@ -536,6 +548,11 @@ struct driver0 { { F(mid, reinterpret_cast<type *>(func), N); } + static inline void + define(T mid, notimpl_type func) + { + F(mid, reinterpret_cast<type *>(func), N); + } }; /// @cond INTERNAL_MACRO template<int N, bool = false> struct specific : public engine<N, type *> {}; @@ -557,7 +574,6 @@ struct driver0 { template<bool b> struct specific< 0, b> : public engine< 0, VALUE(*)(VALUE)> {}; template<bool b> struct specific<-1, b> : public engine<-1, VALUE(*)(int argc, VALUE *argv, VALUE self)> { using engine<-1, VALUE(*)(int argc, VALUE *argv, VALUE self)>::define; - static inline void define(T m, VALUE(*f)(int argc, const VALUE *argv, VALUE self)) { F(m, reinterpret_cast<type *>(f), -1); } static inline void define(T m, VALUE(*f)(int argc, const VALUE *argv, VALUE self, VALUE)) { F(m, reinterpret_cast<type *>(f), -1); } }; template<bool b> struct specific<-2, b> : public engine<-2, VALUE(*)(VALUE, VALUE)> {}; |