diff --git a/druntime/src/rt/dmain2.d b/druntime/src/rt/dmain2.d index 2da31743d755..6b71781b2c03 100644 --- a/druntime/src/rt/dmain2.d +++ b/druntime/src/rt/dmain2.d @@ -596,7 +596,7 @@ extern (C) void _d_print_throwable(Throwable t) void sink(in char[] s) scope nothrow { if (!s.length) return; - int swlen = MultiByteToWideChar( + const swlen = MultiByteToWideChar( CP_UTF8, 0, s.ptr, cast(int)s.length, null, 0); if (!swlen) return; @@ -604,7 +604,7 @@ extern (C) void _d_print_throwable(Throwable t) (this.len + swlen + 1) * WCHAR.sizeof); if (!newPtr) return; ptr = newPtr; - auto written = MultiByteToWideChar( + const written = MultiByteToWideChar( CP_UTF8, 0, s.ptr, cast(int)s.length, ptr+len, swlen); len += written; } @@ -622,10 +622,6 @@ extern (C) void _d_print_throwable(Throwable t) return _fdToHandle(fd); } - auto hStdErr = windowsHandle(fileno(stderr)); - CONSOLE_SCREEN_BUFFER_INFO sbi; - bool isConsole = GetConsoleScreenBufferInfo(hStdErr, &sbi) != 0; - // ensure the exception is shown at the beginning of the line, while also // checking whether stderr is a valid file int written = fprintf(stderr, "\n"); @@ -642,22 +638,22 @@ extern (C) void _d_print_throwable(Throwable t) // Avoid static user32.dll dependency for console applications // by loading it dynamically as needed - auto user32 = LoadLibraryW("user32.dll"); - if (user32) + if (auto user32 = LoadLibraryW("user32.dll")) { alias typeof(&MessageBoxW) PMessageBoxW; - auto pMessageBoxW = cast(PMessageBoxW) - GetProcAddress(user32, "MessageBoxW"); - if (pMessageBoxW) + if (auto pMessageBoxW = cast(PMessageBoxW) GetProcAddress(user32, "MessageBoxW")) pMessageBoxW(null, buf.get(), caption.get(), MB_ICONERROR); + FreeLibrary(user32); } - FreeLibrary(user32); caption.free(); buf.free(); } return; } - else if (isConsole) + auto hStdErr = windowsHandle(fileno(stderr)); + CONSOLE_SCREEN_BUFFER_INFO sbi = void; + const isConsole = GetConsoleScreenBufferInfo(hStdErr, &sbi) != 0; + if (isConsole) { WSink buf; formatThrowable(t, &buf.sink); @@ -665,10 +661,9 @@ extern (C) void _d_print_throwable(Throwable t) if (buf.ptr) { uint codepage = GetConsoleOutputCP(); - int slen = WideCharToMultiByte(codepage, 0, + const slen = WideCharToMultiByte(codepage, 0, buf.ptr, cast(int)buf.len, null, 0, null, null); - auto sptr = cast(char*)malloc(slen * char.sizeof); - if (sptr) + if (auto sptr = cast(char*)malloc(slen * char.sizeof)) { WideCharToMultiByte(codepage, 0, buf.ptr, cast(int)buf.len, sptr, slen, null, null); diff --git a/druntime/src/rt/sections_win64.d b/druntime/src/rt/sections_win64.d index 3ab656349d97..0a24e2483733 100644 --- a/druntime/src/rt/sections_win64.d +++ b/druntime/src/rt/sections_win64.d @@ -215,7 +215,7 @@ version (Shared) auto size = tlsdir.EndAddressOfRawData - tlsdir.StartAddressOfRawData + tlsdir.SizeOfZeroFill; if (conservative) - dg( beg, beg + size); + dg(beg, beg + size); else scanTLSPrecise(cast(uint*)&sec._tpSection[0], cast(uint*)&sec._tpSection[$], beg, dg); } @@ -435,8 +435,7 @@ void* initLibrary(void* mod) // (What? LoadLibrary() is a Windows API call, it shouldn't call rt_init().) if (mod is null) return mod; - gcSetFn gcSet = cast(gcSetFn) GetProcAddress(mod, "gc_setProxy"); - if (gcSet !is null) + if (auto gcSet = cast(gcSetFn) GetProcAddress(mod, "gc_setProxy")) { // BUG: Set proxy, but too late gcSet(gc_getProxy()); } @@ -453,8 +452,7 @@ void* initLibrary(void* mod) */ extern (C) int rt_unloadLibrary(void* ptr) { - gcClrFn gcClr = cast(gcClrFn) GetProcAddress(ptr, "gc_clrProxy"); - if (gcClr !is null) + if (auto gcClr = cast(gcClrFn) GetProcAddress(ptr, "gc_clrProxy")) gcClr(); return FreeLibrary(ptr) != 0; }