aboutsummaryrefslogtreecommitdiffstats
path: root/process.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-07-16 18:47:35 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-07-16 18:57:08 +0900
commite988048e2589b6f517c11430d568e2ccf118e901 (patch)
tree6f76d6ead24b73a31ee90f23ea921e3fa4def7b5 /process.c
parent8deabcd3280f6042ea1ed14b629d70680e081fec (diff)
downloadruby-e988048e2589b6f517c11430d568e2ccf118e901.tar.gz
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.
Diffstat (limited to 'process.c')
-rw-r--r--process.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/process.c b/process.c
index c732fd2cd6..2bc11103f9 100644
--- a/process.c
+++ b/process.c
@@ -2116,6 +2116,13 @@ rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
"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)
}
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)
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;
}