lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


quick note: I apologize for my previous messages which were badly html formatted. A friendly member of the community sent me a screenshot of how my email rendered for them. It was a mess, I blame hotmail and I'll be more careful

I wanted to explain that my userdata handlers are using the lua_newuserdata correctly. As a verification of this bug, I added an int to my userdata and add a mark when it is first disposed and I can detect when a previously detected userdata is used again.

```c
  static int sid = 0;
  struct Plain { int id; }
  static int userdata_new(lua_State* L)
  {
    Plain* p = (Plain*)lua_newuserdata(L, sizeof(Plain));
    p->id = 0;
    return 1;
  }

  static int userdata_dispose(lua_State* L)
  {
    Plain* p = (Plain*)lua_touserdata(L, 1);
    assert(p->id == 0);
    p->id = ++sid;
    return 0;
  }
```

on the lua size, I cache the userdata objects
here is the most simple case:

```lua
  local cache = setmetatable({}, { __mode = "k" })

  local function new_proxy()
    local p = userdata_new()
    local k = setmetatable({}, { __gc = function(self) local p = cache[self] cache[self] = nil userdata_dispose(p) end })
    cache[k] = p
    return k
  end

  do
    local k = new_proxy()
  end
```

This test will likely never hit the bug. There needs to be stack resizing that swaps the order of __gc from the k value leaving the stack and the cache weak key cleanup.
As I mentioned in previous messages (in horrible html formatting)
1. I found this bug is introduced with commit https://github.com/lua/lua/commit/1d8920dd7f508af5f2fd743678be1327f30c079b
2. My code does not fail on any previous lua version tested back to and including 5.2

I am happy to share source code and repro instructions for my project that hits this bug, but it is definitely not a minimal repro - for which I apologize
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org