ruby-changes:59843
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 28 Jan 2020 17:11:27 +0900 (JST)
Subject: [ruby-changes:59843] bbe3420cce (master): add test for rb_define_global_function
https://git.ruby-lang.org/ruby.git/commit/?id=bbe3420cce From bbe3420cce30de74b8c4a4f21adecf57a7d52395 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:08:20 +0900 Subject: add test for rb_define_global_function was missing. diff --git a/ext/-test-/cxxanyargs/cxxanyargs.cpp b/ext/-test-/cxxanyargs/cxxanyargs.cpp index 1a79913..a9f2d9a 100644 --- a/ext/-test-/cxxanyargs/cxxanyargs.cpp +++ b/ext/-test-/cxxanyargs/cxxanyargs.cpp @@ -673,6 +673,62 @@ namespace test_rb_define_private_method { https://github.com/ruby/ruby/blob/trunk/ext/-test-/cxxanyargs/cxxanyargs.cpp#L673 } } +namespace test_rb_define_global_function { + 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_global_function("m1", m1, 1); + rb_define_global_function("m2", m2, 2); + rb_define_global_function("ma", ma, -2); + rb_define_global_function("mv", mv, -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); + + // 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_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); + + return self; + } +} + extern "C" void Init_cxxanyargs(void) { @@ -698,8 +754,10 @@ Init_cxxanyargs(void) https://github.com/ruby/ruby/blob/trunk/ext/-test-/cxxanyargs/cxxanyargs.cpp#L754 test(rb_hash_foreach); test(rb_ivar_foreach); test(rb_define_method); + test(rb_define_method_id); test(rb_define_module_function); test(rb_define_singleton_method); test(rb_define_protected_method); test(rb_define_private_method); + test(rb_define_global_function); } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/