www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3298] New: std.file.read on OSX: "Memory allocation failed"

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3298

           Summary: std.file.read on OSX: "Memory allocation failed"
           Product: D
           Version: 2.032
          Platform: x86_64
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: michel.fortin michelf.com


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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 03 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3298






17:28:35 PDT ---
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! */
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 03 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3298






04:14:33 PDT ---
Created an attachment (id=445)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 04 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3298


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 06 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3298


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED



09:06:42 PDT ---
Please get from svn and test to make sure I pasted it right. Thanks!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 06 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3298




15:14:58 EDT ---
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?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 06 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3298




12:28:10 PDT ---

 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 06 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3298




16:43:40 EDT ---
Patched Phobos from SVN working fine, bug fixed. Thanks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 06 2009