Comment #0 by michel.fortin — 2009-09-03T17:24:51Z
In almost all cases, calling std.file.read a second time I throws a "Memory Allocation Failed" error and the program exits. This simple program (that prints itself) fails on my OS X machine at the second call to read.
import std.file : read;
import std.stdio : writeln;
int main(string[] args)
{
scope(success) writeln("Done");
scope(failure) writeln("Failure");
writeln(read(__FILE__)); // works
writeln(read(__FILE__)); // error
return 0;
}
Debugging a little, I find that "fstat64(fd, &statbuf)" returns an gigantic file size (more than 1 Go), which then gets passed to GC.malloc. So it seems that fstat64 doesn't work correctly on Mac OS X, or more likely the layout of struct_stat64 may be different on Mac OS X and this has not been taken into account in the declaration.
Comment #1 by michel.fortin — 2009-09-03T17:28:35Z
It looks like using this struct definition for "struct_stat64" on OSX fixes the problem.
struct struct_stat64 // distinguish it from the stat() function
{
uint st_dev; /// device
ushort st_mode;
ushort st_nlink; /// link count
ulong st_ino; /// file serial number
uint st_uid; /// user ID of file's owner
uint st_gid; /// user ID of group's owner
uint st_rdev; /// if device then device number
int st_atime;
uint st_atimensec;
int st_mtime;
uint st_mtimensec;
int st_ctime;
uint st_ctimensec;
int st_birthtime;
uint st_birthtimensec;
ulong st_size;
long st_blocks; /// number of allocated 512 byte blocks
int st_blksize; /// optimal I/O block size
ulong st_ino64;
uint st_flags;
uint st_gen;
int st_lspare; /* RESERVED: DO NOT USE! */
long st_qspare[2]; /* RESERVED: DO NOT USE! */
}
Comment #2 by michel.fortin — 2009-09-04T04:14:33Z
Created attachment 445
Patch fixing std.file.read on OSX
Add a definition for struct_stat64 with the correct layout for OSX. This patch probably fix other functions in std.file relying on struct_stat64.
Comment #3 by andrei — 2009-09-06T09:06:42Z
Please get from svn and test to make sure I pasted it right. Thanks!
Comment #4 by michel.fortin — 2009-09-06T12:14:58Z