mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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.
This commit is contained in:
parent
8deabcd328
commit
e988048e25
2 changed files with 14 additions and 10 deletions
|
@ -1977,6 +1977,7 @@ struct rb_execarg {
|
||||||
unsigned uid_given : 1;
|
unsigned uid_given : 1;
|
||||||
unsigned gid_given : 1;
|
unsigned gid_given : 1;
|
||||||
unsigned exception : 1;
|
unsigned exception : 1;
|
||||||
|
unsigned exception_given : 1;
|
||||||
struct waitpid_state *waitpid_state; /* for async process management */
|
struct waitpid_state *waitpid_state; /* for async process management */
|
||||||
rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
|
rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
|
||||||
VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
|
VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
|
||||||
|
|
23
process.c
23
process.c
|
@ -2116,6 +2116,13 @@ rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
|
||||||
"gid option is unimplemented on this machine");
|
"gid option is unimplemented on this machine");
|
||||||
#endif
|
#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 {
|
else {
|
||||||
return ST_STOP;
|
return ST_STOP;
|
||||||
}
|
}
|
||||||
|
@ -2592,23 +2599,16 @@ rb_execarg_get(VALUE execarg_obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
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);
|
struct rb_execarg *eargp = rb_execarg_get(execarg_obj);
|
||||||
VALUE prog, ret, exception = Qnil;
|
VALUE prog, ret;
|
||||||
VALUE env = Qnil, opthash = Qnil;
|
VALUE env = Qnil, opthash = Qnil;
|
||||||
VALUE argv_buf;
|
VALUE argv_buf;
|
||||||
VALUE *argv = ALLOCV_N(VALUE, argv_buf, argc);
|
VALUE *argv = ALLOCV_N(VALUE, argv_buf, argc);
|
||||||
MEMCPY(argv, orig_argv, VALUE, argc);
|
MEMCPY(argv, orig_argv, VALUE, argc);
|
||||||
prog = rb_exec_getargs(&argc, &argv, accept_shell, &env, &opthash);
|
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);
|
rb_exec_fillarg(prog, argc, argv, env, opthash, execarg_obj);
|
||||||
if (RTEST(exception)) {
|
|
||||||
eargp->exception = 1;
|
|
||||||
}
|
|
||||||
ALLOCV_END(argv_buf);
|
ALLOCV_END(argv_buf);
|
||||||
ret = eargp->use_shell ? eargp->invoke.sh.shell_script : eargp->invoke.cmd.command_name;
|
ret = eargp->use_shell ? eargp->invoke.sh.shell_script : eargp->invoke.cmd.command_name;
|
||||||
RB_GC_GUARD(execarg_obj);
|
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;
|
VALUE execarg_obj;
|
||||||
struct rb_execarg *eargp;
|
struct rb_execarg *eargp;
|
||||||
execarg_obj = TypedData_Make_Struct(0, struct rb_execarg, &exec_arg_data_type, 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;
|
return execarg_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue