From: matz@... (Yukihiro Matsumoto) Date: 1997-09-09T18:00:26+09:00 Subject: [ruby-list:4247] Re: ruby-tk on Windows まつもと ゆきひろです In message "[ruby-list:4246] Re: ruby-tk on Windows" on 97/09/09, KIMURA Koichi writes: |木村です。 |ところでまつもとさんのメイルにあった | | In [ruby-list:4244] | |> * popenを使っている実装では終了時にpcloseを呼ぶ | |これは、rubyインタープリターがpcloseを呼んでくれる。という |ことですか? |#なんとなくそう読めてしまうので… そうです.いやあ,言ってみるもんだ.できてしまった. 全然テストしていないコードだと以下のような感じです # ruby-devのノリだな --- io.c~ Tue Sep 9 16:38:23 1997 +++ io.c Tue Sep 9 18:03:55 1997 @@ -782,2 +782,42 @@ #if defined (NT) || defined(DJGPP) +static struct pipe_list { + OpenFile *fptr; + struct pipe_list *next; +} *pipe_list; + +static void +pipe_add_fptr(fptr) + OpenFile *fptr; +{ + struct pipe_list *list; + + list = ALLOC(struct pipe_list); + list->fptr = fptr; + list->next = pipe_list; + pipe_list = list; +} + +static void +pipe_del_fptr(fptr) + OpenFile *fptr; +{ + struct pipe_list *list = pipe_list; + struct pipe_list *tmp; + + if (list->fptr == fptr) { + pipe_list = list->next; + return; + } + + while (list->next) { + if (list->next->fptr == fptr) { + tmp = list->next; + list->next = list->next->next; + free(tmp); + return; + } + list = list->next; + } +} + static void @@ -793,2 +833,19 @@ fptr->f = fptr->f2 = NULL; + pipe_del_fptr(fptr); +} + +static void +pipe_fptr_atexit() +{ + struct pipe_list *list = pipe_list; + + while (list) { + if (list->fptr->f != NULL) { + pclose(list->fptr->f); + } + if (list->fptr->f2 != NULL) { + pclose(list->fptr->f2); + } + list = list->next; + } } @@ -2204,2 +2261,6 @@ Init_File(); + +#if defined (NT) || defined(DJGPP) + atexit(pipe_fptr_atexit); +#endif }