lua-users home
lua-l archive

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


在 2017/8/16 10:32, findstr@sina.com 写道:
> I find a comment in function 'iscleared@lgc.c'
> 
> static int iscleared (global_State *g, const TValue *o) {
> ...
>       markobject(g, tsvalue(o));  /* strings are 'values', so are never weak */
> ...
> }
> 
> The comment point out, `the string are 'values', so are never weak`.
> 
> So, I think it can be fixed by this patch, maybe:
> 
> diff --git a/lgc.c b/lgc.c
> index 7c29fb0..cad6d71 100644
> --- a/lgc.c
> +++ b/lgc.c
> @@ -641,7 +641,7 @@ static void clearkeys (global_State *g, GCObject *l, GCObject *f) {
>      Table *h = gco2t(l);
>      Node *n, *limit = gnodelast(h);
>      for (n = gnode(h, 0); n < limit; n++) {
> -      if (!ttisnil(gval(n)) && (iscleared(g, gkey(n)))) {
> +      if ((iscleared(g, gkey(n))) && !ttisnil(gval(n))) {
>          setnilvalue(gval(n));  /* remove value ... */
>          removeentry(n);  /* and remove entry from table */
>        }
> 
> 
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> findstr@sina.com
> 

have played with this problem a bit more, and then see your post. your patch
seems correct for me. my previous understanding was wrong.

to be honest, I am always confused by the semantic of tables with both weak
keys and weak values.

-- 
the nerdy Peng / 书呆彭 /