lua-users home
lua-l archive

Re: Cons, tuple and __slots__ -- a simple mechanism to implement them in Lua

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


> I'm very sad that nobody reply my last post[1], even Roberto didn't.
> [...]
As you want some comment, I will give a brief comment regarding your
implementation. I guess there is a little "bug" in the garbage
collection of your userdata. Consider your patch:
*** 248,254 ****
 case LUA_TUSERDATA: {
 Table *mt = gco2u(o)->metatable;
 markobject(g, mt);
! markobject(g, gco2u(o)->env);
 gray2black(o); /* all pointers marked */
 return;
 }
--- 248,259 ----
 case LUA_TUSERDATA: {
 Table *mt = gco2u(o)->metatable;
 markobject(g, mt);
! if (gco2u(o)->valuecount != 0)
! {
! int i, len = gco2u(o)->valuecount;
! for (i = 0; i < len; ++i)
! markobject(g, &gco2u(o)->values[i]); <<<<<
! }
 gray2black(o); /* all pointers marked */
 return;
 }
In the original version, the call to 'markobject' was always over
a table, and so we knew the recursion would stop at that level
(the 'reallymarkobject' for tables only queues the table for later
traversal). In your version, the call to 'markobject' (see '<<<<') may
be marking any object, in particular another userdata. So, it seems
that a long linked list of userdata could force an unlimited depth of
recursive calls to 'reallymarkobject', eventually crashing the C stack.
(BTW, as you can now have any value as userdata, it seems that you
should use 'markvalue' instead of 'markobject' in the line marked
with '<<<<'.)
-- Roberto

AltStyle によって変換されたページ (->オリジナル) /