From db944b2b56c86fcf133745976763604d96110285 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sat, 21 Oct 2023 13:11:50 +0200
Subject: [PATCH 1/3] FFI: Fix dangling reference to CType in
carith_checkarg().
Reported by Sergey Kaplun. #1108
---
src/lj_carith.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/lj_carith.c b/src/lj_carith.c
index 96384e8713..bad5fe66b0 100644
--- a/src/lj_carith.c
+++ b/src/lj_carith.c
@@ -42,9 +42,13 @@ static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca)
p = (uint8_t *)cdata_getptr(p, ct->size);
if (ctype_isref(ct->info)) ct = ctype_rawchild(cts, ct);
} else if (ctype_isfunc(ct->info)) {
+ CTypeID id0 = i ? ctype_typeid(cts, ca->ct[0]) : 0;
p = (uint8_t *)*(void **)p;
ct = ctype_get(cts,
lj_ctype_intern(cts, CTINFO(CT_PTR, CTALIGN_PTR|id), CTSIZE_PTR));
+ if (i) { /* cts->tab may have been reallocated. */
+ ca->ct[0] = ctype_get(cts, id0);
+ }
}
if (ctype_isenum(ct->info)) ct = ctype_child(cts, ct);
ca->ct[i] = ct;
From 4eb47df605883e983dadb78f303b22dd0232dd03 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sat, 21 Oct 2023 13:18:51 +0200
Subject: [PATCH 2/3] FFI/Windows: Fix type declaration for int64_t and
uint64_t.
Thanks to Peter Cawley. #1106
---
src/lj_ctype.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/lj_ctype.h b/src/lj_ctype.h
index 45e7234ed7..cde1cf0103 100644
--- a/src/lj_ctype.h
+++ b/src/lj_ctype.h
@@ -276,6 +276,8 @@ typedef struct CTState {
#define CTTYDEFP(_)
#endif
+#define CTF_LONG_IF8 (CTF_LONG * (sizeof(long) == 8))
+
/* Common types. */
#define CTTYDEF(_) \
_(NONE, 0, CT_ATTRIB, CTATTRIB(CTA_BAD)) \
@@ -289,8 +291,8 @@ typedef struct CTState {
_(UINT16, 2, CT_NUM, CTF_UNSIGNED|CTALIGN(1)) \
_(INT32, 4, CT_NUM, CTALIGN(2)) \
_(UINT32, 4, CT_NUM, CTF_UNSIGNED|CTALIGN(2)) \
- _(INT64, 8, CT_NUM, CTF_LONG|CTALIGN(3)) \
- _(UINT64, 8, CT_NUM, CTF_UNSIGNED|CTF_LONG|CTALIGN(3)) \
+ _(INT64, 8, CT_NUM, CTF_LONG_IF8|CTALIGN(3)) \
+ _(UINT64, 8, CT_NUM, CTF_UNSIGNED|CTF_LONG_IF8|CTALIGN(3)) \
_(FLOAT, 4, CT_NUM, CTF_FP|CTALIGN(2)) \
_(DOUBLE, 8, CT_NUM, CTF_FP|CTALIGN(3)) \
_(COMPLEX_FLOAT, 8, CT_ARRAY, CTF_COMPLEX|CTALIGN(2)|CTID_FLOAT) \
From e826d0c101d750fac8334d71e221c50d8dbe236c Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sat, 21 Oct 2023 13:31:45 +0200
Subject: [PATCH 3/3] Add 'cc' file type for saving bytecode.
Contributed by Sergey Bronnikov. #1105
---
doc/running.html | 3 ++-
src/jit/bcsave.lua | 4 ++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/doc/running.html b/doc/running.html
index 3afc1b560b..9dd2b411c6 100644
--- a/doc/running.html
+++ b/doc/running.html
@@ -120,7 +120,8 @@ -b[options] input output
- c — C source file, exported bytecode data.
-- h — C header file, static bytecode data.
+- cc — C++ source file, exported bytecode data.
+- h — C/C++ header file, static bytecode data.
- obj or o — Object file, exported bytecode data
(OS- and architecture-specific).
- raw or any other extension — Raw bytecode file (portable).
diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua
index 74699f3d5f..390d297c3c 100644
--- a/src/jit/bcsave.lua
+++ b/src/jit/bcsave.lua
@@ -38,7 +38,7 @@ Save LuaJIT bytecode: luajit -b[options] input output
-- Stop handling options.
- Use stdin as input and/or stdout as output.
-File types: c h obj o raw (default)
+File types: c cc h obj o raw (default)
]]
os.exit(1)
end
@@ -81,7 +81,7 @@ end
------------------------------------------------------------------------------
local map_type = {
- raw = "raw", c = "c", h = "h", o = "obj", obj = "obj",
+ raw = "raw", c = "c", cc = "c", h = "h", o = "obj", obj = "obj",
}
local map_arch = {