summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-01-31 12:01:39 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-01-31 13:01:52 +0900
commitcdd75d4e7f0402a0537c516b7331a036347b0fa9 (patch)
tree84e64cd8924489dc07fcc33cfd9b8e471e6bb666 /ext
parent4942adf68cd2d8ab0a3ca64a787bdf55e119b337 (diff)
support C++ std::nullptr_t
C++ keyword `nullptr` represents a null pointer (note also that NULL is an integer in C++ due to its design flaw). Its type is `std::nullptr_t`, defined in <cstddef> standard header. Why not support it when the backend implementation can take a null pointer as an argument.
Diffstat (limited to 'ext')
-rw-r--r--ext/-test-/cxxanyargs/cxxanyargs.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/ext/-test-/cxxanyargs/cxxanyargs.cpp b/ext/-test-/cxxanyargs/cxxanyargs.cpp
index 812c6d7..b0d48e0 100644
--- a/ext/-test-/cxxanyargs/cxxanyargs.cpp
+++ b/ext/-test-/cxxanyargs/cxxanyargs.cpp
@@ -36,6 +36,18 @@ namespace test_rb_define_virtual_variable {
RUBY_METHOD_FUNC(getter),
reinterpret_cast<void(*)(ANYARGS)>(setter)); // old
rb_define_virtual_variable("test", getter, setter); // new
+
+#ifdef HAVE_NULLPTR
+ rb_define_virtual_variable("test", nullptr, reinterpret_cast<void(*)(ANYARGS)>(setter));
+ rb_define_virtual_variable("test", nullptr, setter);
+
+ rb_define_virtual_variable("test", RUBY_METHOD_FUNC(getter), nullptr);
+ rb_define_virtual_variable("test", getter, nullptr);
+
+ // It doesn't make any sense for both function pointers be nullptr at
+ // the same time.
+#endif
+
return self;
}
}
@@ -62,6 +74,18 @@ struct test_rb_define_hooked_variable {
RUBY_METHOD_FUNC(getter),
reinterpret_cast<void(*)(ANYARGS)>(setter)); // old
rb_define_hooked_variable("test", &v, getter, setter); // new
+
+#ifdef HAVE_NULLPTR
+ rb_define_hooked_variable("test", &v, nullptr, reinterpret_cast<void(*)(ANYARGS)>(setter));
+ rb_define_hooked_variable("test", &v, nullptr, setter);
+
+ rb_define_hooked_variable("test", &v, RUBY_METHOD_FUNC(getter), nullptr);
+ rb_define_hooked_variable("test", &v, getter, nullptr);
+
+ // It doesn't make any sense for both function pointers be nullptr at
+ // the same time.
+#endif
+
return self;
}
};
@@ -83,6 +107,10 @@ namespace test_rb_iterate {
VALUE
test(VALUE self)
{
+#ifdef HAVE_NULLPTR
+ rb_iterate(iter, self, nullptr, self);
+#endif
+
rb_iterate(iter, self, RUBY_METHOD_FUNC(block), self); // old
return rb_iterate(iter, self, block, self); // new
}
@@ -100,6 +128,11 @@ namespace test_rb_block_call {
{
const ID mid = rb_intern("each");
const VALUE argv[] = { Qundef };
+
+#ifdef HAVE_NULLPTR
+ rb_block_call(self, mid, 0, argv, nullptr, self);
+#endif
+
rb_block_call(self, mid, 0, argv, RUBY_METHOD_FUNC(block), self); // old
return rb_block_call(self, mid, 0, argv, block, self); // new
}
@@ -121,6 +154,11 @@ namespace test_rb_rescue {
VALUE
test(VALUE self)
{
+#ifdef HAVE_NULLPTR
+ rb_rescue(RUBY_METHOD_FUNC(begin), self, nullptr, self);
+ return rb_rescue(begin, self, nullptr, self);
+#endif
+
rb_rescue(RUBY_METHOD_FUNC(begin), self, RUBY_METHOD_FUNC(rescue), self); // old
return rb_rescue(begin, self, rescue, self); // new
}
@@ -142,6 +180,11 @@ namespace test_rb_rescue2 {
VALUE
test(VALUE self)
{
+#ifdef HAVE_NULLPTR
+ rb_rescue2(RUBY_METHOD_FUNC(begin), self, nullptr, self, rb_eStandardError, rb_eFatal, 0);
+ rb_rescue2(begin, self, nullptr, self, rb_eStandardError, rb_eFatal, 0);
+#endif
+
rb_rescue2(RUBY_METHOD_FUNC(begin), self, RUBY_METHOD_FUNC(rescue), self,
rb_eStandardError, rb_eFatal, 0); // old
return rb_rescue2(begin, self, rescue, self, rb_eStandardError, rb_eFatal, 0); // new
@@ -164,6 +207,11 @@ namespace test_rb_ensure {
VALUE
test(VALUE self)
{
+#ifdef HAVE_NULLPTR
+ rb_ensure(RUBY_METHOD_FUNC(begin), self, nullptr, self);
+ rb_ensure(begin, self, nullptr, self);
+#endif
+
rb_ensure(RUBY_METHOD_FUNC(begin), self, RUBY_METHOD_FUNC(ensure), self); // old
return rb_ensure(begin, self, ensure, self); // new
}
@@ -180,6 +228,11 @@ namespace test_rb_catch {
test(VALUE self)
{
static const char *zero = 0;
+
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a catcher.
+#endif
+
rb_catch(zero, RUBY_METHOD_FUNC(catcher), self); // old
return rb_catch(zero, catcher, self); // new
}
@@ -195,6 +248,10 @@ namespace test_rb_catch_obj {
VALUE
test(VALUE self)
{
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a catcher.
+#endif
+
rb_catch_obj(self, RUBY_METHOD_FUNC(catcher), self); // old
return rb_catch_obj(self, catcher, self); // new
}
@@ -210,6 +267,10 @@ namespace test_rb_fiber_new {
VALUE
test(VALUE self)
{
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a fiber.
+#endif
+
rb_fiber_new(RUBY_METHOD_FUNC(fiber), self); // old
return rb_fiber_new(fiber, self); // new
}
@@ -225,6 +286,10 @@ namespace test_rb_proc_new {
VALUE
test(VALUE self)
{
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a proc.
+#endif
+
rb_fiber_new(RUBY_METHOD_FUNC(proc), self); // old
return rb_fiber_new(proc, self); // new
}
@@ -244,6 +309,11 @@ struct test_rb_thread_create {
test(VALUE self)
{
v = self;
+
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a thread.
+#endif
+
rb_thread_create(RUBY_METHOD_FUNC(thread), &v); // old
return rb_thread_create(thread, &v); // new
}
@@ -262,6 +332,11 @@ namespace test_st_foreach {
{
st_data_t data = 0;
st_table *st = st_init_numtable();
+
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as an iterator.
+#endif
+
st_foreach(st, reinterpret_cast<int(*)(ANYARGS)>(iter), data); // old
st_foreach(st, iter, data); // new
return self;
@@ -280,6 +355,11 @@ namespace test_st_foreach_check {
{
st_data_t data = 0;
st_table *st = st_init_numtable();
+
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as an iterator.
+#endif
+
st_foreach_check(st, reinterpret_cast<int(*)(ANYARGS)>(iter), data, data); // old
st_foreach_check(st, iter, data, data); // new
return self;
@@ -298,6 +378,11 @@ namespace test_st_foreach_safe {
{
st_data_t data = 0;
st_table *st = st_init_numtable();
+
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as an iterator.
+#endif
+
st_foreach_safe(st, reinterpret_cast<int(*)(ANYARGS)>(iter), data); // old
st_foreach_safe(st, iter, data); // new
return self;
@@ -315,6 +400,11 @@ namespace test_rb_hash_foreach {
test(VALUE self)
{
VALUE h = rb_hash_new();
+
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as an iterator.
+#endif
+
rb_hash_foreach(h, reinterpret_cast<int(*)(ANYARGS)>(iter), self); // old
rb_hash_foreach(h, iter, self); // new
return self;
@@ -331,6 +421,10 @@ namespace test_rb_ivar_foreach {
VALUE
test(VALUE self)
{
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as an iterator.
+#endif
+
rb_ivar_foreach(self, reinterpret_cast<int(*)(ANYARGS)>(iter), self); // old
rb_ivar_foreach(self, iter, self); // new
return self;
@@ -399,6 +493,10 @@ namespace test_rb_define_method {
rb_define_method(self, "mv", rb_f_notimplement, -1);
rb_define_method(self, "mc", rb_f_notimplement, -1);
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a method.
+#endif
+
return self;
}
}
@@ -465,6 +563,10 @@ namespace test_rb_define_method_id {
rb_define_method_id(self, rb_intern("mv"), rb_f_notimplement, -1);
rb_define_method_id(self, rb_intern("mc"), rb_f_notimplement, -1);
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a method.
+#endif
+
return self;
}
}
@@ -531,6 +633,10 @@ namespace test_rb_define_module_function {
rb_define_module_function(self, "mv", rb_f_notimplement, -1);
rb_define_module_function(self, "mc", rb_f_notimplement, -1);
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a method.
+#endif
+
return self;
}
}
@@ -597,6 +703,10 @@ namespace test_rb_define_singleton_method {
rb_define_singleton_method(self, "mv", rb_f_notimplement, -1);
rb_define_singleton_method(self, "mc", rb_f_notimplement, -1);
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a method.
+#endif
+
return self;
}
}
@@ -663,6 +773,10 @@ namespace test_rb_define_protected_method {
rb_define_protected_method(self, "mv", rb_f_notimplement, -1);
rb_define_protected_method(self, "mc", rb_f_notimplement, -1);
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a method.
+#endif
+
return self;
}
}
@@ -729,6 +843,10 @@ namespace test_rb_define_private_method {
rb_define_private_method(self, "mv", rb_f_notimplement, -1);
rb_define_private_method(self, "mc", rb_f_notimplement, -1);
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a method.
+#endif
+
return self;
}
}
@@ -795,6 +913,10 @@ namespace test_rb_define_global_function {
rb_define_global_function("mv", rb_f_notimplement, -1);
rb_define_global_function("mc", rb_f_notimplement, -1);
+#ifdef HAVE_NULLPTR
+ // It doesn't make any sense at all to pass nullptr as a method.
+#endif
+
return self;
}
}