Share freeze option handling
This commit is contained in:
parent
e724857f42
commit
47a9b58b2a
20
hash.c
20
hash.c
@ -6501,25 +6501,11 @@ static VALUE
|
|||||||
env_clone(int argc, VALUE *argv, VALUE obj)
|
env_clone(int argc, VALUE *argv, VALUE obj)
|
||||||
{
|
{
|
||||||
if (argc) {
|
if (argc) {
|
||||||
static ID keyword_ids[1];
|
|
||||||
VALUE opt, kwfreeze;
|
VALUE opt, kwfreeze;
|
||||||
|
if (rb_scan_args(argc, argv, "0:", &opt) < argc) {
|
||||||
if (!keyword_ids[0]) {
|
kwfreeze = rb_get_freeze_opt(1, &opt);
|
||||||
CONST_ID(keyword_ids[0], "freeze");
|
if (RTEST(kwfreeze)) {
|
||||||
}
|
|
||||||
rb_scan_args(argc, argv, "0:", &opt);
|
|
||||||
if (!NIL_P(opt)) {
|
|
||||||
rb_get_kwargs(opt, keyword_ids, 0, 1, &kwfreeze);
|
|
||||||
switch (kwfreeze) {
|
|
||||||
case Qtrue:
|
|
||||||
rb_raise(rb_eTypeError, "cannot freeze ENV");
|
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_false(VALUE obj);
|
||||||
VALUE rb_convert_type_with_id(VALUE v, int t, const char* nam, ID mid);
|
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_obj_size(VALUE self, VALUE args, VALUE obj);
|
||||||
|
VALUE rb_get_freeze_opt(int argc, VALUE *argv);
|
||||||
MJIT_SYMBOL_EXPORT_END
|
MJIT_SYMBOL_EXPORT_END
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
12
object.c
12
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 immutable_obj_clone(VALUE obj, VALUE kwfreeze);
|
||||||
static VALUE mutable_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 */
|
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
|
VALUE
|
||||||
rb_immutable_obj_clone(int argc, VALUE *argv, VALUE obj)
|
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);
|
return immutable_obj_clone(obj, kwfreeze);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
VALUE
|
||||||
freeze_opt(int argc, VALUE *argv)
|
rb_get_freeze_opt(int argc, VALUE *argv)
|
||||||
{
|
{
|
||||||
static ID keyword_ids[1];
|
static ID keyword_ids[1];
|
||||||
VALUE opt;
|
VALUE opt;
|
||||||
@ -657,9 +656,10 @@ static VALUE
|
|||||||
rb_obj_init_clone(int argc, VALUE *argv, VALUE obj)
|
rb_obj_init_clone(int argc, VALUE *argv, VALUE obj)
|
||||||
{
|
{
|
||||||
VALUE orig, opts;
|
VALUE orig, opts;
|
||||||
rb_scan_args(argc, argv, "1:", &orig, &opts);
|
if (rb_scan_args(argc, argv, "1:", &orig, &opts) < argc) {
|
||||||
/* Ignore a freeze keyword */
|
/* Ignore a freeze keyword */
|
||||||
if (argc == 2) (void)freeze_opt(1, &opts);
|
rb_get_freeze_opt(1, &opts);
|
||||||
|
}
|
||||||
rb_funcall(obj, id_init_copy, 1, orig);
|
rb_funcall(obj, id_init_copy, 1, orig);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user