www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4354] New: Phobos should expose per-thread errno

http://d.puremagic.com/issues/show_bug.cgi?id=4354

           Summary: Phobos should expose per-thread errno
           Product: D
           Version: D1 & D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: torhu yahoo.com



core.stdc.errno should probably expose the per-thread errno, but it doesn't. 
Using the _errno() function instead of the errno macro in errno.c is one way to
fix it.  Or possibly defining _MT when compiling the C parts of phobos.

Test case below is only tested with DMD 2.047, but this issue is present in
both druntime and Phobos 1.x.  Build with -version=fix to see the fix in
action.

---
import core.thread;
import core.stdc.errno : EDOM;
import core.stdc.math;
import std.stdio;
version (fix) { }
else {
    import core.stdc.errno;
}

version (fix) {
    extern (C) int* _errno();
    int errno() { return *_errno(); }
    int errno(int v) { return *_errno() = v; }
}

void main()
{
    pow(-1, 1.5);  // sets EDOM (33)
    assert(errno == EDOM);

    Thread t = new Thread({
            assert(errno == 0);  // fails if using phobos errno
    });
    t.start();

    t.join();
    assert(errno == EDOM);
}
---

I stumpled across this when working on a D wrapper for a C library that uses
errno.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 20 2010