夜行録 - 酔歩.net

日暮れて道遠し さらに夜道を行く もって夜行録と名付く

OSX eof() bug 問題

去年から悩んでいた OSX での eof() bug 問題だが、ちょっとは解決した。

ファイルシステムを疑って、 FAT の USB memory 上のファイルから読んでみたら正常動作するという…………。なにか変なのか?この HDD

症状は

  • OSX 10.5 + Developper Tools 3.1 (2.0) で
  • PGI の C++ コンパイラ pgcpp の 7.2-5 ないし 8.0.3 でコンパイルしたコードで
  • ファイルの途中で eof() が真を返してそれ以上読めなくなる。というもので
  • g++ 4.2 では同一コード、同一環境でファイルの最後まで正常に読める。

以下のような単純なソースを、 pgcpp, g++ でそれぞれコンパイルして実行すると以下の如し。入力は全部書いてないけど要するに行数一緒で桁数が違うだけ。で、gcc では正しい行数が出ているのに pgcpp では、どういうわけか結果が違う。

mymac{yagi(s004)}13795: cat ../A.cc
#include 

int main(void) {
  double A;
  unsigned long L=0;
  do {
    ++L;
    std::cin >> A ;
  } while (!std::cin.eof());
  std::cout << L << "\t" << A << std::endl;
}
mymac{yagi(s004)}13796: head ../Z?
==> ../Z1 <==
00.00
00.02
00.04
00.06
00.08
00.10
00.12
00.14
00.16
00.18

==> ../Z2 <==
0.000
0.020
0.040
0.060
0.080
0.100
0.120
0.140
0.160
0.180

==> ../Z3 <==
0.0000
0.0200
0.0400
0.0600
0.0800
0.1000
0.1200
0.1400
0.1600
0.1800
mymac{yagi(s004)}13797: tail ../Z?
==> ../Z1 <==
29.80
29.82
29.84
29.86
29.88
29.90
29.92
29.94
29.96
29.98

==> ../Z2 <==
29.800
29.820
29.840
29.860
29.880
29.900
29.920
29.940
29.960
29.980

==> ../Z3 <==
29.8000
29.8200
29.8400
29.8600
29.8800
29.9000
29.9200
29.9400
29.9600
29.9800
mymac{yagi(s004)}13798: pgcpp -v -o A_pgi ../A.cc

/opt/pgi/osx86-64/8.0-3/bin/pgcpp1 --nollalign -Dunix -D__unix -D__unix__ -D__LITTLE_ENDIAN__ -D__inline__= -Dosx86 -D__osx86 -D__osx86__ -D__APPLE__ -D__LP64__ -D__x86_64__ -D_M_IX86 -D__NO_MATH_INLINES -D__amd64__ -D__extension__= -D__SSE__ -D__MMX__ -D__SSE2__ -D__SSE3__ -D__SSSE3__ -D__PGI -D__signed__=signed -I/opt/pgi/osx86-64/8.0-3/include/CC -I/opt/pgi/osx86-64/8.0-3/include -I/usr/local/include -I/usr/lib/gcc/i686-apple-darwin9/4.0.1/include -I/usr/lib/gcc/i686-apple-darwin9/4.0.1/include -I/usr/include -q -o /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-/pgcppGN9lGRW4BlBI.il ../A.cc

/opt/pgi/osx86-64/8.0-3/bin/pgcpp2 ../A.cc -opt 1 -x 59 4 -x 119 0x10000010 -x 129 0x80 -x 19 0x400000 -x 119 0x40610400 -x 119 0x1000 -x 59 4 -x 129 0x10 -x 70 0x8000 -x 122 1 -x 120 0x80 -x 122 0x40 -x 123 0x1000 -x 127 21 -tp penryn-64 -y 80 0x40000000 -x 120 0x400 -x 120 0x1000 -astype 1 -fn ../A.cc -il /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-/pgcppGN9lGRW4BlBI.il -x 123 0x80000000 -x 123 4 -x 2 0x400 -x 119 0x20 -alwaysinline /opt/pgi/osx86-64/8.0-3/lib/libintrinsics.il 4 -x 120 0x200000 -cmdline '+pgcpp /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-/pgcppGN9lGRW4BlBI.il -v -o A_pgi' -asm /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-/pgcppGN9lGh2oLyRK.s
PGCC/x86 OSX 8.0-3: compilation successful

/usr/bin/as -arch x86_64 /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-/pgcppGN9lGh2oLyRK.s -o A.o
Action(ReadTIFile(./A.ti))

/usr/bin/ld /usr/lib/crt1.o /opt/pgi/osx86-64/8.0-3/lib/pgimainxx.o -arch x86_64 -L/opt/pgi/osx86-64/8.0-3/lib -L/usr/lib -L/usr/lib/gcc/i686-apple-darwin9/4.0.1/x86_64 -L/usr/lib/gcc/i686-apple-darwin9/4.0.1 A.o -o A_pgi -lstd -lcpp -lc -lnspgc -lpgc -lm -lgcc -lc -lgcc -lSystem
Unlinking /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-/pgcppGN9lGRW4BlBI.il
Unlinking /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-/pgcppGN9lGh2oLyRK.s
mymac{yagi(s004)}13799: for i in 1 2 3; ./A_pgi < ../Z$i
1024    20.46
920     18
766     15.3
mymac{yagi(s004)}13800: g++-4.2 -v -o A_gcc ../A.cc
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc_42/gcc_42-5566~1/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/usr/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-gxx-include-dir=/usr/include/c++/4.0.0 --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5566)
 /usr/libexec/gcc/i686-apple-darwin9/4.2.1/cc1plus -quiet -v -D__DYNAMIC__ ../A.cc -fPIC -quiet -dumpbase A.cc -mmacosx-version-min=10.5.6 -mtune=core2 -auxbase A -version -D__private_extern__=extern -o /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-//cc381FGj.s
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib/gcc/i686-apple-darwin9/4.2.1/../../../../i686-apple-darwin9/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.0.0
 /usr/include/c++/4.0.0/i686-apple-darwin9
 /usr/include/c++/4.0.0/backward
 /usr/lib/gcc/i686-apple-darwin9/4.2.1/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
GNU C++ version 4.2.1 (Apple Inc. build 5566) (i686-apple-darwin9)
        compiled by GNU C version 4.2.1 (Apple Inc. build 5566).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: cba5d8ae150572160e0e3741857019bd
 /usr/libexec/gcc/i686-apple-darwin9/4.2.1/as -arch i386 -force_cpusubtype_ALL -o /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-//cciFfvJU.o /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-//cc381FGj.s
 /usr/libexec/gcc/i686-apple-darwin9/4.2.1/collect2 -dynamic -arch i386 -macosx_version_min 10.5.6 -weak_reference_mismatches non-weak -o A_gcc -lcrt1.10.5.o -L/usr/lib/i686-apple-darwin9/4.2.1 -L/usr/lib/gcc/i686-apple-darwin9/4.2.1 -L/usr/lib/gcc/i686-apple-darwin9/4.2.1 -L/usr/lib/gcc/i686-apple-darwin9/4.2.1/../../../i686-apple-darwin9/4.2.1 -L/usr/lib/gcc/i686-apple-darwin9/4.2.1/../../.. /var/folders/Y7/Y7a45pZjESu3Ppsffq15hk+++TI/-Tmp-//cciFfvJU.o -lstdc++ -lgcc_s.10.5 -lgcc -lSystem
%                                                                               for i in 1 2 3; ./A_gcc < ../Z$i
mymac{yagi(s004)}13801: for i in 1 2 3; ./A_gcc < ../Z$i
1501    29.98
1501    29.98
1501    29.98
mymac{yagi(s004)}13802: uname -a
mymac.local 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386

こっちは USB メモリ上にファイルをコピーした場合の結果。なんなんだ?これ

mymac{yagi(s006)}14920: tail ../Z?
==> ../Z1 <==
29.80
29.82
29.84
29.86
29.88
29.90
29.92
29.94
29.96
29.98

==> ../Z2 <==
29.800
29.820
29.840
29.860
29.880
29.900
29.920
29.940
29.960
29.980

==> ../Z3 <==
29.8000
29.8200
29.8400
29.8600
29.8800
29.9000
29.9200
29.9400
29.9600
29.9800
mymac{yagi(s006)}14921: for i in 1 2 3; ./A_pgi < ../Z$i
1024    20.46
920     18
766     15.3
mymac{yagi(s006)}14922: cp ../Z[123] /Volumes/MY\ USB\ DISK/
mymac{yagi(s006)}14923: for i in 1 2 3; ./A_pgi < /Volumes/MY\ USB\ DISK/Z$i 
1501    29.98
1501    29.98
1501    29.98
mymac{yagi(s006)}14924: pwd
/Users/yagi/work/PGBUG/803
mymac{yagi(s006)}14925: mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local)
fdesc on /dev (fdesc, union)
map -hosts on /net (autofs, automounted)
map auto_home on /home (autofs, automounted)
/dev/disk1s1 on /Volumes/MY USB DISK (msdos, local, nodev, nosuid, noowners)
2009年02月10日 (Tue) - 19:50:00 - その他雑記 - 2959x - permalink
Karma points: 2. Do you like this article? [yes/no]