зеркало из https://github.com/github/ruby.git
improved support for rb_f_notimplement
rb_f_notimplement should be accepted for all possible arities. Test provided for that.
This commit is contained in:
Родитель
7cf5d547e4
Коммит
3c3eb418f9
|
@ -383,6 +383,12 @@ namespace test_rb_define_method {
|
|||
rb_define_method(self, "ma", (VALUE (*)(...))(ma), -2);
|
||||
rb_define_method(self, "mv", (VALUE (*)(...))(mv), -1);
|
||||
|
||||
// rb_f_notimplement
|
||||
rb_define_method(self, "m1", rb_f_notimplement, 1);
|
||||
rb_define_method(self, "m2", rb_f_notimplement, 2);
|
||||
rb_define_method(self, "ma", rb_f_notimplement, -2);
|
||||
rb_define_method(self, "mv", rb_f_notimplement, -1);
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
@ -433,6 +439,12 @@ namespace test_rb_define_module_function {
|
|||
rb_define_module_function(self, "ma", (VALUE (*)(...))(ma), -2);
|
||||
rb_define_module_function(self, "mv", (VALUE (*)(...))(mv), -1);
|
||||
|
||||
// rb_f_notimplement
|
||||
rb_define_module_function(self, "m1", rb_f_notimplement, 1);
|
||||
rb_define_module_function(self, "m2", rb_f_notimplement, 2);
|
||||
rb_define_module_function(self, "ma", rb_f_notimplement, -2);
|
||||
rb_define_module_function(self, "mv", rb_f_notimplement, -1);
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
@ -483,6 +495,12 @@ namespace test_rb_define_singleton_method {
|
|||
rb_define_singleton_method(self, "ma", (VALUE (*)(...))(ma), -2);
|
||||
rb_define_singleton_method(self, "mv", (VALUE (*)(...))(mv), -1);
|
||||
|
||||
// rb_f_notimplement
|
||||
rb_define_singleton_method(self, "m1", rb_f_notimplement, 1);
|
||||
rb_define_singleton_method(self, "m2", rb_f_notimplement, 2);
|
||||
rb_define_singleton_method(self, "ma", rb_f_notimplement, -2);
|
||||
rb_define_singleton_method(self, "mv", rb_f_notimplement, -1);
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
@ -533,6 +551,12 @@ namespace test_rb_define_protected_method {
|
|||
rb_define_protected_method(self, "ma", (VALUE (*)(...))(ma), -2);
|
||||
rb_define_protected_method(self, "mv", (VALUE (*)(...))(mv), -1);
|
||||
|
||||
// rb_f_notimplement
|
||||
rb_define_protected_method(self, "m1", rb_f_notimplement, 1);
|
||||
rb_define_protected_method(self, "m2", rb_f_notimplement, 2);
|
||||
rb_define_protected_method(self, "ma", rb_f_notimplement, -2);
|
||||
rb_define_protected_method(self, "mv", rb_f_notimplement, -1);
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
@ -583,6 +607,12 @@ namespace test_rb_define_private_method {
|
|||
rb_define_private_method(self, "ma", (VALUE (*)(...))(ma), -2);
|
||||
rb_define_private_method(self, "mv", (VALUE (*)(...))(mv), -1);
|
||||
|
||||
// rb_f_notimplement
|
||||
rb_define_private_method(self, "m1", rb_f_notimplement, 1);
|
||||
rb_define_private_method(self, "m2", rb_f_notimplement, 2);
|
||||
rb_define_private_method(self, "ma", rb_f_notimplement, -2);
|
||||
rb_define_private_method(self, "mv", rb_f_notimplement, -1);
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)> {};
|
||||
|
|
Загрузка…
Ссылка в новой задаче