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-ca41b43f53562e64abe433d6346d174c92548603.tar.gz
lua-ca41b43f53562e64abe433d6346d174c92548603.tar.bz2
lua-ca41b43f53562e64abe433d6346d174c92548603.zip
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 @@
1/* 1/*
2** $Id: lobject.h,v 2.96 2014/07/17 17:27:49 roberto Exp roberto $ 2** $Id: lobject.h,v 2.97 2014/07/18 12:17:54 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -156,8 +156,7 @@ typedef struct lua_TValue TValue;
156#define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) 156#define fltvalue(o) check_exp(ttisfloat(o), val_(o).n)
157#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) 157#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
158#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) 158#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
159#define rawtsvalue(o) check_exp(ttisstring(o), rawgco2ts(val_(o).gc)) 159#define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc))
160#define tsvalue(o) (&rawtsvalue(o)->tsv)
161#define rawuvalue(o) check_exp(ttisfulluserdata(o), rawgco2u(val_(o).gc)) 160#define rawuvalue(o) check_exp(ttisfulluserdata(o), rawgco2u(val_(o).gc))
162#define uvalue(o) (&rawuvalue(o)->uv) 161#define uvalue(o) (&rawuvalue(o)->uv)
163#define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc)) 162#define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc))
@@ -210,7 +209,7 @@ typedef struct lua_TValue TValue;
210 209
211#define setsvalue(L,obj,x) \ 210#define setsvalue(L,obj,x) \
212 { TValue *io = (obj); TString *x_ = (x); \ 211 { TValue *io = (obj); TString *x_ = (x); \
213 val_(io).gc = obj2gco(&x_->tsv); settt_(io, ctb(x_->tsv.tt)); \ 212 val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \
214 checkliveness(G(L),io); } 213 checkliveness(G(L),io); }
215 214
216#define setuvalue(L,obj,x) \ 215#define setuvalue(L,obj,x) \
@@ -299,24 +298,36 @@ typedef TValue *StkId; /* index to stack elements */
299 298
300/* 299/*
301** Header for string value; string bytes follow the end of this structure 300** Header for string value; string bytes follow the end of this structure
301** (aligned according to 'UTString'; see next).
302*/ 302*/
303typedef union TString { 303typedef struct TString {
304 L_Umaxalign dummy; /* ensures maximum alignment for strings */ 304 CommonHeader;
305 struct { 305 lu_byte extra; /* reserved words for short strings; "has hash" for longs */
306 CommonHeader; 306 unsigned int hash;
307 lu_byte extra; /* reserved words for short strings; "has hash" for longs */ 307 size_t len; /* number of characters in string */
308 unsigned int hash; 308 struct TString *hnext; /* linked list for hash table */
309 size_t len; /* number of characters in string */
310 union TString *hnext; /* linked list for hash table */
311 } tsv;
312} TString; 309} TString;
313 310
314 311
315/* get the actual string (array of bytes) from a TString */ 312/*
316#define getstr(ts) cast(const char *, (ts) + 1) 313** Ensures that address after this type is always fully aligned.
314*/
315typedef union UTString {
316 L_Umaxalign dummy; /* ensures maximum alignment for strings */
317 TString tsv;
318} UTString;
319
320
321/*
322** Get the actual string (array of bytes) from a 'TString'.
323** (Access to 'extra' ensures that value is really a 'TString'.)
324*/
325#define getaddrstr(ts) (cast(char *, (ts)) + sizeof(UTString))
326#define getstr(ts) \
327 ((void)(ts)->extra, cast(const char*, getaddrstr(ts)))
317 328
318/* get the actual string (array of bytes) from a Lua value */ 329/* get the actual string (array of bytes) from a Lua value */
319#define svalue(o) getstr(rawtsvalue(o)) 330#define svalue(o) getstr(tsvalue(o))
320 331
321 332
322/* 333/*