[#28337] constant look up order in CVS HEAD — Yukihiro Matsumoto <matz@...>

まつもと ゆきひろです

15 messages 2006/02/18
[#28338] Re: constant look up order in CVS HEAD — Tanaka Akira <akr@...17n.org> 2006/02/19

In article <1140229116.805371.31930.nullmailer@x31.priv.netlab.jp>,

[#28341] Re: constant look up order in CVS HEAD — GOTOU Yuuzou <gotoyuzo@...> 2006/02/19

In message <87lkw8xfay.fsf@m17n.org>,

[#28342] Re: constant look up order in CVS HEAD — Yukihiro Matsumoto <matz@...> 2006/02/19

まつもと ゆきひろです

[ruby-dev:28373] Re: ruby_1_8 broken?

From: "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>
Date: 2006-02-23 03:58:44 UTC
List: ruby-dev #28373
山本です。

>C_ALLOCA は定義されていないようです。
>一応 C++Builder にデバッガがついているんですが、どうもうまく
>使えません。とりあえず、最適化を切ると make できるようになる
>ことはわかりました。

まず、CodeGuard で

Error 00001. 0x310000 (スレッド 0x0618):
パラメータ不正: 関数に不正なファイル/パイプ ストリーム (0x32594DB0)
 が渡されました。
fileno(0x32594DB0) 

呼び出し履歴:
   0x004011D0(=z.exe:0x01:0001D0)
   0x3256E7DA(=CC3250.DLL:0x01:06D7DA)

みたいなエラーが出ていたので調べてみると、次のコードがクラッシュする
ことに気づきました。(とはいえ、クラッシュするのは CodeGuard を ON に
したときですが)

#include <stdio.h>
#include <windows.h>
#include <io.h>
#include <fcntl.h>

int main()
{
    HANDLE r, w;
    int h;
    FILE *f;

    if (CreatePipe(&r, &w, NULL, 2048))
    {
	puts("CreatePipe OK");

	if ((h = _open_osfhandle((long)r, O_RDONLY)) != -1)
	{
	    if ((f = _fdopen(h, "r")) != NULL)
	    {
		printf("%p %d\n", f, fileno(f));

		fclose(f);
	    }
	}

	CloseHandle(w);

	CloseHandle(r);
    }
}


つまりパイプ(もしかするとソケットも)_fdopen を使う方法が
bcc32 ではうまくいってなかったということでしょうか・・・

そういえば HEAD はビルドできるんですよね。stdio を捨てたから?

とりあえずこうするとこのエラーは消えました。(正しい処置かどうかは不明)

Index: io.c
===================================================================
RCS file: /src/ruby/io.c,v
retrieving revision 1.246.2.97
diff -u -w -b -p -r1.246.2.97 io.c
--- io.c	14 Feb 2006 02:23:33 -0000	1.246.2.97
+++ io.c	23 Feb 2006 01:43:44 -0000
@@ -2899,7 +2899,12 @@ pipe_open(pstr, pname, mode)
     int modef = rb_io_mode_flags(mode);
     OpenFile *fptr;
 
-#if defined(DJGPP) || defined(__human68k__) || defined(__VMS)
+#if defined(DJGPP) || defined(__human68k__) || defined(__VMS) || defined(__BORLANDC__)
+
+#if defined(__BORLANDC__)
+#define popen _popen
+#endif
+
     FILE *f;
 
     if (!pname) pname = StringValuePtr(pstr);
Index: win32/win32.c
===================================================================
RCS file: /src/ruby/win32/win32.c,v
retrieving revision 1.103.2.43
diff -u -w -b -p -r1.103.2.43 win32.c
--- win32/win32.c	14 Feb 2006 05:03:16 -0000	1.103.2.43
+++ win32/win32.c	23 Feb 2006 02:38:08 -0000
@@ -3429,6 +3429,11 @@ rb_w32_fclose(FILE *fp)
     if (fflush(fp)) return -1;
     if (!is_socket(sock)) {
 	UnlockFile((HANDLE)sock, 0, 0, LK_LEN, LK_LEN);
+#ifdef __BORLANDC__
+	if (GetFileType((HANDLE)sock) == FILE_TYPE_PIPE) {
+	    return _pclose(fp);
+	}
+#endif
 	return fclose(fp);
     }
     _set_osfhnd(fd, (SOCKET)INVALID_HANDLE_VALUE);



しかし、このパッチを当てても本来のエラーは消えません。その後、下のスクリプトでも
おかしくなることがわかりました。最適化を切ると問題なく動きます。

a = {}
1.times do
# a["foo"] ||= proc { puts "boo" }.call # infinite loop (output "boo" forever)
  a["foo"] ||= 3                        # unexpected throw
end

また bcc32 の最適化バグなんでしょうか・・・


In This Thread