1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* intern.h: prepare rb_last_status_get() and rb_last_status_set().

Use these functions instead of rb_last_status ([ruby-dev:30264]).
* process.c: define above functions.
* ext/pty/pty.c: use above functins.
* io.c (pipe_finalize): ditto.
* process.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-02-05 16:22:38 +00:00
parent 48002b881e
commit 27172b8e6f
7 changed files with 34 additions and 22 deletions

View file

@ -1,3 +1,16 @@
Tue Feb 6 01:07:14 2007 Koichi Sasada <ko1@atdot.net>
* intern.h: prepare rb_last_status_get() and rb_last_status_set().
Use these functions instead of rb_last_status ([ruby-dev:30264]).
* process.c: define above functions.
* ext/pty/pty.c: use above functins.
* io.c (pipe_finalize): ditto.
* process.c: ditto.
Mon Feb 5 21:26:56 2007 Koichi Sasada <ko1@atdot.net> Mon Feb 5 21:26:56 2007 Koichi Sasada <ko1@atdot.net>
* ruby.h: add a prototype of rb_id2str(). * ruby.h: add a prototype of rb_id2str().

View file

@ -135,13 +135,12 @@ struct pty_info {
static void static void
raise_from_wait(char *state, struct pty_info *info) raise_from_wait(char *state, struct pty_info *info)
{ {
extern VALUE rb_last_status;
char buf[1024]; char buf[1024];
VALUE exc; VALUE exc;
snprintf(buf, sizeof(buf), "pty - %s: %ld", state, (long)info->child_pid); snprintf(buf, sizeof(buf), "pty - %s: %ld", state, (long)info->child_pid);
exc = rb_exc_new2(eChildExited, buf); exc = rb_exc_new2(eChildExited, buf);
rb_iv_set(exc, "status", rb_last_status); rb_iv_set(exc, "status", rb_last_status_get());
rb_funcall(info->thread, rb_intern("raise"), 1, exc); rb_funcall(info->thread, rb_intern("raise"), 1, exc);
} }

View file

@ -413,6 +413,8 @@ VALUE rb_sym_all_symbols(void);
ID rb_compose_ivar2(ID, VALUE); ID rb_compose_ivar2(ID, VALUE);
ID rb_decompose_ivar2(ID, VALUE*); ID rb_decompose_ivar2(ID, VALUE*);
/* process.c */ /* process.c */
void rb_last_status_set(int status, rb_pid_t pid);
VALUE rb_last_status_get(void);
struct rb_exec_arg { struct rb_exec_arg {
int argc; int argc;
VALUE *argv; VALUE *argv;

2
io.c
View file

@ -2979,7 +2979,7 @@ pipe_finalize(OpenFile *fptr, int noraise)
#if defined DJGPP #if defined DJGPP
status <<= 8; status <<= 8;
#endif #endif
/* TODO: need it? -> rb_last_status = INT2FIX(status); */ rb_last_status_set(status, fptr->pid);
#else #else
fptr_finalize(fptr, noraise); fptr_finalize(fptr, noraise);
#endif #endif

View file

@ -197,8 +197,8 @@ get_ppid(void)
static VALUE rb_cProcStatus; static VALUE rb_cProcStatus;
static void void
last_status_set(int status, int pid) rb_last_status_set(int status, rb_pid_t pid)
{ {
yarv_vm_t *vm = GET_VM(); yarv_vm_t *vm = GET_VM();
vm->last_status = rb_obj_alloc(rb_cProcStatus); vm->last_status = rb_obj_alloc(rb_cProcStatus);
@ -206,8 +206,8 @@ last_status_set(int status, int pid)
rb_iv_set(vm->last_status, "pid", INT2FIX(pid)); rb_iv_set(vm->last_status, "pid", INT2FIX(pid));
} }
static VALUE VALUE
last_status_get(void) rb_last_status_get(void)
{ {
return GET_VM()->last_status; return GET_VM()->last_status;
} }
@ -588,7 +588,7 @@ rb_waitpid(int pid, int *st, int flags)
} }
#else /* NO_WAITPID */ #else /* NO_WAITPID */
if (pid_tbl && st_lookup(pid_tbl, pid, (st_data_t *)st)) { if (pid_tbl && st_lookup(pid_tbl, pid, (st_data_t *)st)) {
last_status_set(*st, pid); rb_last_status_set(*st, pid);
st_delete(pid_tbl, (st_data_t*)&pid, NULL); st_delete(pid_tbl, (st_data_t*)&pid, NULL);
return pid; return pid;
} }
@ -618,7 +618,7 @@ rb_waitpid(int pid, int *st, int flags)
} }
#endif #endif
if (result > 0) { if (result > 0) {
last_status_set(*st, result); rb_last_status_set(*st, result);
} }
return result; return result;
} }
@ -642,7 +642,7 @@ wait_each(int pid, int status, struct wait_data *data)
static int static int
waitall_each(int pid, int status, VALUE ary) waitall_each(int pid, int status, VALUE ary)
{ {
last_status_set(status, pid); rb_last_status_set(status, pid);
rb_ary_push(ary, rb_assoc_new(INT2NUM(pid), GET_VM()->last_status)); rb_ary_push(ary, rb_assoc_new(INT2NUM(pid), GET_VM()->last_status));
return ST_DELETE; return ST_DELETE;
} }
@ -804,7 +804,7 @@ proc_waitall(void)
} }
rb_sys_fail(0); rb_sys_fail(0);
} }
last_status_set(status, pid); rb_last_status_set(status, pid);
rb_ary_push(result, rb_assoc_new(INT2NUM(pid), GET_VM()->last_status)); rb_ary_push(result, rb_assoc_new(INT2NUM(pid), GET_VM()->last_status));
} }
#else #else
@ -1103,7 +1103,7 @@ proc_spawn_v(char **argv, char *prog)
#endif #endif
before_exec(); before_exec();
status = spawnv(P_WAIT, prog, argv); status = spawnv(P_WAIT, prog, argv);
last_status_set(status == -1 ? 127 : status, 0); rb_last_status_set(status == -1 ? 127 : status, 0);
after_exec(); after_exec();
return status; return status;
} }
@ -1140,7 +1140,7 @@ proc_spawn(char *str)
char *shell = dln_find_exe("sh", 0); char *shell = dln_find_exe("sh", 0);
before_exec(); before_exec();
status = shell?spawnl(P_WAIT,shell,"sh","-c",str,(char*)NULL):system(str); status = shell?spawnl(P_WAIT,shell,"sh","-c",str,(char*)NULL):system(str);
last_status_set(status == -1 ? 127 : status, 0); rb_last_status_set(status == -1 ? 127 : status, 0);
after_exec(); after_exec();
return status; return status;
} }
@ -1557,9 +1557,9 @@ rb_spawn(int argc, VALUE *argv)
if (argc) prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" ")); if (argc) prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
status = system(StringValuePtr(prog)); status = system(StringValuePtr(prog));
# if defined(__human68k__) || defined(__DJGPP__) # if defined(__human68k__) || defined(__DJGPP__)
last_status_set(status == -1 ? 127 : status, 0); rb_last_status_set(status == -1 ? 127 : status, 0);
# else # else
last_status_set((status & 0xff) << 8, 0); rb_last_status_set((status & 0xff) << 8, 0);
# endif # endif
#endif #endif
return status; return status;
@ -3600,7 +3600,7 @@ VALUE rb_mProcID_Syscall;
void void
Init_process(void) Init_process(void)
{ {
rb_define_virtual_variable("$?", last_status_get, 0); rb_define_virtual_variable("$?", rb_last_status_get, 0);
rb_define_virtual_variable("$$", get_pid, 0); rb_define_virtual_variable("$$", get_pid, 0);
rb_define_global_function("exec", rb_f_exec, -1); rb_define_global_function("exec", rb_f_exec, -1);
rb_define_global_function("fork", rb_f_fork, 0); rb_define_global_function("fork", rb_f_fork, 0);

View file

@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.0" #define RUBY_VERSION "1.9.0"
#define RUBY_RELEASE_DATE "2007-02-05" #define RUBY_RELEASE_DATE "2007-02-06"
#define RUBY_VERSION_CODE 190 #define RUBY_VERSION_CODE 190
#define RUBY_RELEASE_CODE 20070205 #define RUBY_RELEASE_CODE 20070206
#define RUBY_PATCHLEVEL 0 #define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MAJOR 1
@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 0 #define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 2 #define RUBY_RELEASE_MONTH 2
#define RUBY_RELEASE_DAY 5 #define RUBY_RELEASE_DAY 6
RUBY_EXTERN const char ruby_version[]; RUBY_EXTERN const char ruby_version[];
RUBY_EXTERN const char ruby_release_date[]; RUBY_EXTERN const char ruby_release_date[];

View file

@ -837,8 +837,6 @@ rb_w32_pipe_exec(const char *cmd, const char *prog, int mode, int *pipe)
return ret; return ret;
} }
extern VALUE rb_last_status;
int int
rb_w32_spawn(int mode, const char *cmd, const char *prog) rb_w32_spawn(int mode, const char *cmd, const char *prog)
{ {
@ -863,7 +861,7 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
switch (mode) { switch (mode) {
case P_WAIT: case P_WAIT:
rb_syswait(child->pid); rb_syswait(child->pid);
return NUM2INT(rb_last_status); return NUM2INT(rb_last_status_get());
case P_NOWAIT: case P_NOWAIT:
return child->pid; return child->pid;
case P_OVERLAY: case P_OVERLAY: