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.
This commit is contained in:
parent
5c7c2d9951
commit
703783324c
16
cont.c
16
cont.c
@ -1505,10 +1505,12 @@ make_passing_arg(int argc, const VALUE *argv)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
|
6
dir.c
6
dir.c
@ -1010,8 +1010,9 @@ struct chdir_data {
|
||||
};
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
|
2
eval.c
2
eval.c
@ -1071,7 +1071,7 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate)
|
||||
* \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;
|
||||
|
@ -4,7 +4,7 @@
|
||||
static int invoking; /* TODO: should not be global variable */
|
||||
|
||||
static VALUE
|
||||
invoke_proc_ensure(void *dmy)
|
||||
invoke_proc_ensure(VALUE _)
|
||||
{
|
||||
invoking = 0;
|
||||
return Qnil;
|
||||
|
@ -231,7 +231,7 @@ etc_getpwnam(VALUE obj, VALUE nam)
|
||||
#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)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
passwd_iterate(void)
|
||||
passwd_iterate(VALUE _)
|
||||
{
|
||||
struct passwd *pw;
|
||||
|
||||
@ -475,7 +475,7 @@ etc_getgrnam(VALUE obj, VALUE nam)
|
||||
#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)
|
||||
|
||||
|
||||
static VALUE
|
||||
group_iterate(void)
|
||||
group_iterate(VALUE _)
|
||||
{
|
||||
struct group *pw;
|
||||
|
||||
|
@ -520,8 +520,9 @@ pty_open(VALUE klass)
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -22,8 +22,9 @@ struct inetsock_arg
|
||||
};
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -654,8 +654,9 @@ struct hostent_arg {
|
||||
};
|
||||
|
||||
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;
|
||||
|
@ -50,8 +50,9 @@ struct udp_arg
|
||||
};
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
};
|
||||
|
||||
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;
|
||||
|
@ -85,6 +85,7 @@ static void zstream_passthrough_input(struct zstream*);
|
||||
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)
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
if (ZSTREAM_IS_CLOSING(&gz->z)) return;
|
||||
gz->z.flags |= ZSTREAM_FLAG_CLOSING;
|
||||
|
||||
rb_ensure(gzfile_writer_end_run, (VALUE)gz, zstream_end, (VALUE)&gz->z);
|
||||
rb_ensure(gzfile_writer_end_run, (VALUE)gz, zstream_ensure_end, (VALUE)&gz->z);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
@ -2941,7 +2948,7 @@ gzfile_reader_end(struct gzfile *gz)
|
||||
if (ZSTREAM_IS_CLOSING(&gz->z)) return;
|
||||
gz->z.flags |= ZSTREAM_FLAG_CLOSING;
|
||||
|
||||
rb_ensure(gzfile_reader_end_run, (VALUE)gz, zstream_end, (VALUE)&gz->z);
|
||||
rb_ensure(gzfile_reader_end_run, (VALUE)gz, zstream_ensure_end, (VALUE)&gz->z);
|
||||
}
|
||||
|
||||
static void
|
||||
|
2
gc.c
2
gc.c
@ -2755,7 +2755,7 @@ objspace_each_objects_protected(VALUE arg)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
incremental_enable(void)
|
||||
incremental_enable(VALUE _)
|
||||
{
|
||||
rb_objspace_t *objspace = &rb_objspace;
|
||||
|
||||
|
@ -1968,7 +1968,7 @@ VALUE rb_iterate(VALUE(*)(VALUE),VALUE,rb_block_call_func_t,VALUE);
|
||||
VALUE rb_block_call(VALUE,ID,int,const VALUE*,rb_block_call_func_t,VALUE);
|
||||
VALUE rb_rescue(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE);
|
||||
VALUE rb_rescue2(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE,VALUE),VALUE,...);
|
||||
VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
|
||||
VALUE rb_ensure(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE),VALUE);
|
||||
VALUE rb_catch(const char*,VALUE(*)(ANYARGS),VALUE);
|
||||
VALUE rb_catch_obj(VALUE,VALUE(*)(ANYARGS),VALUE);
|
||||
NORETURN(void rb_throw(const char*,VALUE));
|
||||
|
@ -1469,7 +1469,7 @@ struct rb_thread_struct;
|
||||
/* cont.c */
|
||||
VALUE rb_obj_is_fiber(VALUE);
|
||||
void rb_fiber_reset_root_local_storage(struct rb_thread_struct *);
|
||||
void ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(ANYARGS), VALUE (*rollback_func)(ANYARGS));
|
||||
void ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(VALUE), VALUE (*rollback_func)(VALUE));
|
||||
|
||||
/* debug.c */
|
||||
PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
|
||||
|
12
io.c
12
io.c
@ -10379,8 +10379,9 @@ open_key_args(VALUE klass, int argc, VALUE *argv, VALUE opt, struct foreach_arg
|
||||
}
|
||||
|
||||
static VALUE
|
||||
io_s_foreach(struct getline_arg *arg)
|
||||
io_s_foreach(VALUE v)
|
||||
{
|
||||
struct getline_arg *arg = (void *)v;
|
||||
VALUE str;
|
||||
|
||||
while (!NIL_P(str = rb_io_getline_1(arg->rs, arg->limit, arg->chomp, arg->io))) {
|
||||
@ -10437,8 +10438,9 @@ rb_io_s_foreach(int argc, VALUE *argv, VALUE self)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
io_s_readlines(struct getline_arg *arg)
|
||||
io_s_readlines(VALUE v)
|
||||
{
|
||||
struct getline_arg *arg = (void *)v;
|
||||
return io_readlines(arg, arg->io);
|
||||
}
|
||||
|
||||
@ -10489,8 +10491,9 @@ rb_io_s_readlines(int argc, VALUE *argv, VALUE io)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
io_s_read(struct foreach_arg *arg)
|
||||
io_s_read(VALUE v)
|
||||
{
|
||||
struct foreach_arg *arg = (void *)v;
|
||||
return io_read(arg->argc, arg->argv, arg->io);
|
||||
}
|
||||
|
||||
@ -10626,8 +10629,9 @@ rb_io_s_binread(int argc, VALUE *argv, VALUE io)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
io_s_write0(struct write_arg *arg)
|
||||
io_s_write0(VALUE v)
|
||||
{
|
||||
struct write_arg *arg = (void * )v;
|
||||
return io_write(arg->io,arg->str,arg->nosync);
|
||||
}
|
||||
|
||||
|
@ -1363,8 +1363,9 @@ do_sleep(VALUE args)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
delete_from_waitq(struct sync_waiter *w)
|
||||
delete_from_waitq(VALUE v)
|
||||
{
|
||||
struct sync_waiter *w = (void *)v;
|
||||
list_del(&w->node);
|
||||
|
||||
return Qnil;
|
||||
|
@ -671,8 +671,9 @@ struct trace_data {
|
||||
};
|
||||
|
||||
static VALUE
|
||||
trace_ev(struct trace_data *data)
|
||||
trace_ev(VALUE v)
|
||||
{
|
||||
struct trace_data *data = (void *)v;
|
||||
struct trace_var *trace = data->trace;
|
||||
|
||||
while (trace) {
|
||||
@ -684,8 +685,9 @@ trace_ev(struct trace_data *data)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
trace_en(struct rb_global_variable *var)
|
||||
trace_en(VALUE v)
|
||||
{
|
||||
struct rb_global_variable *var = (void *)v;
|
||||
var->block_trace = 0;
|
||||
remove_trace(var);
|
||||
return Qnil; /* not reached */
|
||||
|
Loading…
x
Reference in New Issue
Block a user