ruby-changes:24101
From: akr <ko1@a...>
Date: Wed, 20 Jun 2012 19:33:47 +0900 (JST)
Subject: [ruby-changes:24101] akr:r36152 (trunk): * internal.h (rb_execarg_new): declared.
akr 2012-06-20 19:31:02 +0900 (Wed, 20 Jun 2012) New Revision: 36152 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36152 Log: * internal.h (rb_execarg_new): declared. (rb_execarg_get): ditto. * process.c (mark_exec_arg): new function. (free_exec_arg): ditto. (memsize_exec_arg): ditto. (exec_arg_data_type): defined. (rb_execarg_new): new function. (rb_execarg_get): ditto. (rb_f_exec): use rb_execarg_new. (rb_spawn_internal): ditto. (rb_f_spawn): ditto. * io.c (pipe_open_v): use rb_execarg_new. (pipe_open_s): ditto. * ext/pty/pty.c (establishShell): use rb_execarg_new. Modified files: trunk/ChangeLog trunk/ext/pty/pty.c trunk/internal.h trunk/io.c trunk/process.c Index: ChangeLog =================================================================== --- ChangeLog (revision 36151) +++ ChangeLog (revision 36152) @@ -1,3 +1,23 @@ +Wed Jun 20 19:13:25 2012 Tanaka Akira <akr@f...> + + * internal.h (rb_execarg_new): declared. + (rb_execarg_get): ditto. + + * process.c (mark_exec_arg): new function. + (free_exec_arg): ditto. + (memsize_exec_arg): ditto. + (exec_arg_data_type): defined. + (rb_execarg_new): new function. + (rb_execarg_get): ditto. + (rb_f_exec): use rb_execarg_new. + (rb_spawn_internal): ditto. + (rb_f_spawn): ditto. + + * io.c (pipe_open_v): use rb_execarg_new. + (pipe_open_s): ditto. + + * ext/pty/pty.c (establishShell): use rb_execarg_new. + Wed Jun 20 16:36:14 2012 Nobuyoshi Nakada <nobu@r...> * missing/setproctitle.c (environ): use (*_NSGetEnviron()) instead of Index: io.c =================================================================== --- io.c (revision 36151) +++ io.c (revision 36152) @@ -5726,9 +5726,13 @@ static VALUE pipe_open_v(int argc, VALUE *argv, const char *modestr, int fmode, convconfig_t *convconfig) { - struct rb_exec_arg earg; - rb_execarg_init(argc, argv, FALSE, &earg); - return pipe_open(&earg, modestr, fmode, convconfig); + VALUE execarg_obj, ret; + struct rb_exec_arg *earg; + execarg_obj = rb_execarg_new(argc, argv, FALSE); + earg = rb_execarg_get(execarg_obj); + ret = pipe_open(earg, modestr, fmode, convconfig); + RB_GC_GUARD(execarg_obj); + return ret; } static VALUE @@ -5737,7 +5741,8 @@ const char *cmd = RSTRING_PTR(prog); int argc = 1; VALUE *argv = &prog; - struct rb_exec_arg earg; + VALUE execarg_obj, ret; + struct rb_exec_arg *earg; if (RSTRING_LEN(prog) == 1 && cmd[0] == '-') { #if !defined(HAVE_FORK) @@ -5747,8 +5752,11 @@ return pipe_open(NULL, modestr, fmode, convconfig); } - rb_execarg_init(argc, argv, TRUE, &earg); - return pipe_open(&earg, modestr, fmode, convconfig); + execarg_obj = rb_execarg_new(argc, argv, TRUE); + earg = rb_execarg_get(execarg_obj); + ret = pipe_open(earg, modestr, fmode, convconfig); + RB_GC_GUARD(execarg_obj); + return ret; } /* Index: process.c =================================================================== --- process.c (revision 36151) +++ process.c (revision 36152) @@ -1270,6 +1270,42 @@ EXEC_OPTION_NEW_PGROUP }; +static void +mark_exec_arg(void *ptr) +{ + struct rb_exec_arg *earg = ptr; + if (earg->use_shell) + rb_gc_mark(earg->invoke.sh.shell_script); + else { + rb_gc_mark(earg->invoke.cmd.command_name); + rb_gc_mark(earg->invoke.cmd.command_abspath); + rb_gc_mark(earg->invoke.cmd.argv_str); + rb_gc_mark(earg->invoke.cmd.argv_buf); + } + rb_gc_mark(earg->options); + rb_gc_mark(earg->redirect_fds); + rb_gc_mark(earg->envp_str); + rb_gc_mark(earg->envp_buf); + rb_gc_mark(earg->dup2_tmpbuf); +} + +static void +free_exec_arg(void *ptr) +{ + xfree(ptr); +} + +static size_t +memsize_exec_arg(const void *ptr) +{ + return ptr ? sizeof(struct rb_exec_arg) : 0; +} + +static const rb_data_type_t exec_arg_data_type = { + "exec_arg", + {mark_exec_arg, free_exec_arg, memsize_exec_arg}, +}; + #if defined(_WIN32) #define HAVE_SPAWNV 1 #endif @@ -2020,6 +2056,24 @@ } VALUE +rb_execarg_new(int argc, VALUE *argv, int accept_shell) +{ + VALUE execarg_obj; + struct rb_exec_arg *e; + execarg_obj = TypedData_Make_Struct(rb_cData, struct rb_exec_arg, &exec_arg_data_type, e); + hide_obj(execarg_obj); + rb_execarg_init(argc, argv, accept_shell, e); + return execarg_obj; +} + +struct rb_exec_arg *rb_execarg_get(VALUE execarg_obj) +{ + struct rb_exec_arg *e; + TypedData_Get_Struct(execarg_obj, struct rb_exec_arg, &exec_arg_data_type, e); + return e; +} + +VALUE rb_execarg_init(int argc, VALUE *argv, int accept_shell, struct rb_exec_arg *e) { VALUE prog; @@ -2193,20 +2247,25 @@ VALUE rb_f_exec(int argc, VALUE *argv) { - struct rb_exec_arg earg; + VALUE execarg_obj, fail_str; + struct rb_exec_arg *earg; #define CHILD_ERRMSG_BUFLEN 80 char errmsg[CHILD_ERRMSG_BUFLEN] = { '\0' }; - rb_exec_arg_prepare(&earg, argc, argv); + execarg_obj = rb_execarg_new(argc, argv, TRUE); + earg = rb_execarg_get(execarg_obj); + rb_execarg_fixup(earg); + fail_str = earg->use_shell ? earg->invoke.sh.shell_script : earg->invoke.cmd.command_name; #ifdef __MacOS_X__ - rb_exec_without_timer_thread(&earg, errmsg, sizeof(errmsg)); + rb_exec_without_timer_thread(earg, errmsg, sizeof(errmsg)); #else - rb_exec_async_signal_safe(&earg, errmsg, sizeof(errmsg)); + rb_exec_async_signal_safe(earg, errmsg, sizeof(errmsg)); #endif + RB_GC_GUARD(execarg_obj); if (errmsg[0]) rb_sys_fail(errmsg); - rb_sys_fail_str(earg.use_shell ? earg.invoke.sh.shell_script : earg.invoke.cmd.command_name); + rb_sys_fail_str(fail_str); return Qnil; /* dummy */ } @@ -3480,9 +3539,16 @@ static rb_pid_t rb_spawn_internal(int argc, VALUE *argv, char *errmsg, size_t errmsg_buflen) { - struct rb_exec_arg earg; - rb_exec_arg_prepare(&earg, argc, argv); - return rb_spawn_process(&earg, errmsg, errmsg_buflen); + VALUE execarg_obj; + struct rb_exec_arg *earg; + VALUE ret; + + execarg_obj = rb_execarg_new(argc, argv, TRUE); + earg = rb_execarg_get(execarg_obj); + rb_execarg_fixup(earg); + ret = rb_spawn_process(earg, errmsg, errmsg_buflen); + RB_GC_GUARD(execarg_obj); + return ret; } rb_pid_t @@ -3813,14 +3879,21 @@ { rb_pid_t pid; char errmsg[CHILD_ERRMSG_BUFLEN] = { '\0' }; - struct rb_exec_arg earg; + VALUE execarg_obj, fail_str; + struct rb_exec_arg *earg; - rb_exec_arg_prepare(&earg, argc, argv); - pid = rb_spawn_process(&earg, errmsg, sizeof(errmsg)); + execarg_obj = rb_execarg_new(argc, argv, TRUE); + earg = rb_execarg_get(execarg_obj); + rb_execarg_fixup(earg); + fail_str = earg->use_shell ? earg->invoke.sh.shell_script : earg->invoke.cmd.command_name; + + pid = rb_spawn_process(earg, errmsg, sizeof(errmsg)); + RB_GC_GUARD(execarg_obj); + if (pid == -1) { const char *prog = errmsg; if (!prog[0]) { - rb_sys_fail_str(earg.use_shell ? earg.invoke.sh.shell_script : earg.invoke.cmd.command_name); + rb_sys_fail_str(fail_str); } rb_sys_fail(prog); } Index: ext/pty/pty.c =================================================================== --- ext/pty/pty.c (revision 36151) +++ ext/pty/pty.c (revision 36152) @@ -78,7 +78,8 @@ struct child_info { int master, slave; char *slavename; - struct rb_exec_arg earg; + VALUE execarg_obj; + struct rb_exec_arg *earg; }; static int @@ -142,7 +143,7 @@ seteuid(getuid()); #endif - return rb_exec_async_signal_safe(&carg->earg, errbuf, sizeof(errbuf_len)); + return rb_exec_async_signal_safe(carg->earg, errbuf, sizeof(errbuf_len)); #undef ERROR_EXIT } @@ -176,8 +177,9 @@ argv = &v; } - rb_execarg_init(argc, argv, 1, &carg.earg); - rb_execarg_fixup(&carg.earg); + carg.execarg_obj = rb_execarg_new(argc, argv, 1); + carg.earg = rb_execarg_get(carg.execarg_obj); + rb_execarg_fixup(carg.earg); getDevice(&master, &slave, SlaveName, 0); @@ -200,6 +202,8 @@ info->child_pid = pid; info->fd = master; + + RB_GC_GUARD(carg.execarg_obj); } static int Index: internal.h =================================================================== --- internal.h (revision 36151) +++ internal.h (revision 36152) @@ -266,6 +266,8 @@ /* process.c */ int rb_exec_async_signal_safe(const struct rb_exec_arg *e, char *errmsg, size_t errmsg_buflen); rb_pid_t rb_fork_async_signal_safe(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALUE fds, char *errmsg, size_t errmsg_buflen); +VALUE rb_execarg_new(int argc, VALUE *argv, int accept_shell); +struct rb_exec_arg *rb_execarg_get(VALUE execarg_obj); /* dangerous. needs GC guard. */ VALUE rb_execarg_init(int argc, VALUE *argv, int accept_shell, struct rb_exec_arg *e); int rb_execarg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val); void rb_execarg_fixup(struct rb_exec_arg *e); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/