summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-14 01:49:33 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-14 01:49:33 -0700
commitb78a345bd63ff2b52ea0f84754ab0988748a9bd0 (patch)
treed529df7726d15a14d21c7b03a99b332dc93ba7d3 /object.c
parentb2c29bbab6e88253f497fc3e66a43cb7b4d425b5 (diff)
Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from Ruby
It is not safe to set this in C functions that can be called from other C functions, as in the non argument-delegation case, you can end up calling a Ruby method with a flag indicating keywords are set without passing keywords. Introduce some new *_kw functions that take a kw_splat flag and use these functions to set RB_PASS_CALLED_KEYWORDS in places where we know we are delegating methods (e.g. Class#new, Method#call)
Diffstat (limited to 'object.c')
-rw-r--r--object.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/object.c b/object.c
index 501fcfcffa..de2d72fae3 100644
--- a/object.c
+++ b/object.c
@@ -2196,7 +2196,19 @@ rb_class_s_new(int argc, const VALUE *argv, VALUE klass)
VALUE obj;
obj = rb_class_alloc(klass);
- rb_obj_call_init(obj, argc, argv);
+ rb_obj_call_init_kw(obj, argc, argv, RB_PASS_CALLED_KEYWORDS);
+
+ return obj;
+}
+
+VALUE
+rb_class_new_instance_kw(int argc, const VALUE *argv, VALUE klass, int kw_splat)
+{
+ VALUE obj;
+ Check_Type(klass, T_CLASS);
+
+ obj = rb_class_alloc(klass);
+ rb_obj_call_init_kw(obj, argc, argv, kw_splat);
return obj;
}
@@ -2216,8 +2228,13 @@ rb_class_s_new(int argc, const VALUE *argv, VALUE klass)
VALUE
rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
{
+ VALUE obj;
Check_Type(klass, T_CLASS);
- return rb_class_s_new(argc, argv, klass);
+
+ obj = rb_class_alloc(klass);
+ rb_obj_call_init_kw(obj, argc, argv, RB_NO_KEYWORDS);
+
+ return obj;
}
/**