From 18f7d60f0d15a18b1b97c4078d91e7ce9c49b22c Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Tue, 11 Sep 2012 19:39:15 -0700 Subject: [PATCH] Win64 fixes --- std/format.d | 15 ++++++++++++++- std/outbuffer.d | 42 +++++++++++++++++++++++++++--------------- std/stream.d | 9 ++++++++- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/std/format.d b/std/format.d index 6b3f16c59..5e49b1f46 100644 --- a/std/format.d +++ b/std/format.d @@ -30,7 +30,7 @@ version(unittest) { import core.exception; } -version (Windows) version (DigitalMars) +version (Win32) version (DigitalMars) { version = DigitalMarsC; } @@ -4656,6 +4656,8 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr) //doFormat(putc, (&valti)[0 .. 1], p); version(X86) argptr = p; + else version(Win64) + argptr = p; else version(X86_64) { __va_list va; @@ -4706,6 +4708,8 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr) //doFormat(putc, (&keyti)[0..1], pkey); version (X86) argptr = pkey; + else version (Win64) + argptr = pkey; else version (X86_64) { __va_list va; va.stack_args = pkey; @@ -4721,6 +4725,8 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr) //doFormat(putc, (&valti)[0..1], pvalue); version (X86) argptr = pvalue; + else version (Win64) + argptr = pvalue; else version (X86_64) { __va_list va2; va2.stack_args = pvalue; @@ -4874,6 +4880,8 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr) case Mangle.Tsarray: version (X86) putArray(argptr, (cast(TypeInfo_StaticArray)ti).len, cast()(cast(TypeInfo_StaticArray)ti).next); + else version (Win64) + putArray(argptr, (cast(TypeInfo_StaticArray)ti).len, cast()(cast(TypeInfo_StaticArray)ti).next); else putArray((cast(__va_list*)argptr).stack_args, (cast(TypeInfo_StaticArray)ti).len, cast()(cast(TypeInfo_StaticArray)ti).next); return; @@ -4973,6 +4981,11 @@ void doFormat(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr) s = tis.xtoString(argptr); argptr += (tis.tsize() + 3) & ~3; } + else version(Win64) + { + s = tis.xtoString(argptr); + argptr += (tis.tsize() + 3) & ~3; + } else version (X86_64) { void[32] parmn = void; // place to copy struct if passed in regs diff --git a/std/outbuffer.d b/std/outbuffer.d index 32730b2aa..5164d7753 100644 --- a/std/outbuffer.d +++ b/std/outbuffer.d @@ -262,7 +262,7 @@ class OutBuffer auto psize = buffer.length; for (;;) { - version(Win32) + version(Windows) { count = _vsnprintf(p,psize,f,args); if (count != -1) @@ -270,7 +270,7 @@ class OutBuffer psize *= 2; p = cast(char *) alloca(psize); // buffer too small, try again with larger size } - version(Posix) + else version(Posix) { count = vsnprintf(p,psize,f,args); if (count == -1) @@ -286,6 +286,10 @@ class OutBuffer +/ p = cast(char *) alloca(psize); // buffer too small, try again with larger size } + else + { + static assert(0); + } } write(cast(ubyte[]) p[0 .. count]); /+ @@ -301,21 +305,29 @@ class OutBuffer * Append output of C's printf() to internal buffer. */ - version (X86_64) void printf(string format, ...) { - va_list ap; - va_start(ap, __va_argsave); - vprintf(format, ap); - va_end(ap); - } - else - void printf(string format, ...) - { - va_list ap; - ap = cast(va_list)&format; - ap += format.sizeof; - vprintf(format, ap); + version (Win64) + { + va_list ap; + ap = cast(va_list)&format; + ap += format.sizeof; + vprintf(format, ap); + } + else version (X86_64) + { + va_list ap; + va_start(ap, __va_argsave); + vprintf(format, ap); + va_end(ap); + } + else + { + va_list ap; + ap = cast(va_list)&format; + ap += format.sizeof; + vprintf(format, ap); + } } /***************************************** diff --git a/std/stream.d b/std/stream.d index 4a384d7fd..fb39beab5 100644 --- a/std/stream.d +++ b/std/stream.d @@ -1164,7 +1164,14 @@ class Stream : InputStream, OutputStream { // writes data to stream using printf() syntax, // returns number of bytes written - version (X86_64) + version (Win64) + size_t printf(const(char)[] format, ...) { + va_list ap; + ap = cast(va_list) &format; + ap += format.sizeof; + return vprintf(format, ap); + } + else version (X86_64) size_t printf(const(char)[] format, ...) { va_list ap; va_start(ap, __va_argsave);