[前][次][番号順一覧][スレッド一覧]

ruby-changes:59845

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 28 Jan 2020 17:11:28 +0900 (JST)
Subject: [ruby-changes:59845] 3c3eb418f9 (master): improved support for rb_f_notimplement

https://git.ruby-lang.org/ruby.git/commit/?id=3c3eb418f9

From 3c3eb418f9ce05740e5ca506b9cd5fe5cabc4bb6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Tue, 28 Jan 2020 17:02:30 +0900
Subject: improved support for rb_f_notimplement

rb_f_notimplement should be accepted for all possible arities.

Test provided for that.

diff --git a/ext/-test-/cxxanyargs/cxxanyargs.cpp b/ext/-test-/cxxanyargs/cxxanyargs.cpp
index efe35fa..eef2387 100644
--- a/ext/-test-/cxxanyargs/cxxanyargs.cpp
+++ b/ext/-test-/cxxanyargs/cxxanyargs.cpp
@@ -383,6 +383,12 @@ namespace test_rb_define_method { https://github.com/ruby/ruby/blob/trunk/ext/-test-/cxxanyargs/cxxanyargs.cpp#L383
         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 { https://github.com/ruby/ruby/blob/trunk/ext/-test-/cxxanyargs/cxxanyargs.cpp#L439
         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 { https://github.com/ruby/ruby/blob/trunk/ext/-test-/cxxanyargs/cxxanyargs.cpp#L495
         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 { https://github.com/ruby/ruby/blob/trunk/ext/-test-/cxxanyargs/cxxanyargs.cpp#L551
         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 { https://github.com/ruby/ruby/blob/trunk/ext/-test-/cxxanyargs/cxxanyargs.cpp#L607
         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 16529f8..31758c1 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) https://github.com/ruby/ruby/blob/trunk/include/ruby/backward/cxxanyargs.hpp#L446
 /// 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 { https://github.com/ruby/ruby/blob/trunk/include/ruby/backward/cxxanyargs.hpp#L493
         {
             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 { https://github.com/ruby/ruby/blob/trunk/include/ruby/backward/cxxanyargs.hpp#L526
     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 { https://github.com/ruby/ruby/blob/trunk/include/ruby/backward/cxxanyargs.hpp#L548
         {
             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 { https://github.com/ruby/ruby/blob/trunk/include/ruby/backward/cxxanyargs.hpp#L574
     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)> {};
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]