diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-08-30 13:01:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-08-30 13:01:37 -0300 |
commit | 8ef9e8460e775793f760deb28d0c3d10dda31b49 (patch) | |
tree | 803abce8b7caba6e5f66b26e55f0bc8dcfc881a2 /llex.c | |
parent | 4f292d753c892e705b6d1796d72758cdd4d49765 (diff) | |
download | lua-8ef9e8460e775793f760deb28d0c3d10dda31b49.tar.gz lua-8ef9e8460e775793f760deb28d0c3d10dda31b49.tar.bz2 lua-8ef9e8460e775793f760deb28d0c3d10dda31b49.zip |
bug (GC can collect long identifier during parser) + change (using
a single constant table for all functions in a chunk)
Diffstat (limited to 'llex.c')
-rw-r--r-- | llex.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.67 2013/06/19 14:27:00 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.68 2013/08/21 20:09:51 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -119,22 +119,25 @@ l_noret luaX_syntaxerror (LexState *ls, const char *msg) { | |||
119 | 119 | ||
120 | 120 | ||
121 | /* | 121 | /* |
122 | ** creates a new string and anchors it in function's table so that | 122 | ** creates a new string and anchors it in scanner's table so that |
123 | ** it will not be collected until the end of the function's compilation | 123 | ** it will not be collected until the end of the compilation |
124 | ** (by that time it should be anchored in function's prototype) | 124 | ** (by that time it should be anchored somewhere) |
125 | */ | 125 | */ |
126 | TString *luaX_newstring (LexState *ls, const char *str, size_t l) { | 126 | TString *luaX_newstring (LexState *ls, const char *str, size_t l) { |
127 | lua_State *L = ls->L; | 127 | lua_State *L = ls->L; |
128 | TValue *o; /* entry for `str' */ | 128 | TValue *o; /* entry for `str' */ |
129 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ | 129 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ |
130 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ | 130 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ |
131 | o = luaH_set(L, ls->fs->h, L->top - 1); | 131 | o = luaH_set(L, ls->h, L->top - 1); |
132 | if (ttisnil(o)) { /* not in use yet? (see 'addK') */ | 132 | if (ttisnil(o)) { /* not in use yet? */ |
133 | /* boolean value does not need GC barrier; | 133 | /* boolean value does not need GC barrier; |
134 | table has no metatable, so it does not need to invalidate cache */ | 134 | table has no metatable, so it does not need to invalidate cache */ |
135 | setbvalue(o, 1); /* t[string] = true */ | 135 | setbvalue(o, 1); /* t[string] = true */ |
136 | luaC_checkGC(L); | 136 | luaC_checkGC(L); |
137 | } | 137 | } |
138 | else { /* string already present */ | ||
139 | ts = rawtsvalue(keyfromval(o)); /* re-use value previously stored */ | ||
140 | } | ||
138 | L->top--; /* remove string from stack */ | 141 | L->top--; /* remove string from stack */ |
139 | return ts; | 142 | return ts; |
140 | } | 143 | } |