www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23196] New: File constructor fails to preallocate oom error,


          Issue ID: 23196
           Summary: File constructor fails to preallocate oom error, uses
                    exception instead
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: su+dlangissues angel-island.zone

std.stdio.File uses enforce incorrectly in two ways. first, on encountering
OOM, it throws an exception rather than an error; and second, it fails to
preallocate that error.

offending code here:

package this(FILE* handle, string name, uint refs = 1, bool isPopened = false)


        import core.stdc.stdlib : malloc;

        import std.exception : enforce;


        _p = cast(Impl*) enforce(malloc(Impl.sizeof), "Out of memory");

        initImpl(handle, name, refs, isPopened);


as an aside, i believe fixing this may allow the function to be labelled with
 nogc nothrow.

Jun 19 2022