zig icon indicating copy to clipboard operation
zig copied to clipboard

send a friendly bug report to wine related to FillConsoleOutputAttribute returning InvalidHandle

Open andrewrk opened this issue 5 years ago • 4 comments

[nix-shell:~/Downloads/zig/build]$ ./zig test ../test/stage1/behavior.zig -target i386-windows-msvc
Created /home/andy/Downloads/zig/build/zig-cache/o/McIyD3Bm3f2jqnD53lAAfZKU-VZa5xY2iE0HA8xJQXJH_WEcw1-0xa3kBwVYa6uL/test.exe but skipping execution because it is non-native.

[nix-shell:~/Downloads/zig/build]$ wine /home/andy/Downloads/zig/build/zig-cache/o/McIyD3Bm3f2jqnD53lAAfZKU-VZa5xY2iE0HA8xJQXJH_WEcw1-0xa3kBwVYa6uL/test.exe
Test [1/926] behavior.align.test "global variable alignment"...reached unreachable code
/home/andy/Downloads/zig/lib/std/progress.zig:170:36: 0x4781c7 in std.progress.Progress::std.progress.Progress.refresh (test.obj)
Panicked during a panic. Aborting.

The code in question is:

                if (windows.kernel32.FillConsoleOutputAttribute(
                    file.handle,
                    info.wAttributes,
                    fill_chars,
                    cursor_pos,
                    &written,
                ) != windows.TRUE) unreachable;

It's hitting the unreachable there. GetLastError() is returning "invalid handle".

cc @LemonBoy cc @alexnask

andrewrk avatar May 01 '20 17:05 andrewrk

Happens for -target x86_64-windows-msvc as well.

andrewrk avatar May 01 '20 19:05 andrewrk

If the code works under Windows the problem is in Wine implementation of the terminal API

LemonBoy avatar May 01 '20 19:05 LemonBoy

The code works on windows in cmd.exe, ConEmu and the git bash console for both targets, not sure why wine fails.

alexnask avatar May 01 '20 19:05 alexnask

Can no longer reproduce with the following code:

// from https://github.com/ziglang/zig/blob/2bae94280058f23ba44dc3857e2b551f5894e1cb/lib/std/progress.zig
const std = @import("std");
const windows = std.os.windows;

pub fn main() !void {
    const file = std.io.getStdErr();

    var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
    if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE)
        unreachable;

    var cursor_pos = windows.COORD{
        .X = info.dwCursorPosition.X,
        .Y = info.dwCursorPosition.Y,
    };

    if (cursor_pos.X < 0)
        cursor_pos.X = 0;

    const fill_chars: windows.DWORD = @intCast(info.dwSize.X - cursor_pos.X);

    var written: windows.DWORD = undefined;
    if (windows.kernel32.FillConsoleOutputAttribute(
        file.handle,
        info.wAttributes,
        fill_chars,
        cursor_pos,
        &written,
    ) != windows.TRUE) return error.OhNo;
}

This works fine now under wine-9.12.

tau-dev avatar Jul 15 '24 08:07 tau-dev