From: Sergey Kaplun via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Maxim Kokryashkin <m.kokryashkin@tarantool.org>,
Sergey Bronnikov <sergeyb@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH luajit 1/6] Abstract out on-demand loading of FFI library.
Date: Mon, 23 Oct 2023 12:22:01 +0300 [thread overview]
Message-ID: <89ded1daa0dcecf89e49055e5b87203c04fdda84.1698049570.git.skaplun@tarantool.org> (raw)
In-Reply-To: <cover.1698049570.git.skaplun@tarantool.org>
From: Mike Pall <mike>
(cherry-picked from commit 50d6883e6027c4c2f9a5e495fee6b7fff1bd73c9)
This patch introduces the macro `ctype_loadffi(L)` to avoid code
duplication while loading the FFI library.
Sergey Kaplun:
* added the description
Part of tarantool/tarantool#9145
---
src/lib_jit.c | 6 +-----
src/lj_bcread.c | 6 +-----
src/lj_ctype.h | 10 ++++++++++
src/lj_lex.c | 6 +-----
4 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/src/lib_jit.c b/src/lib_jit.c
index b3c1c93c..f705f334 100644
--- a/src/lib_jit.c
+++ b/src/lib_jit.c
@@ -339,11 +339,7 @@ LJLIB_CF(jit_util_tracek)
ir = &T->ir[ir->op1];
}
#if LJ_HASFFI
- if (ir->o == IR_KINT64 && !ctype_ctsG(G(L))) {
- ptrdiff_t oldtop = savestack(L, L->top);
- luaopen_ffi(L); /* Load FFI library on-demand. */
- L->top = restorestack(L, oldtop);
- }
+ if (ir->o == IR_KINT64) ctype_loadffi(L);
#endif
lj_ir_kvalue(L, L->top-2, ir);
setintV(L->top-1, (int32_t)irt_type(ir->t));
diff --git a/src/lj_bcread.c b/src/lj_bcread.c
index cddf6ff1..4915240f 100644
--- a/src/lj_bcread.c
+++ b/src/lj_bcread.c
@@ -414,11 +414,7 @@ static int bcread_header(LexState *ls)
if ((flags & BCDUMP_F_FFI)) {
#if LJ_HASFFI
lua_State *L = ls->L;
- if (!ctype_ctsG(G(L))) {
- ptrdiff_t oldtop = savestack(L, L->top);
- luaopen_ffi(L); /* Load FFI library on-demand. */
- L->top = restorestack(L, oldtop);
- }
+ ctype_loadffi(L);
#else
return 0;
#endif
diff --git a/src/lj_ctype.h b/src/lj_ctype.h
index c4f3bdde..fce29409 100644
--- a/src/lj_ctype.h
+++ b/src/lj_ctype.h
@@ -389,6 +389,16 @@ static LJ_AINLINE CTState *ctype_cts(lua_State *L)
return cts;
}
+/* Load FFI library on-demand. */
+#define ctype_loadffi(L) \
+ do { \
+ if (!ctype_ctsG(G(L))) { \
+ ptrdiff_t oldtop = (char *)L->top - mref(L->stack, char); \
+ luaopen_ffi(L); \
+ L->top = (TValue *)(mref(L->stack, char) + oldtop); \
+ } \
+ } while (0)
+
/* Save and restore state of C type table. */
#define LJ_CTYPE_SAVE(cts) CTState savects_ = *(cts)
#define LJ_CTYPE_RESTORE(cts) \
diff --git a/src/lj_lex.c b/src/lj_lex.c
index cef3c683..7c6319cc 100644
--- a/src/lj_lex.c
+++ b/src/lj_lex.c
@@ -112,11 +112,7 @@ static void lex_number(LexState *ls, TValue *tv)
GCcdata *cd;
lj_assertLS(fmt == STRSCAN_I64 || fmt == STRSCAN_U64 || fmt == STRSCAN_IMAG,
"unexpected number format %d", fmt);
- if (!ctype_ctsG(G(L))) {
- ptrdiff_t oldtop = savestack(L, L->top);
- luaopen_ffi(L); /* Load FFI library on-demand. */
- L->top = restorestack(L, oldtop);
- }
+ ctype_loadffi(L);
if (fmt == STRSCAN_IMAG) {
cd = lj_cdata_new_(L, CTID_COMPLEX_DOUBLE, 2*sizeof(double));
((double *)cdataptr(cd))[0] = 0;
--
2.42.0
next prev parent reply other threads:[~2023-10-23 9:27 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 9:22 [Tarantool-patches] [PATCH luajit 0/6] FFI fixes Sergey Kaplun via Tarantool-patches
2023-10-23 9:22 ` Sergey Kaplun via Tarantool-patches [this message]
2023-10-24 14:38 ` [Tarantool-patches] [PATCH luajit 1/6] Abstract out on-demand loading of FFI library Maxim Kokryashkin via Tarantool-patches
2023-11-29 14:35 ` Sergey Bronnikov via Tarantool-patches
2023-10-23 9:22 ` [Tarantool-patches] [PATCH luajit 2/6] FFI: Fix missing cts->L initialization in argv2ctype() Sergey Kaplun via Tarantool-patches
2023-10-24 14:49 ` Maxim Kokryashkin via Tarantool-patches
2023-10-25 10:19 ` Sergey Kaplun via Tarantool-patches
2023-11-29 14:39 ` Sergey Bronnikov via Tarantool-patches
2023-10-23 9:22 ` [Tarantool-patches] [PATCH luajit 3/6] FFI: Ensure returned string is alive in ffi.typeinfo() Sergey Kaplun via Tarantool-patches
2023-10-24 21:33 ` Maxim Kokryashkin via Tarantool-patches
2023-11-29 14:48 ` Sergey Bronnikov via Tarantool-patches
2023-10-23 9:22 ` [Tarantool-patches] [PATCH luajit 4/6] FFI: Fix dangling reference to CType Sergey Kaplun via Tarantool-patches
2023-10-25 7:48 ` Maxim Kokryashkin via Tarantool-patches
2023-10-25 10:43 ` Sergey Kaplun via Tarantool-patches
2023-10-25 11:42 ` Maxim Kokryashkin via Tarantool-patches
2023-10-25 8:06 ` Maxim Kokryashkin via Tarantool-patches
2023-11-29 15:00 ` Sergey Bronnikov via Tarantool-patches
2023-10-23 9:22 ` [Tarantool-patches] [PATCH luajit 5/6] FFI: Fix dangling reference to CType. Improve checks Sergey Kaplun via Tarantool-patches
2023-10-25 8:05 ` Maxim Kokryashkin via Tarantool-patches
2023-10-25 10:46 ` Sergey Kaplun via Tarantool-patches
2023-10-25 11:42 ` Maxim Kokryashkin via Tarantool-patches
2023-11-29 15:41 ` Sergey Bronnikov via Tarantool-patches
2023-11-30 7:25 ` Sergey Kaplun via Tarantool-patches
2023-12-19 10:55 ` Sergey Bronnikov via Tarantool-patches
2023-10-23 9:22 ` [Tarantool-patches] [PATCH luajit 6/6] FFI: Fix dangling reference to CType in carith_checkarg() Sergey Kaplun via Tarantool-patches
2023-10-25 8:07 ` Maxim Kokryashkin via Tarantool-patches
2023-10-25 10:48 ` Sergey Kaplun via Tarantool-patches
2023-10-25 11:42 ` Maxim Kokryashkin via Tarantool-patches
2023-12-19 10:59 ` Sergey Bronnikov via Tarantool-patches
2023-12-19 11:01 ` [Tarantool-patches] [PATCH luajit 0/6] FFI fixes Sergey Bronnikov via Tarantool-patches
2024-01-10 8:53 ` Igor Munkin via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=89ded1daa0dcecf89e49055e5b87203c04fdda84.1698049570.git.skaplun@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=m.kokryashkin@tarantool.org \
--cc=sergeyb@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit 1/6] Abstract out on-demand loading of FFI library.' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox