aboutsummaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-13 16:42:27 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-13 16:42:27 -0700
commit3cfbfa9628435e3b09316a18c2db9e4f250fdd77 (patch)
treeaac052f5a518c9b4aaf296da2a4730c72e5ed521 /eval.c
parent24b1b339757ecab4539a2cb00a545bfcf885d3ef (diff)
downloadruby-3cfbfa9628435e3b09316a18c2db9e4f250fdd77.tar.gz
Consolidate empty keyword handling
Remove rb_add_empty_keyword, and instead of calling that every place you need to add empty keyword hashes, run that code in a single static function in vm_eval.c. Add 4 defines to include/ruby/ruby.h, these are to be used as int kw_splat values when calling the various rb_*_kw functions: RB_NO_KEYWORDS :: Do not pass keywords RB_PASS_KEYWORDS :: Pass final argument (which should be hash) as keywords RB_PASS_EMPTY_KEYWORDS :: Add an empty hash to arguments and pass as keywords RB_PASS_CALLED_KEYWORDS :: Passes same keyword type as current method was called with (for method delegation) rb_empty_keyword_given_p needs to stay. It is required if argument delegation is done but delayed to a later point, which Enumerator does. Use RB_PASS_CALLED_KEYWORDS in rb_call_super to correctly delegate keyword arguments to super method.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c15
1 files changed, 1 insertions, 14 deletions
diff --git a/eval.c b/eval.c
index fbdde7da9b..ca4456d5d2 100644
--- a/eval.c
+++ b/eval.c
@@ -914,14 +914,6 @@ rb_empty_keyword_given_p(void)
{
return rb_vm_cframe_empty_keyword_p(GET_EC()->cfp);
}
-VALUE *
-rb_add_empty_keyword(int argc, const VALUE *argv)
-{
- VALUE *ptr = ALLOC_N(VALUE,argc+1);
- memcpy(ptr, argv, sizeof(VALUE)*(argc));
- ptr[argc] = rb_hash_new();
- return ptr;
-}
VALUE rb_eThreadError;
@@ -1680,12 +1672,7 @@ void
rb_obj_call_init(VALUE obj, int argc, const VALUE *argv)
{
PASS_PASSED_BLOCK_HANDLER();
- if (rb_empty_keyword_given_p()) {
- rb_funcallv_kw(obj, idInitialize, argc+1, rb_add_empty_keyword(argc, argv), 1);
- }
- else {
- rb_funcallv_kw(obj, idInitialize, argc, argv, rb_keyword_given_p());
- }
+ rb_funcallv_kw(obj, idInitialize, argc, argv, RB_PASS_CALLED_KEYWORDS);
}
/*!