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

--- Comment #0 from 2010-06-20 17:51:39 PDT ---
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

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

    assert(errno == EDOM);

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

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

Reply via email to