Apply and update LuaJIT patches
This commit is contained in:
parent
541a9ad590
commit
896ede12f3
4 changed files with 55 additions and 10 deletions
30
vendor/luajit/src/lib_io.c
vendored
30
vendor/luajit/src/lib_io.c
vendored
|
@ -24,6 +24,16 @@
|
||||||
#include "lj_ff.h"
|
#include "lj_ff.h"
|
||||||
#include "lj_lib.h"
|
#include "lj_lib.h"
|
||||||
|
|
||||||
|
#if LJ_TARGET_WINDOWS
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
static int widen(const char *in, wchar_t *out)
|
||||||
|
{
|
||||||
|
return MultiByteToWideChar(CP_UTF8, 0, in, -1, out, MAX_PATH);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Userdata payload for I/O file. */
|
/* Userdata payload for I/O file. */
|
||||||
typedef struct IOFileUD {
|
typedef struct IOFileUD {
|
||||||
FILE *fp; /* File handle. */
|
FILE *fp; /* File handle. */
|
||||||
|
@ -82,7 +92,15 @@ static IOFileUD *io_file_open(lua_State *L, const char *mode)
|
||||||
{
|
{
|
||||||
const char *fname = strdata(lj_lib_checkstr(L, 1));
|
const char *fname = strdata(lj_lib_checkstr(L, 1));
|
||||||
IOFileUD *iof = io_file_new(L);
|
IOFileUD *iof = io_file_new(L);
|
||||||
|
#if LJ_TARGET_WINDOWS
|
||||||
|
wchar_t wfname[MAX_PATH];
|
||||||
|
wchar_t wmode[MAX_PATH];
|
||||||
|
if (!widen(fname, wfname) || !widen(mode, wmode))
|
||||||
|
luaL_argerror(L, 1, lj_str_pushf(L, "%s: failed to convert path to utf-16", fname));
|
||||||
|
iof->fp = _wfopen(wfname, wmode);
|
||||||
|
#else
|
||||||
iof->fp = fopen(fname, mode);
|
iof->fp = fopen(fname, mode);
|
||||||
|
#endif
|
||||||
if (iof->fp == NULL)
|
if (iof->fp == NULL)
|
||||||
luaL_argerror(L, 1, lj_str_pushf(L, "%s: %s", fname, strerror(errno)));
|
luaL_argerror(L, 1, lj_str_pushf(L, "%s: %s", fname, strerror(errno)));
|
||||||
return iof;
|
return iof;
|
||||||
|
@ -399,7 +417,14 @@ LJLIB_CF(io_open)
|
||||||
GCstr *s = lj_lib_optstr(L, 2);
|
GCstr *s = lj_lib_optstr(L, 2);
|
||||||
const char *mode = s ? strdata(s) : "r";
|
const char *mode = s ? strdata(s) : "r";
|
||||||
IOFileUD *iof = io_file_new(L);
|
IOFileUD *iof = io_file_new(L);
|
||||||
|
#if LJ_TARGET_WINDOWS
|
||||||
|
wchar_t wfname[MAX_PATH];
|
||||||
|
wchar_t wmode[MAX_PATH];
|
||||||
|
if (widen(fname, wfname) && widen(mode, wmode))
|
||||||
|
iof->fp = _wfopen(wfname, wmode);
|
||||||
|
#else
|
||||||
iof->fp = fopen(fname, mode);
|
iof->fp = fopen(fname, mode);
|
||||||
|
#endif
|
||||||
return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);
|
return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,7 +440,10 @@ LJLIB_CF(io_popen)
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
iof->fp = popen(fname, mode);
|
iof->fp = popen(fname, mode);
|
||||||
#else
|
#else
|
||||||
iof->fp = _popen(fname, mode);
|
wchar_t wfname[MAX_PATH];
|
||||||
|
wchar_t wmode[MAX_PATH];
|
||||||
|
if (widen(fname, wfname) && widen(mode, wmode))
|
||||||
|
iof->fp = _wpopen(wfname, wmode);
|
||||||
#endif
|
#endif
|
||||||
return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);
|
return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);
|
||||||
#else
|
#else
|
||||||
|
|
17
vendor/luajit/src/lib_os.c
vendored
17
vendor/luajit/src/lib_os.c
vendored
|
@ -32,6 +32,23 @@
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
#if LJ_TARGET_WINDOWS
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
static wchar_t *widen_static(const char *narrow, int idx)
|
||||||
|
{
|
||||||
|
__declspec(thread) static wchar_t buffer[2][MAX_PATH];
|
||||||
|
return MultiByteToWideChar(CP_UTF8, 0, narrow, -1, buffer[idx], MAX_PATH) ? buffer[idx] : L"";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define remove(x) _wremove(widen_static(x, 0))
|
||||||
|
#define system(x) _wsystem(widen_static(x, 0))
|
||||||
|
#define rename(x, y) _wrename(widen_static(x, 0), widen_static(y, 1))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
#define LJLIB_MODULE_os
|
#define LJLIB_MODULE_os
|
||||||
|
|
||||||
LJLIB_CF(os_execute)
|
LJLIB_CF(os_execute)
|
||||||
|
|
8
vendor/luajit/unicode-io.patch
vendored
8
vendor/luajit/unicode-io.patch
vendored
|
@ -1,7 +1,7 @@
|
||||||
diff --git c/vendor/luajit/src/lib_io.c w/vendor/luajit/src/lib_io.c
|
diff --git a/vendor/luajit/src/lib_io.c b/vendor/luajit/src/lib_io.c
|
||||||
index 04f0f73..b59d34b 100644
|
index 037aa28..8923e70 100644
|
||||||
--- c/vendor/luajit/src/lib_io.c
|
--- a/vendor/luajit/src/lib_io.c
|
||||||
+++ w/vendor/luajit/src/lib_io.c
|
+++ b/vendor/luajit/src/lib_io.c
|
||||||
@@ -24,6 +24,16 @@
|
@@ -24,6 +24,16 @@
|
||||||
#include "lj_ff.h"
|
#include "lj_ff.h"
|
||||||
#include "lj_lib.h"
|
#include "lj_lib.h"
|
||||||
|
|
10
vendor/luajit/unicode-os.patch
vendored
10
vendor/luajit/unicode-os.patch
vendored
|
@ -1,8 +1,8 @@
|
||||||
diff --git c/vendor/luajit/src/lib_os.c w/vendor/luajit/src/lib_os.c
|
diff --git a/vendor/luajit/src/lib_os.c b/vendor/luajit/src/lib_os.c
|
||||||
index f62e8c8..08eeb15 100644
|
index bb5a141..a2ed170 100644
|
||||||
--- c/vendor/luajit/src/lib_os.c
|
--- a/vendor/luajit/src/lib_os.c
|
||||||
+++ w/vendor/luajit/src/lib_os.c
|
+++ b/vendor/luajit/src/lib_os.c
|
||||||
@@ -29,6 +29,23 @@
|
@@ -32,6 +32,23 @@
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue