lua-users home
lua-l archive

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


> A few questions:
> - Are you using the generational mode in the collector?
here is a list of every lua_gc call I have on the c side
1. lua_gc(_state, LUA_GCCOLLECT, 0);
2. return lua_gc(_state, LUA_GCCOUNT, 0) * 1024 + lua_gc(_state, LUA_GCCOUNTB, 0);

on the lua side, I call it only 1 way:
1. collectgarbage("collect")

> - Does the bug happen in both modes (generational and incremental)?
I have left the gc in its default mode, which I believe is inc mode. I have tested with: lua_gc(_state, LUA_GCGEN); and the bug still persists

> - Just to be sure, the 'new_proxy' function is exactly as you
> presented (including the __gc method), or have you simplified it
> to present here?

this code is how new_proxy works

```lua
function wrapSingleUserdata(data)
  for k, v in pairs(wrappedUserdata) do
    if v == data then
      return k
    end
  end
  local proxy = {type = "userdata"}
  local methods = pcall(userdata.methods, data)
  for method in pairs(methods) do
    proxy[method] = setmetatable({name=method, proxy=proxy}, userdataCallback)
  end
  wrappedUserdata[proxy] = data
  return setmetatable(proxy, userdataWrapper)
end
local userdataWrapper = {
  __call = function(self, ...)
    return userdata.call(wrappedUserdata[self], ...)
  end,
  __gc = function(self)
    local data = wrappedUserdata[self]
    wrappedUserdata[self] = nil
    userdata.dispose(data)
  end,
  __metatable = "userdata",
}

local function wrapSingleUserdata(data)
  for k, v in pairs(wrappedUserdata) do
    if v == data then
      return k
    end
  end
  local proxy = {type = "userdata"}
  wrappedUserdata[proxy] = data
  return setmetatable(proxy, userdataWrapper)
end

local function new_proxy()
  local user_data = userdata_get()
  return wrapSingleUserdata(user_data)
end
```

While extracting the code you asked for, I found that if I change the __gc to:
```lua
  __gc = function(self)
    local data = wrappedUserdata[self]
    -- wrappedUserdata[self] = nil
    userdata.dispose(data)
  end,
```

The bug appears to never hit

> Can you try your program with different GC parameters
> to see what happens?
I tested with GCGEN and it repros the same. When I have more time I will test with more step and multipliers on incremental

Thanks,
Payo
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org