aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/intercopycontext.cpp2
-rw-r--r--src/lanes.lua48
-rw-r--r--src/universe.cpp6
-rw-r--r--src/universe.h2
4 files changed, 34 insertions, 24 deletions
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
91local default_params = 91local 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
115local param_checkers = 116local 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