From 9514abc2da3525ef4314a8fcf70982ad07319e51 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 19 May 2020 12:42:20 -0300 Subject: Cleaner definition for 'TString' Use a variable-sized array to store string contents at the end of a structure 'TString', instead of raw memory. --- lobject.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lobject.h') diff --git a/lobject.h b/lobject.h index 2d63c001..04a81d3d 100644 --- a/lobject.h +++ b/lobject.h @@ -356,7 +356,7 @@ typedef struct GCObject { /* -** Header for string value; string bytes follow the end of this structure. +** Header for a string value. */ typedef struct TString { CommonHeader; @@ -367,16 +367,15 @@ typedef struct TString { size_t lnglen; /* length for long strings */ struct TString *hnext; /* linked list for hash table */ } u; + char contents[1]; } TString; /* ** Get the actual string (array of bytes) from a 'TString'. -** (Access to 'extra' ensures that value is really a 'TString'.) */ -#define getstr(ts) \ - check_exp(sizeof((ts)->extra), cast_charp((ts)) + sizeof(TString)) +#define getstr(ts) ((ts)->contents) /* get the actual string (array of bytes) from a Lua value */ -- cgit v1.2.3-55-g6feb