Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion std/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -2851,7 +2851,10 @@ unittest
ld = parse!real(s2);
assert(s2.empty);
x = *cast(longdouble *)&ld;
ld1 = strtold(s.ptr, null);
version (Win64)
ld1 = 0x1.FFFFFFFFFFFFFFFEp-16382L; // strtold currently mapped to strtod
else
ld1 = strtold(s.ptr, null);
x1 = *cast(longdouble *)&ld1;
assert(x1 == x && ld1 == ld);

Expand Down
4 changes: 4 additions & 0 deletions std/digest/sha.d
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ version(D_PIC)
{
// Do not use (Bug9378).
}
else version(Win64)
{
// wrong calling convention
}
else version(D_InlineAsm_X86)
{
private version = USE_SSSE3;
Expand Down
47 changes: 35 additions & 12 deletions std/format.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import std.algorithm, std.ascii, std.bitmanip, std.conv,
std.system, std.traits, std.typetuple,
std.utf;
version (Win64) {
import std.math : isnan;
import std.math : isnan, isInfinity;
}
version(unittest) {
import std.math;
Expand Down Expand Up @@ -1580,17 +1580,25 @@ if (is(FloatingPointTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
}
enforceFmt(std.algorithm.find("fgFGaAeEs", fs.spec).length,
"floating");

version (Win64)
{
if (isnan(val)) // snprintf writes 1.#QNAN
double tval = val; // convert early to get "inf" in case of overflow
string s;
if (isnan(tval))
s = "nan"; // snprintf writes 1.#QNAN
else if (isInfinity(tval))
s = val >= 0 ? "inf" : "-inf"; // snprintf writes 1.#INF

if (s.length > 0)
{
version(none)
{
return formatValue(w, "nan", f);
return formatValue(w, s, f);
}
else // FIXME:workaroun
{
auto s = "nan"[0 .. f.precision < $ ? f.precision : $];
s = s[0 .. f.precision < $ ? f.precision : $];
if (!f.flDash)
{
// right align
Expand All @@ -1609,6 +1617,8 @@ if (is(FloatingPointTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
}
}
}
else
alias val tval;
if (fs.spec == 's') fs.spec = 'g';
char[1 /*%*/ + 5 /*flags*/ + 3 /*width.prec*/ + 2 /*format*/
+ 1 /*\0*/] sprintfSpec = void;
Expand All @@ -1626,12 +1636,13 @@ if (is(FloatingPointTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
sprintfSpec[i] = 0;
//printf("format: '%s'; geeba: %g\n", sprintfSpec.ptr, val);
char[512] buf;

immutable n = snprintf(buf.ptr, buf.length,
sprintfSpec.ptr,
fs.width,
// negative precision is same as no precision specified
fs.precision == fs.UNSPECIFIED ? -1 : fs.precision,
val);
sprintfSpec.ptr,
fs.width,
// negative precision is same as no precision specified
fs.precision == fs.UNSPECIFIED ? -1 : fs.precision,
tval);
enforceFmt(n >= 0,
"floating point formatting failure");
put(w, buf[0 .. strlen(buf.ptr)]);
Expand Down Expand Up @@ -3276,6 +3287,11 @@ unittest
assert(stream.data == "1.67 -0XA.3D70A3D70A3D8P-3 nan",
stream.data);
}
else version (Win64)
{
assert(stream.data == "1.67 -0X1.47AE14P+0 nan",
stream.data);
}
else
{
assert(stream.data == "1.67 -0X1.47AE147AE147BP+0 nan",
Expand All @@ -3301,7 +3317,10 @@ unittest

formattedWrite(stream, "%a %A", 1.32, 6.78f);
//formattedWrite(stream, "%x %X", 1.32);
assert(stream.data == "0x1.51eb851eb851fp+0 0X1.B1EB86P+2");
version (Win64)
assert(stream.data == "0x1.51eb85p+0 0X1.B1EB86P+2");
else
assert(stream.data == "0x1.51eb851eb851fp+0 0X1.B1EB86P+2");
stream.clear();

formattedWrite(stream, "%#06.*f",2,12.345);
Expand Down Expand Up @@ -4981,11 +5000,13 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr)
int n;
version (Win64)
{
if(isnan(v)) // snprintf writes 1.#QNAN
if (isnan(v)) // snprintf writes 1.#QNAN
n = snprintf(fbuf.ptr, sl, "nan");
else if(isInfinity(v)) // snprintf writes 1.#INF
n = snprintf(fbuf.ptr, sl, v < 0 ? "-inf" : "inf");
else
n = snprintf(fbuf.ptr, sl, format.ptr, field_width,
precision, cast(double)v);
precision, cast(double)v);
}
else
n = snprintf(fbuf.ptr, sl, format.ptr, field_width,
Expand Down Expand Up @@ -5800,6 +5821,8 @@ unittest
//else
version (MinGW)
assert(s == "1.67 -0XA.3D70A3D70A3D8P-3 nan", s);
else version (Win64)
assert(s == "1.67 -0X1.47AE14P+0 nan", s);
else
assert(s == "1.67 -0X1.47AE147AE147BP+0 nan", s);

Expand Down
19 changes: 13 additions & 6 deletions std/math.d
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ version(unittest)

int ix;
int iy;
ix = sprintf(bufx.ptr, "%.*Lg", ndigits, x);
version(Win64)
alias double real_t;
else
alias real real_t;
ix = sprintf(bufx.ptr, "%.*Lg", ndigits, cast(real_t) x);
iy = sprintf(bufy.ptr, "%.*Lg", ndigits, cast(real_t) y);
assert(ix < bufx.length && ix > 0);
iy = sprintf(bufy.ptr, "%.*Lg", ndigits, y);
assert(ix < bufy.length && ix > 0);

return bufx[0 .. ix] == bufy[0 .. iy];
Expand Down Expand Up @@ -1827,9 +1831,12 @@ unittest
assert(feqrel(exp2(0.5L), SQRT2) >= real.mant_dig -1);
assert(exp2(8.0L) == 256.0);
assert(exp2(-9.0L)== 1.0L/512.0);
assert( core.stdc.math.exp2f(0.0f) == 1 );
assert( core.stdc.math.exp2 (0.0) == 1 );
assert( core.stdc.math.exp2l(0.0L) == 1 );
version(Win64) {} else // aexp2/exp2f/exp2l not implemented
{
assert( core.stdc.math.exp2f(0.0f) == 1 );
assert( core.stdc.math.exp2 (0.0) == 1 );
assert( core.stdc.math.exp2l(0.0L) == 1 );
}
}

unittest
Expand Down Expand Up @@ -3198,7 +3205,7 @@ long lrint(real x) @trusted pure nothrow
{
naked;
fld real ptr [RCX];
fistp 8[RSP];
fistp qword ptr 8[RSP];
mov RAX,8[RSP];
ret;
}
Expand Down
12 changes: 5 additions & 7 deletions std/process.d
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ unittest
auto env = ["foo" : "bar"];
assert (wait(spawnShell(cmd~redir, env)) == 0);
auto f = File(tmpFile, "a");
version(Win64) f.seek(0, SEEK_END); // MSVCRT probably seeks to the end when writing, not before
assert (wait(spawnShell(cmd, std.stdio.stdin, f, std.stdio.stderr, env)) == 0);
f.close();
auto output = std.file.readText(tmpFile);
Expand Down Expand Up @@ -1306,13 +1307,10 @@ void kill(Pid pid, int codeOrSignal)
version (Windows)
{
if (codeOrSignal < 0) throw new ProcessException("Invalid exit code");
version (Win32)
{
// On Windows XP, TerminateProcess() appears to terminate the
// *current* process if it is passed an invalid handle...
if (pid.osHandle == INVALID_HANDLE_VALUE)
throw new ProcessException("Invalid process handle");
}
// On Windows, TerminateProcess() appears to terminate the
// *current* process if it is passed an invalid handle...
if (pid.osHandle == INVALID_HANDLE_VALUE)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hit me for Win8/64, so I guess it happens on all Windows versions. Did you see it not killing the current process elsewhere?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally, GetCurrentProcess() returns 0xFFFFFFFF, which is basically INVALID_HANDLE_VALUE, so that's a "feature".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, calling TerminateProcess with INVALID_HANDLE_VALUE is a stupid idea to start with. I guess the case that was supposed to be solved was that the process might have died without pid.osHandle being updated, but the handle is probably still valid then.

throw new ProcessException("Invalid process handle");
if (!TerminateProcess(pid.osHandle, codeOrSignal))
throw ProcessException.newFromLastError();
}
Expand Down
17 changes: 13 additions & 4 deletions std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ $(D rawRead) always reads in binary mode on Windows.
import std.exception : enforce, errnoEnforce;

enforce(buffer.length, "rawRead must take a non-empty buffer");
version(Win32)
version(Windows)
{
immutable fd = ._fileno(_p.handle);
immutable mode = ._setmode(fd, _O_BINARY);
Expand Down Expand Up @@ -737,7 +737,6 @@ Throws: $(D ErrnoException) if the file is not opened or if the call to $(D fwri
_name, "'"));
}

version(Win64) {} else
unittest
{
static import std.file;
Expand Down Expand Up @@ -776,7 +775,6 @@ Throws: $(D Exception) if the file is not opened.
}
}

version(Win64) {} else
unittest
{
static import std.file;
Expand Down Expand Up @@ -1769,8 +1767,19 @@ the contents may well have changed).
testTerm("bob\r\nmarge\r\nsteve\r\n", ["bob\r\n", "marge\r\n", "steve\r\n"],
KeepTerminator.yes, "\r\n", false);
testTerm("sue\r", ["sue\r"], KeepTerminator.yes, '\r', false);
}

auto file = File.tmpfile();
unittest
{
version(Win64)
{
/* the C function tmpfile doesn't seem to work, even when called from C */
auto deleteme = testFilename();
auto file = File(deleteme, "w+");
scope(success) std.file.remove(deleteme);
}
else
auto file = File.tmpfile();
file.write("1\n2\n3\n");

// bug 9599
Expand Down
11 changes: 1 addition & 10 deletions unittest.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
version(Win64) {}
else
{

public import std.base64;
public import std.compiler;
public import std.concurrency;
Expand Down Expand Up @@ -62,13 +60,7 @@ public import std.digest.crc;
public import std.digest.sha;
public import std.digest.md;

}

int main(char[][] args)
{

version(Win64) {}
else
{
// Bring in unit test for module by referencing function in it

Expand Down Expand Up @@ -132,6 +124,5 @@ else
auto crc = crc32Of("hello");
auto string = toHexString(crc);
puts("Success!");
}
return 0;
}
36 changes: 18 additions & 18 deletions win64.mak
Original file line number Diff line number Diff line change
Expand Up @@ -404,30 +404,30 @@ UNITTEST_OBJS= unittest1.obj unittest2.obj unittest2a.obj \
unittest7.obj

unittest : $(LIB)
$(DMD) $(UDFLAGS) -c -ofunittest1.obj $(SRC_STD_1_HEAVY)
$(DMD) $(UDFLAGS) -c -ofunittest2.obj $(SRC_STD_2_HEAVY)
$(DMD) $(UDFLAGS) -c -ofunittest2a.obj $(SRC_STD_2a_HEAVY)
$(DMD) $(UDFLAGS) -c -ofunittestM.obj $(SRC_STD_math)
$(DMD) $(UDFLAGS) -c -ofunittest3.obj $(SRC_STD_3)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest1.obj $(SRC_STD_1_HEAVY)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest2.obj $(SRC_STD_2_HEAVY)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest2a.obj $(SRC_STD_2a_HEAVY)
$(DMD) $(UDFLAGS) -c -unittest -ofunittestM.obj $(SRC_STD_math)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest3.obj $(SRC_STD_3)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest3a.obj $(SRC_STD_3a)
$(DMD) $(UDFLAGS) -c -ofunittest3b.obj $(SRC_STD_3b)
$(DMD) $(UDFLAGS) -c -ofunittest3c.obj $(SRC_STD_3c)
$(DMD) $(UDFLAGS) -c -ofunittest4.obj $(SRC_STD_4)
$(DMD) $(UDFLAGS) -c -ofunittest5.obj $(SRC_STD_5_HEAVY)
$(DMD) $(UDFLAGS) -c -ofunittest6a.obj $(SRC_STD_6a)
$(DMD) $(UDFLAGS) -c -ofunittest6b.obj $(SRC_STD_6b)
$(DMD) $(UDFLAGS) -c -ofunittest6c.obj $(SRC_STD_6c)
$(DMD) $(UDFLAGS) -c -ofunittest6d.obj $(SRC_STD_6d)
$(DMD) $(UDFLAGS) -c -ofunittest6e.obj $(SRC_STD_6e)
$(DMD) $(UDFLAGS) -c -ofunittest6h.obj $(SRC_STD_6h)
$(DMD) $(UDFLAGS) -c -ofunittest6i.obj $(SRC_STD_6i)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest3b.obj $(SRC_STD_3b)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest3c.obj $(SRC_STD_3c)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest4.obj $(SRC_STD_4)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest5.obj $(SRC_STD_5_HEAVY)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6a.obj $(SRC_STD_6a)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6b.obj $(SRC_STD_6b)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6c.obj $(SRC_STD_6c)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6d.obj $(SRC_STD_6d)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6e.obj $(SRC_STD_6e)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6h.obj $(SRC_STD_6h)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6i.obj $(SRC_STD_6i)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6f.obj $(SRC_STD_6f)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6g.obj $(SRC_STD_6g)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6j.obj $(SRC_STD_6j)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest6k.obj $(SRC_STD_6k)
$(DMD) $(UDFLAGS) -c -ofunittest7.obj $(SRC_STD_7)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest7.obj $(SRC_STD_7)
$(DMD) $(UDFLAGS) -c -unittest -ofunittest8.obj $(SRC_TO_COMPILE_NOT_STD)
$(DMD) $(UDFLAGS) -unittest unittest.d $(UNITTEST_OBJS) \
$(DMD) $(UDFLAGS) -L/OPT:NOICF -unittest unittest.d $(UNITTEST_OBJS) \
$(ZLIB) $(DRUNTIMELIB)
.\unittest.exe

Expand Down