summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2019-08-28 18:19:11 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2019-08-29 18:34:09 +0900
commit7bcfd9189a6a0b2ad58fed988faaf795a4987893 (patch)
tree219f0c172e038ea6be1e103db11f7457dc703328 /eval.c
parent7b6fde4258e700c0e0292bb091aa84a5e473342e (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.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/eval.c b/eval.c
index c2f15fb..90f36b8 100644
--- a/eval.c
+++ b/eval.c
@@ -769,6 +769,12 @@ rb_f_raise(int argc, VALUE *argv)
}
static VALUE
+f_raise(int c, VALUE *v, VALUE _)
+{
+ return rb_f_raise(c, v);
+}
+
+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)
+rb_f_method_name(VALUE _)
{
ID fname = prev_frame_func(); /* need *method* ID */
@@ -1905,7 +1911,7 @@ rb_f_method_name(void)
*/
static VALUE
-rb_f_callee_name(void)
+rb_f_callee_name(VALUE _)
{
ID fname = prev_frame_callee(); /* need *callee* ID */
@@ -1928,7 +1934,7 @@ rb_f_callee_name(void)
*
*/
static VALUE
-f_current_dirname(void)
+f_current_dirname(VALUE _)
{
VALUE base = rb_current_realfilepath();
if (NIL_P(base)) {
@@ -1938,16 +1944,34 @@ f_current_dirname(void)
return base;
}
+static VALUE
+f_global_variables(VALUE _)
+{
+ return rb_f_global_variables();
+}
+
+static VALUE
+f_trace_var(int c, const VALUE *a, VALUE _)
+{
+ return rb_f_trace_var(c, a);
+}
+
+static VALUE
+f_untrace_var(int c, const VALUE *a, VALUE _)
+{
+ return rb_f_untrace_var(c, a);
+}
+
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("raise", f_raise, -1);
+ rb_define_global_function("fail", f_raise, -1);
- rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */
+ rb_define_global_function("global_variables", f_global_variables, 0);
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_define_global_function("trace_var", f_trace_var, -1);
+ rb_define_global_function("untrace_var", f_untrace_var, -1);
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");