From 1d20f33d2905db55fb7191076bbac10f570f9175 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 17 Dec 2021 14:30:44 +0100 Subject: [PATCH] Windows: Fix binary output of jit.bcsave to stdout. Thanks to erw7. --- src/jit/bcsave.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua index ab13667a..bc959327 100644 --- a/src/jit/bcsave.lua +++ b/src/jit/bcsave.lua @@ -60,6 +60,11 @@ local function savefile(name, mode) return check(io.open(name, mode)) end +local function set_stdout_binary(ffi) + ffi.cdef[[int _setmode(int fd, int mode);]] + ffi.C._setmode(1, 0x8000) +end + ------------------------------------------------------------------------------ local map_type = { @@ -125,6 +130,11 @@ local function bcsave_tail(fp, output, s) end local function bcsave_raw(output, s) + if output == "-" and jit.os == "Windows" then + local ok, ffi = pcall(require, "ffi") + check(ok, "FFI library required to write binary file to stdout") + set_stdout_binary(ffi) + end local fp = savefile(output, "wb") bcsave_tail(fp, output, s) end @@ -568,6 +578,9 @@ end local function bcsave_obj(ctx, output, s) local ok, ffi = pcall(require, "ffi") check(ok, "FFI library required to write this file type") + if output == "-" and jit.os == "Windows" then + set_stdout_binary(ffi) + end if ctx.os == "windows" then return bcsave_peobj(ctx, output, s, ffi) elseif ctx.os == "osx" then