diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-01-28 17:20:16 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-01-28 17:29:57 +0900 |
commit | 83d6487ae5c5df6c463373b36ccf1bee3f91d386 (patch) | |
tree | 4e6506890db03f4fc78ceca1bb28579330fc4021 | |
parent | bbe3420cce30de74b8c4a4f21adecf57a7d52395 (diff) | |
download | ruby-83d6487ae5c5df6c463373b36ccf1bee3f91d386.tar.gz |
fix rb_define_global_function to take const VALUE*
It was unable for rb_define_global_function to take VALUE(*)(int argc,
const VLAUE *argv, VALUE self) -style function. Test added.
-rw-r--r-- | ext/-test-/cxxanyargs/cxxanyargs.cpp | 70 | ||||
-rw-r--r-- | include/ruby/backward/cxxanyargs.hpp | 2 |
2 files changed, 71 insertions, 1 deletions
diff --git a/ext/-test-/cxxanyargs/cxxanyargs.cpp b/ext/-test-/cxxanyargs/cxxanyargs.cpp index a9f2d9ab7c..812c6d7e60 100644 --- a/ext/-test-/cxxanyargs/cxxanyargs.cpp +++ b/ext/-test-/cxxanyargs/cxxanyargs.cpp @@ -362,6 +362,12 @@ namespace test_rb_define_method { return Qnil; } + static VALUE + mc(int, const VALUE*, VALUE) + { + return Qnil; + } + VALUE test(VALUE self) { @@ -370,24 +376,28 @@ namespace test_rb_define_method { rb_define_method(self, "m2", m2, 2); rb_define_method(self, "ma", ma, -2); rb_define_method(self, "mv", mv, -1); + rb_define_method(self, "mc", mc, -1); // Cast by RUBY_METHOD_FUNC rb_define_method(self, "m1", RUBY_METHOD_FUNC(m1), 1); rb_define_method(self, "m2", RUBY_METHOD_FUNC(m2), 2); rb_define_method(self, "ma", RUBY_METHOD_FUNC(ma), -2); rb_define_method(self, "mv", RUBY_METHOD_FUNC(mv), -1); + rb_define_method(self, "mc", RUBY_METHOD_FUNC(mc), -1); // Explicit cast instead of RUBY_METHOD_FUNC rb_define_method(self, "m1", (VALUE (*)(...))(m1), 1); rb_define_method(self, "m2", (VALUE (*)(...))(m2), 2); rb_define_method(self, "ma", (VALUE (*)(...))(ma), -2); rb_define_method(self, "mv", (VALUE (*)(...))(mv), -1); + rb_define_method(self, "mc", (VALUE (*)(...))(mc), -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); + rb_define_method(self, "mc", rb_f_notimplement, -1); return self; } @@ -418,6 +428,12 @@ namespace test_rb_define_method_id { return Qnil; } + static VALUE + mc(int, const VALUE*, VALUE) + { + return Qnil; + } + VALUE test(VALUE self) { @@ -426,24 +442,28 @@ namespace test_rb_define_method_id { rb_define_method_id(self, rb_intern("m2"), m2, 2); rb_define_method_id(self, rb_intern("ma"), ma, -2); rb_define_method_id(self, rb_intern("mv"), mv, -1); + rb_define_method_id(self, rb_intern("mc"), mc, -1); // Cast by RUBY_METHOD_FUNC rb_define_method_id(self, rb_intern("m1"), RUBY_METHOD_FUNC(m1), 1); rb_define_method_id(self, rb_intern("m2"), RUBY_METHOD_FUNC(m2), 2); rb_define_method_id(self, rb_intern("ma"), RUBY_METHOD_FUNC(ma), -2); rb_define_method_id(self, rb_intern("mv"), RUBY_METHOD_FUNC(mv), -1); + rb_define_method_id(self, rb_intern("mc"), RUBY_METHOD_FUNC(mc), -1); // Explicit cast instead of RUBY_METHOD_FUNC rb_define_method_id(self, rb_intern("m1"), (VALUE (*)(...))(m1), 1); rb_define_method_id(self, rb_intern("m2"), (VALUE (*)(...))(m2), 2); rb_define_method_id(self, rb_intern("ma"), (VALUE (*)(...))(ma), -2); rb_define_method_id(self, rb_intern("mv"), (VALUE (*)(...))(mv), -1); + rb_define_method_id(self, rb_intern("mc"), (VALUE (*)(...))(mc), -1); // rb_f_notimplement rb_define_method_id(self, rb_intern("m1"), rb_f_notimplement, 1); rb_define_method_id(self, rb_intern("m2"), rb_f_notimplement, 2); rb_define_method_id(self, rb_intern("ma"), rb_f_notimplement, -2); rb_define_method_id(self, rb_intern("mv"), rb_f_notimplement, -1); + rb_define_method_id(self, rb_intern("mc"), rb_f_notimplement, -1); return self; } @@ -474,6 +494,12 @@ namespace test_rb_define_module_function { return Qnil; } + static VALUE + mc(int, const VALUE*, VALUE) + { + return Qnil; + } + VALUE test(VALUE self) { @@ -482,24 +508,28 @@ namespace test_rb_define_module_function { rb_define_module_function(self, "m2", m2, 2); rb_define_module_function(self, "ma", ma, -2); rb_define_module_function(self, "mv", mv, -1); + rb_define_module_function(self, "mc", mc, -1); // Cast by RUBY_METHOD_FUNC rb_define_module_function(self, "m1", RUBY_METHOD_FUNC(m1), 1); rb_define_module_function(self, "m2", RUBY_METHOD_FUNC(m2), 2); rb_define_module_function(self, "ma", RUBY_METHOD_FUNC(ma), -2); rb_define_module_function(self, "mv", RUBY_METHOD_FUNC(mv), -1); + rb_define_module_function(self, "mc", RUBY_METHOD_FUNC(mc), -1); // Explicit cast instead of RUBY_METHOD_FUNC rb_define_module_function(self, "m1", (VALUE (*)(...))(m1), 1); rb_define_module_function(self, "m2", (VALUE (*)(...))(m2), 2); rb_define_module_function(self, "ma", (VALUE (*)(...))(ma), -2); rb_define_module_function(self, "mv", (VALUE (*)(...))(mv), -1); + rb_define_module_function(self, "mc", (VALUE (*)(...))(mc), -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); + rb_define_module_function(self, "mc", rb_f_notimplement, -1); return self; } @@ -530,6 +560,12 @@ namespace test_rb_define_singleton_method { return Qnil; } + static VALUE + mc(int, const VALUE*, VALUE) + { + return Qnil; + } + VALUE test(VALUE self) { @@ -538,24 +574,28 @@ namespace test_rb_define_singleton_method { rb_define_singleton_method(self, "m2", m2, 2); rb_define_singleton_method(self, "ma", ma, -2); rb_define_singleton_method(self, "mv", mv, -1); + rb_define_singleton_method(self, "mc", mc, -1); // Cast by RUBY_METHOD_FUNC rb_define_singleton_method(self, "m1", RUBY_METHOD_FUNC(m1), 1); rb_define_singleton_method(self, "m2", RUBY_METHOD_FUNC(m2), 2); rb_define_singleton_method(self, "ma", RUBY_METHOD_FUNC(ma), -2); rb_define_singleton_method(self, "mv", RUBY_METHOD_FUNC(mv), -1); + rb_define_singleton_method(self, "mc", RUBY_METHOD_FUNC(mc), -1); // Explicit cast instead of RUBY_METHOD_FUNC rb_define_singleton_method(self, "m1", (VALUE (*)(...))(m1), 1); rb_define_singleton_method(self, "m2", (VALUE (*)(...))(m2), 2); rb_define_singleton_method(self, "ma", (VALUE (*)(...))(ma), -2); rb_define_singleton_method(self, "mv", (VALUE (*)(...))(mv), -1); + rb_define_singleton_method(self, "mc", (VALUE (*)(...))(mc), -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); + rb_define_singleton_method(self, "mc", rb_f_notimplement, -1); return self; } @@ -586,6 +626,12 @@ namespace test_rb_define_protected_method { return Qnil; } + static VALUE + mc(int, const VALUE*, VALUE) + { + return Qnil; + } + VALUE test(VALUE self) { @@ -594,24 +640,28 @@ namespace test_rb_define_protected_method { rb_define_protected_method(self, "m2", m2, 2); rb_define_protected_method(self, "ma", ma, -2); rb_define_protected_method(self, "mv", mv, -1); + rb_define_protected_method(self, "mc", mc, -1); // Cast by RUBY_METHOD_FUNC rb_define_protected_method(self, "m1", RUBY_METHOD_FUNC(m1), 1); rb_define_protected_method(self, "m2", RUBY_METHOD_FUNC(m2), 2); rb_define_protected_method(self, "ma", RUBY_METHOD_FUNC(ma), -2); rb_define_protected_method(self, "mv", RUBY_METHOD_FUNC(mv), -1); + rb_define_protected_method(self, "mc", RUBY_METHOD_FUNC(mc), -1); // Explicit cast instead of RUBY_METHOD_FUNC rb_define_protected_method(self, "m1", (VALUE (*)(...))(m1), 1); rb_define_protected_method(self, "m2", (VALUE (*)(...))(m2), 2); rb_define_protected_method(self, "ma", (VALUE (*)(...))(ma), -2); rb_define_protected_method(self, "mv", (VALUE (*)(...))(mv), -1); + rb_define_protected_method(self, "mc", (VALUE (*)(...))(mc), -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); + rb_define_protected_method(self, "mc", rb_f_notimplement, -1); return self; } @@ -642,6 +692,12 @@ namespace test_rb_define_private_method { return Qnil; } + static VALUE + mc(int, const VALUE*, VALUE) + { + return Qnil; + } + VALUE test(VALUE self) { @@ -650,24 +706,28 @@ namespace test_rb_define_private_method { rb_define_private_method(self, "m2", m2, 2); rb_define_private_method(self, "ma", ma, -2); rb_define_private_method(self, "mv", mv, -1); + rb_define_private_method(self, "mc", mc, -1); // Cast by RUBY_METHOD_FUNC rb_define_private_method(self, "m1", RUBY_METHOD_FUNC(m1), 1); rb_define_private_method(self, "m2", RUBY_METHOD_FUNC(m2), 2); rb_define_private_method(self, "ma", RUBY_METHOD_FUNC(ma), -2); rb_define_private_method(self, "mv", RUBY_METHOD_FUNC(mv), -1); + rb_define_private_method(self, "mc", RUBY_METHOD_FUNC(mc), -1); // Explicit cast instead of RUBY_METHOD_FUNC rb_define_private_method(self, "m1", (VALUE (*)(...))(m1), 1); rb_define_private_method(self, "m2", (VALUE (*)(...))(m2), 2); rb_define_private_method(self, "ma", (VALUE (*)(...))(ma), -2); rb_define_private_method(self, "mv", (VALUE (*)(...))(mv), -1); + rb_define_private_method(self, "mc", (VALUE (*)(...))(mc), -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); + rb_define_private_method(self, "mc", rb_f_notimplement, -1); return self; } @@ -698,6 +758,12 @@ namespace test_rb_define_global_function { return Qnil; } + static VALUE + mc(int, const VALUE*, VALUE) + { + return Qnil; + } + VALUE test(VALUE self) { @@ -706,24 +772,28 @@ namespace test_rb_define_global_function { rb_define_global_function("m2", m2, 2); rb_define_global_function("ma", ma, -2); rb_define_global_function("mv", mv, -1); + rb_define_global_function("mc", mc, -1); // Cast by RUBY_METHOD_FUNC rb_define_global_function("m1", RUBY_METHOD_FUNC(m1), 1); rb_define_global_function("m2", RUBY_METHOD_FUNC(m2), 2); rb_define_global_function("ma", RUBY_METHOD_FUNC(ma), -2); rb_define_global_function("mv", RUBY_METHOD_FUNC(mv), -1); + rb_define_global_function("mc", RUBY_METHOD_FUNC(mc), -1); // Explicit cast instead of RUBY_METHOD_FUNC rb_define_global_function("m1", (VALUE (*)(...))(m1), 1); rb_define_global_function("m2", (VALUE (*)(...))(m2), 2); rb_define_global_function("ma", (VALUE (*)(...))(ma), -2); rb_define_global_function("mv", (VALUE (*)(...))(mv), -1); + rb_define_global_function("mc", (VALUE (*)(...))(mc), -1); // rb_f_notimplement rb_define_global_function("m1", rb_f_notimplement, 1); rb_define_global_function("m2", rb_f_notimplement, 2); rb_define_global_function("ma", rb_f_notimplement, -2); rb_define_global_function("mv", rb_f_notimplement, -1); + rb_define_global_function("mc", rb_f_notimplement, -1); return self; } diff --git a/include/ruby/backward/cxxanyargs.hpp b/include/ruby/backward/cxxanyargs.hpp index 31758c14e5..0acbc95443 100644 --- a/include/ruby/backward/cxxanyargs.hpp +++ b/include/ruby/backward/cxxanyargs.hpp @@ -574,7 +574,7 @@ 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, VALUE)) { F(m, reinterpret_cast<type *>(f), -1); } + static inline void define(T m, VALUE(*f)(int argc, const VALUE *argv, VALUE self)) { F(m, reinterpret_cast<type *>(f), -1); } }; template<bool b> struct specific<-2, b> : public engine<-2, VALUE(*)(VALUE, VALUE)> {}; /// @endcond |