www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14318] New: Shared library stdio not loadded

https://issues.dlang.org/show_bug.cgi?id=14318

          Issue ID: 14318
           Summary: Shared library stdio not loadded
           Product: D
           Version: D2
          Hardware: All
                OS: Windows
            Status: NEW
          Severity: trivial
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: alphaglosined gmail.com

Compiler: dmd 2.067-rc1 but present in 2.066.1, I expect it to be present in
basically every D compiler as it is an edge case.

Basically (haven't tested on posix ext.) on Windows if you load a D shared
library it will have not loaded stdin/stdout/stderr.

Here is my "fix" for it. Really if the host binary is also D it should auto set
these values. Otherwise this should be the default behaviour.

void fixStandardIO() {
    import std.stdio: stdin, stdout, stderr, File;
    // Loads up new instances of stdin/stdout/stderr if they have not been
properly created

    if (stdin.error || stdout.error || stderr.error) {
        version(Windows) {
            import core.sys.windows.windows: GetStdHandle, STD_INPUT_HANDLE,
STD_OUTPUT_HANDLE, STD_ERROR_HANDLE;

            File nstdin;
            nstdin.windowsHandleOpen(GetStdHandle(STD_INPUT_HANDLE), ['r']);
            stdin = nstdin;

            File nstdout;
            nstdout.windowsHandleOpen(GetStdHandle(STD_OUTPUT_HANDLE), ['w']);
            stdout = nstdout;

            File nstderr;
            nstderr.windowsHandleOpen(GetStdHandle(STD_ERROR_HANDLE), ['w']);
            stderr = nstderr;
        }
    }
}

--
Mar 22 2015