LuaLanes / lanes

Lanes is a lightweight, native, lazy evaluating multithreading library for Lua 5.1 to 5.4.
Other
436 stars 93 forks source link

__lanesclone'able Userdata -> infinite loop -> stack overflow #189

Closed valid-ptr closed 2 years ago

valid-ptr commented 3 years ago

I'am trying to change my "DeepPreluded" Userdata to "__lanesclone" mechanism in my app. For performance reason.

I use LuaJIT 2.1 (master) / Lua 5.1

There are few things goes wrong: 1) #188 2) Infinite loop: Let's suppose that self is laneclone'able userdata; Let's suppose we have function X with self in upvalues Function X stored inside self's fenv cause stack overflow while cloning. 3) UD can be variable size... It's easy to change __lanesclone's cfunction to receive 1 + 2 arguments against 0 + 2 arguments scheme. When 1 argument comes, it can be treated as source UD where size is stored. PS: It's not a good idea to create many metatables for each UD

benoit-germain commented 2 years ago

I see what's going on with the infinite loop. But fixing this is not trivial. I should keep the "structure" of what is being sent. For example, if a table references the same clonable userdata several times, querying the transfered table should also identify the same values as being equal.

benoit-germain commented 2 years ago

Fixed by 909470be9f7ec1dd2d09ae1a371d69c9c652e957