[前][次][番号順一覧][スレッド一覧]

ruby-changes:57308

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 27 Aug 2019 16:03:33 +0900 (JST)
Subject: [ruby-changes:57308] 卜部昌平: ae2dc3f217 (master): rb_define_hooked_variable now free from ANYARGS

https://git.ruby-lang.org/ruby.git/commit/?id=ae2dc3f217

From ae2dc3f217ba9f181471f39a7e5ce72a28b27c2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Tue, 27 Aug 2019 11:16:52 +0900
Subject: rb_define_hooked_variable now free from ANYARGS

After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is
dangerous and should be extinct.  This commit uses rb_gvar_getter_t /
rb_gvar_setter_t for rb_define_hooked_variable /
rb_define_virtual_variable which revealed lots of function prototype
inconsistencies.  Some of them were literally decades old, going back
to dda5dc00cff334cac373096d444a0fd59e716124.

diff --git a/eval.c b/eval.c
index 9997d28..c2f15fb 100644
--- a/eval.c
+++ b/eval.c
@@ -1816,7 +1816,7 @@ get_errinfo(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L1816
 }
 
 static VALUE
-errinfo_getter(ID id)
+errinfo_getter(ID id, VALUE *_)
 {
     return get_errinfo();
 }
@@ -1851,7 +1851,7 @@ rb_set_errinfo(VALUE err) https://github.com/ruby/ruby/blob/trunk/eval.c#L1851
 }
 
 static VALUE
-errat_getter(ID id)
+errat_getter(ID id, VALUE *_)
 {
     VALUE err = get_errinfo();
     if (!NIL_P(err)) {
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index c5a7f05..aaf73a1 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -801,7 +801,7 @@ VALUE rb_str_replace(VALUE, VALUE); https://github.com/ruby/ruby/blob/trunk/include/ruby/intern.h#L801
 VALUE rb_str_inspect(VALUE);
 VALUE rb_str_dump(VALUE);
 VALUE rb_str_split(VALUE, const char*);
-void rb_str_setter(VALUE, ID, VALUE*);
+rb_gvar_setter_t rb_str_setter;
 VALUE rb_str_intern(VALUE);
 VALUE rb_sym_to_s(VALUE);
 long rb_str_strlen(VALUE);
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 86406ca..e15e3e6 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1776,29 +1776,27 @@ void rb_include_module(VALUE,VALUE); https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1776
 void rb_extend_object(VALUE,VALUE);
 void rb_prepend_module(VALUE,VALUE);
 
-struct rb_global_variable;
-
-typedef VALUE rb_gvar_getter_t(ID id, void *data, struct rb_global_variable *gvar);
-typedef void  rb_gvar_setter_t(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
+typedef VALUE rb_gvar_getter_t(ID id, VALUE *data);
+typedef void  rb_gvar_setter_t(VALUE val, ID id, VALUE *data);
 typedef void  rb_gvar_marker_t(VALUE *var);
 
-VALUE rb_gvar_undef_getter(ID id, void *data, struct rb_global_variable *gvar);
-void  rb_gvar_undef_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
-void  rb_gvar_undef_marker(VALUE *var);
+rb_gvar_getter_t rb_gvar_undef_getter;
+rb_gvar_setter_t rb_gvar_undef_setter;
+rb_gvar_marker_t rb_gvar_undef_marker;
 
-VALUE rb_gvar_val_getter(ID id, void *data, struct rb_global_variable *gvar);
-void  rb_gvar_val_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
-void  rb_gvar_val_marker(VALUE *var);
+rb_gvar_getter_t rb_gvar_val_getter;
+rb_gvar_setter_t rb_gvar_val_setter;
+rb_gvar_marker_t rb_gvar_val_marker;
 
-VALUE rb_gvar_var_getter(ID id, void *data, struct rb_global_variable *gvar);
-void  rb_gvar_var_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
-void  rb_gvar_var_marker(VALUE *var);
+rb_gvar_getter_t rb_gvar_var_getter;
+rb_gvar_setter_t rb_gvar_var_setter;
+rb_gvar_marker_t rb_gvar_var_marker;
 
-NORETURN(void  rb_gvar_readonly_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar));
+NORETURN(rb_gvar_setter_t rb_gvar_readonly_setter);
 
 void rb_define_variable(const char*,VALUE*);
-void rb_define_virtual_variable(const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
-void rb_define_hooked_variable(const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
+void rb_define_virtual_variable(const char*,rb_gvar_getter_t*,rb_gvar_setter_t*);
+void rb_define_hooked_variable(const char*,VALUE*,rb_gvar_getter_t*,rb_gvar_setter_t*);
 void rb_define_readonly_variable(const char*,const VALUE*);
 void rb_define_const(VALUE,const char*,VALUE);
 void rb_define_global_const(const char*,VALUE);
diff --git a/io.c b/io.c
index 1b37723..2f9df89 100644
--- a/io.c
+++ b/io.c
@@ -12986,6 +12986,18 @@ rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char * https://github.com/ruby/ruby/blob/trunk/io.c#L12986
     }
 }
 
+static VALUE
+get_$LAST_READ_LINE(ID _x, VALUE *_y)
+{
+    return rb_lastline_get();
+}
+
+static void
+set_$LAST_READ_LINE(VALUE val, ID _x, VALUE *_y)
+{
+    rb_lastline_set(val);
+}
+
 /*
  * Document-class: IOError
  *
@@ -13259,7 +13271,7 @@ Init_IO(void) https://github.com/ruby/ruby/blob/trunk/io.c#L13271
     rb_define_hooked_variable("$-0", &rb_rs, 0, rb_str_setter);
     rb_define_hooked_variable("$\\", &rb_output_rs, 0, rb_str_setter);
 
-    rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set);
+    rb_define_virtual_variable("$_", get_$LAST_READ_LINE, set_$LAST_READ_LINE);
 
     rb_define_method(rb_cIO, "initialize_copy", rb_io_init_copy, 1);
     rb_define_method(rb_cIO, "reopen", rb_io_reopen, -1);
diff --git a/load.c b/load.c
index 6ebe8e5..bc7abf1 100644
--- a/load.c
+++ b/load.c
@@ -143,8 +143,9 @@ rb_get_expanded_load_path(void) https://github.com/ruby/ruby/blob/trunk/load.c#L143
 }
 
 static VALUE
-load_path_getter(ID id, rb_vm_t *vm)
+load_path_getter(ID id, VALUE * p)
 {
+    rb_vm_t *vm = (void *)p;
     return vm->load_path;
 }
 
@@ -154,6 +155,12 @@ get_loaded_features(void) https://github.com/ruby/ruby/blob/trunk/load.c#L155
     return GET_VM()->loaded_features;
 }
 
+static VALUE
+get_$LOADED_FEATURES(ID _x, VALUE *_y)
+{
+    return get_loaded_features();
+}
+
 static void
 reset_loaded_features_snapshot(void)
 {
@@ -1258,8 +1265,8 @@ Init_load(void) https://github.com/ruby/ruby/blob/trunk/load.c#L1265
     vm->load_path_check_cache = 0;
     rb_define_singleton_method(vm->load_path, "resolve_feature_path", rb_resolve_feature_path, 1);
 
-    rb_define_virtual_variable("$\"", get_loaded_features, 0);
-    rb_define_virtual_variable("$LOADED_FEATURES", get_loaded_features, 0);
+    rb_define_virtual_variable("$\"", get_$LOADED_FEATURES, 0);
+    rb_define_virtual_variable("$LOADED_FEATURES", get_$LOADED_FEATURES, 0);
     vm->loaded_features = rb_ary_new();
     vm->loaded_features_snapshot = rb_ary_tmp_new(0);
     vm->loaded_features_index = st_init_numtable();
diff --git a/process.c b/process.c
index 8cd42db..dad0907 100644
--- a/process.c
+++ b/process.c
@@ -8038,6 +8038,18 @@ rb_clock_getres(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L8038
     }
 }
 
+static VALUE
+get_$CHILD_STATUS(ID _x, VALUE *_y)
+{
+    return rb_last_status_get();
+}
+
+static VALUE
+get_$PROCESS_ID(ID _x, VALUE *_y)
+{
+    return get_pid();
+}
+
 VALUE rb_mProcess;
 static VALUE rb_mProcUID;
 static VALUE rb_mProcGID;
@@ -8054,8 +8066,8 @@ InitVM_process(void) https://github.com/ruby/ruby/blob/trunk/process.c#L8066
 {
 #undef rb_intern
 #define rb_intern(str) rb_intern_const(str)
-    rb_define_virtual_variable("$?", rb_last_status_get, 0);
-    rb_define_virtual_variable("$$", get_pid, 0);
+    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);
diff --git a/re.c b/re.c
index 6fd4fde..f4aad1e 100644
--- a/re.c
+++ b/re.c
@@ -1824,25 +1824,25 @@ rb_reg_match_last(VALUE match) https://github.com/ruby/ruby/blob/trunk/re.c#L1824
 }
 
 static VALUE
-last_match_getter(void)
+last_match_getter(ID _x, VALUE *_y)
 {
     return rb_reg_last_match(rb_backref_get());
 }
 
 static VALUE
-prematch_getter(void)
+prematch_getter(ID _x, VALUE *_y)
 {
     return rb_reg_match_pre(rb_backref_get());
 }
 
 static VALUE
-postmatch_getter(void)
+postmatch_getter(ID _x, VALUE *_y)
 {
     return rb_reg_match_post(rb_backref_get());
 }
 
 static VALUE
-last_paren_match_getter(void)
+last_paren_match_getter(ID _x, VALUE *_y)
 {
     return rb_reg_match_last(rb_backref_get());
 }
@@ -3919,27 +3919,27 @@ rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs, VALUE regexp) https://github.com/ruby/ruby/blob/trunk/re.c#L3919
 }
 
 static VALUE
-kcode_getter(void)
+kcode_getter(ID _x, VALUE *_y)
 {
     rb_warn("variable $KCODE is no longer effective");
     return Qnil;
 }
 
 static void
-kcode_setter(VALUE val, ID id)
+kcode_setter(VALUE val, ID id, VALUE *_)
 {
     rb_warn("variable $KCODE is no longer effective; ignored");
 }
 
 static VALUE
-ignorecase_getter(void)
+ignorecase_getter(ID _x, VALUE *_y)
 {
     rb_warn("variable $= is no longer effective");
     return Qfalse;
 }
 
 static void
-ignorecase_setter(VALUE val, ID id)
+ignorecase_setter(VALUE val, ID id, VALUE *_)
 {
     rb_warn("variable $= is no longer effective; ignored");
 }
@@ -3954,8 +3954,14 @@ match_getter(void) https://github.com/ruby/ruby/blob/trunk/re.c#L3954
     return match;
 }
 
+static VALUE
+get_$LAST_MATCH_INFO(ID _x, VALUE *_y)
+{
+    return match_getter();
+}
+
 static void
-match_setter(VALUE val)
+match_setter(VALUE val, ID _x, VALUE *_y)
 {
     if (!NIL_P(val)) {
 	Check_Type(val, T_MATCH);
@@ -4042,7 +4048,7 @@ Init_Regexp(void) https://github.com/ruby/ruby/blob/trunk/re.c#L4048
     onig_set_warn_func(re_warn);
     onig_set_verb_warn_func(re_warn);
 
-    rb_define_virtual_variable("$~", match_getter, match_setter);
+    rb_define_virtual_variable("$~", get_$LAST_MATCH_INFO, match_setter);
     rb_define_virtual_variable("$&", last_match_getter, 0);
     rb_define_virtual_variable("$`", prematch_getter, 0);
     rb_define_virtual_variable("$'", postmatch_getter, 0);
diff --git a/ruby.c b/ruby.c
index 2610cf2..57c95fa 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1446,13 +1446,13 @@ VALUE rb_argv0; https://github.com/ruby/ruby/blob/trunk/ruby.c#L1446
 VALUE rb_e_script;
 
 static VALUE
-false_value(void)
+false_value(ID _x, VALUE * (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]