diff options
author | 卜部昌平 <[email protected]> | 2019-08-28 18:19:11 +0900 |
---|---|---|
committer | 卜部昌平 <[email protected]> | 2019-08-29 18:34:09 +0900 |
commit | 7bcfd9189a6a0b2ad58fed988faaf795a4987893 () | |
tree | 219f0c172e038ea6be1e103db11f7457dc703328 | |
parent | 7b6fde4258e700c0e0292bb091aa84a5e473342e (diff) |
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.
-rw-r--r-- | class.c | 4 | ||||
-rw-r--r-- | eval.c | 40 | ||||
-rw-r--r-- | eval_jump.c | 2 | ||||
-rw-r--r-- | file.c | 2 | ||||
-rw-r--r-- | include/ruby/ruby.h | 41 | ||||
-rw-r--r-- | io.c | 8 | ||||
-rw-r--r-- | load.c | 2 | ||||
-rw-r--r-- | object.c | 10 | ||||
-rw-r--r-- | proc.c | 16 | ||||
-rw-r--r-- | process.c | 35 | ||||
-rw-r--r-- | ruby.c | 8 | ||||
-rw-r--r-- | vm_backtrace.c | 4 | ||||
-rw-r--r-- | vm_eval.c | 6 |
13 files changed, 140 insertions, 38 deletions
@@ -1767,7 +1767,9 @@ rb_define_module_function(VALUE module, const char *name, VALUE (*func)(ANYARGS) rb_define_singleton_method(module, name, func, argc); } - /*! * Defines a global function * \param name name of the function @@ -769,6 +769,12 @@ rb_f_raise(int argc, VALUE *argv) } static VALUE make_exception(int argc, const VALUE *argv, int isstr) { VALUE mesg, exc; @@ -1883,7 +1889,7 @@ errat_setter(VALUE val, ID id, VALUE *var) */ static VALUE -rb_f_method_name(void) { ID fname = prev_frame_func(); /* need *method* ID */ @@ -1905,7 +1911,7 @@ rb_f_method_name(void) */ static VALUE -rb_f_callee_name(void) { ID fname = prev_frame_callee(); /* need *callee* ID */ @@ -1928,7 +1934,7 @@ rb_f_callee_name(void) * */ static VALUE -f_current_dirname(void) { VALUE base = rb_current_realfilepath(); if (NIL_P(base)) { @@ -1938,16 +1944,34 @@ f_current_dirname(void) return base; } void Init_eval(void) { rb_define_virtual_variable("$@", errat_getter, errat_setter); rb_define_virtual_variable("$!", errinfo_getter, 0); - rb_define_global_function("raise", rb_f_raise, -1); - rb_define_global_function("fail", rb_f_raise, -1); - rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */ rb_define_global_function("__method__", rb_f_method_name, 0); rb_define_global_function("__callee__", rb_f_callee_name, 0); @@ -1980,8 +2004,8 @@ Init_eval(void) rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1); - rb_define_global_function("trace_var", rb_f_trace_var, -1); /* in variable.c */ - rb_define_global_function("untrace_var", rb_f_untrace_var, -1); /* in variable.c */ rb_vm_register_special_exception(ruby_error_reenter, rb_eFatal, "exception reentered"); rb_vm_register_special_exception(ruby_error_stackfatal, rb_eFatal, "machine stack overflow in critical region"); @@ -35,7 +35,7 @@ rb_call_end_proc(VALUE data) */ static VALUE -rb_f_at_exit(void) { VALUE proc; @@ -5225,7 +5225,7 @@ test_check(int n, int argc, VALUE *argv) */ static VALUE -rb_f_test(int argc, VALUE *argv) { int cmd; @@ -2774,6 +2774,47 @@ __attribute__((__unused__,__weakref__("rb_define_module_function"),__nonnull__(2 #define rb_define_module_function_choose_m2(n) rb_define_method_if_constexpr((n)==-2,rb_define_module_functionm2,rb_define_module_function_choose_m1(n)) #define rb_define_module_function_choose_m3(n, f) rb_define_method_if_constexpr(rb_f_notimplement_p(f),rb_define_module_functionm3,rb_define_module_function_choose_m2(n)) #define rb_define_module_function(klass, mid, func, arity) rb_define_module_function_choose_m3((arity),(func))((klass),(mid),(func),(arity)); #endif #endif @@ -7183,7 +7183,7 @@ check_pipe_command(VALUE filename_or_command) */ static VALUE -rb_f_open(int argc, VALUE *argv) { ID to_open = 0; int redirect = FALSE; @@ -7518,7 +7518,7 @@ rb_io_printf(int argc, const VALUE *argv, VALUE out) */ static VALUE -rb_f_printf(int argc, VALUE *argv) { VALUE out; @@ -7619,7 +7619,7 @@ rb_io_print(int argc, const VALUE *argv, VALUE out) */ static VALUE -rb_f_print(int argc, const VALUE *argv) { rb_io_print(argc, argv, rb_stdout); return Qnil; @@ -10007,7 +10007,7 @@ rb_io_fcntl(int argc, VALUE *argv, VALUE io) */ static VALUE -rb_f_syscall(int argc, VALUE *argv) { VALUE arg[8]; #if SIZEOF_VOIDP == 8 && defined(HAVE___SYSCALL) && SIZEOF_INT != 8 /* mainly *BSD */ @@ -690,7 +690,7 @@ rb_load_protect(VALUE fname, int wrap, int *pstate) */ static VALUE -rb_f_load(int argc, VALUE *argv) { VALUE fname, wrap, path, orig_fname; @@ -4048,6 +4048,12 @@ rb_obj_dig(int argc, VALUE *argv, VALUE obj, VALUE notfound) return obj; } /* * 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("Integer", rb_f_integer, -1); rb_define_global_function("Float", rb_f_float, -1); @@ -836,6 +836,12 @@ rb_block_proc(void) return proc_new(rb_cProc, FALSE); } /* * call-seq: * lambda { |...| block } -> a_proc @@ -850,6 +856,12 @@ rb_block_lambda(void) return proc_new(rb_cProc, TRUE); } /* Document-method: Proc#=== * * call-seq: @@ -3623,8 +3635,8 @@ Init_Proc(void) rb_vm_register_special_exception(ruby_error_sysstack, rb_eSysStackError, "stack level too deep"); /* utility functions */ - rb_define_global_function("proc", rb_block_proc, 0); - rb_define_global_function("lambda", rb_block_lambda, 0); /* Method */ rb_cMethod = rb_define_class("Method", rb_cObject); @@ -2981,6 +2981,12 @@ rb_f_exec(int argc, const VALUE *argv) UNREACHABLE_RETURN(Qnil); } #define ERRMSG(str) do { if (errmsg && 0 < errmsg_buflen) strlcpy(errmsg, (str), errmsg_buflen); } while (0) #define ERRMSG1(str, a) do { if (errmsg && 0 < errmsg_buflen) snprintf(errmsg, errmsg_buflen, (str), (a)); } while (0) #define ERRMSG2(str, a, b) do { if (errmsg && 0 < errmsg_buflen) snprintf(errmsg, errmsg_buflen, (str), (a), (b)); } while (0) @@ -4256,6 +4262,11 @@ rb_f_exit(int argc, const VALUE *argv) UNREACHABLE_RETURN(Qnil); } /* * call-seq: @@ -4293,6 +4304,12 @@ rb_f_abort(int argc, const VALUE *argv) UNREACHABLE_RETURN(Qnil); } void rb_syswait(rb_pid_t pid) { @@ -4484,7 +4501,7 @@ rb_spawn(int argc, const VALUE *argv) */ static VALUE -rb_f_system(int argc, VALUE *argv) { /* * n.b. using alloca for now to simplify future Thread::Light code @@ -4811,7 +4828,7 @@ rb_f_system(int argc, VALUE *argv) */ static VALUE -rb_f_spawn(int argc, VALUE *argv) { rb_pid_t pid; char errmsg[CHILD_ERRMSG_BUFLEN] = { '\0' }; @@ -4855,7 +4872,7 @@ rb_f_spawn(int argc, VALUE *argv) */ static VALUE -rb_f_sleep(int argc, VALUE *argv) { time_t beg, end; @@ -8092,14 +8109,14 @@ InitVM_process(void) #define rb_intern(str) rb_intern_const(str) rb_define_virtual_variable("$?", get_CHILD_STATUS, 0); rb_define_virtual_variable("$$", get_PROCESS_ID, 0); - rb_define_global_function("exec", rb_f_exec, -1); rb_define_global_function("fork", rb_f_fork, 0); rb_define_global_function("exit!", rb_f_exit_bang, -1); rb_define_global_function("system", rb_f_system, -1); rb_define_global_function("spawn", rb_f_spawn, -1); rb_define_global_function("sleep", rb_f_sleep, -1); - rb_define_global_function("exit", rb_f_exit, -1); - rb_define_global_function("abort", rb_f_abort, -1); rb_mProcess = rb_define_module("Process"); @@ -8118,12 +8135,12 @@ InitVM_process(void) rb_define_const(rb_mProcess, "WUNTRACED", INT2FIX(0)); #endif - rb_define_singleton_method(rb_mProcess, "exec", rb_f_exec, -1); rb_define_singleton_method(rb_mProcess, "fork", rb_f_fork, 0); rb_define_singleton_method(rb_mProcess, "spawn", rb_f_spawn, -1); rb_define_singleton_method(rb_mProcess, "exit!", rb_f_exit_bang, -1); - rb_define_singleton_method(rb_mProcess, "exit", rb_f_exit, -1); - 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", proc_rb_f_kill, -1); @@ -1484,7 +1484,7 @@ uscore_get(void) */ static VALUE -rb_f_sub(int argc, VALUE *argv) { VALUE str = rb_funcall_passing_block(uscore_get(), rb_intern("sub"), argc, argv); rb_lastline_set(str); @@ -1503,7 +1503,7 @@ rb_f_sub(int argc, VALUE *argv) */ static VALUE -rb_f_gsub(int argc, VALUE *argv) { VALUE str = rb_funcall_passing_block(uscore_get(), rb_intern("gsub"), argc, argv); rb_lastline_set(str); @@ -1521,7 +1521,7 @@ rb_f_gsub(int argc, VALUE *argv) */ static VALUE -rb_f_chop(void) { VALUE str = rb_funcall_passing_block(uscore_get(), rb_intern("chop"), 0, 0); rb_lastline_set(str); @@ -1541,7 +1541,7 @@ rb_f_chop(void) */ static VALUE -rb_f_chomp(int argc, VALUE *argv) { VALUE str = rb_funcall_passing_block(uscore_get(), rb_intern("chomp"), argc, argv); rb_lastline_set(str); @@ -1007,7 +1007,7 @@ rb_vm_thread_backtrace_locations(int argc, const VALUE *argv, VALUE thval) */ static VALUE -rb_f_caller(int argc, VALUE *argv) { return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 1); } @@ -1035,7 +1035,7 @@ rb_f_caller(int argc, VALUE *argv) * entries within the specified range. */ static VALUE -rb_f_caller_locations(int argc, VALUE *argv) { return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 0); } @@ -1880,7 +1880,7 @@ uncaught_throw_to_s(VALUE exc) */ static VALUE -rb_f_throw(int argc, VALUE *argv) { VALUE tag, value; @@ -2085,7 +2085,7 @@ local_var_list_add(const struct local_var_list *vars, ID lid) */ static VALUE -rb_f_local_variables(void) { struct local_var_list vars; rb_execution_context_t *ec = GET_EC(); @@ -2142,7 +2142,7 @@ rb_f_local_variables(void) static VALUE -rb_f_block_given_p(void) { rb_execution_context_t *ec = GET_EC(); rb_control_frame_t *cfp = ec->cfp; |