ruby-changes:66616
From: Nobuyoshi <ko1@a...>
Date: Mon, 28 Jun 2021 12:10:23 +0900 (JST)
Subject: [ruby-changes:66616] 47a9b58b2a (master): Share freeze option handling
https://git.ruby-lang.org/ruby.git/commit/?id=47a9b58b2a From 47a9b58b2ae52a10c93c5368c7aa30b1eb398bc7 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 28 Jun 2021 10:51:42 +0900 Subject: Share freeze option handling --- hash.c | 20 +++----------------- internal/object.h | 1 + object.c | 14 +++++++------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/hash.c b/hash.c index cf19cdb..7ef30b4 100644 --- a/hash.c +++ b/hash.c @@ -6501,25 +6501,11 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/hash.c#L6501 env_clone(int argc, VALUE *argv, VALUE obj) { if (argc) { - static ID keyword_ids[1]; VALUE opt, kwfreeze; - - if (!keyword_ids[0]) { - CONST_ID(keyword_ids[0], "freeze"); - } - rb_scan_args(argc, argv, "0:", &opt); - if (!NIL_P(opt)) { - rb_get_kwargs(opt, keyword_ids, 0, 1, &kwfreeze); - switch (kwfreeze) { - case Qtrue: + if (rb_scan_args(argc, argv, "0:", &opt) < argc) { + kwfreeze = rb_get_freeze_opt(1, &opt); + if (RTEST(kwfreeze)) { rb_raise(rb_eTypeError, "cannot freeze ENV"); - break; - default: - rb_raise(rb_eArgError, "invalid value for freeze keyword"); - break; - case Qnil: - case Qfalse: - break; } } } diff --git a/internal/object.h b/internal/object.h index 2af90c1..512c367 100644 --- a/internal/object.h +++ b/internal/object.h @@ -42,6 +42,7 @@ void rb_obj_copy_ivar(VALUE dest, VALUE obj); https://github.com/ruby/ruby/blob/trunk/internal/object.h#L42 VALUE rb_false(VALUE obj); VALUE rb_convert_type_with_id(VALUE v, int t, const char* nam, ID mid); VALUE rb_obj_size(VALUE self, VALUE args, VALUE obj); +VALUE rb_get_freeze_opt(int argc, VALUE *argv); MJIT_SYMBOL_EXPORT_END static inline void diff --git a/object.c b/object.c index 244f2a6..1994fe9 100644 --- a/object.c +++ b/object.c @@ -369,7 +369,6 @@ init_copy(VALUE dest, VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L369 } } -static VALUE freeze_opt(int argc, VALUE *argv); static VALUE immutable_obj_clone(VALUE obj, VALUE kwfreeze); static VALUE mutable_obj_clone(VALUE obj, VALUE kwfreeze); PUREFUNC(static inline int special_object_p(VALUE obj)); /*!< \private */ @@ -418,12 +417,12 @@ rb_obj_clone2(rb_execution_context_t *ec, VALUE obj, VALUE freeze) https://github.com/ruby/ruby/blob/trunk/object.c#L417 VALUE rb_immutable_obj_clone(int argc, VALUE *argv, VALUE obj) { - VALUE kwfreeze = freeze_opt(argc, argv); + VALUE kwfreeze = rb_get_freeze_opt(argc, argv); return immutable_obj_clone(obj, kwfreeze); } -static VALUE -freeze_opt(int argc, VALUE *argv) +VALUE +rb_get_freeze_opt(int argc, VALUE *argv) { static ID keyword_ids[1]; VALUE opt; @@ -657,9 +656,10 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/object.c#L656 rb_obj_init_clone(int argc, VALUE *argv, VALUE obj) { VALUE orig, opts; - rb_scan_args(argc, argv, "1:", &orig, &opts); - /* Ignore a freeze keyword */ - if (argc == 2) (void)freeze_opt(1, &opts); + if (rb_scan_args(argc, argv, "1:", &orig, &opts) < argc) { + /* Ignore a freeze keyword */ + rb_get_freeze_opt(1, &opts); + } rb_funcall(obj, id_init_copy, 1, orig); return obj; } -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/