From 1947e5387a65b606a086c4aee30198d0bf1c0738 Mon Sep 17 00:00:00 2001 From: Daniel Dinu Date: Sat, 4 Apr 2020 14:08:20 -0700 Subject: [PATCH 01/22] Command line flag to set the sslmode for PostgreSQL (Closes: #326) The flag name and its values match libpq's sslmode connection parameter. The default value (prefer) will first try an SSL connection; if that fails, it will try a non-SSL connection. Libpq documentation: https://www.postgresql.org/docs/14/libpq-connect.html#LIBPQ-CONNECT-SSLMODE --- src/drivers/pgsql/drv_pgsql.c | 11 ++++++++++- tests/t/help_drv_pgsql.t | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/drivers/pgsql/drv_pgsql.c b/src/drivers/pgsql/drv_pgsql.c index 341eae62b..3f2b93ac7 100644 --- a/src/drivers/pgsql/drv_pgsql.c +++ b/src/drivers/pgsql/drv_pgsql.c @@ -47,6 +47,7 @@ static sb_arg_t pgsql_drv_args[] = SB_OPT("pgsql-user", "PostgreSQL user", "sbtest", STRING), SB_OPT("pgsql-password", "PostgreSQL password", "", STRING), SB_OPT("pgsql-db", "PostgreSQL database name", "sbtest", STRING), + SB_OPT("pgsql-sslmode", "PostgreSQL SSL mode (disable, allow, prefer, require, verify-ca, verify-full)", "prefer", STRING), SB_OPT_END }; @@ -180,7 +181,15 @@ int pgsql_drv_init(void) args.port = sb_get_value_string("pgsql-port"); args.user = sb_get_value_string("pgsql-user"); args.password = sb_get_value_string("pgsql-password"); - args.db = sb_get_value_string("pgsql-db"); + + char * dbname = sb_get_value_string("pgsql-db"); + char * sslmode = sb_get_value_string("pgsql-sslmode"); + + args.db = malloc(strlen("dbname= sslmode=") + + strlen(dbname) + + strlen(sslmode) + + 1); + sprintf(args.db, "dbname=%s sslmode=%s", dbname, sslmode); use_ps = 0; pgsql_drv_caps.prepared_statements = 1; diff --git a/tests/t/help_drv_pgsql.t b/tests/t/help_drv_pgsql.t index 9b986ea88..df0d1baf6 100644 --- a/tests/t/help_drv_pgsql.t +++ b/tests/t/help_drv_pgsql.t @@ -12,4 +12,5 @@ Skip test if the PostgreSQL driver is not available. --pgsql-user=STRING PostgreSQL user [sbtest] --pgsql-password=STRING PostgreSQL password [] --pgsql-db=STRING PostgreSQL database name [sbtest] - + --pgsql-sslmode=STRING PostgreSQL SSL mode (disable, allow, prefer, require, verify-ca, verify-full) [prefer] + From 4228c85ff9164aac93eb7af5ed8a622b039e3c5b Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Wed, 3 May 2023 17:02:41 +0300 Subject: [PATCH 02/22] Replace bundled LuaJIT with upstream @ commit 224129a --- third_party/luajit/luajit/COPYRIGHT | 8 +- third_party/luajit/luajit/Makefile | 8 +- third_party/luajit/luajit/README | 4 +- .../luajit/luajit/doc/bluequad-print.css | 2 +- third_party/luajit/luajit/doc/bluequad.css | 2 +- third_party/luajit/luajit/doc/contact.html | 25 +- third_party/luajit/luajit/doc/ext_buffer.html | 695 ++++++++++++++++++ third_party/luajit/luajit/doc/ext_c_api.html | 16 +- third_party/luajit/luajit/doc/ext_ffi.html | 26 +- .../luajit/luajit/doc/ext_ffi_api.html | 24 +- .../luajit/luajit/doc/ext_ffi_semantics.html | 76 +- .../luajit/luajit/doc/ext_ffi_tutorial.html | 40 +- third_party/luajit/luajit/doc/ext_jit.html | 18 +- .../luajit/luajit/doc/ext_profiler.html | 20 +- third_party/luajit/luajit/doc/extensions.html | 56 +- third_party/luajit/luajit/doc/faq.html | 131 ++-- third_party/luajit/luajit/doc/install.html | 400 ++++++---- third_party/luajit/luajit/doc/luajit.html | 22 +- third_party/luajit/luajit/doc/running.html | 31 +- third_party/luajit/luajit/doc/status.html | 44 +- third_party/luajit/luajit/dynasm/dasm_arm.h | 9 +- third_party/luajit/luajit/dynasm/dasm_arm.lua | 8 +- third_party/luajit/luajit/dynasm/dasm_arm64.h | 74 +- .../luajit/luajit/dynasm/dasm_arm64.lua | 137 ++-- third_party/luajit/luajit/dynasm/dasm_mips.h | 17 +- .../luajit/luajit/dynasm/dasm_mips.lua | 8 +- .../luajit/luajit/dynasm/dasm_mips64.lua | 2 +- third_party/luajit/luajit/dynasm/dasm_ppc.h | 9 +- third_party/luajit/luajit/dynasm/dasm_ppc.lua | 19 +- third_party/luajit/luajit/dynasm/dasm_proto.h | 6 +- third_party/luajit/luajit/dynasm/dasm_x64.lua | 2 +- third_party/luajit/luajit/dynasm/dasm_x86.h | 37 +- third_party/luajit/luajit/dynasm/dasm_x86.lua | 52 +- third_party/luajit/luajit/dynasm/dynasm.lua | 14 +- third_party/luajit/luajit/etc/luajit.1 | 8 +- third_party/luajit/luajit/etc/luajit.pc | 2 +- third_party/luajit/luajit/src/Makefile | 29 +- third_party/luajit/luajit/src/Makefile.dep | 93 ++- third_party/luajit/luajit/src/host/buildvm.c | 12 +- third_party/luajit/luajit/src/host/buildvm.h | 2 +- .../luajit/luajit/src/host/buildvm_asm.c | 22 +- .../luajit/luajit/src/host/buildvm_fold.c | 9 +- .../luajit/luajit/src/host/buildvm_lib.c | 18 +- .../luajit/luajit/src/host/buildvm_libbc.h | 101 ++- .../luajit/luajit/src/host/buildvm_peobj.c | 2 +- .../luajit/luajit/src/host/genlibbc.lua | 54 +- .../luajit/luajit/src/host/genminilua.lua | 9 +- third_party/luajit/luajit/src/host/minilua.c | 7 +- third_party/luajit/luajit/src/jit/bc.lua | 2 +- third_party/luajit/luajit/src/jit/bcsave.lua | 64 +- third_party/luajit/luajit/src/jit/dis_arm.lua | 2 +- .../luajit/luajit/src/jit/dis_arm64.lua | 4 +- .../luajit/luajit/src/jit/dis_arm64be.lua | 2 +- .../luajit/luajit/src/jit/dis_mips.lua | 2 +- .../luajit/luajit/src/jit/dis_mips64.lua | 2 +- .../luajit/luajit/src/jit/dis_mips64el.lua | 2 +- .../luajit/luajit/src/jit/dis_mips64r6.lua | 2 +- .../luajit/luajit/src/jit/dis_mips64r6el.lua | 2 +- .../luajit/luajit/src/jit/dis_mipsel.lua | 2 +- third_party/luajit/luajit/src/jit/dis_ppc.lua | 2 +- third_party/luajit/luajit/src/jit/dis_x64.lua | 2 +- third_party/luajit/luajit/src/jit/dis_x86.lua | 2 +- third_party/luajit/luajit/src/jit/dump.lua | 44 +- third_party/luajit/luajit/src/jit/p.lua | 3 +- third_party/luajit/luajit/src/jit/v.lua | 2 +- third_party/luajit/luajit/src/jit/zone.lua | 2 +- third_party/luajit/luajit/src/lib_aux.c | 45 +- third_party/luajit/luajit/src/lib_base.c | 30 +- third_party/luajit/luajit/src/lib_bit.c | 5 +- third_party/luajit/luajit/src/lib_buffer.c | 360 +++++++++ third_party/luajit/luajit/src/lib_debug.c | 14 +- third_party/luajit/luajit/src/lib_ffi.c | 7 +- third_party/luajit/luajit/src/lib_init.c | 2 +- third_party/luajit/luajit/src/lib_io.c | 50 +- third_party/luajit/luajit/src/lib_jit.c | 33 +- third_party/luajit/luajit/src/lib_math.c | 55 +- third_party/luajit/luajit/src/lib_os.c | 4 +- third_party/luajit/luajit/src/lib_package.c | 33 +- third_party/luajit/luajit/src/lib_string.c | 92 +-- third_party/luajit/luajit/src/lib_table.c | 4 +- third_party/luajit/luajit/src/lj_alloc.c | 99 ++- third_party/luajit/luajit/src/lj_alloc.h | 3 +- third_party/luajit/luajit/src/lj_api.c | 169 +++-- third_party/luajit/luajit/src/lj_arch.h | 163 +++- third_party/luajit/luajit/src/lj_asm.c | 347 ++++++--- third_party/luajit/luajit/src/lj_asm.h | 2 +- third_party/luajit/luajit/src/lj_asm_arm.h | 281 ++++--- third_party/luajit/luajit/src/lj_asm_arm64.h | 232 +++--- third_party/luajit/luajit/src/lj_asm_mips.h | 412 +++++++---- third_party/luajit/luajit/src/lj_asm_ppc.h | 264 ++++--- third_party/luajit/luajit/src/lj_asm_x86.h | 339 +++++---- third_party/luajit/luajit/src/lj_assert.c | 28 + third_party/luajit/luajit/src/lj_bc.c | 2 +- third_party/luajit/luajit/src/lj_bc.h | 2 +- third_party/luajit/luajit/src/lj_bcdump.h | 2 +- third_party/luajit/luajit/src/lj_bcread.c | 36 +- third_party/luajit/luajit/src/lj_bcwrite.c | 46 +- third_party/luajit/luajit/src/lj_buf.c | 195 +++-- third_party/luajit/luajit/src/lj_buf.h | 135 +++- third_party/luajit/luajit/src/lj_carith.c | 14 +- third_party/luajit/luajit/src/lj_carith.h | 2 +- third_party/luajit/luajit/src/lj_ccall.c | 59 +- third_party/luajit/luajit/src/lj_ccall.h | 11 +- third_party/luajit/luajit/src/lj_ccallback.c | 72 +- third_party/luajit/luajit/src/lj_ccallback.h | 2 +- third_party/luajit/luajit/src/lj_cconv.c | 66 +- third_party/luajit/luajit/src/lj_cconv.h | 7 +- third_party/luajit/luajit/src/lj_cdata.c | 29 +- third_party/luajit/luajit/src/lj_cdata.h | 9 +- third_party/luajit/luajit/src/lj_clib.c | 10 +- third_party/luajit/luajit/src/lj_clib.h | 2 +- third_party/luajit/luajit/src/lj_cparse.c | 39 +- third_party/luajit/luajit/src/lj_cparse.h | 2 +- third_party/luajit/luajit/src/lj_crecord.c | 93 ++- third_party/luajit/luajit/src/lj_crecord.h | 7 +- third_party/luajit/luajit/src/lj_ctype.c | 39 +- third_party/luajit/luajit/src/lj_ctype.h | 30 +- third_party/luajit/luajit/src/lj_debug.c | 30 +- third_party/luajit/luajit/src/lj_debug.h | 2 +- third_party/luajit/luajit/src/lj_def.h | 40 +- third_party/luajit/luajit/src/lj_dispatch.c | 23 +- third_party/luajit/luajit/src/lj_dispatch.h | 12 +- third_party/luajit/luajit/src/lj_emit_arm.h | 54 +- third_party/luajit/luajit/src/lj_emit_arm64.h | 98 +-- third_party/luajit/luajit/src/lj_emit_mips.h | 26 +- third_party/luajit/luajit/src/lj_emit_ppc.h | 14 +- third_party/luajit/luajit/src/lj_emit_x86.h | 26 +- third_party/luajit/luajit/src/lj_err.c | 585 ++++++++++----- third_party/luajit/luajit/src/lj_err.h | 21 +- third_party/luajit/luajit/src/lj_errmsg.h | 16 +- third_party/luajit/luajit/src/lj_ff.h | 2 +- third_party/luajit/luajit/src/lj_ffrecord.c | 446 ++++++++++- third_party/luajit/luajit/src/lj_ffrecord.h | 2 +- third_party/luajit/luajit/src/lj_frame.h | 25 +- third_party/luajit/luajit/src/lj_func.c | 20 +- third_party/luajit/luajit/src/lj_func.h | 2 +- third_party/luajit/luajit/src/lj_gc.c | 134 +++- third_party/luajit/luajit/src/lj_gc.h | 8 +- third_party/luajit/luajit/src/lj_gdbjit.c | 9 +- third_party/luajit/luajit/src/lj_gdbjit.h | 2 +- third_party/luajit/luajit/src/lj_ir.c | 44 +- third_party/luajit/luajit/src/lj_ir.h | 55 +- third_party/luajit/luajit/src/lj_ircall.h | 83 ++- third_party/luajit/luajit/src/lj_iropt.h | 4 +- third_party/luajit/luajit/src/lj_jit.h | 50 +- third_party/luajit/luajit/src/lj_lex.c | 32 +- third_party/luajit/luajit/src/lj_lex.h | 8 +- third_party/luajit/luajit/src/lj_lib.c | 58 +- third_party/luajit/luajit/src/lj_lib.h | 13 +- third_party/luajit/luajit/src/lj_load.c | 4 +- third_party/luajit/luajit/src/lj_mcode.c | 94 +-- third_party/luajit/luajit/src/lj_mcode.h | 2 +- third_party/luajit/luajit/src/lj_meta.c | 23 +- third_party/luajit/luajit/src/lj_meta.h | 2 +- third_party/luajit/luajit/src/lj_obj.c | 7 +- third_party/luajit/luajit/src/lj_obj.h | 149 ++-- third_party/luajit/luajit/src/lj_opt_dce.c | 7 +- third_party/luajit/luajit/src/lj_opt_fold.c | 267 ++++--- third_party/luajit/luajit/src/lj_opt_loop.c | 8 +- third_party/luajit/luajit/src/lj_opt_mem.c | 146 ++-- third_party/luajit/luajit/src/lj_opt_narrow.c | 49 +- third_party/luajit/luajit/src/lj_opt_sink.c | 18 +- third_party/luajit/luajit/src/lj_opt_split.c | 28 +- third_party/luajit/luajit/src/lj_parse.c | 136 ++-- third_party/luajit/luajit/src/lj_parse.h | 2 +- third_party/luajit/luajit/src/lj_prng.c | 259 +++++++ third_party/luajit/luajit/src/lj_prng.h | 24 + third_party/luajit/luajit/src/lj_profile.c | 11 +- third_party/luajit/luajit/src/lj_profile.h | 2 +- third_party/luajit/luajit/src/lj_record.c | 393 +++++++--- third_party/luajit/luajit/src/lj_record.h | 4 +- third_party/luajit/luajit/src/lj_serialize.c | 539 ++++++++++++++ third_party/luajit/luajit/src/lj_serialize.h | 28 + third_party/luajit/luajit/src/lj_snap.c | 182 +++-- third_party/luajit/luajit/src/lj_snap.h | 5 +- third_party/luajit/luajit/src/lj_state.c | 95 +-- third_party/luajit/luajit/src/lj_state.h | 4 +- third_party/luajit/luajit/src/lj_str.c | 359 ++++++--- third_party/luajit/luajit/src/lj_str.h | 6 +- third_party/luajit/luajit/src/lj_strfmt.c | 220 ++++-- third_party/luajit/luajit/src/lj_strfmt.h | 12 +- third_party/luajit/luajit/src/lj_strfmt_num.c | 10 +- third_party/luajit/luajit/src/lj_strscan.c | 53 +- third_party/luajit/luajit/src/lj_strscan.h | 2 +- third_party/luajit/luajit/src/lj_tab.c | 101 ++- third_party/luajit/luajit/src/lj_tab.h | 28 +- third_party/luajit/luajit/src/lj_target.h | 5 +- third_party/luajit/luajit/src/lj_target_arm.h | 3 +- .../luajit/luajit/src/lj_target_arm64.h | 6 +- .../luajit/luajit/src/lj_target_mips.h | 4 +- third_party/luajit/luajit/src/lj_target_ppc.h | 13 +- third_party/luajit/luajit/src/lj_target_x86.h | 7 +- third_party/luajit/luajit/src/lj_trace.c | 148 +++- third_party/luajit/luajit/src/lj_trace.h | 5 +- third_party/luajit/luajit/src/lj_traceerr.h | 2 +- third_party/luajit/luajit/src/lj_udata.c | 30 +- third_party/luajit/luajit/src/lj_udata.h | 5 +- third_party/luajit/luajit/src/lj_vm.h | 11 +- third_party/luajit/luajit/src/lj_vmevent.c | 2 +- third_party/luajit/luajit/src/lj_vmevent.h | 9 +- third_party/luajit/luajit/src/lj_vmmath.c | 64 +- third_party/luajit/luajit/src/ljamalg.c | 6 +- third_party/luajit/luajit/src/lua.h | 2 +- third_party/luajit/luajit/src/luaconf.h | 4 +- third_party/luajit/luajit/src/luajit.c | 25 +- third_party/luajit/luajit/src/luajit.h | 10 +- third_party/luajit/luajit/src/lualib.h | 3 +- third_party/luajit/luajit/src/msvcbuild.bat | 4 +- third_party/luajit/luajit/src/nxbuild.bat | 160 ++++ third_party/luajit/luajit/src/ps4build.bat | 10 +- third_party/luajit/luajit/src/ps5build.bat | 123 ++++ third_party/luajit/luajit/src/psvitabuild.bat | 2 +- third_party/luajit/luajit/src/vm_arm.dasc | 127 +++- third_party/luajit/luajit/src/vm_arm64.dasc | 343 ++++++--- third_party/luajit/luajit/src/vm_mips.dasc | 163 +++- third_party/luajit/luajit/src/vm_mips64.dasc | 156 +++- third_party/luajit/luajit/src/vm_ppc.dasc | 86 +-- third_party/luajit/luajit/src/vm_x64.dasc | 198 ++--- third_party/luajit/luajit/src/vm_x86.dasc | 233 +++--- third_party/luajit/luajit/src/xb1build.bat | 4 +- third_party/luajit/luajit/src/xedkbuild.bat | 2 +- 221 files changed, 9726 insertions(+), 4009 deletions(-) create mode 100644 third_party/luajit/luajit/doc/ext_buffer.html create mode 100644 third_party/luajit/luajit/src/lib_buffer.c create mode 100644 third_party/luajit/luajit/src/lj_assert.c create mode 100644 third_party/luajit/luajit/src/lj_prng.c create mode 100644 third_party/luajit/luajit/src/lj_prng.h create mode 100644 third_party/luajit/luajit/src/lj_serialize.c create mode 100644 third_party/luajit/luajit/src/lj_serialize.h create mode 100644 third_party/luajit/luajit/src/nxbuild.bat create mode 100644 third_party/luajit/luajit/src/ps5build.bat diff --git a/third_party/luajit/luajit/COPYRIGHT b/third_party/luajit/luajit/COPYRIGHT index 44144197c..c74216c3e 100644 --- a/third_party/luajit/luajit/COPYRIGHT +++ b/third_party/luajit/luajit/COPYRIGHT @@ -1,7 +1,7 @@ =============================================================================== -LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ +LuaJIT -- a Just-In-Time Compiler for Lua. https://luajit.org/ -Copyright (C) 2005-2020 Mike Pall. All rights reserved. +Copyright (C) 2005-2022 Mike Pall. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -[ MIT license: http://www.opensource.org/licenses/mit-license.php ] +[ MIT license: https://www.opensource.org/licenses/mit-license.php ] =============================================================================== [ LuaJIT includes code from Lua 5.1/5.2, which has this license statement: ] @@ -51,6 +51,6 @@ THE SOFTWARE. This is a version (aka dlmalloc) of malloc/free/realloc written by Doug Lea and released to the public domain, as explained at -http://creativecommons.org/licenses/publicdomain +https://creativecommons.org/licenses/publicdomain =============================================================================== diff --git a/third_party/luajit/luajit/Makefile b/third_party/luajit/luajit/Makefile index 45d9f968c..b0288b4db 100644 --- a/third_party/luajit/luajit/Makefile +++ b/third_party/luajit/luajit/Makefile @@ -10,7 +10,7 @@ # For MSVC, please follow the instructions given in src/msvcbuild.bat. # For MinGW and Cygwin, cd to src and run make with the Makefile there. # -# Copyright (C) 2005-2020 Mike Pall. See Copyright Notice in luajit.h +# Copyright (C) 2005-2022 Mike Pall. See Copyright Notice in luajit.h ############################################################################## MAJVER= 2 @@ -33,7 +33,8 @@ DPREFIX= $(DESTDIR)$(PREFIX) INSTALL_BIN= $(DPREFIX)/bin INSTALL_LIB= $(DPREFIX)/$(MULTILIB) INSTALL_SHARE= $(DPREFIX)/share -INSTALL_INC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER) +INSTALL_DEFINC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER) +INSTALL_INC= $(INSTALL_DEFINC) INSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(VERSION) INSTALL_JITLIB= $(INSTALL_LJLIBD)/jit @@ -78,6 +79,9 @@ UNINSTALL= $(RM) LDCONFIG= ldconfig -n 2>/dev/null SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" \ -e "s|^multilib=.*|multilib=$(MULTILIB)|" +ifneq ($(INSTALL_DEFINC),$(INSTALL_INC)) + SED_PC+= -e "s|^includedir=.*|includedir=$(INSTALL_INC)|" +endif FILE_T= luajit FILE_A= libluajit.a diff --git a/third_party/luajit/luajit/README b/third_party/luajit/luajit/README index 5c74038fd..1faef2559 100644 --- a/third_party/luajit/luajit/README +++ b/third_party/luajit/luajit/README @@ -3,9 +3,9 @@ README for LuaJIT 2.1.0-beta3 LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language. -Project Homepage: http://luajit.org/ +Project Homepage: https://luajit.org/ -LuaJIT is Copyright (C) 2005-2020 Mike Pall. +LuaJIT is Copyright (C) 2005-2022 Mike Pall. LuaJIT is free software, released under the MIT license. See full Copyright Notice in the COPYRIGHT file or in luajit.h. diff --git a/third_party/luajit/luajit/doc/bluequad-print.css b/third_party/luajit/luajit/doc/bluequad-print.css index 13ee876f0..a49d309ff 100644 --- a/third_party/luajit/luajit/doc/bluequad-print.css +++ b/third_party/luajit/luajit/doc/bluequad-print.css @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2020 Mike Pall. +/* Copyright (C) 2004-2022 Mike Pall. * * You are welcome to use the general ideas of this design for your own sites. * But please do not steal the stylesheet, the layout or the color scheme. diff --git a/third_party/luajit/luajit/doc/bluequad.css b/third_party/luajit/luajit/doc/bluequad.css index 978719e84..4c1a9082e 100644 --- a/third_party/luajit/luajit/doc/bluequad.css +++ b/third_party/luajit/luajit/doc/bluequad.css @@ -1,4 +1,4 @@ -/* Copyright (C) 2004-2020 Mike Pall. +/* Copyright (C) 2004-2022 Mike Pall. * * You are welcome to use the general ideas of this design for your own sites. * But please do not steal the stylesheet, the layout or the color scheme. diff --git a/third_party/luajit/luajit/doc/contact.html b/third_party/luajit/luajit/doc/contact.html index 3173b2a58..6d609286e 100644 --- a/third_party/luajit/luajit/doc/contact.html +++ b/third_party/luajit/luajit/doc/contact.html @@ -1,9 +1,9 @@ - + Contact - - + + @@ -37,6 +37,8 @@

Contact

FFI Semantics
  • +String Buffers +
  • jit.* Library
  • Lua/C API @@ -48,8 +50,6 @@

    Contact

  • FAQ
  • -Wiki » -
  • Mailing List »
  • @@ -57,11 +57,11 @@

    Contact

    If you want to report bugs, propose fixes or suggest enhancements, please use the -GitHub issue tracker. +» GitHub issue tracker.

    Please send general questions to the -LuaJIT mailing list. +» LuaJIT mailing list.

    You can also send any questions you have directly to me: @@ -84,10 +84,17 @@

    Contact

    +

    +Note: I cannot reply to GMail, Google Workplace, Outlook or Office365 +mail addresses, since they prefer to mindlessly filter out mails sent +from small domains using independent mail servers, such as mine. If you +don't like that, please complain to Google or Microsoft, not me. +

    +

    Copyright

    All documentation is -Copyright © 2005-2020 Mike Pall. +Copyright © 2005-2022 Mike Pall.

    @@ -95,7 +102,7 @@

    Copyright

    @@ -105,7 +105,7 @@

    luaJIT_setmode(L, idx, LUAJIT_MODE_FUNC|flag)
    This sets the mode for the function at the stack index idx or the parent of the calling function (idx = 0). It either enables JIT compilation for a function, disables it and flushes any -already compiled code or only flushes already compiled code. This +already compiled code, or only flushes already compiled code. This applies recursively to all sub-functions of the function with LUAJIT_MODE_ALLFUNC or only to the sub-functions with LUAJIT_MODE_ALLSUBFUNC. @@ -124,7 +124,7 @@

    luaJIT_setmode(L, idx, LUAJIT_MODE_WRAPCFUNC|flag)LUAJIT_MODE_ON, the stack index at idx must be a lightuserdata object holding a pointer to the wrapper -function. From now on all C functions are called through the wrapper +function. From now on, all C functions are called through the wrapper function. If called with LUAJIT_MODE_OFF this mode is turned off and all C functions are directly called.

    @@ -173,7 +173,7 @@

    luaJIT_setmode(L, idx, LUAJIT_MODE_WRAPCFUNC|flag) @@ -155,7 +155,7 @@

    Motivating Example: Calling External C Functions

    Motivating Example: Using C Data Structures

    The FFI library allows you to create and access C data -structures. Of course the main use for this is for interfacing with +structures. Of course, the main use for this is for interfacing with C functions. But they can be used stand-alone, too.

    @@ -167,7 +167,7 @@

    Motivating Example: Using C Data Structures

    both a substantial memory overhead as well as a performance overhead.

    -Here's a sketch of a library that operates on color images plus a +Here's a sketch of a library that operates on color images, plus a simple benchmark. First, the plain Lua version:

    @@ -182,7 +182,7 @@ 

    Motivating Example: Using C Data Structures

    return img end -local function image_to_grey(img, n) +local function image_to_gray(img, n) for i=1,n do local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue) img[i].red = y; img[i].green = y; img[i].blue = y @@ -192,14 +192,14 @@

    Motivating Example: Using C Data Structures

    local N = 400*400 local img = image_ramp_green(N) for i=1,1000 do - image_to_grey(img, N) + image_to_gray(img, N) end

    This creates a table with 160.000 pixels, each of which is a table -holding four number values in the range of 0-255. First an image with +holding four number values in the range of 0-255. First, an image with a green ramp is created (1D for simplicity), then the image is -converted to greyscale 1000 times. Yes, that's silly, but I was in +converted to grayscale 1000 times. Yes, that's silly, but I was in need of a simple example ...

    @@ -306,7 +306,7 @@

    Motivating Example: Using C Data Structures

    ~1.7x). Switching to a struct-of-arrays would help, too.

    -However the resulting code would be less idiomatic and rather +However, the resulting code would be less idiomatic and rather error-prone. And it still doesn't get even close to the performance of the FFI version of the code. Also, high-level data structures cannot be easily passed to other C functions, especially I/O functions, @@ -316,7 +316,7 @@

    Motivating Example: Using C Data Structures

    @@ -119,7 +119,7 @@

    ffi.cdef(def)

    declaration may be omitted.

    -Please note that external symbols are only declared, but they +Please note, that external symbols are only declared, but they are not bound to any specific address, yet. Binding is achieved with C library namespaces (see below).

    @@ -207,7 +207,7 @@

    cdata = ffi.new(ct [,nelem] [,init...])
    ffi.typeof(). Then use the ctype as a constructor repeatedly.

    -Please note that an anonymous struct declaration implicitly +Please note, that an anonymous struct declaration implicitly creates a new and distinguished ctype every time you use it for ffi.new(). This is probably not what you want, especially if you create more than one cdata object. Different anonymous @@ -254,12 +254,12 @@

    ctype = ffi.metatype(ct, metatable)

    contents of an __index table (if any) may be modified afterwards. The associated metatable automatically applies to all uses of this type, no matter how the objects are created or where they -originate from. Note that pre-defined operations on types have -precedence (e.g. declared field names cannot be overriden). +originate from. Note that predefined operations on types have +precedence (e.g. declared field names cannot be overridden).

    All standard Lua metamethods are implemented. These are called directly, -without shortcuts and on any mix of types. For binary operations, the +without shortcuts, and on any mix of types. For binary operations, the left operand is checked first for a valid ctype metamethod. The __gc metamethod only applies to struct/union types and performs an implicit ffi.gc() @@ -490,7 +490,7 @@

    cb:free()

    Free the resources associated with a callback. The associated Lua function is unanchored and may be garbage collected. The callback -function pointer is no longer valid and must not be called anymore +function pointer is no longer valid and must not be called again (it may be reused by a subsequently created callback).

    @@ -556,7 +556,7 @@

    Extensions to the Lua Parser

    @@ -86,7 +86,7 @@

    C Language Support

    functions to declare C types or external symbols.

    -It's only purpose is to parse C declarations, as found e.g. in +Its only purpose is to parse C declarations, as found e.g. in C header files. Although it does evaluate constant expressions, it's not a C compiler. The body of inline C function definitions is simply ignored. @@ -163,7 +163,7 @@

    C Language Support

    -The following C types are pre-defined by the C parser (like +The following C types are predefined by the C parser (like a typedef, except re-declarations will be ignored):

      @@ -581,9 +581,9 @@

      Table Initializers

      Operations on cdata Objects

      -All of the standard Lua operators can be applied to cdata objects or a +All standard Lua operators can be applied to cdata objects or a mix of a cdata object and another Lua object. The following list shows -the pre-defined operations. +the predefined operations.

      Reference types are dereferenced before performing each of @@ -591,7 +591,7 @@

      Operations on cdata Objects

      C type pointed to by the reference.

      -The pre-defined operations are always tried first before deferring to a +The predefined operations are always tried first before deferring to a metamethod or index table (if any) for the corresponding ctype (except for __new). An error is raised if the metamethod lookup or index table lookup fails. @@ -641,7 +641,7 @@

      Indexing a cdata object

    A ctype object can be indexed with a string key, too. The only -pre-defined operation is reading scoped constants of +predefined operation is reading scoped constants of struct/union types. All other accesses defer to the corresponding metamethods or index tables (if any).

    @@ -654,7 +654,7 @@

    Indexing a cdata object

    As a consequence, the elements of complex numbers and vectors are immutable. But the elements of an aggregate holding these -types may be modified of course. I.e. you cannot assign to +types may be modified, of course. I.e. you cannot assign to foo.c.im, but you can assign a (newly created) complex number to foo.c.

    @@ -672,9 +672,9 @@

    Calling a cdata object

    constructor. This is equivalent to ffi.new(ct, ...), unless a __new metamethod is defined. The __new metamethod is called with the ctype object -plus any other arguments passed to the contructor. Note that you have to -use ffi.new inside of it, since calling ct(...) would -cause infinite recursion. +plus any other arguments passed to the constructor. Note that you have to +use ffi.new inside the metamethod, since calling ct(...) +would cause infinite recursion.
  • C function call: a cdata function or cdata function pointer can be called. The passed arguments are @@ -685,7 +685,7 @@

    Calling a cdata object

    C function is called and the return value (if any) is converted to a Lua object.
    On Windows/x86 systems, __stdcall functions are automatically -detected and a function declared as __cdecl (the default) is +detected, and a function declared as __cdecl (the default) is silently fixed up after the first call.
  • @@ -695,7 +695,7 @@

    Arithmetic on cdata objects

  • Pointer arithmetic: a cdata pointer/array and a cdata number or a Lua number can be added or subtracted. The number must be -on the right hand side for a subtraction. The result is a pointer of +on the right-hand side for a subtraction. The result is a pointer of the same type with an address plus or minus the number value multiplied by the element size in bytes. An error is raised if the element size is undefined.
  • @@ -710,7 +710,7 @@

    Arithmetic on cdata objects

    minus) can be applied to two cdata numbers, or a cdata number and a Lua number. If one of them is an uint64_t, the other side is converted to an uint64_t and an unsigned arithmetic operation -is performed. Otherwise both sides are converted to an +is performed. Otherwise, both sides are converted to an int64_t and a signed arithmetic operation is performed. The result is a boxed 64 bit cdata object.
    @@ -757,7 +757,7 @@

    Comparisons of cdata objects

  • 64 bit integer comparison: two cdata numbers, or a cdata number and a Lua number can be compared with each other. If one of them is an uint64_t, the other side is converted to an -uint64_t and an unsigned comparison is performed. Otherwise +uint64_t and an unsigned comparison is performed. Otherwise, both sides are converted to an int64_t and a signed comparison is performed.
    @@ -782,9 +782,9 @@

    cdata objects as table keys

    A cdata object is treated like any other garbage-collected object and is hashed and compared by its address for table indexing. Since there's no interning for cdata value types, the same value may be -boxed in different cdata objects with different addresses. Thus +boxed in different cdata objects with different addresses. Thus, t[1LL+1LL] and t[2LL] usually do not point to -the same hash slot and they certainly do not point to the same +the same hash slot, and they certainly do not point to the same hash slot as t[2].

    @@ -806,7 +806,7 @@

    cdata objects as table keys

    One obvious benefit: t[tonumber(2LL)] does point to the same slot as t[2].
  • -
  • Otherwise use either tostring() on 64 bit integers +
  • Otherwise, use either tostring() on 64 bit integers or complex numbers or combine multiple fields of a cdata aggregate to a Lua string (e.g. with ffi.string()). Then @@ -814,7 +814,7 @@

    cdata objects as table keys

  • Create your own specialized hash table implementation using the C types provided by the FFI library, just like you would in -C code. Ultimately this may give much better performance than the +C code. Ultimately, this may give much better performance than the other alternatives or what a generic by-value hash table could possibly provide.
  • @@ -858,7 +858,7 @@

    Parameterized Types

    The main use for parameterized types are libraries implementing abstract data types -(example), +(» example), similar to what can be achieved with C++ template metaprogramming. Another use case are derived types of anonymous structs, which avoids pollution of the global struct namespace. @@ -880,7 +880,7 @@

    Garbage Collection of cdata Objects

    the end of the next GC cycle).

    -Please note that pointers themselves are cdata objects, however they +Please note, that pointers themselves are cdata objects, however they are not followed by the garbage collector. So e.g. if you assign a cdata array to a pointer, you must keep the cdata object holding the array alive as long as the pointer is still in use: @@ -929,18 +929,18 @@

    Callbacks

    This can happen implicitly due to the usual conversions, e.g. when -passing a Lua function to a function pointer argument. Or you can use +passing a Lua function to a function pointer argument. Or, you can use ffi.cast() to explicitly cast a Lua function to a C function pointer.

    -Currently only certain C function types can be used as callback +Currently, only certain C function types can be used as callback functions. Neither C vararg functions nor functions with pass-by-value aggregate argument or result types are supported. There -are no restrictions for the kind of Lua functions that can be called +are no restrictions on the kind of Lua functions that can be called from the callback — no checks for the proper number of arguments are made. The return value of the Lua function will be converted to the -result type and an error will be thrown for invalid conversions. +result type, and an error will be thrown for invalid conversions.

    It's allowed to throw errors across a callback invocation, but it's not @@ -1001,7 +1001,7 @@

    Callback resource handling

    __stdcall calls to Windows functions.

    -For some use cases it's necessary to free up the resources or to +For some use cases, it's necessary to free up the resources or to dynamically redirect callbacks. Use an explicit cast to a C function pointer and keep the resulting cdata object. Then use the cb:free() @@ -1054,7 +1054,7 @@

    Callback performance

    For new designs avoid push-style APIs: a C function repeatedly -calling a callback for each result. Instead use pull-style APIs: +calling a callback for each result. Instead, use pull-style APIs: call a C function repeatedly to get a new result. Calls from Lua to C via the FFI are much faster than the other way round. Most well-designed libraries already use pull-style APIs (read/write, get/put). @@ -1073,7 +1073,7 @@

    C Library Namespaces

    Indexing a C library namespace object with a symbol name (a Lua -string) automatically binds it to the library. First the symbol type +string) automatically binds it to the library. First, the symbol type is resolved — it must have been declared with ffi.cdef. Then the symbol address is resolved by searching for the symbol name in the @@ -1128,7 +1128,7 @@

    C Library Namespaces

    namespace objects and to the strings used to index it. This effectively turns function cdata objects into constants. It's not useful and actually counter-productive to explicitly cache these -function objects, e.g. local strlen = ffi.C.strlen. OTOH it +function objects, e.g. local strlen = ffi.C.strlen. OTOH, it is useful to cache the namespace itself, e.g. local C = ffi.C.

    @@ -1153,14 +1153,14 @@

    No Hand-holding!

    interoperability with C code. Adding extra safety measures, like bounds checks, would be futile. There's no way to detect misdeclarations of C functions, since shared libraries only -provide symbol names, but no type information. Likewise there's no way +provide symbol names, but no type information. Likewise, there's no way to infer the valid range of indexes for a returned pointer.

    Again: the FFI library is a low-level library. This implies it needs to be used with care, but it's flexibility and performance often outweigh this concern. If you're a C or C++ developer, it'll be easy -to apply your existing knowledge. OTOH writing code for the FFI +to apply your existing knowledge. OTOH, writing code for the FFI library is not for the faint of heart and probably shouldn't be the first exercise for someone with little experience in Lua, C or C++.

    @@ -1188,7 +1188,7 @@

    Current Status

  • C declarations are not passed through a C pre-processor, yet.
  • The C parser is able to evaluate most constant expressions -commonly found in C header files. However it doesn't handle the +commonly found in C header files. However, it doesn't handle the full range of C expression semantics and may fail for some obscure constructs.
  • static const declarations only work for integer types @@ -1219,7 +1219,7 @@

    Current Status

  • Table initializers.
  • Initialization of nested struct/union types.
  • Non-default initialization of VLA/VLS or large C types -(> 128 bytes or > 16 array elements.
  • +(> 128 bytes or > 16 array elements).
  • Bitfield initializations.
  • Pointer differences for element sizes that are not a power of two.
  • @@ -1246,7 +1246,7 @@

    Current Status

    @@ -83,7 +83,7 @@

    Loading the FFI Library

    local ffi = require("ffi")

    -Please note this doesn't define an ffi variable in the table +Please note, this doesn't define an ffi variable in the table of globals — you really need to use the local variable. The require function ensures the library is only loaded once.

    @@ -192,7 +192,7 @@

    Accessing Standard System Functions

    The poll() function takes a couple more arguments we're not going to use. You can simply use nil to pass a NULL pointer and 0 -for the nfds parameter. Please note that the +for the nfds parameter. Please note, that the number 0 does not convert to a pointer value, unlike in C++. You really have to pass pointers to pointer arguments and numbers to number arguments. @@ -216,7 +216,7 @@

    Accessing Standard System Functions

    Accessing the zlib Compression Library

    The following code shows how to access the zlib compression library from Lua code. +href="https://zlib.net/">» zlib compression library from Lua code. We'll define two convenience wrapper functions that take a string and compress or uncompress it to another string:

    @@ -289,17 +289,17 @@

    Accessing the zlib Compression Library

    This defines some of the C functions provided by zlib. For the sake of this example, some -type indirections have been reduced and it uses the pre-defined +type indirections have been reduced and it uses the predefined fixed-size integer types, while still adhering to the zlib API/ABI.

    This loads the zlib shared -library. On POSIX systems it's named libz.so and usually +library. On POSIX systems, it's named libz.so and usually comes pre-installed. Since ffi.load() automatically adds any missing standard prefixes/suffixes, we can simply load the "z" library. On Windows it's named zlib1.dll and you'll have to download it first from the -zlib site. The check for +» zlib site. The check for ffi.os makes sure we pass the right name to ffi.load().

    @@ -322,7 +322,7 @@

    Accessing the zlib Compression Library

    In C you'd pass in the address of a local variable (&buflen). But since there's no address-of operator in -Lua, we'll just pass in a one-element array. Conveniently it can be +Lua, we'll just pass in a one-element array. Conveniently, it can be initialized with the maximum buffer size in one step. Calling the actual zlib.compress2 function is then straightforward.

    @@ -346,7 +346,7 @@

    Accessing the zlib Compression Library

    The uncompress functions does the exact opposite of the compress function. The compressed data doesn't include the size of the original string, -so this needs to be passed in. Otherwise no surprises here. +so this needs to be passed in. Otherwise, no surprises here.

    The code, that makes use @@ -380,7 +380,7 @@

    Accessing the zlib Compression Library

    wherever you'd want to use a number. That's why we get a away with passing n to ffi.string() above. But other Lua library functions or modules don't know how to deal with this. So for -maximum portability one needs to use tonumber() on returned +maximum portability, one needs to use tonumber() on returned long results before passing them on. Otherwise the application might work on some systems, but would fail in a POSIX/x64 environment. @@ -452,7 +452,7 @@

    Defining Metamethods for a C Type

    If we run out of operators, we can -define named methods, too. Here the __index table defines an +define named methods, too. Here, the __index table defines an area function. For custom indexing needs, one might want to define __index and __newindex functions instead.

    @@ -466,13 +466,13 @@

    Defining Metamethods for a C Type

    apply to any and all uses of this type.

    -Please note that the association with a metatable is permanent and +Please note, that the association with a metatable is permanent and the metatable must not be modified afterwards! Ditto for the __index table.

    Here are some simple usage examples -for the point type and their expected results. The pre-defined +for the point type and their expected results. The predefined operations (such as a.x) can be freely mixed with the newly defined metamethods. Note that area is a method and must be called with the Lua syntax for methods: a:area(), not @@ -481,7 +481,7 @@

    Defining Metamethods for a C Type

    The C type metamethod mechanism is most useful when used in conjunction with C libraries that are written in an object-oriented -style. Creators return a pointer to a new instance and methods take an +style. Creators return a pointer to a new instance, and methods take an instance pointer as the first argument. Sometimes you can just point __index to the library namespace and __gc to the destructor and you're done. But often enough you'll want to add @@ -567,7 +567,7 @@

    To Cache or Not to Cache

    This turns them into indirect calls and generates bigger and slower -machine code. Instead you'll want to cache the namespace itself and +machine code. Instead, you'll want to cache the namespace itself and rely on the JIT compiler to eliminate the lookups:

    @@ -587,7 +587,7 @@ 

    To Cache or Not to Cache

    @@ -147,12 +147,12 @@

    jit.os

    jit.arch

    Contains the target architecture name: -"x86", "x64", "arm", "arm64", "ppc", "mips" or "mips64". +"x86", "x64", "arm", "arm64", "arm64be", "ppc", "mips", "mipsel", "mips64", "mips64el", "mips64r6", "mips64r6el".

    jit.opt.* — JIT compiler optimization control

    -This sub-module provides the backend for the -O command line +This submodule provides the backend for the -O command line option.

    @@ -172,7 +172,7 @@

    jit.opt.* — JIT compiler optimization controljit.util.* — JIT compiler introspection

    -This sub-module holds functions to introspect the bytecode, generated +This submodule holds functions to introspect the bytecode, generated traces, the IR and the generated machine code. The functionality provided by this module is still in flux and therefore undocumented.

    @@ -185,7 +185,7 @@

    jit.util.* — JIT compiler introspection

    @@ -156,7 +156,7 @@

    -jp=[options[,output]]

    Combinations of v/z with f/F/l produce two-level views, e.g. -jp=vf or -jp=fv. This shows the time spent in a VM state or zone vs. hotspots. This can be used to answer -questions like "Which time consuming functions are only interpreted?" or +questions like "Which time-consuming functions are only interpreted?" or "What's the garbage collector overhead for a specific function?".

    @@ -215,7 +215,7 @@

    Low-level Lua API

    This module can be used to implement your own higher-level profiler. A typical profiling run starts the profiler, captures stack dumps in the profiler callback, adds them to a hash table to aggregate the number -of samples, stops the profiler and then analyzes all of the captured +of samples, stops the profiler and then analyzes all captured stack dumps. Other parameters can be sampled in the profiler callback, too. But it's important not to spend too much time in the callback, since this may skew the statistics. @@ -269,9 +269,9 @@

    dump = profile.dumpstack([thread,] fmt, depth) formatted according to the fmt argument:

      -
    • p — Preserve the full path for module names. Otherwise +
    • p — Preserve the full path for module names. Otherwise, only the file name is used.
    • -
    • f — Dump the function name if it can be derived. Otherwise +
    • f — Dump the function name if it can be derived. Otherwise, use module:line.
    • F — Ditto, but dump module:name.
    • l — Dump module:line.
    • @@ -349,7 +349,7 @@

      p = luaJIT_profile_dumpstack(L, fmt, depth

  • +String Buffers +
  • jit.* Library
  • Lua/C API @@ -65,17 +67,15 @@

    Extensions

  • FAQ
  • -Wiki » -
  • Mailing List »
  • LuaJIT is fully upwards-compatible with Lua 5.1. It supports all -standard Lua +» standard Lua library functions and the full set of -Lua/C API +» Lua/C API functions.

    @@ -86,7 +86,7 @@

    Extensions

    LuaJIT extends the standard Lua VM with new functionality and adds -several extension modules. Please note this page is only about +several extension modules. Please note, this page is only about functional enhancements and not about performance enhancements, such as the optimized VM, the faster interpreter or the JIT compiler.

    @@ -99,7 +99,7 @@

    Extensions Modules

    bit.* — Bitwise operations

    LuaJIT supports all bitwise operations as defined by -Lua BitOp: +» Lua BitOp:

     bit.tobit  bit.tohex  bit.bnot    bit.band bit.bor  bit.bxor
    @@ -108,7 +108,7 @@ 

    bit.* — Bitwise operations

    This module is a LuaJIT built-in — you don't need to download or install Lua BitOp. The Lua BitOp site has full documentation for all -Lua BitOp API functions. +» Lua BitOp API functions. The FFI adds support for 64 bit bitwise operations, using the same API functions. @@ -195,7 +195,7 @@

    string.dump(f [,strip]) generates portable bytecod

    The generated bytecode is portable and can be loaded on any architecture -that LuaJIT supports, independent of word size or endianess. However the +that LuaJIT supports, independent of word size or endianess. However, the bytecode compatibility versions must match. Bytecode stays compatible for dot releases (x.y.0 → x.y.1), but may change with major or minor releases (2.0 → 2.1) or between any beta release. Foreign @@ -227,7 +227,7 @@

    table.clear(tab) clears a table

    incremental array/hash part growth.

    -Please note this function is meant for very specific situations. In most +Please note, this function is meant for very specific situations. In most cases it's better to replace the (usually single) link with a new table and let the GC do its work.

    @@ -237,7 +237,7 @@

    Enhanced PRNG for math.random()

    LuaJIT uses a Tausworthe PRNG with period 2^223 to implement math.random() and math.randomseed(). The quality of the PRNG results is much superior compared to the standard Lua -implementation which uses the platform-specific ANSI rand(). +implementation, which uses the platform-specific ANSI rand().

    The PRNG generates the same sequences from the same seeds on all @@ -255,7 +255,7 @@

    Enhanced PRNG for math.random()

    io.* functions handle 64 bit file offsets

    The file I/O functions in the standard io.* library handle -64 bit file offsets. In particular this means it's possible +64 bit file offsets. In particular, this means it's possible to open files larger than 2 Gigabytes and to reposition or obtain the current file position for offsets beyond 2 GB (fp:seek() method). @@ -392,29 +392,19 @@

    C++ Exception Interoperability

    Interoperability -POSIX/x64, DWARF2 unwinding -GCC 4.3+, Clang +External frame unwinding +GCC, Clang, MSVC Full -ARM -DLUAJIT_UNWIND_EXTERNAL -GCC, Clang -Full - - -Other platforms, DWARF2 unwinding +Internal frame unwinding + DWARF2 GCC, Clang Limited - -Windows/x64 -MSVC or WinSDK -Full - -Windows/x86 -Any -Full +Windows 64 bit +non-MSVC +Limited Other platforms @@ -435,7 +425,9 @@

    C++ Exception Interoperability

    on the C stack. The contents of the C++ exception object pass through unmodified.
  • Lua errors can be caught on the C++ side with catch(...). -The corresponding Lua error message can be retrieved from the Lua stack.
  • +The corresponding Lua error message can be retrieved from the Lua stack.
    +For MSVC for Windows 64 bit this requires compilation of your C++ code +with /EHa.
  • Throwing Lua errors across C++ frames is safe. C++ destructors will be called.
  • @@ -470,7 +462,7 @@

    C++ Exception Interoperability

    -
    +
    Q: Where can I learn more about LuaJIT and Lua?
    +
    -
    +
    Q: Where can I learn more about the compiler technology used by LuaJIT?
    -I'm planning to write more documentation about the internals of LuaJIT. -In the meantime, please use the following Google Scholar searches -to find relevant papers:
    -Search for: Trace Compiler
    -Search for: JIT Compiler
    -Search for: Dynamic Language Optimizations
    -Search for: SSA Form
    -Search for: Linear Scan Register Allocation
    +Please use the following Google Scholar searches to find relevant papers:
    +Search for: » Trace Compiler
    +Search for: » JIT Compiler
    +Search for: » Dynamic Language Optimizations
    +Search for: » SSA Form
    +Search for: » Linear Scan Register Allocation
    Here is a list of the » innovative features in LuaJIT.
    -And, you know, reading the source is of course the only way to enlightenment. :-) +And, you know, reading the source is of course the only way to enlightenment.
    -
    +
    Q: Why do I get this error: "attempt to index global 'arg' (a nil value)"?
    Q: My vararg functions fail after switching to LuaJIT!
    LuaJIT is compatible to the Lua 5.1 language standard. It doesn't support the implicit arg parameter for old-style vararg functions from Lua 5.0.
    Please convert your code to the -Lua 5.1 +» Lua 5.1 vararg syntax.
    -
    +
    Q: Why do I get this error: "bad FPU precision"?
    Q: I get weird behavior after initializing Direct3D.
    Q: Some FPU operations crash after I load a Delphi DLL.
    @@ -120,57 +116,76 @@

    Frequently Asked Questions (FAQ)

    Consider testing your application with older versions, too.
    Similarly, the Borland/Delphi runtime modifies the FPU control word and -enables FP exceptions. Of course this violates the Windows ABI, too. -Please check the Delphi docs for the Set8087CW method. - +enables FP exceptions. Of course, this violates the Windows ABI, too. +Please check the Delphi docs for the Set8087CW method.
    -
    +
    Q: Sometimes Ctrl-C fails to stop my Lua program. Why?
    The interrupt signal handler sets a Lua debug hook. But this is -currently ignored by compiled code (this will eventually be fixed). If -your program is running in a tight loop and never falls back to the -interpreter, the debug hook never runs and can't throw the -"interrupted!" error.
    In the meantime you have to press Ctrl-C -twice to get stop your program. That's similar to when it's stuck -running inside a C function under the Lua interpreter.
    +ignored by compiled code. If your program is running in a tight loop +and never falls back to the interpreter, the debug hook never runs and +can't throw the "interrupted!" error.
    +You have to press Ctrl-C twice to stop your program. That's similar +to when it's stuck running inside a C function under the Lua interpreter.
    -
    -
    Q: Why doesn't my favorite power-patch for Lua apply against LuaJIT?
    -
    Because it's a completely redesigned VM and has very little code -in common with Lua anymore. Also, if the patch introduces changes to -the Lua semantics, these would need to be reflected everywhere in the -VM, from the interpreter up to all stages of the compiler.
    Please -use only standard Lua language constructs. For many common needs you -can use source transformations or use wrapper or proxy functions. -The compiler will happily optimize away such indirections.
    +
    +
    Q: Table iteration with pairs() does not result in the same order?
    +
    The order of table iteration is explicitly undefined by +the Lua language standard.
    +Different Lua implementations or versions may use different orders for +otherwise identical tables. Different ways of constructing a table may +result in different orders, too.
    +Due to improved VM security, LuaJIT 2.1 may even use a different order +on separate VM invocations or when string keys are newly interned.

    +If your program relies on a deterministic order, it has a bug. Rewrite it, +so it doesn't rely on the key order. Or sort the table keys, if you must.
    -
    +
    +
    Q: Can Lua code be safely sandboxed?
    +
    +Maybe for an extremely restricted subset of Lua and if you relentlessly +scrutinize every single interface function you offer to the untrusted code.
    + +Although Lua provides some sandboxing functionality (setfenv(), hooks), +it's very hard to get this right even for the Lua core libraries. Of course, +you'll need to inspect any extension library, too. And there are libraries +that are inherently unsafe, e.g. the FFI library.
    + +More reading material at the » Lua Wiki and » Wikipedia.

    + +Relatedly, loading untrusted bytecode is not safe!
    + +It's trivial to crash the Lua or LuaJIT VM with maliciously crafted bytecode. +This is well known and there's no bytecode verification on purpose, so please +don't report a bug about it. Check the mode parameter for the +load*() functions to disable loading of bytecode.

    + +In general, the only promising approach is to sandbox Lua code at the +process level and not the VM level. +
    +
    + +
    Q: Lua runs everywhere. Why doesn't LuaJIT support my CPU?
    Because it's a compiler — it needs to generate native machine code. This means the code generator must be ported to each architecture. And the fast interpreter is written in assembler and must be ported, too. This is quite an undertaking.
    The install documentation shows the supported -architectures. Other architectures will follow based on sufficient user -demand and/or sponsoring.
    -
    - -
    -
    Q: When will feature X be added? When will the next version be released?
    -
    When it's ready.
    -C'mon, it's open source — I'm doing it on my own time and you're -getting it for free. You can either contribute a patch or sponsor -the development of certain features, if they are important to you. -
    +architectures.
    +Other architectures may follow based on sufficient user demand and +market-relevance of the architecture. Sponsoring is required to develop +the port itself, to integrate it and to continuously maintain it in the +actively developed branches.

    @@ -93,62 +88,204 @@

    Installation

     make && sudo make install
     
    + +

    Requirements

    +

    Systems

    +

    +LuaJIT currently builds out-of-the box on most systems: +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    OSMin. VersionRequirementsLuaJIT Versions
    Windows7x86 or x64, ARM64: TBAv2.0 –
    Linux  v2.0 –
    *BSD  v2.0 –
    macOS (OSX)10.4 v2.1 –
    POSIX mmap, dlopenv2.0 –
    Android4.0Recent Android NDKv2.0 –
    iOS3.0Xcode iOS SDKv2.1 –
    PS3 PS3 SDKv2.0 – v2.1 EOL
    PS4 PS4 SDK (ORBIS)v2.0 –
    PS5 PS5 SDK (PROSPERO)v2.1 –
    PS Vita PS Vita SDK (PSP2)v2.0 – v2.1 EOL
    Xbox 360 Xbox 360 SDK (XEDK)v2.0 – v2.1 EOL
    Xbox One Xbox One SDK (DURANGO)v2.1 –
    Nintendo Switch NintendoSDK + NX Addonv2.1 –
    +

    +The codebase has compatibility defines for some more systems, but +without official support. +

    +

    Toolchains

    -LuaJIT currently builds out-of-the box on most systems. -Here's the compatibility matrix for the supported combinations of -operating systems, CPUs and compilers: +Building LuaJIT requires a recent toolchain based on GCC, Clang/LLVM or +MSVC++.

    +

    +The Makefile-based build system requires GNU Make and supports +cross-builds. Batch files are provided for MSVC++ builds and console +cross-builds. +

    +

    CPU Architectures

    - - - - - + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + +
    CPU / OSLinux or
    Android
    *BSD, OtherOSX 10.4+ or
    iOS 3.0+
    Windows
    XP/Vista/7
    CPUBitsRequirementsVariantsLuaJIT Versions
    x86 (32 bit)GCC 4.2+GCC 4.2+XCode 5.0+
    Clang
    MSVC
    MinGW, Cygwin
    x8632v2.1+: SSE2 v2.0 –
    x6464  v2.0 –
    ARM32ARMv5+, ARM9E+hard-fp + soft-fpv2.0 –
    ARM6464 ARM64le + ARM64bev2.1 –
    PPC3232 hard-fp + soft-fpv2.0 – v2.1 EOL
    x64 (64 bit)GCC 4.2+GCC 4.2+
    ORBIS (PS4)
    XCode 5.0+
    Clang
    MSVC
    Durango (Xbox One)
    PPC/e50032e500v2 v2.0 EOL
    ARMv5+
    ARM9E+
    GCC 4.2+GCC 4.2+
    PSP2 (PS VITA)
    XCode 5.0+
    Clang
     MIPS3232MIPS32r1 – r5hard-fp + soft-fpv2.0 –
    ARM64GCC 4.8+ XCode 6.0+
    Clang 3.5+
     MIPS6464MIPS64r1 – r5hard-fp + soft-fpv2.1 –
    PPCGCC 4.3+GCC 4.3+
    GCC 4.1 (PS3)
     XEDK (Xbox 360)MIPS6464MIPS64r6hard-fp + soft-fpv2.1 EOL
    MIPS32
    MIPS64
    GCC 4.3+GCC 4.3+  RISC-V64RVA22+ TBA
    +

    +There are no plans to add historic architectures or to continue support +for end-of-life (EOL) architectures, for which no new CPUs are commonly +available anymore. Likewise, there are no plans to support marginal +and/or de-facto-dead architectures. +

    Configuring LuaJIT

    @@ -177,7 +314,7 @@

    Configuring LuaJIT

    bytecode format differences, too.

    -

    POSIX Systems (Linux, OSX, *BSD etc.)

    +

    POSIX Systems (Linux, macOS, *BSD etc.)

    Prerequisites

    Depending on your distribution, you may need to install a package for @@ -185,14 +322,19 @@

    Prerequisites

    Debian/Ubuntu, install libc6-dev with the package manager.

    -Download the current source package of LuaJIT (pick the .tar.gz), -if you haven't already done so. Move it to a directory of your choice, -open a terminal window and change to this directory. Now unpack the archive -and change to the newly created directory: +The recommended way to fetch the latest version is to do a pull from +the git repository. +

    +

    +Alternatively, download the latest source package of LuaJIT (pick the .tar.gz). +Move it to a directory of your choice, open a terminal window and change +to this directory. Now unpack the archive and change to the newly created +directory (replace XX.YY.ZZ with the version you downloaded):

    -tar zxf LuaJIT-2.0.5.tar.gz
    -cd LuaJIT-2.0.5
    +tar zxf LuaJIT-XX.YY.ZZ.tar.gz +cd LuaJIT-XX.YY.ZZ +

    Building LuaJIT

    The supplied Makefiles try to auto-detect the settings needed for your @@ -216,9 +358,12 @@

    Building LuaJIT

    make PREFIX=/home/myself/lj2

    -Note for OSX: you must set the MACOSX_DEPLOYMENT_TARGET -environment variable to a value supported by your toolchain. +Note for macOS: you must set the MACOSX_DEPLOYMENT_TARGET +environment variable to a value supported by your toolchain:

    +
    +MACOSX_DEPLOYMENT_TARGET=XX.YY make
    +

    Installing LuaJIT

    The top-level Makefile installs LuaJIT by default under @@ -245,13 +390,14 @@

    Prerequisites

    Either install one of the open source SDKs (» MinGW or -Cygwin), which come with a modified +» Cygwin), which come with a modified GCC plus the required development headers. Or install Microsoft's Visual Studio (MSVC).

    -Next, download the source package and unpack it using an archive manager -(e.g. the Windows Explorer) to a directory of your choice. +Next, pull from the git repository or download the source package and +unpack it using an archive manager (e.g. the Windows Explorer) to +a directory of your choice.

    Building with MSVC

    @@ -269,8 +415,8 @@

    Building with MSVC

    Building with MinGW or Cygwin

    Open a command prompt window and make sure the MinGW or Cygwin programs -are in your path. Then cd to the directory where -you've unpacked the sources and run this command for MinGW: +are in your path. Then cd to the directory of the git repository +or where you've unpacked the sources. Then run this command for MinGW:

     mingw32-make
    @@ -325,7 +471,7 @@ 

    Cross-compiling LuaJIT

    target OS differ, or you'll get assembler or linker errors:

      -
    • E.g. if you're compiling on a Windows or OSX host for embedded Linux or Android, you need to add TARGET_SYS=Linux to the examples below.
    • +
    • E.g. if you're compiling on a Windows or macOS host for embedded Linux or Android, you need to add TARGET_SYS=Linux to the examples below.
    • For a minimal target OS, you may need to disable the built-in allocator in src/Makefile and use TARGET_SYS=Other.
    • Don't forget to specify the same TARGET_SYS for the install step, too.
    @@ -388,7 +534,7 @@

    Cross-compiling LuaJIT

    make CROSS=mipsel-linux- TARGET_CFLAGS="-mips64r2 -mabi=64"

    -You can cross-compile for Android using the Android NDK. +You can cross-compile for Android using the » Android NDK. Please adapt the environment variables to match the install locations and the desired target platform. E.g. Android 4.1 corresponds to ABI level 16.

    @@ -400,7 +546,8 @@

    Cross-compiling LuaJIT

    NDKCC=$NDKBIN/aarch64-linux-android21-clang make CROSS=$NDKCROSS \ STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \ - TARGET_LD=$NDKCC + TARGET_LD=$NDKCC TARGET_AR="$NDKBIN/llvm-ar rcus" \ + TARGET_STRIP=$NDKBIN/llvm-strip # Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.1+ (JB) NDKDIR=/opt/android/ndk @@ -409,10 +556,11 @@

    Cross-compiling LuaJIT

    NDKCC=$NDKBIN/armv7a-linux-androideabi16-clang make HOST_CC="gcc -m32" CROSS=$NDKCROSS \ STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \ - TARGET_LD=$NDKCC + TARGET_LD=$NDKCC TARGET_AR="$NDKBIN/llvm-ar rcus" \ + TARGET_STRIP=$NDKBIN/llvm-strip

    -You can cross-compile for iOS 3.0+ (iPhone/iPad) using the iOS SDK: +You can cross-compile for iOS 3.0+ (iPhone/iPad) using the » iOS SDK:

    Note: the JIT compiler is disabled for iOS, because regular iOS Apps @@ -433,8 +581,7 @@

    Cross-compiling LuaJIT

    Cross-compiling for consoles

    Building LuaJIT for consoles requires both a supported host compiler -(x86 or x64) and a cross-compiler (to PPC or ARM) from the official -console SDK. +(x86 or x64) and a cross-compiler from the official console SDK.

    Due to restrictions on consoles, the JIT compiler is disabled and only @@ -455,45 +602,58 @@

    Cross-compiling for consoles

    make HOST_CC="gcc -m32" CROSS=ppu-lv2-

    -To cross-compile for PS4 from a Windows host, -open a "Visual Studio .NET Command Prompt" (64 bit host compiler), -cd to the directory where you've unpacked the sources and -run the following commands: +To cross-compile for the other consoles from a Windows host, open a +"Native Tools Command Prompt for VS". You need to choose either the 32 +or the 64 bit version of the host compiler to match the target. +Then cd to the src directory below where you've +unpacked the sources and run the build command given in the table:

    -
    -cd src
    -ps4build
    -
    -

    -To cross-compile for PS Vita from a Windows host, -open a "Visual Studio .NET Command Prompt" (32 bit host compiler), -cd to the directory where you've unpacked the sources and -run the following commands: -

    -
    -cd src
    -psvitabuild
    -
    -

    -To cross-compile for Xbox 360 from a Windows host, -open a "Visual Studio .NET Command Prompt" (32 bit host compiler), -cd to the directory where you've unpacked the sources and run -the following commands: -

    -
    -cd src
    -xedkbuild
    -
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ConsoleBitsBuild Command
    PS464ps4build
    PS564ps5build
    PS Vita32psvitabuild
    Xbox 36032xedkbuild
    Xbox One64xb1build
    Nintendo Switch NX3232nxbuild
    Nintendo Switch NX6464nxbuild

    -To cross-compile for Xbox One from a Windows host, -open a "Visual Studio .NET Command Prompt" (64 bit host compiler), -cd to the directory where you've unpacked the sources and run -the following commands: +Please check out the comments in the corresponding *.bat +file for more options.

    -
    -cd src
    -xb1build
    -

    Embedding LuaJIT

    @@ -522,14 +682,6 @@

    Embedding LuaJIT

    intend to load Lua/C modules at runtime. -
  • -If you're building a 64 bit application on OSX which links directly or -indirectly against LuaJIT which is not built for LJ_GC64 mode, -you need to link your main executable with these flags: -
    --pagezero_size 10000 -image_base 100000000
    -
    -
  • Additional hints for initializing LuaJIT using the C API functions:

      @@ -538,16 +690,16 @@

      Embedding LuaJIT

      for embedding Lua or LuaJIT into your application.
    • Make sure you use luaL_newstate. Avoid using lua_newstate, since this uses the (slower) default memory -allocator from your system (no support for this on x64).
    • +allocator from your system (no support for this on 64 bit architectures).
    • Make sure you use luaL_openlibs and not the old Lua 5.0 style of calling luaopen_base etc. directly.
    • To change or extend the list of standard libraries to load, copy src/lib_init.c to your project and modify it accordingly. -Make sure the jit library is loaded or the JIT compiler +Make sure the jit library is loaded, or the JIT compiler will not be activated.
    • The bit.* module for bitwise operations is already built-in. There's no need to statically link -Lua BitOp to your application.
    • +» Lua BitOp to your application.

    Hints for Distribution Maintainers

    @@ -562,7 +714,7 @@

    Hints for Distribution Maintainers

    There should be absolutely no need to patch luaconf.h or any of the Makefiles. And please do not hand-pick files for your packages — simply use whatever make install creates. There's a reason -for all of the files and directories it creates. +for all the files and directories it creates.

    The build system uses GNU make and auto-detects most settings based on @@ -614,7 +766,7 @@

    Hints for Distribution Maintainers

    LuaJIT is a Just-In-Time Compiler (JIT) for the -Lua programming language. +» Lua programming language. Lua is a powerful, dynamic and light-weight programming language. It may be embedded or used as a general-purpose, stand-alone language.

    -LuaJIT is Copyright © 2005-2020 Mike Pall, released under the -MIT open source license. +LuaJIT is Copyright © 2005-2022 Mike Pall, released under the +» MIT open source license.

    Compatibility

    - +
    WindowsLinuxBSDOSXPOSIX
    WindowsLinuxBSDmacOSPOSIX
    EmbeddedAndroidiOS
    - +
    PS3PS4PS VitaXbox 360Xbox One
    PS3PS4
    PS5
    PS VitaXbox 360Xbox OneNintendo
    Switch
    @@ -220,7 +220,7 @@

    More ...

    @@ -89,7 +89,7 @@

    Command Line Options

    version of the regular lua stand-alone executable. It supports the same basic options, too. luajit -h prints a short list of the available options. Please have a look at the -Lua manual +» Lua manual for details.

    @@ -109,6 +109,7 @@

    -b[options] input output

  • -t type — Set output file type (default: auto-detect from output name).
  • -a arch — Override architecture for object files (default: native).
  • -o os — Override OS for object files (default: native).
  • +
  • -F name — Override filename (default: input filename).
  • -e chunk — Use chunk string as input.
  • - (a single minus sign) — Use stdin as input and/or stdout as output.
  • @@ -182,9 +183,9 @@

    -j cmd[=arg[,arg...]]

    itself. For a description of their options and output format, please read the comment block at the start of their source. They can be found in the lib directory of the source -distribution or installed under the jit directory. By default -this is /usr/local/share/luajit-2.0.5/jit on POSIX -systems. +distribution or installed under the jit directory. By default, +this is /usr/local/share/luajit-XX.YY.ZZ>/jit on POSIX +systems (replace XX.YY.ZZ by the installed version).

    -O[level]
    @@ -214,11 +215,17 @@

    -O[level]
    You can either use this option multiple times (like -Ocse -O-dce -Ohotloop=10) or separate several settings with a comma (like -O+cse,-dce,hotloop=10). The settings are applied from -left to right and later settings override earlier ones. You can freely +left to right, and later settings override earlier ones. You can freely mix the three forms, but note that setting an optimization level overrides all earlier flags.

    +Note that -Ofma is not enabled by default at any level, +because it affects floating-point result accuracy. Only enable this, +if you fully understand the trade-offs of FMA for performance (higher), +determinism (lower) and numerical accuracy (higher). +

    +

    Here are the available flags and at what optimization levels they are enabled:

    @@ -250,6 +257,8 @@

    -O[level]

    + +
    GCCClang
    LLVM
    MSVC
    sink  Allocation/Store Sinking
    fuse  Fusion of operands into instructions
    fma    Fused multiply-add

    Here are the parameters and their default settings: @@ -293,7 +302,7 @@

    -O[level]

    -LuaJIT 2.0 is the current -stable branch. This branch is in -feature-freeze — new features will only be added to LuaJIT 2.1. +This documentation is for LuaJIT 2.1.0-beta3. Please check the doc +directory in each git branch for the version-specific documentation. +

    +

    +The currently developed branches are LuaJIT 2.1 and LuaJIT 2.0. +

    +

    +LuaJIT 2.0 is in feature-freeze — new features will only +be added to LuaJIT 2.1.

    Current Status

    @@ -75,7 +81,7 @@

    Current Status

    • There are some differences in implementation-defined behavior. -These either have a good reason, are arbitrary design choices +These either have a good reason, are arbitrary design choices, or are due to quirks in the VM. The latter cases may get fixed if a demonstrable need is shown.
    • @@ -84,30 +90,12 @@

      Current Status

      hooks for non-Lua functions) and shows slightly different behavior in LuaJIT (no per-coroutine hooks, no tail call counting). -
    • -Currently some out-of-memory errors from on-trace code are not -handled correctly. The error may fall through an on-trace -pcall or it may be passed on to the function set with -lua_atpanic on x64. This issue will be fixed with the new -garbage collector. -
    • -
    • -LuaJIT on 64 bit systems provides a limited range of 47 bits for the -legacy lightuserdata data type. -This is only relevant on x64 systems which use the negative part of the -virtual address space in user mode, e.g. Solaris/x64, and on ARM64 systems -configured with a 48 bit or 52 bit VA. -Avoid using lightuserdata to hold pointers that may point outside -of that range, e.g. variables on the stack. In general, avoid this data -type for new code and replace it with (much more performant) FFI bindings. -FFI cdata pointers can address the full 64 bit range. -