From: Nobuyoshi Nakada Date: 2009-02-24T11:07:05+09:00 Subject: [ruby-dev:38074] Re: build breakage with NO_WAITPID macro なかだです。 At Fri, 20 Feb 2009 01:12:24 +0900, shinichiro.h wrote in [ruby-dev:38054]: > NO_WAITPID が define される環境で > process.c のコンパイルが通りません。 > > たぶん下記パッチでなおります。 ありがとうございます。コミットしました。 > あと、 wait_each は使われてないので > 消してしまって良いように思います。 使われていないのが間違いのような気がします。NO_WAITPIDな環境では Process.wait(-1)が利いてないということはありませんか。 Index: process.c =================================================================== --- process.c (revision 22587) +++ process.c (working copy) @@ -591,4 +591,27 @@ pst_wcoredump(VALUE st) #define NO_WAITPID static st_table *pid_tbl; + +struct wait_data { + rb_pid_t pid; + int status; +}; + +static int +wait_each(rb_pid_t pid, int status, struct wait_data *data) +{ + if (data->status != -1) return ST_STOP; + + data->pid = pid; + data->status = status; + return ST_DELETE; +} + +static int +waitall_each(rb_pid_t pid, int status, VALUE ary) +{ + rb_last_status_set(status, pid); + rb_ary_push(ary, rb_assoc_new(PIDT2NUM(pid), rb_last_status_get())); + return ST_DELETE; +} #else struct waitpid_arg { @@ -636,11 +659,23 @@ retry: goto retry; } - return -1; + return (rb_pid_t)-1; } #else /* NO_WAITPID */ - if (pid_tbl && st_lookup(pid_tbl, pid, (st_data_t *)st)) { - rb_last_status_set(*st, pid); - st_delete(pid_tbl, (st_data_t*)&pid, NULL); - return pid; + if (pid_tbl) { + st_data_t status; + if (pid == (rb_pid_t)-1) { + struct wait_data data; + data.pid = (rb_pid_t)-1; + data.status = -1; + st_foreach(pid_tbl, wait_each, (st_data_t)&data); + if (data.status != -1) { + rb_last_status_set(data.status, data.pid); + return data.pid; + } + } + else if (st_delete(pid_tbl, (st_data_t)pid, &status)) { + rb_last_status_set(*st = (int)status, pid); + return pid; + } } @@ -657,11 +692,11 @@ retry: continue; } - return -1; + return (rb_pid_t)-1; } - if (result == pid) { + if (result == pid || pid == (rb_pid_t)-1) { break; } if (!pid_tbl) - pid_tbl = st_init_numtable(); + pid_tbl = st_init_numtable(); st_insert(pid_tbl, pid, (st_data_t)st); if (!rb_thread_alone()) rb_thread_schedule(); @@ -674,29 +709,4 @@ retry: } -#ifdef NO_WAITPID -struct wait_data { - rb_pid_t pid; - int status; -}; - -static int -wait_each(rb_pid_t pid, int status, struct wait_data *data) -{ - if (data->status != -1) return ST_STOP; - - data->pid = pid; - data->status = status; - return ST_DELETE; -} - -static int -waitall_each(rb_pid_t pid, int status, VALUE ary) -{ - rb_last_status_set(status, pid); - rb_ary_push(ary, rb_assoc_new(PIDT2NUM(pid), rb_last_status_get())); - return ST_DELETE; -} -#endif - /* [MG]:FIXME: I wasn't sure how this should be done, since ::wait() -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦