summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2019-08-28 17:48:48 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2019-08-29 18:34:09 +0900
commit7b6fde4258e700c0e0292bb091aa84a5e473342e (patch)
treea9ac636ca63307dd4507e99814ae511daa96e34a
parent9ef51b0b89a10c8c401cb9f2337e47a25be72cbe (diff)
drop-in type check for rb_define_module_function
We can check the function pointer passed to rb_define_module_function like how we do so in rb_define_method. The difference is that this changeset reveales lots of atiry mismatches.
-rw-r--r--class.c5
-rw-r--r--ext/etc/etc.c2
-rw-r--r--ext/openssl/ossl.c2
-rw-r--r--include/ruby/ruby.h41
-rw-r--r--marshal.c4
-rw-r--r--process.c64
-rw-r--r--signal.c4
7 files changed, 94 insertions, 28 deletions
diff --git a/class.c b/class.c
index f35e9bb..05440f5 100644
--- a/class.c
+++ b/class.c
@@ -1750,8 +1750,9 @@ rb_define_singleton_method(VALUE obj, const char *name, VALUE (*func)(ANYARGS),
rb_define_method(singleton_class_of(obj), name, func, argc);
}
-
-
+#ifdef rb_define_module_function
+#undef rb_define_module_function
+#endif
/*!
* Defines a module function for \a module.
* \param module an module or a class.
diff --git a/ext/etc/etc.c b/ext/etc/etc.c
index a3a9bbc..28761df 100644
--- a/ext/etc/etc.c
+++ b/ext/etc/etc.c
@@ -647,7 +647,7 @@ etc_sysconfdir(VALUE obj)
* Returns system temporary directory; typically "/tmp".
*/
static VALUE
-etc_systmpdir(void)
+etc_systmpdir(VALUE _)
{
VALUE tmpdir;
#ifdef _WIN32
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
index 69758ae..e4196f0 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -338,7 +338,7 @@ ossl_clear_error(void)
* implementation.
*/
VALUE
-ossl_get_errors(void)
+ossl_get_errors(VALUE _)
{
VALUE ary;
long e;
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 59793e6..33bafa9 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -2733,6 +2733,47 @@ __attribute__((__unused__,__weakref__("rb_define_method"),__nonnull__(2,3)))stat
#define rb_define_method_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_methodm2,rb_define_method_choose_prototypem1(n))
#define rb_define_method_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_methodm3,rb_define_method_choose_prototypem2(n))
#define rb_define_method(klass, mid, func, arity) rb_define_method_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity));
+
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_functionm3(VALUE,const char*,VALUE(*)(ANYARGS),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_functionm2(VALUE,const char*,VALUE(*)(VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_functionm1(VALUE,const char*,VALUE(*)(int,union __attribute__((__transparent_union__)){VALUE*x;const VALUE*y;},VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function0 (VALUE,const char*,VALUE(*)(VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function1 (VALUE,const char*,VALUE(*)(VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function2 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function3 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function4 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function5 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function6 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function7 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function8 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function9 (VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function10(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function11(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function12(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function13(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+__attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2,3)))static void rb_define_module_function14(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_module_function"),__nonnull__(2,3)))static void rb_define_module_function15(VALUE,const char*,VALUE(*)(VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE),int);
+
+#define rb_define_module_function_choose_prototype15(n) rb_define_method_if_constexpr((n)==15,rb_define_module_function15,rb_define_module_functionm3)
+#define rb_define_module_function_choose_prototype14(n) rb_define_method_if_constexpr((n)==14,rb_define_module_function14,rb_define_module_function_choose_prototype15(n))
+#define rb_define_module_function_choose_prototype13(n) rb_define_method_if_constexpr((n)==13,rb_define_module_function13,rb_define_module_function_choose_prototype14(n))
+#define rb_define_module_function_choose_prototype12(n) rb_define_method_if_constexpr((n)==12,rb_define_module_function12,rb_define_module_function_choose_prototype13(n))
+#define rb_define_module_function_choose_prototype11(n) rb_define_method_if_constexpr((n)==11,rb_define_module_function11,rb_define_module_function_choose_prototype12(n))
+#define rb_define_module_function_choose_prototype10(n) rb_define_method_if_constexpr((n)==10,rb_define_module_function10,rb_define_module_function_choose_prototype11(n))
+#define rb_define_module_function_choose_prototype9(n) rb_define_method_if_constexpr((n)== 9,rb_define_module_function9, rb_define_module_function_choose_prototype10(n))
+#define rb_define_module_function_choose_prototype8(n) rb_define_method_if_constexpr((n)== 8,rb_define_module_function8, rb_define_module_function_choose_prototype9(n))
+#define rb_define_module_function_choose_prototype7(n) rb_define_method_if_constexpr((n)== 7,rb_define_module_function7, rb_define_module_function_choose_prototype8(n))
+#define rb_define_module_function_choose_prototype6(n) rb_define_method_if_constexpr((n)== 6,rb_define_module_function6, rb_define_module_function_choose_prototype7(n))
+#define rb_define_module_function_choose_prototype5(n) rb_define_method_if_constexpr((n)== 5,rb_define_module_function5, rb_define_module_function_choose_prototype6(n))
+#define rb_define_module_function_choose_prototype4(n) rb_define_method_if_constexpr((n)== 4,rb_define_module_function4, rb_define_module_function_choose_prototype5(n))
+#define rb_define_module_function_choose_prototype3(n) rb_define_method_if_constexpr((n)== 3,rb_define_module_function3, rb_define_module_function_choose_prototype4(n))
+#define rb_define_module_function_choose_prototype2(n) rb_define_method_if_constexpr((n)== 2,rb_define_module_function2, rb_define_module_function_choose_prototype3(n))
+#define rb_define_module_function_choose_prototype1(n) rb_define_method_if_constexpr((n)== 1,rb_define_module_function1, rb_define_module_function_choose_prototype2(n))
+#define rb_define_module_function_choose_prototype0(n) rb_define_method_if_constexpr((n)== 0,rb_define_module_function0, rb_define_module_function_choose_prototype1(n))
+#define rb_define_module_function_choose_prototypem1(n) rb_define_method_if_constexpr((n)==-1,rb_define_module_functionm1,rb_define_module_function_choose_prototype0(n))
+#define rb_define_module_function_choose_prototypem2(n) rb_define_method_if_constexpr((n)==-2,rb_define_module_functionm2,rb_define_module_function_choose_prototypem1(n))
+#define rb_define_module_function_choose_prototypem3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_module_functionm3,rb_define_module_function_choose_prototypem2(n))
+#define rb_define_module_function(klass, mid, func, arity) rb_define_module_function_choose_prototypem3((arity),(func))((klass),(mid),(func),(arity));
#endif
#endif
diff --git a/marshal.c b/marshal.c
index b21db26..71480bf 100644
--- a/marshal.c
+++ b/marshal.c
@@ -1047,7 +1047,7 @@ io_needed(void)
* * objects which define singleton methods
*/
static VALUE
-marshal_dump(int argc, VALUE *argv)
+marshal_dump(int argc, VALUE *argv, VALUE _)
{
VALUE obj, port, a1, a2;
int limit = -1;
@@ -2104,7 +2104,7 @@ clear_load_arg(struct load_arg *arg)
* Please see the overview for further details.
*/
static VALUE
-marshal_load(int argc, VALUE *argv)
+marshal_load(int argc, VALUE *argv, VALUE _)
{
VALUE port, proc;
diff --git a/process.c b/process.c
index a21b171..9c82b4a 100644
--- a/process.c
+++ b/process.c
@@ -435,6 +435,12 @@ get_pid(void)
return PIDT2NUM(getpid());
}
+static VALUE
+proc_get_pid(VALUE _)
+{
+ return get_pid();
+}
+
/*
* call-seq:
@@ -458,6 +464,12 @@ get_ppid(void)
return PIDT2NUM(getppid());
}
+static VALUE
+proc_get_ppid(VALUE _)
+{
+ return get_ppid();
+}
+
/*********************************************************************
*
@@ -1303,6 +1315,12 @@ proc_wait(int argc, VALUE *argv)
return PIDT2NUM(pid);
}
+static VALUE
+proc_m_wait(int c, VALUE *v, VALUE _)
+{
+ return proc_wait(c, v);
+}
+
/*
* call-seq:
@@ -1321,7 +1339,7 @@ proc_wait(int argc, VALUE *argv)
*/
static VALUE
-proc_wait2(int argc, VALUE *argv)
+proc_wait2(int argc, VALUE *argv, VALUE _)
{
VALUE pid = proc_wait(argc, argv);
if (NIL_P(pid)) return Qnil;
@@ -1350,7 +1368,7 @@ proc_wait2(int argc, VALUE *argv)
*/
static VALUE
-proc_waitall(void)
+proc_waitall(VALUE _)
{
VALUE result;
rb_pid_t pid;
@@ -4869,7 +4887,7 @@ rb_f_sleep(int argc, VALUE *argv)
*/
static VALUE
-proc_getpgrp(void)
+proc_getpgrp(VALUE _)
{
rb_pid_t pgrp;
@@ -4898,7 +4916,7 @@ proc_getpgrp(void)
*/
static VALUE
-proc_setpgrp(void)
+proc_setpgrp(VALUE _)
{
/* check for posix setpgid() first; this matches the posix */
/* getpgrp() above. It appears that configure will set SETPGRP_VOID */
@@ -4980,7 +4998,7 @@ proc_setpgid(VALUE obj, VALUE pid, VALUE pgrp)
* Process.getsid(Process.pid()) #=> 27422
*/
static VALUE
-proc_getsid(int argc, VALUE *argv)
+proc_getsid(int argc, VALUE *argv, VALUE _)
{
rb_pid_t sid;
rb_pid_t pid = 0;
@@ -5014,7 +5032,7 @@ static rb_pid_t ruby_setsid(void);
*/
static VALUE
-proc_setsid(void)
+proc_setsid(VALUE _)
{
rb_pid_t pid;
@@ -6477,7 +6495,7 @@ static int rb_daemon(int nochdir, int noclose);
*/
static VALUE
-proc_daemon(int argc, VALUE *argv)
+proc_daemon(int argc, VALUE *argv, VALUE _)
{
int n, nochdir = FALSE, noclose = FALSE;
@@ -6996,7 +7014,7 @@ p_gid_grant_privilege(VALUE obj, VALUE id)
*/
static VALUE
-p_uid_exchangeable(void)
+p_uid_exchangeable(VALUE _)
{
#if defined(HAVE_SETRESUID)
return Qtrue;
@@ -7058,7 +7076,7 @@ p_uid_exchange(VALUE obj)
*/
static VALUE
-p_gid_exchangeable(void)
+p_gid_exchangeable(VALUE _)
{
#if defined(HAVE_SETRESGID)
return Qtrue;
@@ -7121,7 +7139,7 @@ p_gid_exchange(VALUE obj)
*/
static VALUE
-p_uid_have_saved_id(void)
+p_uid_have_saved_id(VALUE _)
{
#if defined(HAVE_SETRESUID) || defined(HAVE_SETEUID) || defined(_POSIX_SAVED_IDS)
return Qtrue;
@@ -7236,7 +7254,7 @@ p_uid_switch(VALUE obj)
*/
static VALUE
-p_gid_have_saved_id(void)
+p_gid_have_saved_id(VALUE _)
{
#if defined(HAVE_SETRESGID) || defined(HAVE_SETEGID) || defined(_POSIX_SAVED_IDS)
return Qtrue;
@@ -7737,8 +7755,8 @@ ruby_real_ms_time(void)
* So the result can be interpreted differently across systems.
* Time.now is recommended over CLOCK_REALTIME.
*/
-VALUE
-rb_clock_gettime(int argc, VALUE *argv)
+static VALUE
+rb_clock_gettime(int argc, VALUE *argv, VALUE _)
{
int ret;
@@ -7934,8 +7952,8 @@ rb_clock_gettime(int argc, VALUE *argv)
* #=> 1.0e-09
*
*/
-VALUE
-rb_clock_getres(int argc, VALUE *argv)
+static VALUE
+rb_clock_getres(int argc, VALUE *argv, VALUE _)
{
struct timetick tt;
timetick_int_t numerators[2];
@@ -8050,6 +8068,12 @@ get_PROCESS_ID(ID _x, VALUE *_y)
return get_pid();
}
+static VALUE
+proc_rb_f_kill(int c, const VALUE *v, VALUE _)
+{
+ return rb_f_kill(c, v);
+}
+
VALUE rb_mProcess;
static VALUE rb_mProcUID;
static VALUE rb_mProcGID;
@@ -8102,10 +8126,10 @@ InitVM_process(void)
rb_define_singleton_method(rb_mProcess, "abort", rb_f_abort, -1);
rb_define_singleton_method(rb_mProcess, "last_status", proc_s_last_status, 0);
- rb_define_module_function(rb_mProcess, "kill", rb_f_kill, -1); /* in signal.c */
- rb_define_module_function(rb_mProcess, "wait", proc_wait, -1);
+ rb_define_module_function(rb_mProcess, "kill", proc_rb_f_kill, -1);
+ rb_define_module_function(rb_mProcess, "wait", proc_m_wait, -1);
rb_define_module_function(rb_mProcess, "wait2", proc_wait2, -1);
- rb_define_module_function(rb_mProcess, "waitpid", proc_wait, -1);
+ rb_define_module_function(rb_mProcess, "waitpid", proc_m_wait, -1);
rb_define_module_function(rb_mProcess, "waitpid2", proc_wait2, -1);
rb_define_module_function(rb_mProcess, "waitall", proc_waitall, 0);
rb_define_module_function(rb_mProcess, "detach", proc_detach, 1);
@@ -8137,8 +8161,8 @@ InitVM_process(void)
rb_define_method(rb_cProcessStatus, "success?", pst_success_p, 0);
rb_define_method(rb_cProcessStatus, "coredump?", pst_wcoredump, 0);
- rb_define_module_function(rb_mProcess, "pid", get_pid, 0);
- rb_define_module_function(rb_mProcess, "ppid", get_ppid, 0);
+ rb_define_module_function(rb_mProcess, "pid", proc_get_pid, 0);
+ rb_define_module_function(rb_mProcess, "ppid", proc_get_ppid, 0);
rb_define_module_function(rb_mProcess, "getpgrp", proc_getpgrp, 0);
rb_define_module_function(rb_mProcess, "setpgrp", proc_setpgrp, 0);
diff --git a/signal.c b/signal.c
index 3c31935..fd53ce2 100644
--- a/signal.c
+++ b/signal.c
@@ -1405,7 +1405,7 @@ reserved_signal_p(int signo)
* Terminating: 27460
*/
static VALUE
-sig_trap(int argc, VALUE *argv)
+sig_trap(int argc, VALUE *argv, VALUE _)
{
int sig;
sighandler_t func;
@@ -1448,7 +1448,7 @@ sig_trap(int argc, VALUE *argv)
* Signal.list #=> {"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "IOT"=>6, "ABRT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
*/
static VALUE
-sig_list(void)
+sig_list(VALUE _)
{
VALUE h = rb_hash_new();
const struct signals *sigs;