Cleaner definition for 'TString'

Use a variable-sized array to store string contents at the end of a
structure 'TString', instead of raw memory.
This commit is contained in:
Roberto Ierusalimschy
2020-05-19 12:42:20 -03:00
parent 0be57b9b6d
commit 9514abc2da
2 changed files with 8 additions and 5 deletions

View File

@@ -19,7 +19,11 @@
#define MEMERRMSG "not enough memory"
#define sizelstring(l) (sizeof(TString) + ((l) + 1) * sizeof(char))
/*
** Size of a TString: Size of the header plus space for the string
** itself (including final '\0').
*/
#define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char))
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
(sizeof(s)/sizeof(char))-1))