How do I call std_stdio_static_this() in std.stdio from a dynamically loaded shared library (osx) ?

I need to do this in my scenario:
1) main program is launched
2) dynamic library is created
3) dynamic library is loaded and a function from it is called
4) everything works fine until a writeln(0) is called from a function inside the dynamic lib, at which point it crashes. But by calling std_stdio_static_this2 (see below) BEFORE any call to writeln (and similar functions), everything works fine.

When I call std_stdio_static_this from another module, I'm pretty sure that code doesn't get called, because when I add a printf or assert(0) statement inside std_stdio_static_this, nothing happens.

My current (working!) workaround is shown below, but I was hoping for a solution that didn't involve modifying std.stdio.

----
void std_stdio_static_this2(T=void)()
{
    //copy contents of std_stdio_static_this() function here:
//putting assert(0); here WILL crash, as expected; but it won't if the signature is std_stdio_static_this2().
    //Bind stdin, stdout, stderr
    __gshared File.Impl stdinImpl;
    stdinImpl.handle = core.stdc.stdio.stdin;
    .stdin.p = &stdinImpl;
    // stdout
    __gshared File.Impl stdoutImpl;
    stdoutImpl.handle = core.stdc.stdio.stdout;
    .stdout.p = &stdoutImpl;
    // stderr
    __gshared File.Impl stderrImpl;
    stderrImpl.handle = core.stdc.stdio.stderr;
    .stderr.p = &stderrImpl;
}
----





Reply via email to