From 7bcfd9189a6a0b2ad58fed988faaf795a4987893 Mon Sep 17 00:00:00 2001 From: 卜部昌平 Date: Wed, 28 Aug 2019 18:19:11 +0900 Subject: drop-in type check for rb_define_global_function We can check the function pointer passed to rb_define_global_function like we do so in rb_define_method. It turns out that almost anybody is misunderstanding the API. --- object.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 28b393d051..14cc409f2e 100644 --- a/object.c +++ b/object.c @@ -4048,6 +4048,12 @@ rb_obj_dig(int argc, VALUE *argv, VALUE obj, VALUE notfound) return obj; } +static VALUE +f_sprintf(int c, const VALUE *v, VALUE _) +{ + return rb_f_sprintf(c, v); +} + /* * Document-class: Class * @@ -4299,8 +4305,8 @@ InitVM_Object(void) rb_define_method(rb_mKernel, "is_a?", rb_obj_is_kind_of, 1); rb_define_method(rb_mKernel, "tap", rb_obj_tap, 0); - rb_define_global_function("sprintf", rb_f_sprintf, -1); /* in sprintf.c */ - rb_define_global_function("format", rb_f_sprintf, -1); /* in sprintf.c */ + rb_define_global_function("sprintf", f_sprintf, -1); + rb_define_global_function("format", f_sprintf, -1); rb_define_global_function("Integer", rb_f_integer, -1); rb_define_global_function("Float", rb_f_float, -1); -- cgit v1.2.3