diff options
| author | Mike Pall <mike> | 2021-12-17 14:30:44 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2021-12-17 14:30:44 +0100 |
| commit | 1d20f33d2905db55fb7191076bbac10f570f9175 (patch) | |
| tree | d2154e218fcb6c623f68c20ad3838a85a254fa20 | |
| parent | 8b7ea5c1af6502c4ed051bb9b5ff795b8cceffc0 (diff) | |
| download | luajit-1d20f33d2905db55fb7191076bbac10f570f9175.tar.gz luajit-1d20f33d2905db55fb7191076bbac10f570f9175.tar.bz2 luajit-1d20f33d2905db55fb7191076bbac10f570f9175.zip | |
Windows: Fix binary output of jit.bcsave to stdout.
Thanks to erw7.
| -rw-r--r-- | src/jit/bcsave.lua | 13 |
1 files changed, 13 insertions, 0 deletions
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) | |||
| 60 | return check(io.open(name, mode)) | 60 | return check(io.open(name, mode)) |
| 61 | end | 61 | end |
| 62 | 62 | ||
| 63 | local function set_stdout_binary(ffi) | ||
| 64 | ffi.cdef[[int _setmode(int fd, int mode);]] | ||
| 65 | ffi.C._setmode(1, 0x8000) | ||
| 66 | end | ||
| 67 | |||
| 63 | ------------------------------------------------------------------------------ | 68 | ------------------------------------------------------------------------------ |
| 64 | 69 | ||
| 65 | local map_type = { | 70 | local map_type = { |
| @@ -125,6 +130,11 @@ local function bcsave_tail(fp, output, s) | |||
| 125 | end | 130 | end |
| 126 | 131 | ||
| 127 | local function bcsave_raw(output, s) | 132 | local function bcsave_raw(output, s) |
| 133 | if output == "-" and jit.os == "Windows" then | ||
| 134 | local ok, ffi = pcall(require, "ffi") | ||
| 135 | check(ok, "FFI library required to write binary file to stdout") | ||
| 136 | set_stdout_binary(ffi) | ||
| 137 | end | ||
| 128 | local fp = savefile(output, "wb") | 138 | local fp = savefile(output, "wb") |
| 129 | bcsave_tail(fp, output, s) | 139 | bcsave_tail(fp, output, s) |
| 130 | end | 140 | end |
| @@ -568,6 +578,9 @@ end | |||
| 568 | local function bcsave_obj(ctx, output, s) | 578 | local function bcsave_obj(ctx, output, s) |
| 569 | local ok, ffi = pcall(require, "ffi") | 579 | local ok, ffi = pcall(require, "ffi") |
| 570 | check(ok, "FFI library required to write this file type") | 580 | check(ok, "FFI library required to write this file type") |
| 581 | if output == "-" and jit.os == "Windows" then | ||
| 582 | set_stdout_binary(ffi) | ||
| 583 | end | ||
| 571 | if ctx.os == "windows" then | 584 | if ctx.os == "windows" then |
| 572 | return bcsave_peobj(ctx, output, s, ffi) | 585 | return bcsave_peobj(ctx, output, s, ffi) |
| 573 | elseif ctx.os == "osx" then | 586 | elseif ctx.os == "osx" then |
