summaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-07-18 10:36:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-07-18 10:36:14 -0300
commitca41b43f53562e64abe433d6346d174c92548603 (patch)
tree03f7a99f76359fc1e0bbc45fc13e579ff2aafabb /lobject.h
parent3511e186cde4b78f268d17199d0f46fb3eaa9638 (diff)
downloadlua-github-ca41b43f53562e64abe433d6346d174c92548603.tar.gz
type 'TString' refers directly to the structure inside the union
(union used only for size purposes)
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h43
1 files changed, 27 insertions, 16 deletions
diff --git a/lobject.h b/lobject.h
index e49f8dcc..3bf7045a 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 2.96 2014/07/17 17:27:49 roberto Exp roberto $
+** $Id: lobject.h,v 2.97 2014/07/18 12:17:54 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -156,8 +156,7 @@ typedef struct lua_TValue TValue;
#define fltvalue(o) check_exp(ttisfloat(o), val_(o).n)
#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
-#define rawtsvalue(o) check_exp(ttisstring(o), rawgco2ts(val_(o).gc))
-#define tsvalue(o) (&rawtsvalue(o)->tsv)
+#define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc))
#define rawuvalue(o) check_exp(ttisfulluserdata(o), rawgco2u(val_(o).gc))
#define uvalue(o) (&rawuvalue(o)->uv)
#define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc))
@@ -210,7 +209,7 @@ typedef struct lua_TValue TValue;
#define setsvalue(L,obj,x) \
{ TValue *io = (obj); TString *x_ = (x); \
- val_(io).gc = obj2gco(&x_->tsv); settt_(io, ctb(x_->tsv.tt)); \
+ val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \
checkliveness(G(L),io); }
#define setuvalue(L,obj,x) \
@@ -299,24 +298,36 @@ typedef TValue *StkId; /* index to stack elements */
/*
** Header for string value; string bytes follow the end of this structure
+** (aligned according to 'UTString'; see next).
*/
-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 */
- union TString *hnext; /* linked list for hash table */
- } tsv;
+typedef struct TString {
+ CommonHeader;
+ lu_byte extra; /* reserved words for short strings; "has hash" for longs */
+ unsigned int hash;
+ size_t len; /* number of characters in string */
+ struct TString *hnext; /* linked list for hash table */
} TString;
-/* get the actual string (array of bytes) from a TString */
-#define getstr(ts) cast(const char *, (ts) + 1)
+/*
+** Ensures that address after this type is always fully aligned.
+*/
+typedef union UTString {
+ L_Umaxalign dummy; /* ensures maximum alignment for strings */
+ TString tsv;
+} UTString;
+
+
+/*
+** Get the actual string (array of bytes) from a 'TString'.
+** (Access to 'extra' ensures that value is really a 'TString'.)
+*/
+#define getaddrstr(ts) (cast(char *, (ts)) + sizeof(UTString))
+#define getstr(ts) \
+ ((void)(ts)->extra, cast(const char*, getaddrstr(ts)))
/* get the actual string (array of bytes) from a Lua value */
-#define svalue(o) getstr(rawtsvalue(o))
+#define svalue(o) getstr(tsvalue(o))
/*