From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 1306666C07F; Mon, 23 Oct 2023 12:27:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1306666C07F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1698053229; bh=lD5TSHFYj+ujCxw6XlarUG9IGqUrI0ycqtukt0f6iUA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=uqnKMnHTBo/589vA7wZJqFgT/Pg3OuGAXug+Ph05mABsqLIAVtXiL5rU5S2kww9mL i9Z8wxmzZbS4Yit1uxkDD2NbLBdQXAa+HCzWigl9yAPzvFIXv3vVxgHsF3nwkRN5sK CHZwUXHKeQ68FhTL339kItwb31+yuXsEzIKqBIC0= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id C636F66C07F for ; Mon, 23 Oct 2023 12:26:37 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C636F66C07F Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1qurCm-0007cl-OT; Mon, 23 Oct 2023 12:26:37 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Mon, 23 Oct 2023 12:22:01 +0300 Message-ID: <89ded1daa0dcecf89e49055e5b87203c04fdda84.1698049570.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9C197A170B57C5E4302C07E91BCD7E616F852EEDD2BC7E32200894C459B0CD1B91E5CAE50CCEC674643E2C2E6E202185408F89D8EC0FEE90F54C85456B1E49444 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE75263010198C72082EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063724170451E8B6ECF78638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8BB48ABF6DA53F3AEC09EE99F7DF9D820117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC1F9C260F03842663A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520140C956E756FBB7AE5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269176DF2183F8FC7C03E69C4AB24A3574568655334FD4449CB33AC447995A7AD1857739F23D657EF2BD5E8D9A59859A8B679E85A9FDE02C04A75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5BE40CE0E8F52EB06F5A1C08BD931AD5F581EFFFF43196E3BF87CCE6106E1FC07E67D4AC08A07B9B05E59ED9F89912417C79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF87ABF3D931527374FF3BD8FD2857FA61FE100B3575E05C0685DDF943732BDA30F02FE508BB13AAFBA8B50B9382ADB12A030895EE1A6419E7E1D5CF6736738BE8A74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojqlVu258LHAGBtGS49m/iUQ== X-DA7885C5: 7151158F76C336337C62A0077695275CD266CE22DB7D47A7D93D5E141D72919D262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986BFEE39FC835F5360F1D2BAF1055FEA0210FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 1/6] Abstract out on-demand loading of FFI library. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall (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