Skip to content

lua: add flex array field to TString type #16583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions module/lua/lobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,22 @@ typedef TValue *StkId; /* index to stack elements */
/*
** Header for string value; string bytes follow the end of this structure
*/
typedef union TString {
L_Umaxalign dummy; /* ensures maximum alignment for strings */
struct {
CommonHeader;
lu_byte extra; /* reserved words for short strings; "has hash" for longs */
unsigned int hash;
size_t len; /* number of characters in string */
} tsv;
typedef struct TString {
union {
L_Umaxalign dummy; /* ensures maximum alignment for strings */
struct {
CommonHeader;
lu_byte extra; /* reserved words for short strings; "has hash" for longs */
unsigned int hash;
size_t len; /* number of characters in string */
} tsv;
};
char contents[];
} TString;


/* get the actual string (array of bytes) from a TString */
#define getstr(ts) cast(const char *, (ts) + 1)
#define getstr(ts) ((ts)->contents)

/* get the actual string (array of bytes) from a Lua value */
#define svalue(o) getstr(rawtsvalue(o))
Expand Down
2 changes: 1 addition & 1 deletion module/lua/lstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ struct lua_State {
*/
union GCObject {
GCheader gch; /* common header */
union TString ts;
struct TString ts;
union Udata u;
union Closure cl;
struct Table h;
Expand Down
2 changes: 1 addition & 1 deletion module/lua/lstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static TString *createstrobj (lua_State *L, const char *str, size_t l,
ts->tsv.len = l;
ts->tsv.hash = h;
ts->tsv.extra = 0;
sbuf = (char *)(TString *)(ts + 1);
sbuf = ts->contents;
memcpy(sbuf, str, l*sizeof(char));
sbuf[l] = '\0'; /* ending 0 */
return ts;
Expand Down
2 changes: 1 addition & 1 deletion module/lua/lstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "lstate.h"


#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char))
#define sizestring(s) (sizeof(struct TString)+((s)->len+1)*sizeof(char))

#define sizeudata(u) (sizeof(union Udata)+(u)->len)

Expand Down
Loading