aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-01-28 17:02:30 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-01-28 17:09:42 +0900
commit3c3eb418f9ce05740e5ca506b9cd5fe5cabc4bb6 (patch)
treedef41d273b86918acf1c0d918f4080819d4dbaad
parent7cf5d547e422134d506d37a179f64be9e98b105c (diff)
downloadruby-3c3eb418f9ce05740e5ca506b9cd5fe5cabc4bb6.tar.gz
improved support for rb_f_notimplement
rb_f_notimplement should be accepted for all possible arities. Test provided for that.
-rw-r--r--ext/-test-/cxxanyargs/cxxanyargs.cpp30
-rw-r--r--include/ruby/backward/cxxanyargs.hpp20
2 files changed, 48 insertions, 2 deletions
diff --git a/ext/-test-/cxxanyargs/cxxanyargs.cpp b/ext/-test-/cxxanyargs/cxxanyargs.cpp
index efe35fa359..eef2387650 100644
--- a/ext/-test-/cxxanyargs/cxxanyargs.cpp
+++ b/ext/-test-/cxxanyargs/cxxanyargs.cpp
@@ -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;
}
}
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)> {};