diff options
| author | Benoit Germain <bnt period germain arrobase gmail period com> | 2013-12-20 11:46:42 +0100 |
|---|---|---|
| committer | Benoit Germain <bnt period germain arrobase gmail period com> | 2013-12-20 11:46:42 +0100 |
| commit | 4ece73b1e0d8f75fa63a5b39a91731147870bd0a (patch) | |
| tree | 7b55c53524805988be95b7ecd34f3df0aa33ab23 /src | |
| parent | bfe766927eeced475904acdc08c0ec5375e5ab49 (diff) | |
| download | lanes-4ece73b1e0d8f75fa63a5b39a91731147870bd0a.tar.gz lanes-4ece73b1e0d8f75fa63a5b39a91731147870bd0a.tar.bz2 lanes-4ece73b1e0d8f75fa63a5b39a91731147870bd0a.zip | |
new config option demote_full_userdata
use demote_full_userdata to select between light userdata demotion or
raising an error when attempting to transfer a non-deep full userdata
Diffstat (limited to 'src')
| -rw-r--r-- | src/lanes.lua | 50 | ||||
| -rw-r--r-- | src/tools.c | 25 |
2 files changed, 38 insertions, 37 deletions
diff --git a/src/lanes.lua b/src/lanes.lua index 6e2a736..4856a2d 100644 --- a/src/lanes.lua +++ b/src/lanes.lua | |||
| @@ -71,52 +71,34 @@ lanes.configure = function( settings_) | |||
| 71 | shutdown_timeout = 0.25, | 71 | shutdown_timeout = 0.25, |
| 72 | with_timers = true, | 72 | with_timers = true, |
| 73 | track_lanes = false, | 73 | track_lanes = false, |
| 74 | demote_full_userdata = nil, | ||
| 74 | verbose_errors = false, | 75 | verbose_errors = false, |
| 75 | -- LuaJIT provides a thread-unsafe allocator by default, so we need to protect it when used in parallel lanes | 76 | -- LuaJIT provides a thread-unsafe allocator by default, so we need to protect it when used in parallel lanes |
| 76 | protect_allocator = (jit and jit.version) and true or false | 77 | protect_allocator = (jit and jit.version) and true or false |
| 77 | } | 78 | } |
| 79 | local boolean_param_checker = function( val_) | ||
| 80 | -- non-'boolean-false' should be 'boolean-true' or nil | ||
| 81 | return val_ and (val_ == true) or true | ||
| 82 | end | ||
| 78 | local param_checkers = | 83 | local param_checkers = |
| 79 | { | 84 | { |
| 80 | nb_keepers = function( _val) | 85 | nb_keepers = function( val_) |
| 81 | -- nb_keepers should be a number > 0 | 86 | -- nb_keepers should be a number > 0 |
| 82 | return type( _val) == "number" and _val > 0 | 87 | return type( val_) == "number" and val_ > 0 |
| 83 | end, | ||
| 84 | with_timers = function( _val) | ||
| 85 | -- with_timers may be nil or boolean | ||
| 86 | if _val then | ||
| 87 | return type( _val) == "boolean" | ||
| 88 | else | ||
| 89 | return true -- _val is either false or nil | ||
| 90 | end | ||
| 91 | end, | 88 | end, |
| 92 | protect_allocator = function( _val) | 89 | with_timers = boolean_param_checker, |
| 93 | -- protect_allocator may be nil or boolean | 90 | protect_allocator = boolean_param_checker, |
| 94 | if _val then | 91 | on_state_create = function( val_) |
| 95 | return type( _val) == "boolean" | ||
| 96 | else | ||
| 97 | return true -- _val is either false or nil | ||
| 98 | end | ||
| 99 | end, | ||
| 100 | on_state_create = function( _val) | ||
| 101 | -- on_state_create may be nil or a function | 92 | -- on_state_create may be nil or a function |
| 102 | return _val and type( _val) == "function" or true | 93 | return val_ and type( val_) == "function" or true |
| 103 | end, | 94 | end, |
| 104 | shutdown_timeout = function( _val) | 95 | shutdown_timeout = function( val_) |
| 105 | -- shutdown_timeout should be a number >= 0 | 96 | -- shutdown_timeout should be a number >= 0 |
| 106 | return type( _val) == "number" and _val >= 0 | 97 | return type( val_) == "number" and val_ >= 0 |
| 107 | end, | ||
| 108 | track_lanes = function( _val) | ||
| 109 | -- track_lanes may be nil or boolean | ||
| 110 | return _val and type( _val) == "boolean" or true | ||
| 111 | end, | 98 | end, |
| 112 | verbose_errors = function( _val) | 99 | track_lanes = boolean_param_checker, |
| 113 | -- verbose_errors may be nil or boolean | 100 | demote_full_userdata = boolean_param_checker, |
| 114 | if _val then | 101 | verbose_errors = boolean_param_checker |
| 115 | return type( _val) == "boolean" | ||
| 116 | else | ||
| 117 | return true -- _val is either false or nil | ||
| 118 | end | ||
| 119 | end | ||
| 120 | } | 102 | } |
| 121 | 103 | ||
| 122 | local params_checker = function( settings_) | 104 | local params_checker = function( settings_) |
diff --git a/src/tools.c b/src/tools.c index b5f2f4b..e743393 100644 --- a/src/tools.c +++ b/src/tools.c | |||
| @@ -1886,9 +1886,28 @@ static bool_t inter_copy_one_( lua_State* L2, uint_t L2_cache_i, lua_State* L, u | |||
| 1886 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "USERDATA\n" INDENT_END)); | 1886 | DEBUGSPEW_CODE( fprintf( stderr, INDENT_BEGIN "USERDATA\n" INDENT_END)); |
| 1887 | if( !luaG_copydeep( L, L2, i)) | 1887 | if( !luaG_copydeep( L, L2, i)) |
| 1888 | { | 1888 | { |
| 1889 | // Cannot copy it full; copy as light userdata | 1889 | // Not a deep full userdata |
| 1890 | // | 1890 | bool_t demote = FALSE; |
| 1891 | lua_pushlightuserdata( L2, lua_touserdata( L, i)); | 1891 | lua_getfield( L, LUA_REGISTRYINDEX, CONFIG_REGKEY); |
| 1892 | if( lua_istable( L, -1)) // should not happen, but who knows... | ||
| 1893 | { | ||
| 1894 | lua_getfield( L, -1, "demote_full_userdata"); | ||
| 1895 | demote = lua_toboolean( L, -1); | ||
| 1896 | lua_pop( L, 2); | ||
| 1897 | } | ||
| 1898 | else | ||
| 1899 | { | ||
| 1900 | lua_pop( L, 1); | ||
| 1901 | } | ||
| 1902 | if( demote) // attempt demotion to light userdata | ||
| 1903 | { | ||
| 1904 | void* lud = lua_touserdata( L, i); | ||
| 1905 | lua_pushlightuserdata( L2, lud); | ||
| 1906 | } | ||
| 1907 | else // raise an error | ||
| 1908 | { | ||
| 1909 | (void) luaL_error( L, "can't copy non-deep full userdata across lanes"); | ||
| 1910 | } | ||
| 1892 | } | 1911 | } |
| 1893 | break; | 1912 | break; |
| 1894 | 1913 | ||
