Summary: std.stdio.File and std.typecons.Unique not GC-heap
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from Michel Fortin <> 2010-08-11 
15:28:53 EDT ---
Just took a look at Phobos for struct destructors. Both std.stdio.File and
std.typeconst.Unique seem unsafe to store anywhere in the GC heap (in an array
or in a class).

For std.stdio.File, it's because because the destructor assumes the
GC-allocated Impl instance can be dereferenced (which is a risky bet during the
collection that the GC will deallocate things in the "right" order):

    this(string name, in char[] stdioOpenmode = "rb")
        p = new Impl(errnoEnforce(.fopen(name, stdioOpenmode),
                        "Cannot open file `"~name
                        ~"' in mode `"~stdioOpenmode.idup~"'"),
                1, name);

        if (!p) return;
        // @@@BUG@@@ These lines prematurely close the file
        //printf("Destroying file `%s' with %d refs\n", toStringz(,
        if (p.refs == 1) close;
        else --p.refs;

In struct std.typecons.Unique(T), unique calls delete on the object it
references, but since that object is in the GC heap the same problem arises: it
might already have been deallocated:

        writeln("Unique destructor of ", (_p is null)? null: _p);
        delete _p;
        _p = null;

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to