diff options
Diffstat (limited to '')
-rw-r--r-- | docs/index.html | 11 | ||||
-rw-r--r-- | src/intercopycontext.cpp | 2 | ||||
-rw-r--r-- | src/lanes.lua | 48 | ||||
-rw-r--r-- | src/universe.cpp | 6 | ||||
-rw-r--r-- | src/universe.h | 2 | ||||
-rw-r--r-- | tests/basic.lua | 24 |
6 files changed, 58 insertions, 35 deletions
diff --git a/docs/index.html b/docs/index.html index c3e8285..0cad4a0 100644 --- a/docs/index.html +++ b/docs/index.html | |||
@@ -436,6 +436,17 @@ | |||
436 | Select the cancellation mode used at Lanes shutdown to request free running lane termination. See <a href="#cancelling">lane cancellation</a>. Default is <tt>"hard"</tt>. | 436 | Select the cancellation mode used at Lanes shutdown to request free running lane termination. See <a href="#cancelling">lane cancellation</a>. Default is <tt>"hard"</tt>. |
437 | </td> | 437 | </td> |
438 | </tr> | 438 | </tr> |
439 | <tr valign=top> | ||
440 | <td id="strip_functions"> | ||
441 | <code>.strip_functions</code> | ||
442 | </td> | ||
443 | <td> | ||
444 | <tt>nil</tt>/<tt>false</tt>/<tt>true</tt> | ||
445 | </td> | ||
446 | <td> | ||
447 | Controls function bytecode stripping when dumping them for lane transfer. Choose between faster copies or more debug info. Default is <tt>true</tt>. | ||
448 | </td> | ||
449 | </tr> | ||
439 | </table> | 450 | </table> |
440 | </p> | 451 | </p> |
441 | 452 | ||
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 3557c7b..07eea24 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -196,7 +196,7 @@ void InterCopyContext::copy_func() const | |||
196 | // not sure this could ever fail but for memory shortage reasons | 196 | // not sure this could ever fail but for memory shortage reasons |
197 | // last parameter is Lua 5.4-specific (no stripping) | 197 | // last parameter is Lua 5.4-specific (no stripping) |
198 | luaL_Buffer B{}; | 198 | luaL_Buffer B{}; |
199 | if (lua504_dump(L1, buf_writer, &B, 0) != 0) { | 199 | if (lua504_dump(L1, buf_writer, &B, U->stripFunctions) != 0) { |
200 | raise_luaL_error(getErrL(), "internal error: function dump failed."); | 200 | raise_luaL_error(getErrL(), "internal error: function dump failed."); |
201 | } | 201 | } |
202 | 202 | ||
diff --git a/src/lanes.lua b/src/lanes.lua index 4f11033..95c4eff 100644 --- a/src/lanes.lua +++ b/src/lanes.lua | |||
@@ -90,19 +90,20 @@ local isLuaJIT = (package and package.loaded.jit and jit.version) and true or fa | |||
90 | 90 | ||
91 | local default_params = | 91 | local default_params = |
92 | { | 92 | { |
93 | nb_user_keepers = 0, | 93 | -- LuaJIT provides a thread-unsafe allocator by default, so we need to protect it when used in parallel lanes |
94 | allocator = isLuaJIT and "protected" or nil, | ||
95 | demote_full_userdata = nil, | ||
96 | -- it looks also like LuaJIT allocator may not appreciate direct use of its allocator for other purposes than the VM operation | ||
97 | internal_allocator = isLuaJIT and "libc" or "allocator", | ||
94 | keepers_gc_threshold = -1, | 98 | keepers_gc_threshold = -1, |
99 | nb_user_keepers = 0, | ||
95 | on_state_create = nil, | 100 | on_state_create = nil, |
96 | shutdown_timeout = 0.25, | ||
97 | shutdown_mode = "hard", | 101 | shutdown_mode = "hard", |
98 | with_timers = false, | 102 | shutdown_timeout = 0.25, |
103 | strip_functions = true, | ||
99 | track_lanes = false, | 104 | track_lanes = false, |
100 | demote_full_userdata = nil, | ||
101 | verbose_errors = false, | 105 | verbose_errors = false, |
102 | -- LuaJIT provides a thread-unsafe allocator by default, so we need to protect it when used in parallel lanes | 106 | with_timers = false, |
103 | allocator = isLuaJIT and "protected" or nil, | ||
104 | -- it looks also like LuaJIT allocator may not appreciate direct use of its allocator for other purposes than the VM operation | ||
105 | internal_allocator = isLuaJIT and "libc" or "allocator" | ||
106 | } | 107 | } |
107 | 108 | ||
108 | -- ################################################################################################# | 109 | -- ################################################################################################# |
@@ -114,39 +115,40 @@ end | |||
114 | 115 | ||
115 | local param_checkers = | 116 | local param_checkers = |
116 | { | 117 | { |
117 | nb_user_keepers = function(val_) | ||
118 | -- nb_user_keepers should be a number in [0,100] (so that nobody tries to run OOM by specifying a huge amount) | ||
119 | return type(val_) == "number" and val_ >= 0 and val_ <= 100 | ||
120 | end, | ||
121 | keepers_gc_threshold = function(val_) | ||
122 | -- keepers_gc_threshold should be a number | ||
123 | return type(val_) == "number" | ||
124 | end, | ||
125 | with_timers = boolean_param_checker, | ||
126 | allocator = function(val_) | 118 | allocator = function(val_) |
127 | -- can be nil, "protected", or a function | 119 | -- can be nil, "protected", or a function |
128 | return val_ and (type(val_) == "function" or val_ == "protected") or true | 120 | return val_ and (type(val_) == "function" or val_ == "protected") or true |
129 | end, | 121 | end, |
122 | demote_full_userdata = boolean_param_checker, | ||
130 | internal_allocator = function(val_) | 123 | internal_allocator = function(val_) |
131 | -- can be "libc" or "allocator" | 124 | -- can be "libc" or "allocator" |
132 | return val_ == "libc" or val_ == "allocator" | 125 | return val_ == "libc" or val_ == "allocator" |
133 | end, | 126 | end, |
127 | keepers_gc_threshold = function(val_) | ||
128 | -- keepers_gc_threshold should be a number | ||
129 | return type(val_) == "number" | ||
130 | end, | ||
131 | nb_user_keepers = function(val_) | ||
132 | -- nb_user_keepers should be a number in [0,100] (so that nobody tries to run OOM by specifying a huge amount) | ||
133 | return type(val_) == "number" and val_ >= 0 and val_ <= 100 | ||
134 | end, | ||
134 | on_state_create = function(val_) | 135 | on_state_create = function(val_) |
135 | -- on_state_create may be nil or a function | 136 | -- on_state_create may be nil or a function |
136 | return val_ and type(val_) == "function" or true | 137 | return val_ and type(val_) == "function" or true |
137 | end, | 138 | end, |
138 | shutdown_timeout = function(val_) | ||
139 | -- shutdown_timeout should be a number >= 0 | ||
140 | return type(val_) == "number" and val_ >= 0 | ||
141 | end, | ||
142 | shutdown_mode = function(val_) | 139 | shutdown_mode = function(val_) |
143 | local valid_hooks = { soft = true, hard = true, call = true, ret = true, line = true, count = true } | 140 | local valid_hooks = { soft = true, hard = true, call = true, ret = true, line = true, count = true } |
144 | -- shutdown_mode should be a known hook mask | 141 | -- shutdown_mode should be a known hook mask |
145 | return valid_hooks[val_] | 142 | return valid_hooks[val_] |
146 | end, | 143 | end, |
144 | shutdown_timeout = function(val_) | ||
145 | -- shutdown_timeout should be a number >= 0 | ||
146 | return type(val_) == "number" and val_ >= 0 | ||
147 | end, | ||
148 | strip_functions = boolean_param_checker, | ||
147 | track_lanes = boolean_param_checker, | 149 | track_lanes = boolean_param_checker, |
148 | demote_full_userdata = boolean_param_checker, | 150 | verbose_errors = boolean_param_checker, |
149 | verbose_errors = boolean_param_checker | 151 | with_timers = boolean_param_checker, |
150 | } | 152 | } |
151 | 153 | ||
152 | -- ################################################################################################# | 154 | -- ################################################################################################# |
diff --git a/src/universe.cpp b/src/universe.cpp index 2e7fd55..5a52f7e 100644 --- a/src/universe.cpp +++ b/src/universe.cpp | |||
@@ -107,6 +107,12 @@ Universe::Universe() | |||
107 | lua_setfield(L_, -2, "__gc"); // L_: settings universe {mt} | 107 | lua_setfield(L_, -2, "__gc"); // L_: settings universe {mt} |
108 | lua_setmetatable(L_, -2); // L_: settings universe | 108 | lua_setmetatable(L_, -2); // L_: settings universe |
109 | lua_pop(L_, 1); // L_: settings | 109 | lua_pop(L_, 1); // L_: settings |
110 | |||
111 | // TODO: write some tests to see what happens when we trigger errors in stripped mode | ||
112 | std::ignore = luaG_getfield(L_, 1, "strip_functions"); // L_: settings strip_functions | ||
113 | _U->stripFunctions = lua_toboolean(L_, -1) ? true : false; | ||
114 | lua_pop(L_, 1); // L_: settings | ||
115 | |||
110 | std::ignore = luaG_getfield(L_, 1, "verbose_errors"); // L_: settings verbose_errors | 116 | std::ignore = luaG_getfield(L_, 1, "verbose_errors"); // L_: settings verbose_errors |
111 | _U->verboseErrors = lua_toboolean(L_, -1) ? true : false; | 117 | _U->verboseErrors = lua_toboolean(L_, -1) ? true : false; |
112 | lua_pop(L_, 1); // L_: settings | 118 | lua_pop(L_, 1); // L_: settings |
diff --git a/src/universe.h b/src/universe.h index 7b9f309..4239466 100644 --- a/src/universe.h +++ b/src/universe.h | |||
@@ -133,6 +133,8 @@ class Universe | |||
133 | 133 | ||
134 | bool demoteFullUserdata{ false }; | 134 | bool demoteFullUserdata{ false }; |
135 | 135 | ||
136 | bool stripFunctions{ true }; | ||
137 | |||
136 | // before a state is created, this function will be called to obtain the allocator | 138 | // before a state is created, this function will be called to obtain the allocator |
137 | lua_CFunction provideAllocator{ nullptr }; | 139 | lua_CFunction provideAllocator{ nullptr }; |
138 | 140 | ||
diff --git a/tests/basic.lua b/tests/basic.lua index da7d756..fff19ed 100644 --- a/tests/basic.lua +++ b/tests/basic.lua | |||
@@ -6,8 +6,8 @@ | |||
6 | -- To do: | 6 | -- To do: |
7 | -- - ... | 7 | -- - ... |
8 | -- | 8 | -- |
9 | 9 | local config = { with_timers = false, strip_functions = false, internal_allocator = "libc"} | |
10 | local require_lanes_result_1, require_lanes_result_2 = require "lanes".configure{ with_timers = false, internal_allocator = "libc"} | 10 | local require_lanes_result_1, require_lanes_result_2 = require "lanes".configure(config) |
11 | print("require_lanes_result:", require_lanes_result_1, require_lanes_result_2) | 11 | print("require_lanes_result:", require_lanes_result_1, require_lanes_result_2) |
12 | local lanes = require_lanes_result_1 | 12 | local lanes = require_lanes_result_1 |
13 | 13 | ||
@@ -403,26 +403,28 @@ local function chunk2(linda) | |||
403 | -- | 403 | -- |
404 | local info= debug.getinfo(1) -- 1 = us | 404 | local info= debug.getinfo(1) -- 1 = us |
405 | -- | 405 | -- |
406 | PRINT "debug.getinfo->" | ||
406 | for k,v in pairs(info) do PRINT(k,v) end | 407 | for k,v in pairs(info) do PRINT(k,v) end |
407 | 408 | ||
408 | assert(info.nups == (_VERSION == "Lua 5.1" and 2 or 3)) -- one upvalue + PRINT + _ENV (Lua 5.2 only) | 409 | -- some assertions are adjusted depending on config.strip_functions, because it changes what we get out of debug.getinfo |
409 | assert(info.what == "Lua") | 410 | assert(info.nups == (_VERSION == "Lua 5.1" and 3 or 4), "bad nups") -- upvalue + config + PRINT + _ENV (Lua > 5.2 only) |
411 | assert(info.what == "Lua", "bad what") | ||
410 | --assert(info.name == "chunk2") -- name does not seem to come through | 412 | --assert(info.name == "chunk2") -- name does not seem to come through |
411 | assert(string.match(info.source, "^@.*basic.lua$")) | 413 | assert(config.strip_functions and info.source=="=?" or string.match(info.source, "^@.*basic.lua$"), "bad info.source") |
412 | assert(string.match(info.short_src, "^.*basic.lua$")) | 414 | assert(config.strip_functions and info.short_src=="?" or string.match(info.short_src, "^.*basic.lua$"), "bad info.short_src") |
413 | -- These vary so let's not be picky (they're there..) | 415 | -- These vary so let's not be picky (they're there..) |
414 | -- | 416 | -- |
415 | assert(info.linedefined > 200) -- start of 'chunk2' | 417 | assert(info.linedefined == 400, "bad linedefined") -- start of 'chunk2' |
416 | assert(info.currentline > info.linedefined) -- line of 'debug.getinfo' | 418 | assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo' |
417 | assert(info.lastlinedefined > info.currentline) -- end of 'chunk2' | 419 | assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2' |
418 | local k,func= linda:receive("down") | 420 | local k,func= linda:receive("down") |
419 | assert(type(func)=="function") | 421 | assert(type(func)=="function", "not a function") |
420 | assert(k=="down") | 422 | assert(k=="down") |
421 | 423 | ||
422 | func(linda) | 424 | func(linda) |
423 | 425 | ||
424 | local k,str= linda:receive("down") | 426 | local k,str= linda:receive("down") |
425 | assert(str=="ok") | 427 | assert(str=="ok", "bad receive result") |
426 | 428 | ||
427 | linda:send("up", function() return ":)" end, "ok2") | 429 | linda:send("up", function() return ":)" end, "ok2") |
428 | end | 430 | end |