From 687a1f60fbe893ae22226de9f0298d717beb8f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 27 Aug 2019 13:03:47 +0900 Subject: [PATCH 01/18] delete rb_method_defined_by declaration. Ko1 missed this in d5893b91faa7dc77ca6c9728d1054dabd757aead. --- internal.h | 1 - 1 file changed, 1 deletion(-) diff --git a/internal.h b/internal.h index eb18581d4793c5..d6b762aeebf587 100644 --- a/internal.h +++ b/internal.h @@ -2311,7 +2311,6 @@ void Init_vm_stack_canary(void); /* vm_method.c */ void Init_eval_method(void); -int rb_method_defined_by(VALUE obj, ID mid, VALUE (*cfunc)(ANYARGS)); /* miniprelude.c, prelude.c */ void Init_prelude(void); From 7354e3e7b8251315be8fd6c0ec25a0badd032640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 27 Aug 2019 14:11:02 +0900 Subject: [PATCH 02/18] fix function prototype mismatch of rb_block_call Nobu missed it in f0e73fc9862c8d2c57a89349fb79012b826b8245. --- vm_eval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm_eval.c b/vm_eval.c index a0f8e55f5d7310..b449cd49966ad3 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1218,7 +1218,7 @@ iterate_method(VALUE obj) VALUE rb_block_call(VALUE obj, ID mid, int argc, const VALUE * argv, - VALUE (*bl_proc) (ANYARGS), VALUE data2) + rb_block_call_func_t bl_proc, VALUE data2) { struct iter_method_arg arg; @@ -1257,7 +1257,7 @@ iterate_check_method(VALUE obj) VALUE rb_check_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, - VALUE (*bl_proc) (ANYARGS), VALUE data2) + rb_block_call_func_t bl_proc, VALUE data2) { struct iter_method_arg arg; From 6325d8245c8ffa1e53b3bc4c25a122366423cca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 26 Aug 2019 13:30:04 +0900 Subject: [PATCH 03/18] #define RB_BLOCK_CALL_FUNC_STRICT 1 After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. Let's start from making rb_block_call_func_t strict, and apply RB_BLOCK_CALL_FUNC_ARGLIST liberally. --- enum.c | 4 ++-- enumerator.c | 6 +++--- include/ruby/ruby.h | 6 +----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/enum.c b/enum.c index bae32cb04528c6..665c97ffbe54c1 100644 --- a/enum.c +++ b/enum.c @@ -1535,7 +1535,7 @@ nmin_filter(struct nmin_data *data) } static VALUE -nmin_i(VALUE i, VALUE *_data, int argc, VALUE *argv) +nmin_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, _data)) { struct nmin_data *data = (struct nmin_data *)_data; VALUE cmpv; @@ -1595,7 +1595,7 @@ rb_nmin_run(VALUE obj, VALUE num, int by, int rev, int ary) for (i = 0; i < RARRAY_LEN(obj); i++) { VALUE args[1]; args[0] = RARRAY_AREF(obj, i); - nmin_i(obj, (VALUE*)&data, 1, args); + nmin_i(obj, (VALUE)&data, 1, args, Qundef); } } else { diff --git a/enumerator.c b/enumerator.c index 6a2443fcaf81af..beea1c728fb6fb 100644 --- a/enumerator.c +++ b/enumerator.c @@ -1567,7 +1567,7 @@ lazy_init_block_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, m)) #define LAZY_MEMO_RESET_PACKED(memo) ((memo)->memo_flags &= ~LAZY_MEMO_PACKED) static VALUE -lazy_init_yielder(VALUE val, VALUE m, int argc, VALUE *argv) +lazy_init_yielder(RB_BLOCK_CALL_FUNC_ARGLIST(_, m)) { VALUE yielder = RARRAY_AREF(m, 0); VALUE procs_array = RARRAY_AREF(m, 1); @@ -1598,7 +1598,7 @@ lazy_init_yielder(VALUE val, VALUE m, int argc, VALUE *argv) } static VALUE -lazy_init_block(VALUE val, VALUE m, int argc, VALUE *argv) +lazy_init_block(RB_BLOCK_CALL_FUNC_ARGLIST(val, m)) { VALUE procs = RARRAY_AREF(m, 1); @@ -2860,7 +2860,7 @@ enum_chain_enum_size(VALUE obj, VALUE args, VALUE eobj) } static VALUE -enum_chain_yield_block(VALUE arg, VALUE block, int argc, VALUE *argv) +enum_chain_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(_, block)) { return rb_funcallv(block, id_call, argc, argv); } diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 1bb4671c54f3ca..cf065e974e175d 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1949,16 +1949,12 @@ PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2); COLDFUNC PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2); PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4); +#define RB_BLOCK_CALL_FUNC_STRICT 1 #define RUBY_BLOCK_CALL_FUNC_TAKES_BLOCKARG 1 #define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg) \ VALUE yielded_arg, VALUE callback_arg, int argc, const VALUE *argv, VALUE blockarg typedef VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)); - -#if defined RB_BLOCK_CALL_FUNC_STRICT && RB_BLOCK_CALL_FUNC_STRICT typedef rb_block_call_func *rb_block_call_func_t; -#else -typedef VALUE (*rb_block_call_func_t)(ANYARGS); -#endif VALUE rb_each(VALUE); VALUE rb_yield(VALUE); From 747a2469f424608e5d2b6c719e5a2b61ab397ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 26 Aug 2019 14:25:53 +0900 Subject: [PATCH 04/18] decouple compile.c usage of imemo_ifunc After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from struct vm_ifunc, but in doing so we also have to decouple the usage of this struct in compile.c, which (I think) is an abuse of ANYARGS. --- compile.c | 45 ++++++++++++++++++++++++--------------------- internal.h | 6 +++--- iseq.c | 10 ++++++---- iseq.h | 2 +- proc.c | 8 ++++---- vm_core.h | 19 +++++++++++++++++-- vm_insnhelper.c | 2 +- 7 files changed, 56 insertions(+), 36 deletions(-) diff --git a/compile.c b/compile.c index 008dfc8d678dff..29965df7a48167 100644 --- a/compile.c +++ b/compile.c @@ -615,7 +615,7 @@ validate_labels(rb_iseq_t *iseq, st_table *labels_table) } VALUE -rb_iseq_compile_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc) +rb_iseq_compile_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func * ifunc) { DECL_ANCHOR(ret); INIT_ANCHOR(ret); @@ -1206,16 +1206,16 @@ new_child_iseq(rb_iseq_t *iseq, const NODE *const node, } static rb_iseq_t * -new_child_iseq_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc, +new_child_iseq_with_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func *ifunc, VALUE name, const rb_iseq_t *parent, enum iseq_type type, int line_no) { rb_iseq_t *ret_iseq; - debugs("[new_child_iseq_ifunc]> ---------------------------------------\n"); - ret_iseq = rb_iseq_new_ifunc(ifunc, name, + debugs("[new_child_iseq_with_callback]> ---------------------------------------\n"); + ret_iseq = rb_iseq_new_with_callback(ifunc, name, rb_iseq_path(iseq), rb_iseq_realpath(iseq), INT2FIX(line_no), parent, type, ISEQ_COMPILE_DATA(iseq)->option); - debugs("[new_child_iseq_ifunc]< ---------------------------------------\n"); + debugs("[new_child_iseq_with_callback]< ---------------------------------------\n"); iseq_add_mark_object_compile_time(iseq, (VALUE)ret_iseq); return ret_iseq; } @@ -4629,12 +4629,11 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, } } -static VALUE -build_defined_rescue_iseq(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *unused) +static void +build_defined_rescue_iseq(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const void *unused) { ADD_INSN(ret, 0, putnil); iseq_set_exception_local_table(iseq); - return Qnil; } static void @@ -4648,7 +4647,9 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *const ret, LABEL *lstart = NEW_LABEL(line); LABEL *lend = NEW_LABEL(line); const rb_iseq_t *rescue; - rescue = new_child_iseq_ifunc(iseq, IFUNC_NEW(build_defined_rescue_iseq, 0, 0), + struct rb_iseq_new_with_callback_callback_func *ifunc = + rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL); + rescue = new_child_iseq_with_callback(iseq, ifunc, rb_str_concat(rb_str_new2("defined guard in "), iseq->body->location.label), iseq, ISEQ_TYPE_RESCUE, 0); @@ -4871,9 +4872,10 @@ setup_args(rb_iseq_t *iseq, LINK_ANCHOR *const args, const NODE *argn, return ret; } -static VALUE -build_postexe_iseq(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *body) +static void +build_postexe_iseq(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *ptr) { + const NODE *body = ptr; int line = nd_line(body); VALUE argc = INT2FIX(0); const rb_iseq_t *block = NEW_CHILD_ISEQ(body, make_name_for_block(iseq->body->parent_iseq), ISEQ_TYPE_BLOCK, line); @@ -4881,7 +4883,6 @@ build_postexe_iseq(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *body) ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); ADD_CALL_WITH_BLOCK(ret, line, id_core_set_postexe, argc, block); iseq_set_local_table(iseq, 0); - return Qnil; } static void @@ -8008,8 +8009,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in * ONCE{ rb_mRubyVMFrozenCore::core#set_postexe{ ... } } */ int is_index = body->is_size++; + struct rb_iseq_new_with_callback_callback_func *ifunc = + rb_iseq_new_with_callback_new_callback(build_postexe_iseq, node->nd_body); const rb_iseq_t *once_iseq = - new_child_iseq_ifunc(iseq, IFUNC_NEW(build_postexe_iseq, node->nd_body, 0), + new_child_iseq_with_callback(iseq, ifunc, rb_fstring(make_name_for_block(iseq)), iseq, ISEQ_TYPE_BLOCK, line); ADD_INSN2(ret, line, once, once_iseq, INT2FIX(is_index)); @@ -8978,7 +8981,7 @@ typedef struct { static const rb_iseq_t * method_for_self(VALUE name, VALUE arg, rb_insn_func_t func, - VALUE (*build)(rb_iseq_t *, LINK_ANCHOR *const, VALUE)) + void (*build)(rb_iseq_t *, LINK_ANCHOR *, const void *)) { VALUE path, realpath; accessor_args acc; @@ -8986,13 +8989,15 @@ method_for_self(VALUE name, VALUE arg, rb_insn_func_t func, acc.arg = arg; acc.func = func; acc.line = caller_location(&path, &realpath); - return rb_iseq_new_ifunc(IFUNC_NEW(build, (VALUE)&acc, 0), + struct rb_iseq_new_with_callback_callback_func *ifunc = + rb_iseq_new_with_callback_new_callback(build, &acc); + return rb_iseq_new_with_callback(ifunc, rb_sym2str(name), path, realpath, INT2FIX(acc.line), 0, ISEQ_TYPE_METHOD, 0); } -static VALUE -for_self_aref(rb_iseq_t *iseq, LINK_ANCHOR *const ret, VALUE a) +static void +for_self_aref(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *a) { const accessor_args *const args = (void *)a; const int line = args->line; @@ -9004,11 +9009,10 @@ for_self_aref(rb_iseq_t *iseq, LINK_ANCHOR *const ret, VALUE a) ADD_INSN1(ret, line, putobject, args->arg); ADD_INSN1(ret, line, opt_call_c_function, (VALUE)args->func); - return Qnil; } -static VALUE -for_self_aset(rb_iseq_t *iseq, LINK_ANCHOR *const ret, VALUE a) +static void +for_self_aset(rb_iseq_t *iseq, LINK_ANCHOR *ret, const void *a) { const accessor_args *const args = (void *)a; const int line = args->line; @@ -9023,7 +9027,6 @@ for_self_aset(rb_iseq_t *iseq, LINK_ANCHOR *const ret, VALUE a) ADD_INSN1(ret, line, putobject, args->arg); ADD_INSN1(ret, line, opt_call_c_function, (VALUE)args->func); ADD_INSN(ret, line, pop); - return Qnil; } /* diff --git a/internal.h b/internal.h index d6b762aeebf587..01009b616a96bd 100644 --- a/internal.h +++ b/internal.h @@ -1181,15 +1181,15 @@ struct vm_ifunc_argc { struct vm_ifunc { VALUE flags; VALUE reserved; - VALUE (*func)(ANYARGS); + rb_block_call_func_t func; const void *data; struct vm_ifunc_argc argc; }; #define IFUNC_NEW(a, b, c) ((struct vm_ifunc *)rb_imemo_new(imemo_ifunc, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0)) -struct vm_ifunc *rb_vm_ifunc_new(VALUE (*func)(ANYARGS), const void *data, int min_argc, int max_argc); +struct vm_ifunc *rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc); static inline struct vm_ifunc * -rb_vm_ifunc_proc_new(VALUE (*func)(ANYARGS), const void *data) +rb_vm_ifunc_proc_new(rb_block_call_func_t func, const void *data) { return rb_vm_ifunc_new(func, data, 0, UNLIMITED_ARGUMENTS); } diff --git a/iseq.c b/iseq.c index 86ef5cd498dde5..9154001dc9fd48 100644 --- a/iseq.c +++ b/iseq.c @@ -809,9 +809,11 @@ rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE rea } rb_iseq_t * -rb_iseq_new_ifunc(const struct vm_ifunc *ifunc, VALUE name, VALUE path, VALUE realpath, - VALUE first_lineno, const rb_iseq_t *parent, - enum iseq_type type, const rb_compile_option_t *option) +rb_iseq_new_with_callback( + const struct rb_iseq_new_with_callback_callback_func * ifunc, + VALUE name, VALUE path, VALUE realpath, + VALUE first_lineno, const rb_iseq_t *parent, + enum iseq_type type, const rb_compile_option_t *option) { /* TODO: argument check */ rb_iseq_t *iseq = iseq_alloc(); @@ -819,7 +821,7 @@ rb_iseq_new_ifunc(const struct vm_ifunc *ifunc, VALUE name, VALUE path, VALUE re if (!option) option = &COMPILE_OPTION_DEFAULT; prepare_iseq_build(iseq, name, path, realpath, first_lineno, NULL, -1, parent, type, option); - rb_iseq_compile_ifunc(iseq, ifunc); + rb_iseq_compile_callback(iseq, ifunc); finish_iseq_build(iseq); return iseq_translate(iseq); diff --git a/iseq.h b/iseq.h index 0326577c5aed7f..13cbd9056975cd 100644 --- a/iseq.h +++ b/iseq.h @@ -162,7 +162,7 @@ RUBY_SYMBOL_EXPORT_BEGIN /* compile.c */ VALUE rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node); -VALUE rb_iseq_compile_ifunc(rb_iseq_t *iseq, const struct vm_ifunc *ifunc); +VALUE rb_iseq_compile_callback(rb_iseq_t *iseq, const struct rb_iseq_new_with_callback_callback_func * ifunc); int rb_iseq_translate_threaded_code(rb_iseq_t *iseq); VALUE *rb_iseq_original_iseq(const rb_iseq_t *iseq); void rb_iseq_build_from_ary(rb_iseq_t *iseq, VALUE misc, diff --git a/proc.c b/proc.c index 810fe79c928aab..1c0a5dfcd9e4f8 100644 --- a/proc.c +++ b/proc.c @@ -43,7 +43,7 @@ VALUE rb_cMethod; VALUE rb_cBinding; VALUE rb_cProc; -static VALUE bmcall(VALUE, VALUE, int, VALUE *, VALUE); +static rb_block_call_func bmcall; static int method_arity(VALUE); static int method_min_max_arity(VALUE, int *max); @@ -696,7 +696,7 @@ sym_proc_new(VALUE klass, VALUE sym) } struct vm_ifunc * -rb_vm_ifunc_new(VALUE (*func)(ANYARGS), const void *data, int min_argc, int max_argc) +rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc) { union { struct vm_ifunc_argc argc; @@ -2783,9 +2783,9 @@ mlambda(VALUE method) } static VALUE -bmcall(VALUE args, VALUE method, int argc, VALUE *argv, VALUE passed_proc) +bmcall(RB_BLOCK_CALL_FUNC_ARGLIST(args, method)) { - return rb_method_call_with_block(argc, argv, method, passed_proc); + return rb_method_call_with_block(argc, argv, method, blockarg); } VALUE diff --git a/vm_core.h b/vm_core.h index e4a793365b7593..987d1b15c50517 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1022,8 +1022,23 @@ rb_iseq_t *rb_iseq_new_top (const rb_ast_body_t *ast, VALUE name, VALUE path rb_iseq_t *rb_iseq_new_main (const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent); rb_iseq_t *rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*); -rb_iseq_t *rb_iseq_new_ifunc(const struct vm_ifunc *ifunc, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, - const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*); +struct iseq_link_anchor; +struct rb_iseq_new_with_callback_callback_func { + VALUE flags; + VALUE reserved; + void (*func)(rb_iseq_t *, struct iseq_link_anchor *, const void *); + const void *data; +}; +static inline struct rb_iseq_new_with_callback_callback_func * +rb_iseq_new_with_callback_new_callback( + void (*func)(rb_iseq_t *, struct iseq_link_anchor *, const void *), const void *ptr) +{ + VALUE memo = rb_imemo_new(imemo_ifunc, (VALUE)func, (VALUE)ptr, Qundef, Qfalse); + return (struct rb_iseq_new_with_callback_callback_func *)memo; +} +rb_iseq_t *rb_iseq_new_with_callback(const struct rb_iseq_new_with_callback_callback_func * ifunc, + VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, + const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*); /* src -> iseq */ rb_iseq_t *rb_iseq_compile(VALUE src, VALUE file, VALUE line); diff --git a/vm_insnhelper.c b/vm_insnhelper.c index cc89398b905808..e80a036e06ca68 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2858,7 +2858,7 @@ vm_yield_with_cfunc(rb_execution_context_t *ec, VM_GUARDED_PREV_EP(captured->ep), (VALUE)me, 0, ec->cfp->sp, 0, 0); - val = (*ifunc->func)(arg, ifunc->data, argc, argv, blockarg); + val = (*ifunc->func)(arg, (VALUE)ifunc->data, argc, argv, blockarg); rb_vm_pop_frame(ec); return val; From f27ca32f2afe3c2cddece320f735236e2ef463c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 26 Aug 2019 14:42:08 +0900 Subject: [PATCH 05/18] rb_iterate now takes rb_block_call_func_t After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit makes rb_iterate free from ANYARGS. --- ext/openssl/ossl_ssl.c | 2 +- include/ruby/ruby.h | 2 +- vm_eval.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index f25dc959b14107..587ca2473fdd2b 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -592,7 +592,7 @@ ssl_renegotiation_cb(const SSL *ssl) #if !defined(OPENSSL_NO_NEXTPROTONEG) || \ defined(HAVE_SSL_CTX_SET_ALPN_SELECT_CB) static VALUE -ssl_npn_encode_protocol_i(VALUE cur, VALUE encoded) +ssl_npn_encode_protocol_i(RB_BLOCK_CALL_FUNC_ARGLIST(cur, encoded)) { int len = RSTRING_LENINT(cur); char len_byte; diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index cf065e974e175d..1f05dd4dc63c0f 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1964,7 +1964,7 @@ VALUE rb_yield_splat(VALUE); VALUE rb_yield_block(VALUE, VALUE, int, const VALUE *, VALUE); /* rb_block_call_func */ int rb_block_given_p(void); void rb_need_block(void); -VALUE rb_iterate(VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE); +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(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE); VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...); diff --git a/vm_eval.c b/vm_eval.c index b449cd49966ad3..2670c2caab3bba 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1193,7 +1193,7 @@ rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1, VALUE rb_iterate(VALUE (* it_proc)(VALUE), VALUE data1, - VALUE (* bl_proc)(ANYARGS), VALUE data2) + rb_block_call_func_t bl_proc, VALUE data2) { return rb_iterate0(it_proc, data1, bl_proc ? rb_vm_ifunc_proc_new(bl_proc, (void *)data2) : 0, From c575fa169913ed8cfa511e89271615c07fe83563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 26 Aug 2019 14:51:00 +0900 Subject: [PATCH 06/18] rb_rescue / rb_rescue2 now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_rescue / rb_rescue2, which revealed many arity / type mismatches. --- enum.c | 6 ++++-- enumerator.c | 2 +- eval.c | 8 ++++---- ext/zlib/zlib.c | 6 ++---- include/ruby/ruby.h | 4 ++-- io.c | 2 +- time.c | 2 +- vm_eval.c | 8 +++++--- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/enum.c b/enum.c index 665c97ffbe54c1..829d67a0464926 100644 --- a/enum.c +++ b/enum.c @@ -2723,14 +2723,16 @@ zip_ary(RB_BLOCK_CALL_FUNC_ARGLIST(val, memoval)) } static VALUE -call_next(VALUE *v) +call_next(VALUE w) { + VALUE *v = (VALUE *)w; return v[0] = rb_funcallv(v[1], id_next, 0, 0); } static VALUE -call_stop(VALUE *v) +call_stop(VALUE w, VALUE _) { + VALUE *v = (VALUE *)w; return v[0] = Qundef; } diff --git a/enumerator.c b/enumerator.c index beea1c728fb6fb..afc9ed94fa2edf 100644 --- a/enumerator.c +++ b/enumerator.c @@ -2231,7 +2231,7 @@ call_next(VALUE obj) } static VALUE -next_stopped(VALUE obj) +next_stopped(VALUE obj, VALUE _) { return Qnil; } diff --git a/eval.c b/eval.c index 01e4fa6e42979b..b06e87f33fc36c 100644 --- a/eval.c +++ b/eval.c @@ -931,8 +931,8 @@ rb_need_block(void) * \ingroup exception */ VALUE -rb_rescue2(VALUE (* b_proc) (ANYARGS), VALUE data1, - VALUE (* r_proc) (ANYARGS), VALUE data2, ...) +rb_rescue2(VALUE (* b_proc) (VALUE), VALUE data1, + VALUE (* r_proc) (VALUE, VALUE), VALUE data2, ...) { enum ruby_tag_type state; rb_execution_context_t * volatile ec = GET_EC(); @@ -1003,8 +1003,8 @@ rb_rescue2(VALUE (* b_proc) (ANYARGS), VALUE data1, * \ingroup exception */ VALUE -rb_rescue(VALUE (* b_proc)(ANYARGS), VALUE data1, - VALUE (* r_proc)(ANYARGS), VALUE data2) +rb_rescue(VALUE (* b_proc)(VALUE), VALUE data1, + VALUE (* r_proc)(VALUE, VALUE), VALUE data2) { return rb_rescue2(b_proc, data1, r_proc, data2, rb_eStandardError, (VALUE)0); diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index f1fd2b5c8a05a4..e84e5659322c42 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -140,7 +140,7 @@ static void gzfile_reset(struct gzfile*); static void gzfile_close(struct gzfile*, int); static void gzfile_write_raw(struct gzfile*); static VALUE gzfile_read_raw_partial(VALUE); -static VALUE gzfile_read_raw_rescue(VALUE); +static VALUE gzfile_read_raw_rescue(VALUE,VALUE); static VALUE gzfile_read_raw(struct gzfile*, VALUE outbuf); static int gzfile_read_raw_ensure(struct gzfile*, long, VALUE outbuf); static char *gzfile_read_raw_until_zero(struct gzfile*, long); @@ -2385,7 +2385,7 @@ gzfile_read_raw_partial(VALUE arg) } static VALUE -gzfile_read_raw_rescue(VALUE arg) +gzfile_read_raw_rescue(VALUE arg, VALUE _) { struct read_raw_arg *ra = (struct read_raw_arg *)arg; VALUE str = Qnil; @@ -4888,5 +4888,3 @@ Init_zlib(void) * Raised when the data length recorded in the gzip file footer is not equivalent * to the length of the actual uncompressed data. */ - - diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 1f05dd4dc63c0f..b1e5b0dc519cf8 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1966,8 +1966,8 @@ int rb_block_given_p(void); void rb_need_block(void); 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(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE); -VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),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_catch(const char*,VALUE(*)(ANYARGS),VALUE); VALUE rb_catch_obj(VALUE,VALUE(*)(ANYARGS),VALUE); diff --git a/io.c b/io.c index e918f1c79bd3b1..8f48ba1dd6e9df 100644 --- a/io.c +++ b/io.c @@ -11457,7 +11457,7 @@ copy_stream_fallback(struct copy_stream_struct *stp) rb_raise(rb_eArgError, "cannot specify src_offset for non-IO"); } rb_rescue2(copy_stream_fallback_body, (VALUE)stp, - (VALUE (*) (ANYARGS))0, (VALUE)0, + (VALUE (*) (VALUE, VALUE))0, (VALUE)0, rb_eEOFError, (VALUE)0); return Qnil; } diff --git a/time.c b/time.c index 40b2f06bc6023a..1e760f6ca5f673 100644 --- a/time.c +++ b/time.c @@ -5204,7 +5204,7 @@ mload_zone(VALUE time, VALUE zone) VALUE z, args[2]; args[0] = time; args[1] = zone; - z = rb_rescue(mload_findzone, (VALUE)args, (VALUE (*)(ANYARGS))NULL, Qnil); + z = rb_rescue(mload_findzone, (VALUE)args, 0, Qnil); if (NIL_P(z)) return rb_fstring(zone); if (RB_TYPE_P(z, T_STRING)) return rb_fstring(z); return z; diff --git a/vm_eval.c b/vm_eval.c index 2670c2caab3bba..e9045bbb413fe0 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -322,16 +322,18 @@ struct rescue_funcall_args { }; static VALUE -check_funcall_exec(struct rescue_funcall_args *args) +check_funcall_exec(VALUE v) { + struct rescue_funcall_args *args = (void *)v; return call_method_entry(args->ec, args->defined_class, args->recv, idMethodMissing, args->me, args->argc, args->argv); } static VALUE -check_funcall_failed(struct rescue_funcall_args *args, VALUE e) +check_funcall_failed(VALUE v, VALUE e) { + struct rescue_funcall_args *args = (void *)v; int ret = args->respond; if (!ret) { switch (rb_method_boundp(args->defined_class, args->mid, @@ -1075,7 +1077,7 @@ rb_yield_block(VALUE val, VALUE arg, int argc, const VALUE *argv, VALUE blockarg } static VALUE -loop_i(void) +loop_i(VALUE _) { for (;;) { rb_yield_0(0, 0); From 11ec4806446ef714cc5bb0a4de98a407a523d62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 26 Aug 2019 15:20:15 +0900 Subject: [PATCH 07/18] 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. --- cont.c | 16 +++++++++------- dir.c | 6 ++++-- eval.c | 2 +- ext/-test-/tracepoint/gc_hook.c | 2 +- ext/etc/etc.c | 8 ++++---- ext/pty/pty.c | 3 ++- ext/socket/ipsocket.c | 6 ++++-- ext/socket/raddrinfo.c | 3 ++- ext/socket/udpsocket.c | 9 ++++++--- ext/zlib/zlib.c | 15 +++++++++++---- gc.c | 2 +- include/ruby/ruby.h | 2 +- internal.h | 2 +- io.c | 12 ++++++++---- thread_sync.c | 3 ++- variable.c | 6 ++++-- vm_core.h | 2 +- 17 files changed, 62 insertions(+), 37 deletions(-) diff --git a/cont.c b/cont.c index de2f8436013a3a..db422d9880003b 100644 --- a/cont.c +++ b/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); } diff --git a/dir.c b/dir.c index 18c10f2139821f..bfd085e16cf33f 100644 --- a/dir.c +++ b/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) diff --git a/eval.c b/eval.c index b06e87f33fc36c..9997d288a3e7ef 100644 --- a/eval.c +++ b/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; diff --git a/ext/-test-/tracepoint/gc_hook.c b/ext/-test-/tracepoint/gc_hook.c index 6d8485ecb14edd..2e695a9fbad780 100644 --- a/ext/-test-/tracepoint/gc_hook.c +++ b/ext/-test-/tracepoint/gc_hook.c @@ -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; diff --git a/ext/etc/etc.c b/ext/etc/etc.c index b6dca94b9992f2..a3a9bbc23303ef 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -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; diff --git a/ext/pty/pty.c b/ext/pty/pty.c index 7b9df4b5b93af1..4c6ae26127eb56 100644 --- a/ext/pty/pty.c +++ b/ext/pty/pty.c @@ -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) diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c index f214d852ae1023..a2cb6e0e125510 100644 --- a/ext/socket/ipsocket.c +++ b/ext/socket/ipsocket.c @@ -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; diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index b59cc4900574ca..dad11ad1ac6d45 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -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; diff --git a/ext/socket/udpsocket.c b/ext/socket/udpsocket.c index c2e273c2a3ee48..6ef8242a1ef493 100644 --- a/ext/socket/udpsocket.c +++ b/ext/socket/udpsocket.c @@ -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; diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index e84e5659322c42..afd761f1c1a1c0 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -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 diff --git a/gc.c b/gc.c index d655e362dc2fe7..654a6c85e3323c 100644 --- a/gc.c +++ b/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; diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index b1e5b0dc519cf8..ae073222d0c15a 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -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)); diff --git a/internal.h b/internal.h index 01009b616a96bd..bd9ee44ddced46 100644 --- a/internal.h +++ b/internal.h @@ -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); diff --git a/io.c b/io.c index 8f48ba1dd6e9df..1b37723b26dd89 100644 --- a/io.c +++ b/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); } diff --git a/thread_sync.c b/thread_sync.c index c2612c14152801..f98a7655c0beea 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -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; diff --git a/variable.c b/variable.c index 2a3862fca10eea..3db3e3d5ef90a7 100644 --- a/variable.c +++ b/variable.c @@ -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 */ diff --git a/vm_core.h b/vm_core.h index 987d1b15c50517..74700f37f01f2f 100644 --- a/vm_core.h +++ b/vm_core.h @@ -839,7 +839,7 @@ typedef struct rb_thread_list_struct{ typedef struct rb_ensure_entry { VALUE marker; - VALUE (*e_proc)(ANYARGS); + VALUE (*e_proc)(VALUE); VALUE data2; } rb_ensure_entry_t; From 2edaff2b9a7ff447220cbe7448f8e4f4eaf6af07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 26 Aug 2019 15:27:48 +0900 Subject: [PATCH 08/18] rb_catch now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_catch, and fixes some bugs revealed by that. --- ext/racc/cparse/cparse.c | 4 ++-- include/ruby/ruby.h | 4 ++-- vm_eval.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/racc/cparse/cparse.c b/ext/racc/cparse/cparse.c index cc0e8659bec8ab..ca74b80000482d 100644 --- a/ext/racc/cparse/cparse.c +++ b/ext/racc/cparse/cparse.c @@ -212,7 +212,7 @@ static void extract_user_token _((struct cparse_params *v, VALUE block_args, VALUE *tok, VALUE *val)); static void shift _((struct cparse_params* v, long act, VALUE tok, VALUE val)); static int reduce _((struct cparse_params* v, long act)); -static VALUE reduce0 _((VALUE block_args, VALUE data, VALUE self)); +static rb_block_call_func reduce0; #ifdef DEBUG # define D_puts(msg) if (v->sys_debug) puts(msg) @@ -708,7 +708,7 @@ reduce(struct cparse_params *v, long act) } static VALUE -reduce0(VALUE val, VALUE data, VALUE self) +reduce0(RB_BLOCK_CALL_FUNC_ARGLIST(_, data)) { struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type); VALUE reduce_to, reduce_len, method_id; diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index ae073222d0c15a..86406ca50e7144 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1969,8 +1969,8 @@ 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(*)(VALUE),VALUE,VALUE(*)(VALUE),VALUE); -VALUE rb_catch(const char*,VALUE(*)(ANYARGS),VALUE); -VALUE rb_catch_obj(VALUE,VALUE(*)(ANYARGS),VALUE); +VALUE rb_catch(const char*,rb_block_call_func_t,VALUE); +VALUE rb_catch_obj(VALUE,rb_block_call_func_t,VALUE); NORETURN(void rb_throw(const char*,VALUE)); NORETURN(void rb_throw_obj(VALUE,VALUE)); diff --git a/vm_eval.c b/vm_eval.c index e9045bbb413fe0..8c7e01edcebe50 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1921,7 +1921,7 @@ rb_throw(const char *tag, VALUE val) } static VALUE -catch_i(VALUE tag, VALUE data) +catch_i(RB_BLOCK_CALL_FUNC_ARGLIST(tag, _)) { return rb_yield_0(1, &tag); } @@ -1985,7 +1985,7 @@ rb_f_catch(int argc, VALUE *argv, VALUE self) } VALUE -rb_catch(const char *tag, VALUE (*func)(), VALUE data) +rb_catch(const char *tag, rb_block_call_func_t func, VALUE data) { VALUE vtag = tag ? rb_sym_intern_ascii_cstr(tag) : rb_obj_alloc(rb_cObject); return rb_catch_obj(vtag, func, data); @@ -2027,7 +2027,7 @@ rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, enum ruby_tag_ty } VALUE -rb_catch_obj(VALUE t, VALUE (*func)(), VALUE data) +rb_catch_obj(VALUE t, rb_block_call_func_t func, VALUE data) { enum ruby_tag_type state; rb_execution_context_t *ec = GET_EC(); From d6b21a9dab9721c74fe9b2a5c41835884fbfc6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 26 Aug 2019 15:35:28 +0900 Subject: [PATCH 09/18] rb_proc_new / rb_fiber_new now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_proc_new / rb_fiber_new, and applies RB_BLOCK_CALL_FUNC_ARGLIST wherever necessary. --- cont.c | 2 +- enumerator.c | 2 +- gc.c | 2 +- include/ruby/intern.h | 4 ++-- proc.c | 16 ++++++++-------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cont.c b/cont.c index db422d9880003b..ea21b322b588ed 100644 --- a/cont.c +++ b/cont.c @@ -1770,7 +1770,7 @@ rb_fiber_initialize(int argc, VALUE* argv, VALUE self) } VALUE -rb_fiber_new(VALUE (*func)(ANYARGS), VALUE obj) +rb_fiber_new(rb_block_call_func_t func, VALUE obj) { return fiber_initialize(fiber_alloc(rb_cFiber), rb_proc_new(func, obj), &shared_fiber_pool); } diff --git a/enumerator.c b/enumerator.c index afc9ed94fa2edf..96daad2b4b2583 100644 --- a/enumerator.c +++ b/enumerator.c @@ -713,7 +713,7 @@ next_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, obj)) } static VALUE -next_i(VALUE curr, VALUE obj) +next_i(RB_BLOCK_CALL_FUNC_ARGLIST(_, obj)) { struct enumerator *e = enumerator_ptr(obj); VALUE nil = Qnil; diff --git a/gc.c b/gc.c index 654a6c85e3323c..42559eb3772bb6 100644 --- a/gc.c +++ b/gc.c @@ -8867,7 +8867,7 @@ compat_key(VALUE key) } static VALUE -default_proc_for_compat_func(VALUE hash, VALUE dmy, int argc, VALUE *argv) +default_proc_for_compat_func(RB_BLOCK_CALL_FUNC_ARGLIST(hash, _)) { VALUE key, new_key; diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 0aaeb82fb62a52..f3d3c29fbceb71 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -238,7 +238,7 @@ VALUE rb_singleton_class(VALUE); int rb_cmpint(VALUE, VALUE, VALUE); NORETURN(void rb_cmperr(VALUE, VALUE)); /* cont.c */ -VALUE rb_fiber_new(VALUE (*)(ANYARGS), VALUE); +VALUE rb_fiber_new(rb_block_call_func_t, VALUE); VALUE rb_fiber_resume(VALUE fib, int argc, const VALUE *argv); VALUE rb_fiber_yield(int argc, const VALUE *argv); VALUE rb_fiber_current(void); @@ -446,7 +446,7 @@ void rb_obj_call_init(VALUE, int, const VALUE*); VALUE rb_class_new_instance(int, const VALUE*, VALUE); VALUE rb_block_proc(void); VALUE rb_block_lambda(void); -VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE); +VALUE rb_proc_new(rb_block_call_func_t, VALUE); VALUE rb_obj_is_proc(VALUE); VALUE rb_proc_call(VALUE, VALUE); VALUE rb_proc_call_with_block(VALUE, int argc, const VALUE *argv, VALUE); diff --git a/proc.c b/proc.c index 1c0a5dfcd9e4f8..1b8aa3953bbaf4 100644 --- a/proc.c +++ b/proc.c @@ -2790,7 +2790,7 @@ bmcall(RB_BLOCK_CALL_FUNC_ARGLIST(args, method)) VALUE rb_proc_new( - VALUE (*func)(ANYARGS), /* VALUE yieldarg[, VALUE procarg] */ + rb_block_call_func_t func, VALUE val) { VALUE procval = rb_iterate(mproc, 0, func, val); @@ -2987,7 +2987,7 @@ proc_binding(VALUE self) return bindval; } -static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc); +static rb_block_call_func curry; static VALUE make_curry_proc(VALUE proc, VALUE passed, VALUE arity) @@ -3007,7 +3007,7 @@ make_curry_proc(VALUE proc, VALUE passed, VALUE arity) } static VALUE -curry(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc) +curry(RB_BLOCK_CALL_FUNC_ARGLIST(_, args)) { VALUE proc, passed, arity; proc = RARRAY_AREF(args, 0); @@ -3018,14 +3018,14 @@ curry(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc) rb_ary_freeze(passed); if (RARRAY_LEN(passed) < FIX2INT(arity)) { - if (!NIL_P(passed_proc)) { + if (!NIL_P(blockarg)) { rb_warn("given block not used"); } arity = make_curry_proc(proc, passed, arity); return arity; } else { - return rb_proc_call_with_block(proc, check_argc(RARRAY_LEN(passed)), RARRAY_CONST_PTR(passed), passed_proc); + return rb_proc_call_with_block(proc, check_argc(RARRAY_LEN(passed)), RARRAY_CONST_PTR(passed), blockarg); } } @@ -3130,16 +3130,16 @@ rb_method_curry(int argc, const VALUE *argv, VALUE self) } static VALUE -compose(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc) +compose(RB_BLOCK_CALL_FUNC_ARGLIST(_, args)) { VALUE f, g, fargs; f = RARRAY_AREF(args, 0); g = RARRAY_AREF(args, 1); if (rb_obj_is_proc(g)) - fargs = rb_proc_call_with_block(g, argc, argv, passed_proc); + fargs = rb_proc_call_with_block(g, argc, argv, blockarg); else - fargs = rb_funcall_with_block(g, idCall, argc, argv, passed_proc); + fargs = rb_funcall_with_block(g, idCall, argc, argv, blockarg); if (rb_obj_is_proc(f)) return rb_proc_call(f, rb_ary_new3(1, fargs)); From 22418f6cf80773862880ab6a60b86d3960a70798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 26 Aug 2019 15:53:57 +0900 Subject: [PATCH 10/18] rb_thread_create now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_thread_create, which seems very safe to do. --- include/ruby/intern.h | 2 +- thread.c | 4 ++-- thread_pthread.c | 2 +- vm_core.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/ruby/intern.h b/include/ruby/intern.h index f3d3c29fbceb71..c5a7f052db0788 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -474,7 +474,7 @@ VALUE rb_thread_wakeup(VALUE); VALUE rb_thread_wakeup_alive(VALUE); VALUE rb_thread_run(VALUE); VALUE rb_thread_kill(VALUE); -VALUE rb_thread_create(VALUE (*)(ANYARGS), void*); +VALUE rb_thread_create(VALUE (*)(void *), void*); int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *); void rb_thread_wait_for(struct timeval); VALUE rb_thread_current(void); diff --git a/thread.c b/thread.c index db4326bd31a0c8..57ccfef8b74949 100644 --- a/thread.c +++ b/thread.c @@ -810,7 +810,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start) } static VALUE -thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(ANYARGS)) +thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(void *)) { rb_thread_t *th = rb_thread_ptr(thval), *current_th = GET_THREAD(); int err; @@ -944,7 +944,7 @@ thread_initialize(VALUE thread, VALUE args) } VALUE -rb_thread_create(VALUE (*fn)(ANYARGS), void *arg) +rb_thread_create(VALUE (*fn)(void *), void *arg) { return thread_create_core(rb_thread_alloc(rb_cThread), (VALUE)arg, fn); } diff --git a/thread_pthread.c b/thread_pthread.c index 39c3ed0ed4b693..cbe6aa028a19b4 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -2156,7 +2156,7 @@ timer_pthread_fn(void *p) #endif /* UBF_TIMER_PTHREAD */ static VALUE -ubf_caller(const void *ignore) +ubf_caller(void *ignore) { rb_thread_sleep_forever(); diff --git a/vm_core.h b/vm_core.h index 74700f37f01f2f..cb22fc411508c0 100644 --- a/vm_core.h +++ b/vm_core.h @@ -975,7 +975,7 @@ typedef struct rb_thread_struct { VALUE args; } proc; struct { - VALUE (*func)(ANYARGS); + VALUE (*func)(void *); void *arg; } func; } invoke_arg; From ecdc692709b61038d90e30e9ac72991e2b0efd7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Mon, 26 Aug 2019 16:06:40 +0900 Subject: [PATCH 11/18] st_foreach now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from st_foreach. I strongly believe that this commit should have had come with b0af0592fdd9e9d4e4b863fde006d67ccefeac21, which added extra parameter to st_foreach callbacks. --- ext/-test-/st/foreach/foreach.c | 2 +- ext/-test-/st/numhash/numhash.c | 3 +-- ext/objspace/object_tracing.c | 4 ++-- gc.c | 2 +- include/ruby/st.h | 8 +++++--- marshal.c | 2 +- regparse.c | 8 ++++---- st.c | 23 ++++++++++++++++++----- 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/ext/-test-/st/foreach/foreach.c b/ext/-test-/st/foreach/foreach.c index 209b5355036e5d..27ac18046f03d2 100644 --- a/ext/-test-/st/foreach/foreach.c +++ b/ext/-test-/st/foreach/foreach.c @@ -106,7 +106,7 @@ unp_fec(VALUE self, VALUE test) } static int -unp_fe_i(st_data_t key, st_data_t val, st_data_t args, int error) +unp_fe_i(st_data_t key, st_data_t val, st_data_t args) { struct checker *c = (struct checker *)args; diff --git a/ext/-test-/st/numhash/numhash.c b/ext/-test-/st/numhash/numhash.c index fc35f476cdc797..71eeed4910018b 100644 --- a/ext/-test-/st/numhash/numhash.c +++ b/ext/-test-/st/numhash/numhash.c @@ -57,7 +57,7 @@ numhash_aset(VALUE self, VALUE key, VALUE data) } static int -numhash_i(st_data_t key, st_data_t value, st_data_t arg) +numhash_i(st_data_t key, st_data_t value, st_data_t arg, int _) { VALUE ret; ret = rb_yield_values(3, (VALUE)key, (VALUE)value, (VALUE)arg); @@ -135,4 +135,3 @@ Init_numhash(void) rb_define_method(st, "size", numhash_size, 0); rb_define_method(st, "delete_safe", numhash_delete_safe, 1); } - diff --git a/ext/objspace/object_tracing.c b/ext/objspace/object_tracing.c index 7c354498ab3787..a057ac2a961c94 100644 --- a/ext/objspace/object_tracing.c +++ b/ext/objspace/object_tracing.c @@ -138,14 +138,14 @@ freeobj_i(VALUE tpval, void *data) } static int -free_keys_i(st_data_t key, st_data_t value, void *data) +free_keys_i(st_data_t key, st_data_t value, st_data_t data) { ruby_xfree((void *)key); return ST_CONTINUE; } static int -free_values_i(st_data_t key, st_data_t value, void *data) +free_values_i(st_data_t key, st_data_t value, st_data_t data) { ruby_xfree((void *)value); return ST_CONTINUE; diff --git a/gc.c b/gc.c index 42559eb3772bb6..32b7807d745a9e 100644 --- a/gc.c +++ b/gc.c @@ -5620,7 +5620,7 @@ gc_check_after_marks_i(st_data_t k, st_data_t v, void *ptr) } static void -gc_marks_check(rb_objspace_t *objspace, int (*checker_func)(ANYARGS), const char *checker_name) +gc_marks_check(rb_objspace_t *objspace, st_foreach_callback_func *checker_func, const char *checker_name) { size_t saved_malloc_increase = objspace->malloc_params.increase; #if RGENGC_ESTIMATE_OLDMALLOC diff --git a/include/ruby/st.h b/include/ruby/st.h index a7eb0c6d7c216c..9b48d514a9be99 100644 --- a/include/ruby/st.h +++ b/include/ruby/st.h @@ -118,9 +118,11 @@ typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t * results of hash() are same and compare() returns 0, otherwise the * behavior is undefined */ int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg); -int st_foreach_with_replace(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg); -int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); -int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t); +typedef int st_foreach_callback_func(st_data_t, st_data_t, st_data_t); +typedef int st_foreach_check_callback_func(st_data_t, st_data_t, st_data_t, int); +int st_foreach_with_replace(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg); +int st_foreach(st_table *, st_foreach_callback_func *, st_data_t); +int st_foreach_check(st_table *, st_foreach_check_callback_func *, st_data_t, st_data_t); st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size); st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never); st_index_t st_values(st_table *table, st_data_t *values, st_index_t size); diff --git a/marshal.c b/marshal.c index b6de65023cb471..0d7cbc169c8b61 100644 --- a/marshal.c +++ b/marshal.c @@ -112,7 +112,7 @@ static VALUE rb_marshal_dump_limited(VALUE obj, VALUE port, int limit); static VALUE rb_marshal_load_with_proc(VALUE port, VALUE proc); static int -mark_marshal_compat_i(st_data_t key, st_data_t value) +mark_marshal_compat_i(st_data_t key, st_data_t value, st_data_t _) { marshal_compat_t *p = (marshal_compat_t *)value; rb_gc_mark(p->newclass); diff --git a/regparse.c b/regparse.c index 574a07e05d5c43..5f118900de4127 100644 --- a/regparse.c +++ b/regparse.c @@ -493,7 +493,7 @@ onig_print_names(FILE* fp, regex_t* reg) if (IS_NOT_NULL(t)) { fprintf(fp, "name table\n"); - onig_st_foreach(t, i_print_name_entry, (HashDataType )fp); + onig_st_foreach(t, (st_foreach_callback_func *)i_print_name_entry, (HashDataType )fp); fputs("\n", fp); } return 0; @@ -516,7 +516,7 @@ names_clear(regex_t* reg) NameTable* t = (NameTable* )reg->name_table; if (IS_NOT_NULL(t)) { - onig_st_foreach(t, i_free_name_entry, 0); + onig_st_foreach(t, (st_foreach_callback_func *)i_free_name_entry, 0); } return 0; } @@ -585,7 +585,7 @@ onig_foreach_name(regex_t* reg, narg.reg = reg; narg.arg = arg; narg.enc = reg->enc; /* should be pattern encoding. */ - onig_st_foreach(t, i_names, (HashDataType )&narg); + onig_st_foreach(t, (st_foreach_callback_func *)i_names, (HashDataType )&narg); } return narg.ret; } @@ -613,7 +613,7 @@ onig_renumber_name_table(regex_t* reg, GroupNumRemap* map) NameTable* t = (NameTable* )reg->name_table; if (IS_NOT_NULL(t)) { - onig_st_foreach(t, i_renumber_name, (HashDataType )map); + onig_st_foreach(t, (st_foreach_callback_func *)i_renumber_name, (HashDataType )map); } return 0; } diff --git a/st.c b/st.c index cecc2ac67f8a20..c32a7ed208a01f 100644 --- a/st.c +++ b/st.c @@ -1548,7 +1548,7 @@ st_update(st_table *tab, st_data_t key, different for ST_CHECK and when the current element is removed during traversing. */ static inline int -st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg, +st_general_foreach(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg, int check_p) { st_index_t bin; @@ -1659,20 +1659,33 @@ st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_update_callback_func } int -st_foreach_with_replace(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg) +st_foreach_with_replace(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg) { return st_general_foreach(tab, func, replace, arg, TRUE); } +struct functor { + st_foreach_callback_func *func; + st_data_t arg; +}; + +static int +apply_functor(st_data_t k, st_data_t v, st_data_t d, int _) +{ + const struct functor *f = (void *)d; + return f->func(k, v, f->arg); +} + int -st_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg) +st_foreach(st_table *tab, st_foreach_callback_func *func, st_data_t arg) { - return st_general_foreach(tab, func, NULL, arg, FALSE); + const struct functor f = { func, arg }; + return st_general_foreach(tab, apply_functor, NULL, (st_data_t)&f, FALSE); } /* See comments for function st_delete_safe. */ int -st_foreach_check(st_table *tab, int (*func)(ANYARGS), st_data_t arg, +st_foreach_check(st_table *tab, st_foreach_check_callback_func *func, st_data_t arg, st_data_t never ATTRIBUTE_UNUSED) { return st_general_foreach(tab, func, NULL, arg, TRUE); From 652b97e156e978c06a3746dcefaa9948efc296ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 27 Aug 2019 12:21:36 +0900 Subject: [PATCH 12/18] struct st_hash_type now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit adds function prototypes for struct st_hash_type. Honestly I don't understand why they were commented out at the first place. --- include/ruby/st.h | 4 ++-- st.c | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/ruby/st.h b/include/ruby/st.h index 9b48d514a9be99..2ca43844aa01ed 100644 --- a/include/ruby/st.h +++ b/include/ruby/st.h @@ -59,8 +59,8 @@ typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index #define SIZEOF_ST_INDEX_T SIZEOF_VOIDP struct st_hash_type { - int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */ - st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */ + int (*compare)(st_data_t, st_data_t); /* st_compare_func* */ + st_index_t (*hash)(st_data_t); /* st_hash_func* */ }; #define ST_INDEX_BITS (SIZEOF_ST_INDEX_T * CHAR_BIT) diff --git a/st.c b/st.c index c32a7ed208a01f..880ab8769b5582 100644 --- a/st.c +++ b/st.c @@ -145,16 +145,17 @@ static const struct st_hash_type st_hashtype_num = { st_numhash, }; -/* extern int strcmp(const char *, const char *); */ +static int st_strcmp(st_data_t, st_data_t); static st_index_t strhash(st_data_t); static const struct st_hash_type type_strhash = { - strcmp, + st_strcmp, strhash, }; +static int st_locale_insensitive_strcasecmp_i(st_data_t lhs, st_data_t rhs); static st_index_t strcasehash(st_data_t); static const struct st_hash_type type_strcasehash = { - st_locale_insensitive_strcasecmp, + st_locale_insensitive_strcasecmp_i, strcasehash, }; @@ -2091,6 +2092,22 @@ st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n) return 0; } +static int +st_strcmp(st_data_t lhs, st_data_t rhs) +{ + const char *s1 = (char *)lhs; + const char *s2 = (char *)rhs; + return strcmp(s1, s2); +} + +static int +st_locale_insensitive_strcasecmp_i(st_data_t lhs, st_data_t rhs) +{ + const char *s1 = (char *)lhs; + const char *s2 = (char *)rhs; + return st_locale_insensitive_strcasecmp(s1, s2); +} + NO_SANITIZE("unsigned-integer-overflow", PUREFUNC(static st_index_t strcasehash(st_data_t))); static st_index_t strcasehash(st_data_t arg) From 3b707fc0d3cb45204a8bb00b86e5d6b28540325b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 27 Aug 2019 11:16:52 +0900 Subject: [PATCH 13/18] 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. --- eval.c | 4 ++-- include/ruby/intern.h | 2 +- include/ruby/ruby.h | 30 ++++++++++++++---------------- io.c | 14 +++++++++++++- load.c | 13 ++++++++++--- process.c | 16 ++++++++++++++-- re.c | 26 ++++++++++++++++---------- ruby.c | 12 +++++------- safe.c | 4 ++-- variable.c | 33 +++++++++++++++++---------------- 10 files changed, 94 insertions(+), 60 deletions(-) diff --git a/eval.c b/eval.c index 9997d288a3e7ef..c2f15fb95fb7fd 100644 --- a/eval.c +++ b/eval.c @@ -1816,7 +1816,7 @@ get_errinfo(void) } static VALUE -errinfo_getter(ID id) +errinfo_getter(ID id, VALUE *_) { return get_errinfo(); } @@ -1851,7 +1851,7 @@ rb_set_errinfo(VALUE err) } 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 c5a7f052db0788..aaf73a154431c6 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -801,7 +801,7 @@ VALUE rb_str_replace(VALUE, VALUE); 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 86406ca50e7144..e15e3e60ef5ee2 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1776,29 +1776,27 @@ void rb_include_module(VALUE,VALUE); 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 1b37723b26dd89..2f9df89d6aacf1 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 * } } +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) 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 6ebe8e59823e8f..bc7abf15217d82 100644 --- a/load.c +++ b/load.c @@ -143,8 +143,9 @@ rb_get_expanded_load_path(void) } 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) 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) 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 8cd42db8021fd8..dad090712c6e45 100644 --- a/process.c +++ b/process.c @@ -8038,6 +8038,18 @@ rb_clock_getres(int argc, VALUE *argv) } } +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) { #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 6fd4fde7f8ce32..f4aad1e0447057 100644 --- a/re.c +++ b/re.c @@ -1824,25 +1824,25 @@ rb_reg_match_last(VALUE match) } 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) } 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) 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) 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 2610cf2387b2d7..57c95fa4ae7a8a 100644 --- a/ruby.c +++ b/ruby.c @@ -1446,13 +1446,13 @@ VALUE rb_argv0; VALUE rb_e_script; static VALUE -false_value(void) +false_value(ID _x, VALUE *_y) { return Qfalse; } static VALUE -true_value(void) +true_value(ID _x, VALUE *_y) { return Qtrue; } @@ -2230,7 +2230,7 @@ ruby_setproctitle(VALUE title) } static void -set_arg0(VALUE val, ID id) +set_arg0(VALUE val, ID id, VALUE *_) { if (origarg.argv == 0) rb_raise(rb_eRuntimeError, "$0 not initialized"); @@ -2304,16 +2304,14 @@ forbid_setid(const char *s, const ruby_cmdline_options_t *opt) } static void -verbose_setter(VALUE val, ID id, void *data) +verbose_setter(VALUE val, ID id, VALUE *variable) { - VALUE *variable = data; *variable = RTEST(val) ? Qtrue : val; } static VALUE -opt_W_getter(ID id, void *data) +opt_W_getter(ID id, VALUE *variable) { - VALUE *variable = data; switch (*variable) { case Qnil: return INT2FIX(0); diff --git a/safe.c b/safe.c index 68ec59689f28ff..9c668e38424be4 100644 --- a/safe.c +++ b/safe.c @@ -66,13 +66,13 @@ rb_set_safe_level(int level) } static VALUE -safe_getter(void) +safe_getter(ID _x, VALUE *_y) { return INT2NUM(rb_safe_level()); } static void -safe_setter(VALUE val) +safe_setter(VALUE val, ID _x, VALUE *_y) { int level = NUM2INT(val); rb_set_safe_level(level); diff --git a/variable.c b/variable.c index 3db3e3d5ef90a7..bc79dd6cc3b4a3 100644 --- a/variable.c +++ b/variable.c @@ -309,7 +309,7 @@ struct trace_var { struct rb_global_variable { int counter; int block_trace; - void *data; + VALUE *data; rb_gvar_getter_t *getter; rb_gvar_setter_t *setter; rb_gvar_marker_t *marker; @@ -354,7 +354,7 @@ rb_global_entry(ID id) } VALUE -rb_gvar_undef_getter(ID id, void *data, struct rb_global_variable *var) +rb_gvar_undef_getter(ID id, VALUE *_) { rb_warning("global variable `%"PRIsVALUE"' not initialized", QUOTE_ID(id)); @@ -362,8 +362,9 @@ rb_gvar_undef_getter(ID id, void *data, struct rb_global_variable *var) } void -rb_gvar_undef_setter(VALUE val, ID id, void *d, struct rb_global_variable *var) +rb_gvar_undef_setter(VALUE val, ID id, VALUE *_) { + struct rb_global_variable *var = rb_global_entry(id)->var; var->getter = rb_gvar_val_getter; var->setter = rb_gvar_val_setter; var->marker = rb_gvar_val_marker; @@ -377,14 +378,15 @@ rb_gvar_undef_marker(VALUE *var) } VALUE -rb_gvar_val_getter(ID id, void *data, struct rb_global_variable *var) +rb_gvar_val_getter(ID id, VALUE *data) { return (VALUE)data; } void -rb_gvar_val_setter(VALUE val, ID id, void *data, struct rb_global_variable *var) +rb_gvar_val_setter(VALUE val, ID id, VALUE *_) { + struct rb_global_variable *var = rb_global_entry(id)->var; var->data = (void*)val; } @@ -396,17 +398,16 @@ rb_gvar_val_marker(VALUE *var) } VALUE -rb_gvar_var_getter(ID id, void *data, struct rb_global_variable *gvar) +rb_gvar_var_getter(ID id, VALUE *var) { - VALUE *var = data; if (!var) return Qnil; return *var; } void -rb_gvar_var_setter(VALUE val, ID id, void *data, struct rb_global_variable *g) +rb_gvar_var_setter(VALUE val, ID id, VALUE *data) { - *(VALUE *)data = val; + *data = val; } void @@ -416,7 +417,7 @@ rb_gvar_var_marker(VALUE *var) } void -rb_gvar_readonly_setter(VALUE v, ID id, void *d, struct rb_global_variable *g) +rb_gvar_readonly_setter(VALUE v, ID id, VALUE *_) { rb_name_error(id, "%"PRIsVALUE" is a read-only variable", QUOTE_ID(id)); } @@ -487,8 +488,8 @@ void rb_define_hooked_variable( const char *name, VALUE *var, - VALUE (*getter)(ANYARGS), - void (*setter)(ANYARGS)) + rb_gvar_getter_t *getter, + rb_gvar_setter_t *setter) { volatile VALUE tmp = var ? *var : Qnil; ID id = global_id(name); @@ -517,8 +518,8 @@ rb_define_readonly_variable(const char *name, const VALUE *var) void rb_define_virtual_variable( const char *name, - VALUE (*getter)(ANYARGS), - void (*setter)(ANYARGS)) + rb_gvar_getter_t *getter, + rb_gvar_setter_t *setter) { if (!getter) getter = rb_gvar_val_getter; if (!setter) setter = rb_gvar_readonly_setter; @@ -662,7 +663,7 @@ MJIT_FUNC_EXPORTED VALUE rb_gvar_get(struct rb_global_entry *entry) { struct rb_global_variable *var = entry->var; - return (*var->getter)(entry->id, var->data, var); + return (*var->getter)(entry->id, var->data); } struct trace_data { @@ -699,7 +700,7 @@ rb_gvar_set(struct rb_global_entry *entry, VALUE val) struct trace_data trace; struct rb_global_variable *var = entry->var; - (*var->setter)(val, entry->id, var->data, var); + (*var->setter)(val, entry->id, var->data); if (var->trace && !var->block_trace) { var->block_trace = 1; From 920206fc3bab5ef2cb351ff2c0eefa32d42b9484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 27 Aug 2019 11:53:39 +0900 Subject: [PATCH 14/18] rb_hash_foreach now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit adds function prototypes for rb_hash_foreach / st_foreach_safe. Also fixes some prototype mismatches. --- compile.c | 2 +- hash.c | 41 +++++++++++++++++++++++++++-------------- include/ruby/intern.h | 4 ++-- internal.h | 4 ++-- marshal.c | 3 ++- 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/compile.c b/compile.c index 29965df7a48167..cf29da3e1be819 100644 --- a/compile.c +++ b/compile.c @@ -1827,7 +1827,7 @@ struct cdhash_set_label_struct { }; static int -cdhash_set_label_i(VALUE key, VALUE val, void *ptr) +cdhash_set_label_i(VALUE key, VALUE val, VALUE ptr) { struct cdhash_set_label_struct *data = (struct cdhash_set_label_struct *)ptr; LABEL *lobj = (LABEL *)(val & ~1); diff --git a/hash.c b/hash.c index 9a863962e708ea..4671adfd554ffb 100644 --- a/hash.c +++ b/hash.c @@ -868,7 +868,7 @@ ar_add_direct_with_hash(VALUE hash, st_data_t key, st_data_t val, st_hash_t hash } static int -ar_general_foreach(VALUE hash, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg) +ar_general_foreach(VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg) { if (RHASH_AR_TABLE_SIZE(hash) > 0) { unsigned i, bound = RHASH_AR_TABLE_BOUND(hash); @@ -909,19 +909,32 @@ ar_general_foreach(VALUE hash, int (*func)(ANYARGS), st_update_callback_func *re } static int -ar_foreach_with_replace(VALUE hash, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg) +ar_foreach_with_replace(VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg) { return ar_general_foreach(hash, func, replace, arg); } +struct functor { + st_foreach_callback_func *func; + st_data_t arg; +}; + +static int +apply_functor(st_data_t k, st_data_t v, st_data_t d, int _) +{ + const struct functor *f = (void *)d; + return f->func(k, v, f->arg); +} + static int -ar_foreach(VALUE hash, int (*func)(ANYARGS), st_data_t arg) +ar_foreach(VALUE hash, st_foreach_callback_func *func, st_data_t arg) { - return ar_general_foreach(hash, func, NULL, arg); + const struct functor f = { func, arg }; + return ar_general_foreach(hash, apply_functor, NULL, (st_data_t)&f); } static int -ar_foreach_check(VALUE hash, int (*func)(ANYARGS), st_data_t arg, +ar_foreach_check(VALUE hash, st_foreach_check_callback_func *func, st_data_t arg, st_data_t never) { if (RHASH_AR_TABLE_SIZE(hash) > 0) { @@ -1267,7 +1280,7 @@ foreach_safe_i(st_data_t key, st_data_t value, st_data_t args, int error) } void -st_foreach_safe(st_table *table, int (*func)(ANYARGS), st_data_t a) +st_foreach_safe(st_table *table, st_foreach_func *func, st_data_t a) { struct foreach_safe_arg arg; @@ -1415,7 +1428,7 @@ hash_foreach_ensure(VALUE hash) } int -rb_hash_stlike_foreach(VALUE hash, int (*func)(ANYARGS), st_data_t arg) +rb_hash_stlike_foreach(VALUE hash, st_foreach_callback_func *func, st_data_t arg) { if (RHASH_AR_TABLE_P(hash)) { return ar_foreach(hash, func, arg); @@ -1426,7 +1439,7 @@ rb_hash_stlike_foreach(VALUE hash, int (*func)(ANYARGS), st_data_t arg) } int -rb_hash_stlike_foreach_with_replace(VALUE hash, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg) +rb_hash_stlike_foreach_with_replace(VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg) { if (RHASH_AR_TABLE_P(hash)) { return ar_foreach_with_replace(hash, func, replace, arg); @@ -1456,7 +1469,7 @@ hash_foreach_call(VALUE arg) } void -rb_hash_foreach(VALUE hash, int (*func)(ANYARGS), VALUE farg) +rb_hash_foreach(VALUE hash, rb_foreach_func *func, VALUE farg) { struct hash_foreach_arg arg; @@ -2923,7 +2936,7 @@ rb_hash_empty_p(VALUE hash) } static int -each_value_i(VALUE key, VALUE value) +each_value_i(VALUE key, VALUE value, VALUE _) { rb_yield(value); return ST_CONTINUE; @@ -2957,7 +2970,7 @@ rb_hash_each_value(VALUE hash) } static int -each_key_i(VALUE key, VALUE value) +each_key_i(VALUE key, VALUE value, VALUE _) { rb_yield(key); return ST_CONTINUE; @@ -2990,14 +3003,14 @@ rb_hash_each_key(VALUE hash) } static int -each_pair_i(VALUE key, VALUE value) +each_pair_i(VALUE key, VALUE value, VALUE _) { rb_yield(rb_assoc_new(key, value)); return ST_CONTINUE; } static int -each_pair_i_fast(VALUE key, VALUE value) +each_pair_i_fast(VALUE key, VALUE value, VALUE _) { VALUE argv[2]; argv[0] = key; @@ -5918,7 +5931,7 @@ env_replace(VALUE env, VALUE hash) } static int -env_update_i(VALUE key, VALUE val) +env_update_i(VALUE key, VALUE val, VALUE _) { if (rb_block_given_p()) { val = rb_yield_values(3, key, rb_f_getenv(Qnil, key), val); diff --git a/include/ruby/intern.h b/include/ruby/intern.h index aaf73a154431c6..51d4132ae66ab5 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -529,9 +529,9 @@ size_t rb_gc_stat(VALUE); VALUE rb_gc_latest_gc_info(VALUE); void rb_gc_adjust_memory_usage(ssize_t); /* hash.c */ -void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t); +void st_foreach_safe(struct st_table *, int (*)(st_data_t, st_data_t, st_data_t), st_data_t); VALUE rb_check_hash_type(VALUE); -void rb_hash_foreach(VALUE, int (*)(ANYARGS), VALUE); +void rb_hash_foreach(VALUE, int (*)(VALUE, VALUE, VALUE), VALUE); VALUE rb_hash(VALUE); VALUE rb_hash_new(void); VALUE rb_hash_dup(VALUE); diff --git a/internal.h b/internal.h index bd9ee44ddced46..5e73c1113340a9 100644 --- a/internal.h +++ b/internal.h @@ -1661,8 +1661,8 @@ VALUE rb_hash_set_pair(VALUE hash, VALUE pair); int rb_hash_stlike_lookup(VALUE hash, st_data_t key, st_data_t *pval); int rb_hash_stlike_delete(VALUE hash, st_data_t *pkey, st_data_t *pval); -int rb_hash_stlike_foreach(VALUE hash, int (*func)(ANYARGS), st_data_t arg); -int rb_hash_stlike_foreach_with_replace(VALUE hash, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg); +int rb_hash_stlike_foreach(VALUE hash, st_foreach_callback_func *func, st_data_t arg); +int rb_hash_stlike_foreach_with_replace(VALUE hash, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg); int rb_hash_stlike_update(VALUE hash, st_data_t key, st_update_callback_func func, st_data_t arg); /* inits.c */ diff --git a/marshal.c b/marshal.c index 0d7cbc169c8b61..b21db2653f5ace 100644 --- a/marshal.c +++ b/marshal.c @@ -500,8 +500,9 @@ w_unique(VALUE s, struct dump_arg *arg) static void w_object(VALUE,struct dump_arg*,int); static int -hash_each(VALUE key, VALUE value, struct dump_call_arg *arg) +hash_each(VALUE key, VALUE value, VALUE v) { + struct dump_call_arg *arg = (void *)v; w_object(key, arg->arg, arg->limit); w_object(value, arg->arg, arg->limit); return ST_CONTINUE; From 7aad4f06f34a1e1ec8db64c56f57e6de66b1334d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 27 Aug 2019 12:08:32 +0900 Subject: [PATCH 15/18] rb_ivar_foreach now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit adds a function prototype for rb_ivar_foreach. Luckily this change revealed no problematic usage of the function. --- include/ruby/intern.h | 2 +- variable.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 51d4132ae66ab5..3e418c39113144 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -957,7 +957,7 @@ void rb_free_generic_ivar(VALUE); VALUE rb_ivar_get(VALUE, ID); VALUE rb_ivar_set(VALUE, ID, VALUE); VALUE rb_ivar_defined(VALUE, ID); -void rb_ivar_foreach(VALUE, int (*)(ANYARGS), st_data_t); +void rb_ivar_foreach(VALUE, int (*)(ID, VALUE, st_data_t), st_data_t); st_index_t rb_ivar_count(VALUE); VALUE rb_attr_get(VALUE, ID); VALUE rb_obj_instance_variables(VALUE); diff --git a/variable.c b/variable.c index bc79dd6cc3b4a3..4a922126c54d06 100644 --- a/variable.c +++ b/variable.c @@ -1391,9 +1391,11 @@ rb_ivar_defined(VALUE obj, ID id) return Qfalse; } +typedef int rb_ivar_foreach_callback_func(ID key, VALUE val, st_data_t arg); + struct obj_ivar_tag { VALUE obj; - int (*func)(ID key, VALUE val, st_data_t arg); + rb_ivar_foreach_callback_func *func; st_data_t arg; }; @@ -1411,7 +1413,7 @@ obj_ivar_i(st_data_t key, st_data_t index, st_data_t arg) } static void -obj_ivar_each(VALUE obj, int (*func)(ANYARGS), st_data_t arg) +obj_ivar_each(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg) { st_table *tbl; struct obj_ivar_tag data; @@ -1429,7 +1431,7 @@ obj_ivar_each(VALUE obj, int (*func)(ANYARGS), st_data_t arg) struct gen_ivar_tag { struct gen_ivtbl *ivtbl; - int (*func)(ID key, VALUE val, st_data_t arg); + rb_ivar_foreach_callback_func *func; st_data_t arg; }; @@ -1448,7 +1450,7 @@ gen_ivar_each_i(st_data_t key, st_data_t index, st_data_t data) } static void -gen_ivar_each(VALUE obj, int (*func)(ANYARGS), st_data_t arg) +gen_ivar_each(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg) { struct gen_ivar_tag data; st_table *iv_index_tbl = RCLASS_IV_INDEX_TBL(rb_obj_class(obj)); @@ -1531,7 +1533,7 @@ rb_copy_generic_ivar(VALUE clone, VALUE obj) } void -rb_ivar_foreach(VALUE obj, int (*func)(ANYARGS), st_data_t arg) +rb_ivar_foreach(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg) { if (SPECIAL_CONST_P(obj)) return; switch (BUILTIN_TYPE(obj)) { From a545ad2ac505adc91451b3d82575dc95ce70c517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 27 Aug 2019 12:29:00 +0900 Subject: [PATCH 16/18] struct MEMO now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. There is only one usage of MEMO::u3::func in load.c (where void Init_Foobar(vodi) is registered) so why not just be explicit. --- internal.h | 2 +- load.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal.h b/internal.h index 5e73c1113340a9..7d6bf1ec7229db 100644 --- a/internal.h +++ b/internal.h @@ -1245,7 +1245,7 @@ struct MEMO { long cnt; long state; const VALUE value; - VALUE (*func)(ANYARGS); + void (*func)(void); } u3; }; diff --git a/load.c b/load.c index bc7abf15217d82..3a21f5c0cf7be5 100644 --- a/load.c +++ b/load.c @@ -728,7 +728,7 @@ load_lock(const char *ftptr) } else if (imemo_type_p(data, imemo_memo)) { struct MEMO *memo = MEMO_CAST(data); - void (*init)(void) = (void (*)(void))memo->u3.func; + void (*init)(void) = memo->u3.func; data = (st_data_t)rb_thread_shield_new(); st_insert(loading_tbl, (st_data_t)ftptr, data); (*init)(); From db20159d315926000a83fd8fe24aa943bd3dc82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 27 Aug 2019 12:40:06 +0900 Subject: [PATCH 17/18] rb_uninterruptible now free from ANYARGS After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This function has only one call site so adding appropriate prototype is trivial. --- internal.h | 2 +- thread.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal.h b/internal.h index 7d6bf1ec7229db..5a846c13e02bae 100644 --- a/internal.h +++ b/internal.h @@ -2215,7 +2215,7 @@ VALUE rb_thread_shield_release(VALUE self); VALUE rb_thread_shield_destroy(VALUE self); int rb_thread_to_be_killed(VALUE thread); void rb_mutex_allow_trap(VALUE self, int val); -VALUE rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data); +VALUE rb_uninterruptible(VALUE (*b_proc)(VALUE), VALUE data); VALUE rb_mutex_owned_p(VALUE self); /* transcode.c */ diff --git a/thread.c b/thread.c index 57ccfef8b74949..752b8b0cd30495 100644 --- a/thread.c +++ b/thread.c @@ -5507,7 +5507,7 @@ rb_default_coverage(int n) } VALUE -rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data) +rb_uninterruptible(VALUE (*b_proc)(VALUE), VALUE data) { VALUE interrupt_mask = rb_ident_hash_new(); rb_thread_t *cur_th = GET_THREAD(); From 83688452f37d8d2f8d3624de2134613a379358f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 27 Aug 2019 14:21:18 +0900 Subject: [PATCH 18/18] delete `$` sign from C identifiers They lack portability. See also https://travis-ci.org/shyouhei/ruby/jobs/577164015 --- io.c | 6 +++--- load.c | 6 +++--- process.c | 8 ++++---- re.c | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/io.c b/io.c index 2f9df89d6aacf1..e0b81fcc3a741c 100644 --- a/io.c +++ b/io.c @@ -12987,13 +12987,13 @@ rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char * } static VALUE -get_$LAST_READ_LINE(ID _x, VALUE *_y) +get_LAST_READ_LINE(ID _x, VALUE *_y) { return rb_lastline_get(); } static void -set_$LAST_READ_LINE(VALUE val, ID _x, VALUE *_y) +set_LAST_READ_LINE(VALUE val, ID _x, VALUE *_y) { rb_lastline_set(val); } @@ -13271,7 +13271,7 @@ Init_IO(void) 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("$_", get_$LAST_READ_LINE, set_$LAST_READ_LINE); + 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 3a21f5c0cf7be5..571995daed2346 100644 --- a/load.c +++ b/load.c @@ -156,7 +156,7 @@ get_loaded_features(void) } static VALUE -get_$LOADED_FEATURES(ID _x, VALUE *_y) +get_LOADED_FEATURES(ID _x, VALUE *_y) { return get_loaded_features(); } @@ -1265,8 +1265,8 @@ Init_load(void) 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 dad090712c6e45..a21b17125e02d6 100644 --- a/process.c +++ b/process.c @@ -8039,13 +8039,13 @@ rb_clock_getres(int argc, VALUE *argv) } static VALUE -get_$CHILD_STATUS(ID _x, VALUE *_y) +get_CHILD_STATUS(ID _x, VALUE *_y) { return rb_last_status_get(); } static VALUE -get_$PROCESS_ID(ID _x, VALUE *_y) +get_PROCESS_ID(ID _x, VALUE *_y) { return get_pid(); } @@ -8066,8 +8066,8 @@ InitVM_process(void) { #undef rb_intern #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_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 f4aad1e0447057..d5f9a8792edefa 100644 --- a/re.c +++ b/re.c @@ -3955,7 +3955,7 @@ match_getter(void) } static VALUE -get_$LAST_MATCH_INFO(ID _x, VALUE *_y) +get_LAST_MATCH_INFO(ID _x, VALUE *_y) { return match_getter(); } @@ -4048,7 +4048,7 @@ Init_Regexp(void) onig_set_warn_func(re_warn); onig_set_verb_warn_func(re_warn); - rb_define_virtual_variable("$~", get_$LAST_MATCH_INFO, 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);