From 7c439d1b6f6c6115f38605b2d51c44d7a6c08052 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 22 Feb 2024 16:23:02 +0100 Subject: Detect runtime LuaJIT/PUC-Lua mismatch --- CHANGES | 4 +++ docs/index.html | 2 +- lanes-3.16.2-0.rockspec | 78 ------------------------------------------------- lanes-3.16.3-0.rockspec | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lanes.c | 21 +++++++++---- src/lanes.h | 2 +- 6 files changed, 100 insertions(+), 85 deletions(-) delete mode 100644 lanes-3.16.2-0.rockspec create mode 100644 lanes-3.16.3-0.rockspec diff --git a/CHANGES b/CHANGES index b5ad5df..77c34b3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ CHANGES: +CHANGE 158: BGe 22-Feb-24 + * naive luajit detection in PUC-Lua-based builds to detect mismatches (don't run ) + * internal version bumped to 3.16.3 + CHANGE 157: Mitalie 17-Aug-23 * Prevent crash on linux as non-root * internal version bumped to 3.16.2 diff --git a/docs/index.html b/docs/index.html index bca8340..3fd77dc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -70,7 +70,7 @@

- This document was revised on 17-Aug-23, and applies to version 3.16.2. + This document was revised on 22-Feb-24, and applies to version 3.16.3.

diff --git a/lanes-3.16.2-0.rockspec b/lanes-3.16.2-0.rockspec deleted file mode 100644 index 5c4e437..0000000 --- a/lanes-3.16.2-0.rockspec +++ /dev/null @@ -1,78 +0,0 @@ --- --- Lanes rockspec --- --- Ref: --- --- - -package = "Lanes" - -version = "3.16.2-0" - -source= { - url= "git+https://github.com/LuaLanes/lanes.git", - branch= "v3.16.2" -} - -description = { - summary= "Multithreading support for Lua", - detailed= [[ - Lua Lanes is a portable, message passing multithreading library - providing the possibility to run multiple Lua states in parallel. - ]], - license= "MIT/X11", - homepage="https://github.com/LuaLanes/lanes", - maintainer="Benoit Germain " -} - --- Q: What is the difference of "windows" and "win32"? Seems there is none; --- so should we list either one or both? --- -supported_platforms= { "win32", - "macosx", - "linux", - "freebsd", -- TBD: not tested - "msys", -- TBD: not supported by LuaRocks 1.0 (or is it?) -} - -dependencies= { - "lua >= 5.1", -- builds with either 5.1, 5.2, 5.3 and 5.4 -} - -build = { - type = "builtin", - platforms = - { - linux = - { - modules = - { - ["lanes.core"] = - { - libraries = "pthread" - }, - } - } - }, - modules = - { - ["lanes.core"] = - { - sources = - { - "src/cancel.c", - "src/compat.c", - "src/deep.c", - "src/keeper.c", - "src/lanes.c", - "src/linda.c", - "src/tools.c", - "src/state.c", - "src/threading.c", - "src/universe.c" - }, - incdirs = { "src"}, - }, - lanes = "src/lanes.lua" - } -} diff --git a/lanes-3.16.3-0.rockspec b/lanes-3.16.3-0.rockspec new file mode 100644 index 0000000..e223a19 --- /dev/null +++ b/lanes-3.16.3-0.rockspec @@ -0,0 +1,78 @@ +-- +-- Lanes rockspec +-- +-- Ref: +-- +-- + +package = "Lanes" + +version = "3.16.3-0" + +source= { + url= "git+https://github.com/LuaLanes/lanes.git", + branch= "v3.16.3" +} + +description = { + summary= "Multithreading support for Lua", + detailed= [[ + Lua Lanes is a portable, message passing multithreading library + providing the possibility to run multiple Lua states in parallel. + ]], + license= "MIT/X11", + homepage="https://github.com/LuaLanes/lanes", + maintainer="Benoit Germain " +} + +-- Q: What is the difference of "windows" and "win32"? Seems there is none; +-- so should we list either one or both? +-- +supported_platforms= { "win32", + "macosx", + "linux", + "freebsd", -- TBD: not tested + "msys", -- TBD: not supported by LuaRocks 1.0 (or is it?) +} + +dependencies= { + "lua >= 5.1", -- builds with either 5.1/LuaJIT, 5.2, 5.3 and 5.4 +} + +build = { + type = "builtin", + platforms = + { + linux = + { + modules = + { + ["lanes.core"] = + { + libraries = "pthread" + }, + } + } + }, + modules = + { + ["lanes.core"] = + { + sources = + { + "src/cancel.c", + "src/compat.c", + "src/deep.c", + "src/keeper.c", + "src/lanes.c", + "src/linda.c", + "src/tools.c", + "src/state.c", + "src/threading.c", + "src/universe.c" + }, + incdirs = { "src"}, + }, + lanes = "src/lanes.lua" + } +} diff --git a/src/lanes.c b/src/lanes.c index d2c95ee..332a1b8 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -2083,6 +2083,17 @@ int LANES_API luaopen_lanes_core( lua_State* L) STACK_GROW( L, 4); STACK_CHECK( L, 0); + // Prevent PUC-Lua/LuaJIT mismatch. Hopefully this works for MoonJIT too + lua_getglobal( L, "jit"); // {jit?} +#if LUAJIT_FLAVOR() == 0 + if (!lua_isnil( L, -1)) + return luaL_error( L, "Lanes is built for PUC-Lua, don't run from LuaJIT"); +#else + if (lua_isnil( L, -1)) + return luaL_error( L, "Lanes is built for LuaJIT, don't run from PUC-Lua"); +#endif + lua_pop( L, 1); // + // Create main module interface table // we only have 1 closure, which must be called to configure Lanes lua_newtable( L); // M @@ -2092,15 +2103,15 @@ int LANES_API luaopen_lanes_core( lua_State* L) REGISTRY_GET( L, CONFIG_REGKEY); // M LG_configure() settings if( !lua_isnil( L, -1)) // this is not the first require "lanes.core": call configure() immediately { - lua_pushvalue( L, -1); // M LG_configure() settings settings - lua_setfield( L, -4, "settings"); // M LG_configure() settings - lua_call( L, 1, 0); // M + lua_pushvalue( L, -1); // M LG_configure() settings settings + lua_setfield( L, -4, "settings"); // M LG_configure() settings + lua_call( L, 1, 0); // M } else { // will do nothing on first invocation, as we haven't stored settings in the registry yet - lua_setfield( L, -3, "settings"); // M LG_configure() - lua_setfield( L, -2, "configure"); // M + lua_setfield( L, -3, "settings"); // M LG_configure() + lua_setfield( L, -2, "configure"); // M } STACK_END( L, 1); diff --git a/src/lanes.h b/src/lanes.h index b9245f3..7e1a2e5 100644 --- a/src/lanes.h +++ b/src/lanes.h @@ -12,7 +12,7 @@ #define LANES_VERSION_MAJOR 3 #define LANES_VERSION_MINOR 16 -#define LANES_VERSION_PATCH 2 +#define LANES_VERSION_PATCH 3 #define LANES_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR>MAJOR) || (LANES_VERSION_MAJOR==MAJOR && (LANES_VERSION_MINOR>MINOR || (LANES_VERSION_MINOR==MINOR && LANES_VERSION_PATCH>=PATCH)))) #define LANES_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((LANES_VERSION_MAJOR