ruby-changes:57309
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 27 Aug 2019 16:03:34 +0900 (JST)
Subject: [ruby-changes:57309] 卜部昌平: 703783324c (master): rb_ensure now free from ANYARGS
https://git.ruby-lang.org/ruby.git/commit/?id=703783324c From 703783324c16b8b2b50210d1a7d1119902abbb8b 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: Mon, 26 Aug 2019 15:20:15 +0900 Subject: rb_ensure now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_ensure, which also revealed many arity / type mismatches. diff --git a/cont.c b/cont.c index de2f843..db422d9 100644 --- a/cont.c +++ b/cont.c @@ -1505,10 +1505,12 @@ make_passing_arg(int argc, const VALUE *argv) https://github.com/ruby/ruby/blob/trunk/cont.c#L1505 } } +typedef VALUE e_proc(VALUE); + /* CAUTION!! : Currently, error in rollback_func is not supported */ /* same as rb_protect if set rollback_func to NULL */ void -ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(ANYARGS), VALUE (*rollback_func)(ANYARGS)) +ruby_register_rollback_func_for_ensure(e_proc *ensure_func, e_proc *rollback_func) { st_table **table_p = &GET_VM()->ensure_rollback_table; if (UNLIKELY(*table_p == NULL)) { @@ -1517,14 +1519,14 @@ ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(ANYARGS), VALUE (*ro https://github.com/ruby/ruby/blob/trunk/cont.c#L1519 st_insert(*table_p, (st_data_t)ensure_func, (st_data_t)rollback_func); } -static inline VALUE -lookup_rollback_func(VALUE (*ensure_func)(ANYARGS)) +static inline e_proc * +lookup_rollback_func(e_proc *ensure_func) { st_table *table = GET_VM()->ensure_rollback_table; st_data_t val; if (table && st_lookup(table, (st_data_t)ensure_func, &val)) - return (VALUE) val; - return Qundef; + return (e_proc *) val; + return (e_proc *) Qundef; } @@ -1537,7 +1539,7 @@ rollback_ensure_stack(VALUE self,rb_ensure_list_t *current,rb_ensure_entry_t *ta https://github.com/ruby/ruby/blob/trunk/cont.c#L1539 size_t cur_size; size_t target_size; size_t base_point; - VALUE (*func)(ANYARGS); + e_proc *func; cur_size = 0; for (p=current; p; p=p->next) @@ -1572,7 +1574,7 @@ rollback_ensure_stack(VALUE self,rb_ensure_list_t *current,rb_ensure_entry_t *ta https://github.com/ruby/ruby/blob/trunk/cont.c#L1574 } /* push ensure stack */ for (j = 0; j < i; j++) { - func = (VALUE (*)(ANYARGS)) lookup_rollback_func(target[i - j - 1].e_proc); + func = lookup_rollback_func(target[i - j - 1].e_proc); if ((VALUE)func != Qundef) { (*func)(target[i - j - 1].data2); } diff --git a/dir.c b/dir.c index 18c10f2..bfd085e 100644 --- a/dir.c +++ b/dir.c @@ -1010,8 +1010,9 @@ struct chdir_data { https://github.com/ruby/ruby/blob/trunk/dir.c#L1010 }; static VALUE -chdir_yield(struct chdir_data *args) +chdir_yield(VALUE v) { + struct chdir_data *args = (void *)v; dir_chdir(args->new_path); args->done = TRUE; chdir_blocking++; @@ -1021,8 +1022,9 @@ chdir_yield(struct chdir_data *args) https://github.com/ruby/ruby/blob/trunk/dir.c#L1022 } static VALUE -chdir_restore(struct chdir_data *args) +chdir_restore(VALUE v) { + struct chdir_data *args = (void *)v; if (args->done) { chdir_blocking--; if (chdir_blocking == 0) diff --git a/eval.c b/eval.c index b06e87f..9997d28 100644 --- a/eval.c +++ b/eval.c @@ -1071,7 +1071,7 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate) https://github.com/ruby/ruby/blob/trunk/eval.c#L1071 * \ingroup exception */ VALUE -rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE data2) +rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2) { int state; volatile VALUE result = Qnil; diff --git a/ext/-test-/tracepoint/gc_hook.c b/ext/-test-/tracepoint/gc_hook.c index 6d8485e..2e695a9 100644 --- a/ext/-test-/tracepoint/gc_hook.c +++ b/ext/-test-/tracepoint/gc_hook.c @@ -4,7 +4,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/tracepoint/gc_hook.c#L4 static int invoking; /* TODO: should not be global variable */ static VALUE -invoke_proc_ensure(void *dmy) +invoke_proc_ensure(VALUE _) { invoking = 0; return Qnil; diff --git a/ext/etc/etc.c b/ext/etc/etc.c index b6dca94..a3a9bbc 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -231,7 +231,7 @@ etc_getpwnam(VALUE obj, VALUE nam) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L231 #ifdef HAVE_GETPWENT static int passwd_blocking = 0; static VALUE -passwd_ensure(void) +passwd_ensure(VALUE _) { endpwent(); passwd_blocking = (int)Qfalse; @@ -239,7 +239,7 @@ passwd_ensure(void) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L239 } static VALUE -passwd_iterate(void) +passwd_iterate(VALUE _) { struct passwd *pw; @@ -475,7 +475,7 @@ etc_getgrnam(VALUE obj, VALUE nam) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L475 #ifdef HAVE_GETGRENT static int group_blocking = 0; static VALUE -group_ensure(void) +group_ensure(VALUE _) { endgrent(); group_blocking = (int)Qfalse; @@ -484,7 +484,7 @@ group_ensure(void) https://github.com/ruby/ruby/blob/trunk/ext/etc/etc.c#L484 static VALUE -group_iterate(void) +group_iterate(VALUE _) { struct group *pw; diff --git a/ext/pty/pty.c b/ext/pty/pty.c index 7b9df4b..4c6ae26 100644 --- a/ext/pty/pty.c +++ b/ext/pty/pty.c @@ -520,8 +520,9 @@ pty_open(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/pty/pty.c#L520 } static VALUE -pty_detach_process(struct pty_info *info) +pty_detach_process(VALUE v) { + struct pty_info *info = (void *)v; #ifdef WNOHANG int st; if (rb_waitpid(info->child_pid, &st, WNOHANG) <= 0) diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c index f214d85..a2cb6e0 100644 --- a/ext/socket/ipsocket.c +++ b/ext/socket/ipsocket.c @@ -22,8 +22,9 @@ struct inetsock_arg https://github.com/ruby/ruby/blob/trunk/ext/socket/ipsocket.c#L22 }; static VALUE -inetsock_cleanup(struct inetsock_arg *arg) +inetsock_cleanup(VALUE v) { + struct inetsock_arg *arg = (void *)v; if (arg->remote.res) { rb_freeaddrinfo(arg->remote.res); arg->remote.res = 0; @@ -39,8 +40,9 @@ inetsock_cleanup(struct inetsock_arg *arg) https://github.com/ruby/ruby/blob/trunk/ext/socket/ipsocket.c#L40 } static VALUE -init_inetsock_internal(struct inetsock_arg *arg) +init_inetsock_internal(VALUE v) { + struct inetsock_arg *arg = (void *)v; int error = 0; int type = arg->type; struct addrinfo *res, *lres; diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index b59cc49..dad11ad 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -654,8 +654,9 @@ struct hostent_arg { https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L654 }; static VALUE -make_hostent_internal(struct hostent_arg *arg) +make_hostent_internal(VALUE v) { + struct hostent_arg *arg = (void *)v; VALUE host = arg->host; struct addrinfo* addr = arg->addr->ai; VALUE (*ipaddr)(struct sockaddr*, socklen_t) = arg->ipaddr; diff --git a/ext/socket/udpsocket.c b/ext/socket/udpsocket.c index c2e273c..6ef8242 100644 --- a/ext/socket/udpsocket.c +++ b/ext/socket/udpsocket.c @@ -50,8 +50,9 @@ struct udp_arg https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L50 }; static VALUE -udp_connect_internal(struct udp_arg *arg) +udp_connect_internal(VALUE v) { + struct udp_arg *arg = (void *)v; rb_io_t *fptr; int fd; struct addrinfo *res; @@ -97,8 +98,9 @@ udp_connect(VALUE sock, VALUE host, VALUE port) https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L98 } static VALUE -udp_bind_internal(struct udp_arg *arg) +udp_bind_internal(VALUE v) { + struct udp_arg *arg = (void *)v; rb_io_t *fptr; int fd; struct addrinfo *res; @@ -147,8 +149,9 @@ struct udp_send_arg { https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L149 }; static VALUE -udp_send_internal(struct udp_send_arg *arg) +udp_send_internal(VALUE v) { + struct udp_send_arg *arg = (void *)v; rb_io_t *fptr; int n; struct addrinfo *res; diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index e84e565..afd761f 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -85,6 +85,7 @@ static void zstream_passthrough_input(struct zstream*); https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L85 static VALUE zstream_detach_input(struct zstream*); static void zstream_reset(struct zstream*); static VALUE zstream_end(struct zstream*); +static VALUE zstream_ensure_end(VALUE v); static void zstream_run(struct zstream*, Bytef*, long, int); static VALUE zstream_sync(struct zstream*, Bytef*, long); static void zstream_mark(void*); @@ -955,6 +956,12 @@ zstream_end(struct zstream *z) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L956 return Qnil; } +static VALUE +zstream_ensure_end(VALUE v) +{ + return zstream_end((struct zstream *)v); +} + static void * zstream_run_func(void *ptr) { @@ -1640,7 +1647,7 @@ rb_deflate_s_deflate(int argc, VALUE *argv, VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1647 args[0] = (VALUE)&z; args[1] = src; - dst = rb_ensure(deflate_run, (VALUE)args, zstream_end, (VALUE)&z); + dst = rb_ensure(deflate_run, (VALUE)args, zstream_ensure_end, (VALUE)&z); OBJ_INFECT(dst, src); return dst; @@ -1955,7 +1962,7 @@ rb_inflate_s_inflate(VALUE obj, VALUE src) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1962 args[0] = (VALUE)&z; args[1] = src; - dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)&z); + dst = rb_ensure(inflate_run, (VALUE)args, zstream_ensure_end, (VALUE)&z); OBJ_INFECT(dst, src); return dst; @@ -2919,7 +2926,7 @@ gzfile_writer_end(struct gzfile *gz) https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L2926 if (ZSTREAM_IS_CLOSING(&gz->z)) return; gz->z.flags |= ZSTREAM_FLAG_CLOSING; - rb_ensure(gzfile_writer_end_run, (VALUE (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/