diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-01-28 17:05:43 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-01-28 17:09:42 +0900 |
commit | 16592d6b69dc2538f419edcbd4c91ebb917db5ac (patch) | |
tree | 80c0d6a66453978f163db1af5c250ebf1b3418bc | |
parent | 3c3eb418f9ce05740e5ca506b9cd5fe5cabc4bb6 (diff) | |
download | ruby-16592d6b69dc2538f419edcbd4c91ebb917db5ac.tar.gz |
add test for rb_define_method_id
was missing.
-rw-r--r-- | ext/-test-/cxxanyargs/cxxanyargs.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/ext/-test-/cxxanyargs/cxxanyargs.cpp b/ext/-test-/cxxanyargs/cxxanyargs.cpp index eef2387650..1a79913a13 100644 --- a/ext/-test-/cxxanyargs/cxxanyargs.cpp +++ b/ext/-test-/cxxanyargs/cxxanyargs.cpp @@ -393,6 +393,62 @@ namespace test_rb_define_method { } } +namespace test_rb_define_method_id { + static VALUE + m1(VALUE, VALUE) + { + return Qnil; + } + + static VALUE + m2(VALUE, VALUE, VALUE) + { + return Qnil; + } + + static VALUE + ma(VALUE, VALUE) + { + return Qnil; + } + + static VALUE + mv(int, VALUE*, VALUE) + { + return Qnil; + } + + VALUE + test(VALUE self) + { + // No cast + rb_define_method_id(self, rb_intern("m1"), m1, 1); + 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); + + // 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); + + // 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_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); + + return self; + } +} + namespace test_rb_define_module_function { static VALUE m1(VALUE, VALUE) |