aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2021-09-22 15:39:13 +0200
committerBenoit Germain <bnt.germain@gmail.com>2021-09-22 15:39:13 +0200
commit9a53a224283fb1d41bae229ad34d61fe6dbc1b76 (patch)
tree8b21350377c3fdf2844871a01b1106c5ea6a0589
parent53e6c545448a9763cabc0b22ac56f6dc8b9cf96d (diff)
downloadlanes-9a53a224283fb1d41bae229ad34d61fe6dbc1b76.tar.gz
lanes-9a53a224283fb1d41bae229ad34d61fe6dbc1b76.tar.bz2
lanes-9a53a224283fb1d41bae229ad34d61fe6dbc1b76.zip
fix require() wrapper to return all values returned by original require()
Diffstat (limited to '')
-rw-r--r--CHANGES3
-rw-r--r--lanes-3.14.0-0.rockspec66
-rw-r--r--lanes-3.15.0-0.rockspec66
-rw-r--r--src/macros_and_utils.h2
-rw-r--r--src/state.c28
-rw-r--r--tests/basic.lua8
6 files changed, 22 insertions, 151 deletions
diff --git a/CHANGES b/CHANGES
index c21a3ed..0aca28a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
1CHANGES: 1CHANGES:
2 2
3CHANGE 150: BGe 22-Sep-21
4 * fix require() wrapper to return all values returned by original require()
5
3CHANGE 149: BGe 8-Jul-21 6CHANGE 149: BGe 8-Jul-21
4 * bumped version to 3.15.1 7 * bumped version to 3.15.1
5 * fix function transfer with lua_dump for Lua 5.4 failing for functions big enough to necessitate a buffer reallocation 8 * fix function transfer with lua_dump for Lua 5.4 failing for functions big enough to necessitate a buffer reallocation
diff --git a/lanes-3.14.0-0.rockspec b/lanes-3.14.0-0.rockspec
deleted file mode 100644
index 8d56b80..0000000
--- a/lanes-3.14.0-0.rockspec
+++ /dev/null
@@ -1,66 +0,0 @@
1--
2-- Lanes rockspec
3--
4-- Ref:
5-- <http://luarocks.org/en/Rockspec_format>
6--
7
8package = "Lanes"
9
10version = "3.14.0-0"
11
12source= {
13 url= "git://github.com/LuaLanes/lanes.git",
14 branch= "v3.14.0"
15}
16
17description = {
18 summary= "Multithreading support for Lua",
19 detailed= [[
20 Lua Lanes is a portable, message passing multithreading library
21 providing the possibility to run multiple Lua states in parallel.
22 ]],
23 license= "MIT/X11",
24 homepage="https://github.com/LuaLanes/lanes",
25 maintainer="Benoit Germain <bnt.germain@gmail.com>"
26}
27
28-- Q: What is the difference of "windows" and "win32"? Seems there is none;
29-- so should we list either one or both?
30--
31supported_platforms= { "win32",
32 "macosx",
33 "linux",
34 "freebsd", -- TBD: not tested
35 "msys", -- TBD: not supported by LuaRocks 1.0 (or is it?)
36}
37
38dependencies= {
39 "lua >= 5.1", -- builds with either 5.1, 5.2, 5.3 and 5.4
40}
41
42build = {
43 type = "builtin",
44 platforms =
45 {
46 linux =
47 {
48 modules =
49 {
50 ["lanes.core"] =
51 {
52 libraries = "pthread"
53 },
54 }
55 }
56 },
57 modules =
58 {
59 ["lanes.core"] =
60 {
61 sources = { "src/cancel.c", "src/compat.c", "src/deep.c", "src/lanes.c", "src/linda.c", "src/keeper.c", "src/tools.c", "src/threading.c", "src/universe.c"},
62 incdirs = { "src"},
63 },
64 lanes = "src/lanes.lua"
65 }
66}
diff --git a/lanes-3.15.0-0.rockspec b/lanes-3.15.0-0.rockspec
deleted file mode 100644
index bb23a7f..0000000
--- a/lanes-3.15.0-0.rockspec
+++ /dev/null
@@ -1,66 +0,0 @@
1--
2-- Lanes rockspec
3--
4-- Ref:
5-- <http://luarocks.org/en/Rockspec_format>
6--
7
8package = "Lanes"
9
10version = "3.15.0-0"
11
12source= {
13 url= "git://github.com/LuaLanes/lanes.git",
14 branch= "v3.15.0"
15}
16
17description = {
18 summary= "Multithreading support for Lua",
19 detailed= [[
20 Lua Lanes is a portable, message passing multithreading library
21 providing the possibility to run multiple Lua states in parallel.
22 ]],
23 license= "MIT/X11",
24 homepage="https://github.com/LuaLanes/lanes",
25 maintainer="Benoit Germain <bnt.germain@gmail.com>"
26}
27
28-- Q: What is the difference of "windows" and "win32"? Seems there is none;
29-- so should we list either one or both?
30--
31supported_platforms= { "win32",
32 "macosx",
33 "linux",
34 "freebsd", -- TBD: not tested
35 "msys", -- TBD: not supported by LuaRocks 1.0 (or is it?)
36}
37
38dependencies= {
39 "lua >= 5.1", -- builds with either 5.1, 5.2, 5.3 and 5.4
40}
41
42build = {
43 type = "builtin",
44 platforms =
45 {
46 linux =
47 {
48 modules =
49 {
50 ["lanes.core"] =
51 {
52 libraries = "pthread"
53 },
54 }
55 }
56 },
57 modules =
58 {
59 ["lanes.core"] =
60 {
61 sources = { "src/compat.c", "src/deep.c", "src/lanes.c", "src/linda.c", "src/keeper.c", "src/tools.c", "src/state.c", "src/threading.c", "src/universe.c"},
62 incdirs = { "src"},
63 },
64 lanes = "src/lanes.lua"
65 }
66}
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h
index ae3a6c9..dba0010 100644
--- a/src/macros_and_utils.h
+++ b/src/macros_and_utils.h
@@ -60,7 +60,7 @@ extern char const* debugspew_indent;
60 int const L##_oldtop = 0 60 int const L##_oldtop = 0
61 61
62#define STACK_MID( L, change) \ 62#define STACK_MID( L, change) \
63 do \ 63 do if( change != LUA_MULTRET) \
64 { \ 64 { \
65 int stack_check_a = lua_gettop( L) - L##_oldtop; \ 65 int stack_check_a = lua_gettop( L) - L##_oldtop; \
66 int stack_check_b = (change); \ 66 int stack_check_b = (change); \
diff --git a/src/state.c b/src/state.c
index cbbc0d8..81371b7 100644
--- a/src/state.c
+++ b/src/state.c
@@ -51,7 +51,7 @@ THE SOFTWARE.
51*/ 51*/
52 52
53//--- 53//---
54// [val]= new_require( ... ) 54// [val,...]= new_require( ... )
55// 55//
56// Call 'old_require' but only one lane at a time. 56// Call 'old_require' but only one lane at a time.
57// 57//
@@ -59,36 +59,32 @@ THE SOFTWARE.
59// 59//
60static int luaG_new_require( lua_State* L) 60static int luaG_new_require( lua_State* L)
61{ 61{
62 int rc, i; 62 int rc;
63 int args = lua_gettop( L); 63 int const args = lua_gettop( L); // args
64 Universe* U = universe_get( L); 64 Universe* U = universe_get( L);
65 //char const* modname = luaL_checkstring( L, 1); 65 //char const* modname = luaL_checkstring( L, 1);
66 66
67 STACK_GROW( L, args + 1); 67 STACK_GROW( L, 1);
68 STACK_CHECK( L, 0);
69 68
70 lua_pushvalue( L, lua_upvalueindex( 1)); 69 lua_pushvalue( L, lua_upvalueindex( 1)); // args require
71 for( i = 1; i <= args; ++ i) 70 lua_insert( L, 1); // require args
72 {
73 lua_pushvalue( L, i);
74 }
75 71
76 // Using 'lua_pcall()' to catch errors; otherwise a failing 'require' would 72 // Using 'lua_pcall()' to catch errors; otherwise a failing 'require' would
77 // leave us locked, blocking any future 'require' calls from other lanes. 73 // leave us locked, blocking any future 'require' calls from other lanes.
78 // 74
79 MUTEX_LOCK( &U->require_cs); 75 MUTEX_LOCK( &U->require_cs);
80 rc = lua_pcall( L, args, 1 /*retvals*/, 0 /*errfunc*/ ); 76 // starting with Lua 5.4, require may return a second optional value, so we need LUA_MULTRET
77 rc = lua_pcall( L, args, LUA_MULTRET, 0 /*errfunc*/ ); // err|result(s)
81 MUTEX_UNLOCK( &U->require_cs); 78 MUTEX_UNLOCK( &U->require_cs);
82 79
83 // the required module (or an error message) is left on the stack as returned value by original require function 80 // the required module (or an error message) is left on the stack as returned value by original require function
84 STACK_END( L, 1);
85 81
86 if( rc != LUA_OK) // LUA_ERRRUN / LUA_ERRMEM ? 82 if( rc != LUA_OK) // LUA_ERRRUN / LUA_ERRMEM ?
87 { 83 {
88 return lua_error( L); // error message already at [-1] 84 return lua_error( L);
89 } 85 }
90 86 // should be 1 for Lua <= 5.3, 1 or 2 starting with Lua 5.4
91 return 1; 87 return lua_gettop(L); // result(s)
92} 88}
93 89
94/* 90/*
diff --git a/tests/basic.lua b/tests/basic.lua
index 6fcfd53..7bbcbb3 100644
--- a/tests/basic.lua
+++ b/tests/basic.lua
@@ -7,8 +7,12 @@
7-- - ... 7-- - ...
8-- 8--
9 9
10local lanes = require "lanes".configure{ with_timers = false} 10local require_lanes_result_1, require_lanes_result_2 = require "lanes".configure{ with_timers = false}
11require "assert" -- assert.fails() 11print( "require_lanes_result:", require_lanes_result_1, require_lanes_result_2)
12local lanes = require_lanes_result_1
13
14local require_assert_result_1, require_assert_result_2 = require "assert" -- assert.fails()
15print( "require_assert_result:", require_assert_result_1, require_assert_result_2)
12 16
13local lanes_gen= assert( lanes.gen ) 17local lanes_gen= assert( lanes.gen )
14local lanes_linda= assert( lanes.linda ) 18local lanes_linda= assert( lanes.linda )