From 57374de4a119558fd1eed8e4d7dbc16dccf9ea88 Mon Sep 17 00:00:00 2001 From: erw7 Date: Fri, 17 Dec 2021 02:31:28 +0900 Subject: [PATCH] Fix output of jit.bcsave to stdout on Windows --- src/jit/bcsave.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua index 73654297..0970c924 100644 --- a/src/jit/bcsave.lua +++ b/src/jit/bcsave.lua @@ -56,6 +56,17 @@ local function savefile(name, mode) return check(io.open(name, mode)) end +local function set_stdout_mode() + local ok, ffi = pcall(require, "ffi") + check(ok, "FFI library is required to write to stdout on this platform") + local FD_STDOUT = 1 + local O_BINARY = 0x8000 + ffi.cdef[[ + int _setmode(int fd, int mode); + ]] + ffi.C._setmode(FD_STDOUT, O_BINARY) +end + ------------------------------------------------------------------------------ local map_type = { @@ -587,10 +598,16 @@ local function bcsave(ctx, input, output) ctx.type = t end if t == "raw" then + if output == "-" and ctx.os == "windows" then + set_stdout_mode() + end bcsave_raw(output, s) else if not ctx.modname then ctx.modname = detectmodname(input) end if t == "obj" then + if output == "-" and ctx.os == "windows" then + set_stdout_mode() + end bcsave_obj(ctx, output, s) else bcsave_c(ctx, output, s)