зеркало из https://github.com/github/ruby.git
drop-in type check for rb_define_private_method
We can check the function pointer passed to rb_define_private_method like how we do so in rb_define_method. Doing so revealed some problematic usages of rb_obj_dummy. They had to be split according to their arity.
This commit is contained in:
Родитель
9b429eb3b1
Коммит
bfe5d22f89
3
class.c
3
class.c
|
@ -1561,6 +1561,9 @@ rb_define_protected_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS)
|
|||
rb_add_method_cfunc(klass, rb_intern(name), func, argc, METHOD_VISI_PROTECTED);
|
||||
}
|
||||
|
||||
#ifdef rb_define_private_method
|
||||
#undef rb_define_private_method
|
||||
#endif
|
||||
void
|
||||
rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
|
||||
{
|
||||
|
|
|
@ -1086,6 +1086,47 @@ __attribute__((__unused__,__weakref__("rb_define_protected_method"),__nonnull__(
|
|||
#define rb_define_protected_method_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_protected_methodm2,rb_define_protected_method_choose_prototypem1(n))
|
||||
#define rb_define_protected_method_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_protected_methodm3,rb_define_protected_method_choose_prototypem2(n))
|
||||
#define rb_define_protected_method(klass, mid, func, arity) rb_define_protected_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity));
|
||||
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_methodm3(VALUE,const char*,VALUE(*)(ANYARGS),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_methodm2(VALUE,const char*,VALUE(*)(VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_methodm1(VALUE,const char*,VALUE(*)(int,union __attribute__((__transparent_union__)){VALUE*x;const VALUE*y;},VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method0 (VALUE,const char*,VALUE(*)(VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method1 (VALUE,const char*,VALUE(*)(VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method2 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method3 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method4 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method5 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method6 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method7 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method8 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method9 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method10(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method11(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method12(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method13(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method14(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
__attribute__((__unused__,__weakref__("rb_define_private_method"),__nonnull__(2,3)))static void rb_define_private_method15(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
|
||||
|
||||
#define rb_define_private_method_choose_prototype15(n) rb_define_method_if_constexpr((n)==15,rb_define_private_method15,rb_define_private_methodm3)
|
||||
#define rb_define_private_method_choose_prototype14(n) rb_define_method_if_constexpr((n)==14,rb_define_private_method14,rb_define_private_method_choose_prototype15(n))
|
||||
#define rb_define_private_method_choose_prototype13(n) rb_define_method_if_constexpr((n)==13,rb_define_private_method13,rb_define_private_method_choose_prototype14(n))
|
||||
#define rb_define_private_method_choose_prototype12(n) rb_define_method_if_constexpr((n)==12,rb_define_private_method12,rb_define_private_method_choose_prototype13(n))
|
||||
#define rb_define_private_method_choose_prototype11(n) rb_define_method_if_constexpr((n)==11,rb_define_private_method11,rb_define_private_method_choose_prototype12(n))
|
||||
#define rb_define_private_method_choose_prototype10(n) rb_define_method_if_constexpr((n)==10,rb_define_private_method10,rb_define_private_method_choose_prototype11(n))
|
||||
#define rb_define_private_method_choose_prototype9(n) rb_define_method_if_constexpr((n)== 9,rb_define_private_method9, rb_define_private_method_choose_prototype10(n))
|
||||
#define rb_define_private_method_choose_prototype8(n) rb_define_method_if_constexpr((n)== 8,rb_define_private_method8, rb_define_private_method_choose_prototype9(n))
|
||||
#define rb_define_private_method_choose_prototype7(n) rb_define_method_if_constexpr((n)== 7,rb_define_private_method7, rb_define_private_method_choose_prototype8(n))
|
||||
#define rb_define_private_method_choose_prototype6(n) rb_define_method_if_constexpr((n)== 6,rb_define_private_method6, rb_define_private_method_choose_prototype7(n))
|
||||
#define rb_define_private_method_choose_prototype5(n) rb_define_method_if_constexpr((n)== 5,rb_define_private_method5, rb_define_private_method_choose_prototype6(n))
|
||||
#define rb_define_private_method_choose_prototype4(n) rb_define_method_if_constexpr((n)== 4,rb_define_private_method4, rb_define_private_method_choose_prototype5(n))
|
||||
#define rb_define_private_method_choose_prototype3(n) rb_define_method_if_constexpr((n)== 3,rb_define_private_method3, rb_define_private_method_choose_prototype4(n))
|
||||
#define rb_define_private_method_choose_prototype2(n) rb_define_method_if_constexpr((n)== 2,rb_define_private_method2, rb_define_private_method_choose_prototype3(n))
|
||||
#define rb_define_private_method_choose_prototype1(n) rb_define_method_if_constexpr((n)== 1,rb_define_private_method1, rb_define_private_method_choose_prototype2(n))
|
||||
#define rb_define_private_method_choose_prototype0(n) rb_define_method_if_constexpr((n)== 0,rb_define_private_method0, rb_define_private_method_choose_prototype1(n))
|
||||
#define rb_define_private_method_choose_prototypem1(n) rb_define_method_if_constexpr((n)==-1,rb_define_private_methodm1,rb_define_private_method_choose_prototype0(n))
|
||||
#define rb_define_private_method_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_private_methodm2,rb_define_private_method_choose_prototypem1(n))
|
||||
#define rb_define_private_method_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_private_methodm3,rb_define_private_method_choose_prototypem2(n))
|
||||
#define rb_define_private_method(klass, mid, func, arity) rb_define_private_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
36
object.c
36
object.c
|
@ -1141,11 +1141,23 @@ rb_obj_tap(VALUE obj)
|
|||
*/
|
||||
|
||||
static VALUE
|
||||
rb_obj_dummy(void)
|
||||
rb_obj_dummy()
|
||||
{
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_obj_dummy0(VALUE _)
|
||||
{
|
||||
return rb_obj_dummy();
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_obj_dummy1(VALUE _x, VALUE _y)
|
||||
{
|
||||
return rb_obj_dummy();
|
||||
}
|
||||
|
||||
/**
|
||||
* call-seq:
|
||||
* obj.tainted? -> true or false
|
||||
|
@ -4486,16 +4498,16 @@ InitVM_Object(void)
|
|||
#undef rb_intern
|
||||
#define rb_intern(str) rb_intern_const(str)
|
||||
|
||||
rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_dummy, 0);
|
||||
rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_dummy0, 0);
|
||||
rb_define_alloc_func(rb_cBasicObject, rb_class_allocate_instance);
|
||||
rb_define_method(rb_cBasicObject, "==", rb_obj_equal, 1);
|
||||
rb_define_method(rb_cBasicObject, "equal?", rb_obj_equal, 1);
|
||||
rb_define_method(rb_cBasicObject, "!", rb_obj_not, 0);
|
||||
rb_define_method(rb_cBasicObject, "!=", rb_obj_not_equal, 1);
|
||||
|
||||
rb_define_private_method(rb_cBasicObject, "singleton_method_added", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cBasicObject, "singleton_method_removed", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cBasicObject, "singleton_method_undefined", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cBasicObject, "singleton_method_added", rb_obj_dummy1, 1);
|
||||
rb_define_private_method(rb_cBasicObject, "singleton_method_removed", rb_obj_dummy1, 1);
|
||||
rb_define_private_method(rb_cBasicObject, "singleton_method_undefined", rb_obj_dummy1, 1);
|
||||
|
||||
/* Document-module: Kernel
|
||||
*
|
||||
|
@ -4511,13 +4523,13 @@ InitVM_Object(void)
|
|||
*/
|
||||
rb_mKernel = rb_define_module("Kernel");
|
||||
rb_include_module(rb_cObject, rb_mKernel);
|
||||
rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cModule, "extended", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cModule, "prepended", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1);
|
||||
rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy1, 1);
|
||||
rb_define_private_method(rb_cModule, "included", rb_obj_dummy1, 1);
|
||||
rb_define_private_method(rb_cModule, "extended", rb_obj_dummy1, 1);
|
||||
rb_define_private_method(rb_cModule, "prepended", rb_obj_dummy1, 1);
|
||||
rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy1, 1);
|
||||
rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy1, 1);
|
||||
rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy1, 1);
|
||||
|
||||
rb_define_method(rb_mKernel, "nil?", rb_false, 0);
|
||||
rb_define_method(rb_mKernel, "===", rb_equal, 1);
|
||||
|
|
|
@ -1802,7 +1802,7 @@ rb_mod_private_method(int argc, VALUE *argv, VALUE obj)
|
|||
*/
|
||||
|
||||
static VALUE
|
||||
top_public(int argc, VALUE *argv)
|
||||
top_public(int argc, VALUE *argv, VALUE _)
|
||||
{
|
||||
return rb_mod_public(argc, argv, rb_cObject);
|
||||
}
|
||||
|
@ -1820,7 +1820,7 @@ top_public(int argc, VALUE *argv)
|
|||
* String arguments are converted to symbols.
|
||||
*/
|
||||
static VALUE
|
||||
top_private(int argc, VALUE *argv)
|
||||
top_private(int argc, VALUE *argv, VALUE _)
|
||||
{
|
||||
return rb_mod_private(argc, argv, rb_cObject);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче