From 2c0000d5169cacf950d06637ada1a371cf382896 Mon Sep 17 00:00:00 2001
From: Benoit Germain
Date: Tue, 8 Feb 2022 10:39:48 +0100
Subject: __lanesclone is now called only once with 3 parameters dest, source,
size -> BREAKS CUSTOM DEEP USERDATA API
---
CHANGES | 4 +
deep_test/deep_test.c | 13 +--
deep_test/deep_test.vcxproj.user | 2 +-
deep_test/deeptest.lua | 24 +++--
docs/index.html | 28 ++---
lanes-3.15.1-0.rockspec | 78 --------------
lanes-3.16.0-0.rockspec | 78 ++++++++++++++
src/lanes.h | 4 +-
src/tools.c | 220 ++++++++++++++++++---------------------
9 files changed, 218 insertions(+), 233 deletions(-)
delete mode 100644 lanes-3.15.1-0.rockspec
create mode 100644 lanes-3.16.0-0.rockspec
diff --git a/CHANGES b/CHANGES
index f356c26..490d651 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,9 @@
CHANGES:
+CHANGE 152: BGe 7-Feb-22
+ * bumped version to 3.16.0
+ * __lanesclone is now called only once with 3 parameters dest, source, size -> BREAKS CUSTOM DEEP USERDATA API
+
CHANGE 151: BGe 7-Feb-22
* bumped version to 3.15.2
* Lanes no longer relies on malloc/free for internal allocations, but uses the primary alloc function from the master Lua state
diff --git a/deep_test/deep_test.c b/deep_test/deep_test.c
index a725902..cb89741 100644
--- a/deep_test/deep_test.c
+++ b/deep_test/deep_test.c
@@ -1,5 +1,6 @@
#include
#include
+#include
#include "lua.h"
#include "lualib.h"
@@ -196,18 +197,12 @@ static int clonable_lanesclone( lua_State* L)
{
switch( lua_gettop( L))
{
- case 1:
- {
- // in case we need it to compute the amount of memory we need
- struct s_MyClonableUserdata* self = lua_touserdata( L, 1);
- lua_pushinteger( L, sizeof( struct s_MyClonableUserdata));
- }
- return 1;
-
- case 2:
+ case 3:
{
struct s_MyClonableUserdata* self = lua_touserdata( L, 1);
struct s_MyClonableUserdata* from = lua_touserdata( L, 2);
+ size_t len = lua_tointeger( L, 3);
+ assert( len == sizeof(struct s_MyClonableUserdata));
*self = *from;
}
return 0;
diff --git a/deep_test/deep_test.vcxproj.user b/deep_test/deep_test.vcxproj.user
index c5d6237..6ffc0ba 100644
--- a/deep_test/deep_test.vcxproj.user
+++ b/deep_test/deep_test.vcxproj.user
@@ -13,7 +13,7 @@
D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\
- D:\Boulot\anubis\Lua\framework\lua53.exe
+ D:\Boulot\anubis\Lua\framework\lua54.exe
WindowsLocalDebugger
-i deeptest.lua
D:\Boulot\anubis\Lua\bindings\Lanes\lanes\deep_test\
diff --git a/deep_test/deeptest.lua b/deep_test/deeptest.lua
index 3c89c3d..cbd08de 100644
--- a/deep_test/deeptest.lua
+++ b/deep_test/deeptest.lua
@@ -6,7 +6,8 @@ local dt = lanes.require "deep_test"
local test_deep = true
local test_clonable = true
-local test_uvtype = "function"
+local test_uvtype = "string"
+local nupvals = _VERSION == "Lua 5.4" and 2 or 1
local makeUserValue = function( obj_)
if test_uvtype == "string" then
@@ -21,14 +22,17 @@ local makeUserValue = function( obj_)
end
local printDeep = function( prefix_, obj_, t_)
- local uservalue = obj_:getuv( 1)
- print( prefix_)
- print ( obj_, uservalue, type( uservalue) == "function" and uservalue() or "")
+ print( prefix_, obj_)
+ for uvi = 1, nupvals do
+ local uservalue = obj_:getuv( 1)
+ print ( "uv #" .. uvi, uservalue, type( uservalue) == "function" and uservalue() or "")
+ end
if t_ then
for k, v in pairs( t_) do
print( k, v)
end
end
+ print()
end
local performTest = function( obj_)
@@ -38,12 +42,14 @@ local performTest = function( obj_)
-- lua 5.3 supports an arbitrary type uservalue
obj_:setuv( 1, makeUserValue( obj_))
-- lua 5.4 supports multiple uservalues of arbitrary types
- -- obj_:setuv( 2, "ENDUV")
+ if nupvals > 1 then
+ obj_:setuv( 2, "ENDUV")
+ end
local t =
{
["key"] = obj_,
- -- [obj_] = "val"
+ [obj_] = "val" -- this one won't transfer because we don't support full uservalue as keys
}
-- read back the contents of the object
@@ -76,11 +82,13 @@ local performTest = function( obj_)
end
if test_deep then
+ print "================================================================"
print "DEEP"
- performTest( dt.new_deep())
+ performTest( dt.new_deep(nupvals))
end
if test_clonable then
+ print "================================================================"
print "CLONABLE"
- performTest( dt.new_clonable())
+ performTest( dt.new_clonable(nupvals))
end
diff --git a/docs/index.html b/docs/index.html
index 290383e..0e1a30b 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -70,7 +70,7 @@
- This document was revised on 8-Feb-22, and applies to version 3.15.2.
+ This document was revised on 8-Feb-22, and applies to version 3.16.0.
@@ -1550,27 +1550,20 @@ events to a common Linda, but... :).
Clonable full userdata in your own apps
Starting with version 3.13.0, a new way of passing full userdata across lanes uses a new __lanesclone metamethod.
- When a deep userdata is cloned, Lanes calls __lanesclone twice, in the context of the source lane.
- The first call receives the original as light userdata, as in ud:__lanesclone(), and should return the amount of memory used to create the cloned full userdata.
- The second call receives the clone and original as light userdata, as in clone:__lanesclone(original), and should perform the actual cloning.
- A typical implementation would look like:
+ When a deep userdata is cloned, Lanes calls __lanesclone once, in the context of the source lane.
+ The call receives the clone and original as light userdata, plus the actual userdata size, as in clone:__lanesclone(original,size), and should perform the actual cloning.
+ A typical implementation would look like (BEWARE, THIS CHANGED WITH VERSION 3.16.0):
static int clonable_lanesclone( lua_State* L)
{
switch( lua_gettop( L))
{
- case 1: // original:__lanesclone()
- {
- // the original (as light userdata), in case you need it to compute the size of the clone
- struct s_MyClonableUserdata* self = lua_touserdata( L, 1);
- lua_pushinteger( L, sizeof( struct s_MyClonableUserdata));
- }
- return 1;
-
- case 2: // clone:__lanesclone(original)
+ case 3:
{
struct s_MyClonableUserdata* self = lua_touserdata( L, 1);
struct s_MyClonableUserdata* from = lua_touserdata( L, 2);
+ size_t len = lua_tointeger( L, 3);
+ assert( len == sizeof(struct s_MyClonableUserdata));
*self = *from;
}
return 0;
@@ -1736,9 +1729,7 @@ int luaD_new_clonable( lua_State* L)
Change log
- v3.14.0: lane:cancel() rework: opt.cancelstep is gone, hook is installed by lane:cancel() if requested.
-
- For older stuff see CHANGES.
+ See CHANGES.
@@ -1754,5 +1745,4 @@ int luaD_new_clonable( lua_State* L)
|