Skip to content

Commit cb06b66

Browse files
committed
Remove unions in rb_strterm structs for alignment
1 parent 82c8f22 commit cb06b66

2 files changed

Lines changed: 17 additions & 41 deletions

File tree

internal/parse.h

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,24 @@ struct rb_iseq_struct; /* in vm_core.h */
2222

2323
/* structs for managing terminator of string literal and heredocment */
2424
typedef struct rb_strterm_literal_struct {
25-
union {
26-
VALUE dummy;
27-
long nest;
28-
} u0;
29-
union {
30-
VALUE dummy;
31-
long func; /* STR_FUNC_* (e.g., STR_FUNC_ESCAPE and STR_FUNC_EXPAND) */
32-
} u1;
33-
union {
34-
VALUE dummy;
35-
long paren; /* '(' of `%q(...)` */
36-
} u2;
37-
union {
38-
VALUE dummy;
39-
long term; /* ')' of `%q(...)` */
40-
} u3;
25+
long nest;
26+
long func; /* STR_FUNC_* (e.g., STR_FUNC_ESCAPE and STR_FUNC_EXPAND) */
27+
long paren; /* '(' of `%q(...)` */
28+
long term; /* ')' of `%q(...)` */
4129
} rb_strterm_literal_t;
4230

43-
#define HERETERM_LENGTH_BITS ((SIZEOF_VALUE - 1) * CHAR_BIT - 1)
44-
4531
typedef struct rb_strterm_heredoc_struct {
4632
VALUE lastline; /* the string of line that contains `<<"END"` */
4733
long offset; /* the column of END in `<<"END"` */
4834
int sourceline; /* lineno of the line that contains `<<"END"` */
49-
unsigned length /* the length of END in `<<"END"` */
50-
#if HERETERM_LENGTH_BITS < SIZEOF_INT * CHAR_BIT
51-
: HERETERM_LENGTH_BITS
52-
# define HERETERM_LENGTH_MAX ((1U << HERETERM_LENGTH_BITS) - 1)
53-
#else
54-
# define HERETERM_LENGTH_MAX UINT_MAX
55-
#endif
56-
;
57-
#if HERETERM_LENGTH_BITS < SIZEOF_INT * CHAR_BIT
58-
unsigned quote: 1;
59-
unsigned func: 8;
60-
#else
35+
unsigned length; /* the length of END in `<<"END"` */
6136
uint8_t quote;
6237
uint8_t func;
63-
#endif
6438
} rb_strterm_heredoc_t;
6539
STATIC_ASSERT(rb_strterm_heredoc_t, sizeof(rb_strterm_heredoc_t) <= 4 * SIZEOF_VALUE);
6640

41+
#define HERETERM_LENGTH_MAX UINT_MAX
42+
6743
typedef struct rb_strterm_struct {
6844
VALUE flags;
6945
union {

parse.y

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7852,7 +7852,7 @@ tokadd_codepoint(struct parser_params *p, rb_encoding **encp,
78527852
p->lex.pcur += numlen;
78537853
if (p->lex.strterm == NULL ||
78547854
(strterm_is_heredoc((VALUE)p->lex.strterm)) ||
7855-
(p->lex.strterm->u.literal.u1.func != str_regexp)) {
7855+
(p->lex.strterm->u.literal.func != str_regexp)) {
78567856
if (wide ? (numlen == 0 || numlen > 6) : (numlen < 4)) {
78577857
literal_flush(p, p->lex.pcur);
78587858
yyerror0("invalid Unicode escape");
@@ -7908,7 +7908,7 @@ tokadd_utf8(struct parser_params *p, rb_encoding **encp,
79087908
if (regexp_literal) { tokadd(p, '\\'); tokadd(p, 'u'); }
79097909

79107910
if (peek(p, open_brace)) { /* handle \u{...} form */
7911-
if (regexp_literal && p->lex.strterm->u.literal.u1.func == str_regexp) {
7911+
if (regexp_literal && p->lex.strterm->u.literal.func == str_regexp) {
79127912
/*
79137913
* Skip parsing validation code and copy bytes as-is until term or
79147914
* closing brace, in order to correctly handle extended regexps where
@@ -8567,9 +8567,9 @@ parser_string_term(struct parser_params *p, int func)
85678567
static enum yytokentype
85688568
parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
85698569
{
8570-
int func = (int)quote->u1.func;
8571-
int term = (int)quote->u3.term;
8572-
int paren = (int)quote->u2.paren;
8570+
int func = (int)quote->func;
8571+
int term = (int)quote->term;
8572+
int paren = (int)quote->paren;
85738573
int c, space = 0;
85748574
rb_encoding *enc = p->enc;
85758575
rb_encoding *base_enc = 0;
@@ -8587,12 +8587,12 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
85878587
space = 1;
85888588
}
85898589
if (func & STR_FUNC_LIST) {
8590-
quote->u1.func &= ~STR_FUNC_LIST;
8590+
quote->func &= ~STR_FUNC_LIST;
85918591
space = 1;
85928592
}
8593-
if (c == term && !quote->u0.nest) {
8593+
if (c == term && !quote->nest) {
85948594
if (func & STR_FUNC_QWORDS) {
8595-
quote->u1.func |= STR_FUNC_TERM;
8595+
quote->func |= STR_FUNC_TERM;
85968596
pushback(p, c); /* dispatch the term at tSTRING_END */
85978597
add_delayed_token(p, p->lex.ptok, p->lex.pcur, __LINE__);
85988598
return ' ';
@@ -8612,7 +8612,7 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
86128612
c = nextc(p);
86138613
}
86148614
pushback(p, c);
8615-
if (tokadd_string(p, func, term, paren, &quote->u0.nest,
8615+
if (tokadd_string(p, func, term, paren, &quote->nest,
86168616
&enc, &base_enc) == -1) {
86178617
if (p->eofp) {
86188618
#ifndef RIPPER
@@ -8633,7 +8633,7 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
86338633
else {
86348634
unterminated_literal("unterminated string meets end of file");
86358635
}
8636-
quote->u1.func |= STR_FUNC_TERM;
8636+
quote->func |= STR_FUNC_TERM;
86378637
}
86388638
}
86398639

0 commit comments

Comments
 (0)