From: Katsuyuki Komatsu Date: 2000-02-17T20:03:42+09:00 Subject: [ruby-dev:9250] Re: RubyCRT.dll (Re: xmalloc() in Windows) 小松です。 In the message of [ruby-dev:9240] Re: RubyCRT.dll (Re: xmalloc() in Windows) on 2000/2/17 11:17 WATANABE Hirofumi wrote: >:MSVCRT の内部構造まで必要とする理由はなんなのでしょうか? > >バグがあるからです. >Perl の win32/win32.c Perlの方のO_NOINHERITの対応も入れた方がいいでしょうね。 バグ以外だと、struct OpenFileにFILE *fとFILE *f2があって、 同じソケットハンドルを指させる必要があるというのも関係しています。 >http://www.perl.com/CPAN/authors/id/D/DO/DOUGL/PerlCRT-README-2.05.txt >ついでにここに書いてある patch もあてたほうがいいかもしれない. そうですね…… 入れましたが、95が入っているマシンがないや。 以下は、RubyCRT.dllを導入するためのwin32.{h,c}の変更です。 # mypopen(), getcwd()のバグフィックスも入ってますが。 Ruby 1.4.4にもそのまま適応可能です。 Thu Feb 17 19:09:05 2000 Katsuyuki Komatsu * win32/win32.c (mypopen): don't close handle if it is not assigned. * win32/win32.c (my_open_osfhandle): support O_NOINHERIT flag. * win32/win32.c (win32_getcwd): rename getcwd to win32_getcwd in order to avoid using the C/C++ runtime DLL's getcwd. Use CharNext() to process directory name. * win32/win32.h: map getcwd to win32_getcwd. diff -ru2p ruby-1.5.2.dist/win32/win32.c ruby-1.5.2/win32/win32.c --- ruby-1.5.2.dist/win32/win32.c Tue Feb 1 12:12:21 2000 +++ ruby-1.5.2/win32/win32.c Thu Feb 17 19:09:05 2000 @@ -547,13 +547,12 @@ mypopen (char *cmd, char *mode) free(lpCmd2); - CloseHandle(aProcessInformation.hThread); - if (!fRet) { CloseHandle(hInFile); CloseHandle(hOutFile); - CloseHandle(aProcessInformation.hProcess); return NULL; } + CloseHandle(aProcessInformation.hThread); + if (reading) { fd = _open_osfhandle((long)hInFile, (_O_RDONLY | pipemode)); @@ -1542,5 +1541,5 @@ typedef struct { } ioinfo; -EXTERN_C ioinfo * __pioinfo[]; +EXTERN_C _CRTIMP ioinfo * __pioinfo[]; #define IOINFO_L2E 5 @@ -1550,4 +1549,5 @@ EXTERN_C ioinfo * __pioinfo[]; #define FOPEN 0x01 /* file handle open */ +#define FNOINHERIT 0x10 /* file handle opened O_NOINHERIT */ #define FAPPEND 0x20 /* file handle opened O_APPEND */ #define FDEV 0x40 /* file handle refers to device */ @@ -1569,4 +1569,7 @@ my_open_osfhandle(long osfhandle, int fl fileflags |= FTEXT; + if (flags & O_NOINHERIT) + fileflags |= FNOINHERIT; + /* attempt to allocate a C Runtime file handle */ if ((fh = _alloc_osfhnd()) == -1) { @@ -2204,5 +2207,5 @@ gettimeofday(struct timeval *tv, struct char * -getcwd(buffer, size) +win32_getcwd(buffer, size) char *buffer; int size; @@ -2219,5 +2222,5 @@ getcwd(buffer, size) } - for (bp = buffer; *bp != '\0'; bp++) { + for (bp = buffer; *bp != '\0'; bp = CharNext(bp)) { if (*bp == '\\') { *bp = '/'; diff -ru2p ruby-1.5.2.dist/win32/win32.h ruby-1.5.2/win32/win32.h --- ruby-1.5.2.dist/win32/win32.h Wed Jan 5 13:37:27 2000 +++ ruby-1.5.2/win32/win32.h Thu Feb 17 19:09:05 2000 @@ -388,4 +388,9 @@ extern char *mystrerror(int); #define get_osfhandle myget_osfhandle +#ifdef getcwd +#undef getcwd +#endif +#define getcwd win32_getcwd + #ifdef getenv #undef getenv -- 小松克行 / Katsuyuki Komatsu