From 07c7fdb9df82c7fc4ae501e21262f781df4ae5e5 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 29 Jul 2014 13:22:24 -0300 Subject: [PATCH] simpler definition for 'setobj' (trust the compiler for the assignment) --- lgc.c | 4 ++-- lobject.h | 12 +++++++++--- ltable.c | 9 +++++---- ltable.h | 9 +++++++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lgc.c b/lgc.c index 0fe426e8..a4059d34 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.190 2014/07/19 15:09:37 roberto Exp roberto $ +** $Id: lgc.c,v 2.191 2014/07/19 15:14:46 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -112,7 +112,7 @@ static void reallymarkobject (global_State *g, GCObject *o); static void removeentry (Node *n) { lua_assert(ttisnil(gval(n))); if (valiswhite(gkey(n))) - setdeadvalue(gkey(n)); /* unused and unmarked key; remove it */ + setdeadvalue(wgkey(n)); /* unused and unmarked key; remove it */ } diff --git a/lobject.h b/lobject.h index a5827f84..93356dd2 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.98 2014/07/18 13:36:14 roberto Exp roberto $ +** $Id: lobject.h,v 2.99 2014/07/18 14:46:47 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -241,8 +241,7 @@ typedef struct lua_TValue TValue; #define setobj(L,obj1,obj2) \ - { const TValue *io2=(obj2); TValue *io1=(obj1); \ - io1->value_ = io2->value_; io1->tt_ = io2->tt_; \ + { TValue *io1=(obj1); *io1 = *(obj2); \ (void)L; checkliveness(G(L),io1); } @@ -471,6 +470,13 @@ typedef union TKey { } TKey; +/* copy a value into a key without messing up field 'next' */ +#define setkey(L,key,obj) \ + { TKey *k_=(key); const TValue *io_=(obj); \ + k_->nk.value_ = io_->value_; k_->nk.tt_ = io_->tt_; \ + (void)L; checkliveness(G(L),io_); } + + typedef struct Node { TValue i_val; TKey i_key; diff --git a/ltable.c b/ltable.c index a234bebb..543c34df 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 2.91 2014/06/26 16:17:35 roberto Exp roberto $ +** $Id: ltable.c,v 2.92 2014/07/18 13:36:14 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -309,7 +309,7 @@ static void setnodevector (lua_State *L, Table *t, int size) { for (i=0; ii_key, key); luaC_barrierback(L, t, key); lua_assert(ttisnil(gval(mp))); return gval(mp); @@ -503,7 +503,8 @@ const TValue *luaH_getstr (Table *t, TString *key) { Node *n = hashstr(t, key); lua_assert(key->tt == LUA_TSHRSTR); for (;;) { /* check whether `key' is somewhere in the chain */ - if (ttisshrstring(gkey(n)) && eqshrstr(tsvalue(gkey(n)), key)) + const TValue *k = gkey(n); + if (ttisshrstring(k) && eqshrstr(tsvalue(k), key)) return gval(n); /* that's it */ else { int nx = gnext(n); diff --git a/ltable.h b/ltable.h index f377c009..a4570d9d 100644 --- a/ltable.h +++ b/ltable.h @@ -1,5 +1,5 @@ /* -** $Id: ltable.h,v 2.17 2013/04/26 15:39:25 roberto Exp roberto $ +** $Id: ltable.h,v 2.18 2013/08/30 16:01:37 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -11,10 +11,15 @@ #define gnode(t,i) (&(t)->node[i]) -#define gkey(n) (&(n)->i_key.tvk) #define gval(n) (&(n)->i_val) #define gnext(n) ((n)->i_key.nk.next) + +/* 'const' to avoid wrong writings that can mess up field 'next' */ +#define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) + +#define wgkey(n) (&(n)->i_key.nk) + #define invalidateTMcache(t) ((t)->flags = 0)