Bug 3298 – std.file.read on OSX: "Memory allocation failed"

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Mac OS X
Creation time
2009-09-03T17:24:00Z
Last change time
2015-06-09T01:26:46Z
Keywords
patch
Assigned to
andrei
Creator
michel.fortin

Attachments

IDFilenameSummaryContent-TypeSize
445fix_std_file_osx.diffPatch fixing std.file.read on OSXtext/plain3234

Comments

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
I can't see any trace of a recent change to std.file. The web interface doesn't have it either: http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/file.d Am I looking at the right place?
Comment #5 by andrei — 2009-09-06T12:28:10Z
(In reply to comment #4) > I can't see any trace of a recent change to std.file. The web interface doesn't > have it either: > > http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/file.d > > Am I looking at the right place? Sorry, checking mishap. Please try again.
Comment #6 by michel.fortin — 2009-09-06T13:43:40Z
Patched Phobos from SVN working fine, bug fixed. Thanks.