ruby-changes:56577
From: Nobuyoshi <ko1@a...>
Date: Tue, 16 Jul 2019 19:02:46 +0900 (JST)
Subject: [ruby-changes:56577] Nobuyoshi Nakada: e988048e25 (master): Moved the check for `exception` to rb_execarg_addopt
https://git.ruby-lang.org/ruby.git/commit/?id=e988048e25 From e988048e2589b6f517c11430d568e2ccf118e901 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 16 Jul 2019 18:47:35 +0900 Subject: Moved the check for `exception` to rb_execarg_addopt Check for `exception` option in rb_execarg_addopt, as well as other options. And then raise a particular ArgumentError if it is not allowed. diff --git a/internal.h b/internal.h index 2f0a5af..b931c11 100644 --- a/internal.h +++ b/internal.h @@ -1977,6 +1977,7 @@ struct rb_execarg { https://github.com/ruby/ruby/blob/trunk/internal.h#L1977 unsigned uid_given : 1; unsigned gid_given : 1; unsigned exception : 1; + unsigned exception_given : 1; struct waitpid_state *waitpid_state; /* for async process management */ rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */ VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */ diff --git a/process.c b/process.c index c732fd2..2bc1110 100644 --- a/process.c +++ b/process.c @@ -2116,6 +2116,13 @@ rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val) https://github.com/ruby/ruby/blob/trunk/process.c#L2116 "gid option is unimplemented on this machine"); #endif } + else if (id == id_exception) { + if (eargp->exception_given) { + rb_raise(rb_eArgError, "exception option specified twice"); + } + eargp->exception = RTEST(val); + eargp->exception_given = 1; + } else { return ST_STOP; } @@ -2592,23 +2599,16 @@ rb_execarg_get(VALUE execarg_obj) https://github.com/ruby/ruby/blob/trunk/process.c#L2599 } static VALUE -rb_execarg_init(int argc, const VALUE *orig_argv, int accept_shell, VALUE execarg_obj, int allow_exc_opt) +rb_execarg_init(int argc, const VALUE *orig_argv, int accept_shell, VALUE execarg_obj) { struct rb_execarg *eargp = rb_execarg_get(execarg_obj); - VALUE prog, ret, exception = Qnil; + VALUE prog, ret; VALUE env = Qnil, opthash = Qnil; VALUE argv_buf; VALUE *argv = ALLOCV_N(VALUE, argv_buf, argc); MEMCPY(argv, orig_argv, VALUE, argc); prog = rb_exec_getargs(&argc, &argv, accept_shell, &env, &opthash); - if (allow_exc_opt && !NIL_P(opthash) && rb_hash_has_key(opthash, ID2SYM(id_exception))) { - opthash = rb_hash_dup(opthash); - exception = rb_hash_delete(opthash, ID2SYM(id_exception)); - } rb_exec_fillarg(prog, argc, argv, env, opthash, execarg_obj); - if (RTEST(exception)) { - eargp->exception = 1; - } ALLOCV_END(argv_buf); ret = eargp->use_shell ? eargp->invoke.sh.shell_script : eargp->invoke.cmd.command_name; RB_GC_GUARD(execarg_obj); @@ -2621,7 +2621,10 @@ rb_execarg_new(int argc, const VALUE *argv, int accept_shell, int allow_exc_opt) https://github.com/ruby/ruby/blob/trunk/process.c#L2621 VALUE execarg_obj; struct rb_execarg *eargp; execarg_obj = TypedData_Make_Struct(0, struct rb_execarg, &exec_arg_data_type, eargp); - rb_execarg_init(argc, argv, accept_shell, execarg_obj, allow_exc_opt); + rb_execarg_init(argc, argv, accept_shell, execarg_obj); + if (!allow_exc_opt && eargp->exception_given) { + rb_raise(rb_eArgError, "exception option is not allowed"); + } return execarg_obj; } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/