diff options
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -388,35 +388,38 @@ typedef struct GCObject { | |||
388 | typedef struct TString { | 388 | typedef struct TString { |
389 | CommonHeader; | 389 | CommonHeader; |
390 | lu_byte extra; /* reserved words for short strings; "has hash" for longs */ | 390 | lu_byte extra; /* reserved words for short strings; "has hash" for longs */ |
391 | lu_byte shrlen; /* length for short strings, 0xFF for long strings */ | 391 | ls_byte shrlen; /* length for short strings, negative for long strings */ |
392 | unsigned int hash; | 392 | unsigned int hash; |
393 | union { | 393 | union { |
394 | size_t lnglen; /* length for long strings */ | 394 | size_t lnglen; /* length for long strings */ |
395 | struct TString *hnext; /* linked list for hash table */ | 395 | struct TString *hnext; /* linked list for hash table */ |
396 | } u; | 396 | } u; |
397 | char contents[1]; /* string body starts here */ | 397 | char *contents; /* pointer to content in long strings */ |
398 | } TString; | 398 | } TString; |
399 | 399 | ||
400 | 400 | ||
401 | #define strisshr(ts) ((ts)->shrlen >= 0) | ||
402 | |||
401 | 403 | ||
402 | /* | 404 | /* |
403 | ** Get the actual string (array of bytes) from a 'TString'. (Generic | 405 | ** Get the actual string (array of bytes) from a 'TString'. (Generic |
404 | ** version and specialized versions for long and short strings.) | 406 | ** version and specialized versions for long and short strings.) |
405 | */ | 407 | */ |
406 | #define getlngstr(ts) check_exp((ts)->shrlen == 0xFF, (ts)->contents) | 408 | #define rawgetshrstr(ts) (cast_charp(&(ts)->contents)) |
407 | #define getshrstr(ts) check_exp((ts)->shrlen != 0xFF, (ts)->contents) | 409 | #define getshrstr(ts) check_exp(strisshr(ts), rawgetshrstr(ts)) |
408 | #define getstr(ts) ((ts)->contents) | 410 | #define getlngstr(ts) check_exp(!strisshr(ts), (ts)->contents) |
411 | #define getstr(ts) (strisshr(ts) ? rawgetshrstr(ts) : (ts)->contents) | ||
409 | 412 | ||
410 | 413 | ||
411 | /* get string length from 'TString *s' */ | 414 | /* get string length from 'TString *ts' */ |
412 | #define tsslen(s) \ | 415 | #define tsslen(ts) \ |
413 | ((s)->shrlen != 0xFF ? (s)->shrlen : (s)->u.lnglen) | 416 | (strisshr(ts) ? cast_uint((ts)->shrlen) : (ts)->u.lnglen) |
414 | 417 | ||
415 | /* | 418 | /* |
416 | ** Get string and length */ | 419 | ** Get string and length */ |
417 | #define getlstr(ts, len) \ | 420 | #define getlstr(ts, len) \ |
418 | ((ts)->shrlen != 0xFF \ | 421 | (strisshr(ts) \ |
419 | ? (cast_void(len = (ts)->shrlen), (ts)->contents) \ | 422 | ? (cast_void(len = (ts)->shrlen), rawgetshrstr(ts)) \ |
420 | : (cast_void(len = (ts)->u.lnglen), (ts)->contents)) | 423 | : (cast_void(len = (ts)->u.lnglen), (ts)->contents)) |
421 | 424 | ||
422 | /* }================================================================== */ | 425 | /* }================================================================== */ |