lua-users home
lua-l archive

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


--- In lua-l@egroups.com, Luiz Henrique de Figueiredo <lhf@t...> 
wrote:
> 
> In 4.0, GC tag methods for userdata are called in decreasing order 
of tags.
> We'll say so in the manual for 4.0 final.
> 
Fortunately this is the correct order, provided that you also say in 
the manual that lua_newtag() dishes out the tags in increasing 
order :)  However, the tag may already be used for something else, 
such as to indicate the C++ type of the userdata, in which case this 
is not a solution.

> 
> Yes, but we removed this "feature" because they open the way to 
>subtle bugs.
> For instance, could you access the fields of the table during GC?
I certainly would like to be able to read the fields in the table, in 
order to get at the userdata I want to delete.

> Could you write to them? 
Writing to fields in the table should not cause problems for the Lua 
internals, only to the programmer who tries to do that, since no 
reference external to the table need be created on a write to an 
existing field.  Similarly for creating new fields in the table.

>Could you create a reference to the table or one of its fields?
> 
Creating an external ref to the fields may or may not be a problem, 
depending on whether the fields have already been marked for 
collection.

A programmer should not be creating a ref to the table about to be 
collected.  Should the Lua internals try 
to prevent(protect) the programmer from doing this ?  I think not.  
If the manual provides enough description and warnings, it is up to 
the programmer to decide whether he really wants to mess up.  I do 
not think that it is something that can happen by accident for these 
reasons:
1) Most programmers would not need to use this feature,
2) The programmer has to deliberately set the tag of the table to a 
non-default table tag, 
3) Set the tag method for the table,
4) Create  the mess in the tag method, and
5) You can only write "gc" methods in C.  

In the past, have any bugs been reported that were due to this 
feature ?  Using any of the other tag methods is also fraught with 
danger, if the programmer does not fully understand the features.

> you can only write GC tag methods in C.
No problem with this.

Cheers,
PYI