зеркало из https://github.com/github/ruby.git
Share freeze option handling
This commit is contained in:
Родитель
e724857f42
Коммит
47a9b58b2a
20
hash.c
20
hash.c
|
@ -6501,25 +6501,11 @@ static VALUE
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ void rb_obj_copy_ivar(VALUE dest, VALUE obj);
|
|||
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
|
||||
|
|
14
object.c
14
object.c
|
@ -369,7 +369,6 @@ init_copy(VALUE dest, VALUE obj)
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
|||
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
|
|||
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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче