Skip to content

Commit c23f705

Browse files
committedAug 30, 2013
BUG: GC can collect a long string still in use during parser
1 parent 42cf5f8 commit c23f705

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

‎llex.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: llex.c,v 2.63 2013/03/16 21:10:18 roberto Exp $
2+
** $Id: llex.c,v 2.63.1.1 2013/04/12 18:48:47 roberto Exp roberto $
33
** Lexical Analyzer
44
** See Copyright Notice in lua.h
55
*/
@@ -133,6 +133,9 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
133133
setbvalue(o, 1); /* t[string] = true */
134134
luaC_checkGC(L);
135135
}
136+
else { /* string already present */
137+
ts = rawtsvalue(keyfromval(o)); /* re-use value previously stored */
138+
}
136139
L->top--; /* remove string from stack */
137140
return ts;
138141
}

‎ltable.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: ltable.h,v 2.16 2011/08/17 20:26:47 roberto Exp $
2+
** $Id: ltable.h,v 2.16.1.1 2013/04/12 18:48:47 roberto Exp roberto $
33
** Lua tables (hash)
44
** See Copyright Notice in lua.h
55
*/
@@ -17,6 +17,10 @@
1717

1818
#define invalidateTMcache(t) ((t)->flags = 0)
1919

20+
/* returns the key, given the value of a table entry */
21+
#define keyfromval(v) \
22+
(gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
23+
2024

2125
LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
2226
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value);

0 commit comments

Comments
 (0)
Please sign in to comment.