diff options
| author | Benoit Germain <bnt.germain@gmail.com> | 2018-11-30 11:13:21 +0100 |
|---|---|---|
| committer | Benoit Germain <bnt.germain@gmail.com> | 2018-11-30 11:13:21 +0100 |
| commit | b33d86abb9997c1c056d2f6e55a9754dffed5f48 (patch) | |
| tree | 63dc7e24d0abe2a5121a196063c6e8866e1f02bc | |
| parent | c64ad48fdf3aa9505fcf8505c832d1e397d60e85 (diff) | |
| download | lanes-b33d86abb9997c1c056d2f6e55a9754dffed5f48.tar.gz lanes-b33d86abb9997c1c056d2f6e55a9754dffed5f48.tar.bz2 lanes-b33d86abb9997c1c056d2f6e55a9754dffed5f48.zip | |
Fix clonable userdata uservalue transfer
| -rw-r--r-- | deep_test/deep_test.c | 27 | ||||
| -rw-r--r-- | deep_test/deep_test.vcxproj | 8 | ||||
| -rw-r--r-- | deep_test/deep_test.vcxproj.filters | 6 | ||||
| -rw-r--r-- | deep_test/deep_test.vcxproj.user | 2 | ||||
| -rw-r--r-- | deep_test/deeptest.lua | 13 | ||||
| -rw-r--r-- | src/tools.c | 9 |
6 files changed, 51 insertions, 14 deletions
diff --git a/deep_test/deep_test.c b/deep_test/deep_test.c index 7edd33f..9585a3c 100644 --- a/deep_test/deep_test.c +++ b/deep_test/deep_test.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "lauxlib.h" | 6 | #include "lauxlib.h" |
| 7 | 7 | ||
| 8 | #include "deep.h" | 8 | #include "deep.h" |
| 9 | #include "compat.h" | ||
| 9 | 10 | ||
| 10 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) | 11 | #if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC) |
| 11 | #define LANES_API __declspec(dllexport) | 12 | #define LANES_API __declspec(dllexport) |
| @@ -123,6 +124,27 @@ static int clonable_set( lua_State* L) | |||
| 123 | 124 | ||
| 124 | // ################################################################################################ | 125 | // ################################################################################################ |
| 125 | 126 | ||
| 127 | static int clonable_setuv( lua_State* L) | ||
| 128 | { | ||
| 129 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | ||
| 130 | int uv = (int) luaL_optinteger( L, 2, 1); | ||
| 131 | lua_settop( L, 3); | ||
| 132 | lua_pushboolean( L, lua_setiuservalue( L, 1, uv) != 0); | ||
| 133 | return 1; | ||
| 134 | } | ||
| 135 | |||
| 136 | // ################################################################################################ | ||
| 137 | |||
| 138 | static int clonable_getuv( lua_State* L) | ||
| 139 | { | ||
| 140 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | ||
| 141 | int uv = (int) luaL_optinteger( L, 2, 1); | ||
| 142 | lua_getiuservalue( L, 1, uv); | ||
| 143 | return 1; | ||
| 144 | } | ||
| 145 | |||
| 146 | // ################################################################################################ | ||
| 147 | |||
| 126 | static int clonable_tostring(lua_State* L) | 148 | static int clonable_tostring(lua_State* L) |
| 127 | { | 149 | { |
| 128 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); | 150 | struct s_MyClonableUserdata* self = (struct s_MyClonableUserdata*) lua_touserdata( L, 1); |
| @@ -170,6 +192,8 @@ static luaL_Reg const clonable_mt[] = | |||
| 170 | { "__gc", clonable_gc}, | 192 | { "__gc", clonable_gc}, |
| 171 | { "__lanesclone", clonable_lanesclone}, | 193 | { "__lanesclone", clonable_lanesclone}, |
| 172 | { "set", clonable_set}, | 194 | { "set", clonable_set}, |
| 195 | { "setuv", clonable_setuv}, | ||
| 196 | { "getuv", clonable_getuv}, | ||
| 173 | { NULL, NULL } | 197 | { NULL, NULL } |
| 174 | }; | 198 | }; |
| 175 | 199 | ||
| @@ -177,7 +201,8 @@ static luaL_Reg const clonable_mt[] = | |||
| 177 | 201 | ||
| 178 | int luaD_new_clonable( lua_State* L) | 202 | int luaD_new_clonable( lua_State* L) |
| 179 | { | 203 | { |
| 180 | lua_newuserdata( L, sizeof( struct s_MyClonableUserdata)); | 204 | int nuv = (int) luaL_optinteger( L, 1, 1); |
| 205 | lua_newuserdatauv( L, sizeof( struct s_MyClonableUserdata), nuv); | ||
| 181 | luaL_setmetatable( L, "clonable"); | 206 | luaL_setmetatable( L, "clonable"); |
| 182 | return 1; | 207 | return 1; |
| 183 | } | 208 | } |
diff --git a/deep_test/deep_test.vcxproj b/deep_test/deep_test.vcxproj index 110a191..d94b855 100644 --- a/deep_test/deep_test.vcxproj +++ b/deep_test/deep_test.vcxproj | |||
| @@ -65,7 +65,7 @@ | |||
| 65 | <CharacterSet>MultiByte</CharacterSet> | 65 | <CharacterSet>MultiByte</CharacterSet> |
| 66 | </PropertyGroup> | 66 | </PropertyGroup> |
| 67 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release 5.3|x64'" Label="Configuration"> | 67 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release 5.3|x64'" Label="Configuration"> |
| 68 | <ConfigurationType>Application</ConfigurationType> | 68 | <ConfigurationType>DynamicLibrary</ConfigurationType> |
| 69 | <UseDebugLibraries>false</UseDebugLibraries> | 69 | <UseDebugLibraries>false</UseDebugLibraries> |
| 70 | <PlatformToolset>v141</PlatformToolset> | 70 | <PlatformToolset>v141</PlatformToolset> |
| 71 | <WholeProgramOptimization>true</WholeProgramOptimization> | 71 | <WholeProgramOptimization>true</WholeProgramOptimization> |
| @@ -132,6 +132,10 @@ | |||
| 132 | <AdditionalDependencies>lua53.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> | 132 | <AdditionalDependencies>lua53.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies> |
| 133 | <AdditionalLibraryDirectories>$(SolutionDir)..\lualib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | 133 | <AdditionalLibraryDirectories>$(SolutionDir)..\lualib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
| 134 | </Link> | 134 | </Link> |
| 135 | <PostBuildEvent> | ||
| 136 | <Command>xcopy /R /F /Y /I "$(TargetPath)" $(SolutionDir)..\framework\</Command> | ||
| 137 | <Message>Copy to framework</Message> | ||
| 138 | </PostBuildEvent> | ||
| 135 | </ItemDefinitionGroup> | 139 | </ItemDefinitionGroup> |
| 136 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.3|Win32'"> | 140 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.3|Win32'"> |
| 137 | <ClCompile> | 141 | <ClCompile> |
| @@ -224,11 +228,13 @@ | |||
| 224 | </Link> | 228 | </Link> |
| 225 | </ItemDefinitionGroup> | 229 | </ItemDefinitionGroup> |
| 226 | <ItemGroup> | 230 | <ItemGroup> |
| 231 | <ClCompile Include="..\src\compat.c" /> | ||
| 227 | <ClCompile Include="..\src\deep.c" /> | 232 | <ClCompile Include="..\src\deep.c" /> |
| 228 | <ClCompile Include="..\src\universe.c" /> | 233 | <ClCompile Include="..\src\universe.c" /> |
| 229 | <ClCompile Include="deep_test.c" /> | 234 | <ClCompile Include="deep_test.c" /> |
| 230 | </ItemGroup> | 235 | </ItemGroup> |
| 231 | <ItemGroup> | 236 | <ItemGroup> |
| 237 | <ClInclude Include="..\src\compat.h" /> | ||
| 232 | <ClInclude Include="..\src\deep.h" /> | 238 | <ClInclude Include="..\src\deep.h" /> |
| 233 | <ClInclude Include="..\src\universe.h" /> | 239 | <ClInclude Include="..\src\universe.h" /> |
| 234 | </ItemGroup> | 240 | </ItemGroup> |
diff --git a/deep_test/deep_test.vcxproj.filters b/deep_test/deep_test.vcxproj.filters index b5c696f..93f6148 100644 --- a/deep_test/deep_test.vcxproj.filters +++ b/deep_test/deep_test.vcxproj.filters | |||
| @@ -24,6 +24,9 @@ | |||
| 24 | <ClCompile Include="..\src\universe.c"> | 24 | <ClCompile Include="..\src\universe.c"> |
| 25 | <Filter>Lanes</Filter> | 25 | <Filter>Lanes</Filter> |
| 26 | </ClCompile> | 26 | </ClCompile> |
| 27 | <ClCompile Include="..\src\compat.c"> | ||
| 28 | <Filter>Lanes</Filter> | ||
| 29 | </ClCompile> | ||
| 27 | </ItemGroup> | 30 | </ItemGroup> |
| 28 | <ItemGroup> | 31 | <ItemGroup> |
| 29 | <ClInclude Include="..\src\deep.h"> | 32 | <ClInclude Include="..\src\deep.h"> |
| @@ -32,6 +35,9 @@ | |||
| 32 | <ClInclude Include="..\src\universe.h"> | 35 | <ClInclude Include="..\src\universe.h"> |
| 33 | <Filter>Lanes</Filter> | 36 | <Filter>Lanes</Filter> |
| 34 | </ClInclude> | 37 | </ClInclude> |
| 38 | <ClInclude Include="..\src\compat.h"> | ||
| 39 | <Filter>Lanes</Filter> | ||
| 40 | </ClInclude> | ||
| 35 | </ItemGroup> | 41 | </ItemGroup> |
| 36 | <ItemGroup> | 42 | <ItemGroup> |
| 37 | <None Include="deeptest.lua"> | 43 | <None Include="deeptest.lua"> |
diff --git a/deep_test/deep_test.vcxproj.user b/deep_test/deep_test.vcxproj.user index 372bf91..f6a2db8 100644 --- a/deep_test/deep_test.vcxproj.user +++ b/deep_test/deep_test.vcxproj.user | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.3|x64'"> | 3 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.3|x64'"> |
| 4 | <LocalDebuggerCommand>D:\Boulot\anubis\Lua\framework\lua53.exe</LocalDebuggerCommand> | 4 | <LocalDebuggerCommand>D:\Boulot\anubis\Lua\framework\lua53.exe</LocalDebuggerCommand> |
| 5 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> | 5 | <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> |
| 6 | <LocalDebuggerCommandArguments>-i deeptest.lua</LocalDebuggerCommandArguments> | 6 | <LocalDebuggerCommandArguments>-i -- deeptest.lua</LocalDebuggerCommandArguments> |
| 7 | <LocalDebuggerWorkingDirectory>D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> | 7 | <LocalDebuggerWorkingDirectory>D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\</LocalDebuggerWorkingDirectory> |
| 8 | </PropertyGroup> | 8 | </PropertyGroup> |
| 9 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.4|x64'"> | 9 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug 5.4|x64'"> |
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua index c0bbab4..16059d9 100644 --- a/deep_test/deeptest.lua +++ b/deep_test/deeptest.lua | |||
| @@ -4,16 +4,17 @@ local l = lanes.linda "my linda" | |||
| 4 | -- we will transfer userdata created by this module, so we need to make Lanes aware of it | 4 | -- we will transfer userdata created by this module, so we need to make Lanes aware of it |
| 5 | local dt = lanes.require "deep_test" | 5 | local dt = lanes.require "deep_test" |
| 6 | 6 | ||
| 7 | local test_deep = true | 7 | local test_deep = false |
| 8 | local test_clonable = false | 8 | local test_clonable = true |
| 9 | 9 | ||
| 10 | local performTest = function( obj_) | 10 | local performTest = function( obj_) |
| 11 | obj_:set(666) | 11 | obj_:set( 666) |
| 12 | obj_:setuv( 1, "my uservalue") | ||
| 12 | print( "immediate:", obj_) | 13 | print( "immediate:", obj_) |
| 13 | 14 | ||
| 14 | l:set( "key", obj_) | 15 | l:set( "key", obj_) |
| 15 | local out = l:get( "key") | 16 | local out = l:get( "key") |
| 16 | print( "out of linda:", out) | 17 | print( "out of linda:", out, out:getuv( 1)) |
| 17 | 18 | ||
| 18 | local g = lanes.gen( | 19 | local g = lanes.gen( |
| 19 | "package" | 20 | "package" |
| @@ -21,13 +22,13 @@ local performTest = function( obj_) | |||
| 21 | required = { "deep_test"} -- we will transfer userdata created by this module, so we need to make this lane aware of it | 22 | required = { "deep_test"} -- we will transfer userdata created by this module, so we need to make this lane aware of it |
| 22 | } | 23 | } |
| 23 | , function( obj_) | 24 | , function( obj_) |
| 24 | print( "in lane:", obj_) | 25 | print( "in lane:", obj_, obj_:getuv( 1)) |
| 25 | return obj_ | 26 | return obj_ |
| 26 | end | 27 | end |
| 27 | ) | 28 | ) |
| 28 | h = g( obj_) | 29 | h = g( obj_) |
| 29 | local from_lane = h[1] | 30 | local from_lane = h[1] |
| 30 | print( "from lane:", from_lane) | 31 | print( "from lane:", from_lane, from_lane:getuv( 1)) |
| 31 | end | 32 | end |
| 32 | 33 | ||
| 33 | if test_deep then | 34 | if test_deep then |
diff --git a/src/tools.c b/src/tools.c index ff23e36..48e904c 100644 --- a/src/tools.c +++ b/src/tools.c | |||
| @@ -1907,13 +1907,14 @@ static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i | |||
| 1907 | { | 1907 | { |
| 1908 | int const clone_i = lua_gettop( L2); | 1908 | int const clone_i = lua_gettop( L2); |
| 1909 | int uvi = 0; | 1909 | int uvi = 0; |
| 1910 | while( lua_getiuservalue( L, i, uvi + 1) != LUA_TNONE) // ... u uv | 1910 | while( lua_getiuservalue( L, -1, uvi + 1) != LUA_TNONE) // ... u uv |
| 1911 | { | 1911 | { |
| 1912 | luaG_inter_move( U, L, L2, 1, mode_); // ... u // ... mt __lanesclone nil [uv]+ | 1912 | luaG_inter_move( U, L, L2, 1, mode_); // ... u // ... mt __lanesclone nil [uv]+ |
| 1913 | ++ uvi; | 1913 | ++ uvi; |
| 1914 | } | 1914 | } |
| 1915 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now | 1915 | // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now at the same time as the rest |
| 1916 | lua_pop( L, 1); // ... u | 1916 | lua_pop( L, 2); // ... u |
| 1917 | STACK_MID( L, 0); // ... | ||
| 1917 | // create the clone userdata with the required number of uservalue slots | 1918 | // create the clone userdata with the required number of uservalue slots |
| 1918 | clone = lua_newuserdatauv( L2, userdata_size, uvi); // ... mt __lanesclone nil [uv]+ u | 1919 | clone = lua_newuserdatauv( L2, userdata_size, uvi); // ... mt __lanesclone nil [uv]+ u |
| 1919 | lua_replace( L2, clone_i); // ... mt __lanesclone u [uv]+ | 1920 | lua_replace( L2, clone_i); // ... mt __lanesclone u [uv]+ |
| @@ -1927,13 +1928,11 @@ static bool_t inter_copy_function( Universe* U, lua_State* L2, uint_t L2_cache_i | |||
| 1927 | // when we are done, all uservalues are popped from the stack | 1928 | // when we are done, all uservalues are popped from the stack |
| 1928 | STACK_MID( L2, 3); // ... mt __lanesclone u | 1929 | STACK_MID( L2, 3); // ... mt __lanesclone u |
| 1929 | } | 1930 | } |
| 1930 | STACK_MID( L, 1); // u | ||
| 1931 | lua_insert( L2, -3); // ... u mt __lanesclone | 1931 | lua_insert( L2, -3); // ... u mt __lanesclone |
| 1932 | lua_pushlightuserdata( L2, clone); // ... u mt __lanesclone clone | 1932 | lua_pushlightuserdata( L2, clone); // ... u mt __lanesclone clone |
| 1933 | lua_pushlightuserdata( L2, source); // ... u mt __lanesclone clone source | 1933 | lua_pushlightuserdata( L2, source); // ... u mt __lanesclone clone source |
| 1934 | lua_call( L2, 2, 0); // ... u mt | 1934 | lua_call( L2, 2, 0); // ... u mt |
| 1935 | lua_setmetatable( L2, -2); // ... u | 1935 | lua_setmetatable( L2, -2); // ... u |
| 1936 | lua_pop( L, 1); // ... | ||
| 1937 | } | 1936 | } |
| 1938 | else | 1937 | else |
| 1939 | { | 1938 | { |
