Skip to content

Commit b90dde3

Browse files
committed
Rename identifiers
1 parent ad249f1 commit b90dde3

10 files changed

Lines changed: 229 additions & 229 deletions

tests/unit/union_addrof_external.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
#include <stdint.h>
55
#include <string.h>
66

7-
struct header {
8-
uint16_t tag;
9-
uint16_t port;
10-
uint32_t addr;
7+
struct record {
8+
uint16_t code;
9+
uint16_t lo;
10+
uint32_t hi;
1111
char pad[8];
1212
};
1313

14-
struct Storage {
14+
struct Container {
1515
union {
16-
struct header h;
16+
struct record h;
1717
char raw[128];
18-
} buffer;
18+
} view;
1919
};
2020

21-
static void external_writer(void *out, size_t cap) {
21+
static void fill(void *out, size_t cap) {
2222
unsigned char src[16] = {0};
2323
src[0] = 2;
2424
src[1] = 0;
@@ -33,17 +33,17 @@ static void external_writer(void *out, size_t cap) {
3333
}
3434

3535
int main(void) {
36-
struct Storage s;
37-
memset(&s, 0, sizeof(s));
36+
struct Container c;
37+
memset(&c, 0, sizeof(c));
3838

39-
external_writer((void *)&s.buffer, sizeof(s.buffer));
39+
fill((void *)&c.view, sizeof(c.view));
4040

41-
assert(s.buffer.h.tag == 2);
42-
assert(((unsigned char *)&s.buffer.h.port)[0] == 0x00);
43-
assert(((unsigned char *)&s.buffer.h.port)[1] == 0x50);
41+
assert(c.view.h.code == 2);
42+
assert(((unsigned char *)&c.view.h.lo)[0] == 0x00);
43+
assert(((unsigned char *)&c.view.h.lo)[1] == 0x50);
4444

45-
assert(s.buffer.raw[0] == 2);
46-
assert((unsigned char)s.buffer.raw[3] == 0x50);
45+
assert(c.view.raw[0] == 2);
46+
assert((unsigned char)c.view.raw[3] == 0x50);
4747

4848
return 0;
4949
}

tests/unit/union_cross_arm_cast.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,43 @@
44
#include <stdint.h>
55
#include <string.h>
66

7-
struct header_a {
8-
uint16_t tag;
9-
char data[14];
7+
struct shape_a {
8+
uint16_t code;
9+
char pad[14];
1010
};
1111

12-
struct header_b {
13-
uint16_t tag;
14-
uint16_t port;
15-
uint32_t flags;
16-
uint8_t body[16];
17-
uint32_t extra;
12+
struct shape_b {
13+
uint16_t code;
14+
uint16_t lo;
15+
uint32_t mid;
16+
uint8_t fill[16];
17+
uint32_t tail;
1818
};
1919

20-
struct Storage {
20+
struct Container {
2121
unsigned int len;
2222
union {
23-
struct header_a a;
24-
struct header_b b;
23+
struct shape_a a;
24+
struct shape_b b;
2525
char raw[64];
2626
} u;
2727
};
2828

2929
int main(void) {
30-
struct Storage s;
31-
memset(&s, 0, sizeof(s));
30+
struct Container c;
31+
memset(&c, 0, sizeof(c));
3232

33-
s.u.a.tag = 10;
34-
s.len = sizeof(struct header_b);
33+
c.u.a.code = 10;
34+
c.len = sizeof(struct shape_b);
3535

36-
((struct header_b *)(void *)&s.u.a)->extra = 0xDEADBEEF;
36+
((struct shape_b *)(void *)&c.u.a)->tail = 0xDEADBEEF;
3737

38-
assert(s.u.b.extra == 0xDEADBEEF);
39-
assert(s.u.b.tag == 10);
38+
assert(c.u.b.tail == 0xDEADBEEF);
39+
assert(c.u.b.code == 10);
4040

41-
s.u.b.port = 0x1F90;
42-
assert(((unsigned char *)&s.u.raw)[2] == 0x90);
43-
assert(((unsigned char *)&s.u.raw)[3] == 0x1F);
41+
c.u.b.lo = 0x1F90;
42+
assert(((unsigned char *)&c.u.raw)[2] == 0x90);
43+
assert(((unsigned char *)&c.u.raw)[3] == 0x1F);
4444

4545
return 0;
4646
}

tests/unit/union_field_alignment.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
#include <stddef.h>
44
#include <stdint.h>
55

6-
struct chunk {
7-
struct chunk *next;
6+
struct node {
7+
struct node *next;
88
union {
9-
uint8_t data[1];
10-
void *dummy;
9+
uint8_t bytes[1];
10+
void *aligner;
1111
} x;
1212
};
1313

1414
int main(void) {
15-
struct chunk c;
16-
c.next = 0;
17-
c.x.data[0] = 0xAB;
15+
struct node n;
16+
n.next = 0;
17+
n.x.bytes[0] = 0xAB;
1818

19-
assert(c.x.data[0] == 0xAB);
20-
assert(sizeof(c.x) >= sizeof(void *));
21-
assert(((uintptr_t)&c.x % _Alignof(void *)) == 0);
19+
assert(n.x.bytes[0] == 0xAB);
20+
assert(sizeof(n.x) >= sizeof(void *));
21+
assert(((uintptr_t)&n.x % _Alignof(void *)) == 0);
2222
return 0;
2323
}

tests/unit/union_flex_array_member.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
#include <stdlib.h>
66
#include <string.h>
77

8-
struct chunk {
9-
size_t dlen;
8+
struct node {
9+
size_t len;
1010
union {
11-
uint8_t data[1];
12-
void *dummy;
11+
uint8_t bytes[1];
12+
void *aligner;
1313
} x;
1414
};
1515

1616
int main(void) {
17-
size_t chunk_size = 32;
18-
struct chunk *c = (struct chunk *)malloc(sizeof(struct chunk) + chunk_size);
19-
c->dlen = chunk_size;
17+
size_t tail_size = 32;
18+
struct node *n = (struct node *)malloc(sizeof(struct node) + tail_size);
19+
n->len = tail_size;
2020

21-
for (size_t i = 0; i < chunk_size; i++) {
22-
c->x.data[i] = (uint8_t)(i & 0xFF);
21+
for (size_t i = 0; i < tail_size; i++) {
22+
n->x.bytes[i] = (uint8_t)(i & 0xFF);
2323
}
24-
for (size_t i = 0; i < chunk_size; i++) {
25-
assert(c->x.data[i] == (uint8_t)(i & 0xFF));
24+
for (size_t i = 0; i < tail_size; i++) {
25+
assert(n->x.bytes[i] == (uint8_t)(i & 0xFF));
2626
}
2727

28-
uint8_t *p = &c->x.data[10];
28+
uint8_t *p = &n->x.bytes[10];
2929
assert(*p == 10);
3030
*p = 0xAA;
31-
assert(c->x.data[10] == 0xAA);
31+
assert(n->x.bytes[10] == 0xAA);
3232

33-
free(c);
33+
free(n);
3434
return 0;
3535
}

tests/unit/union_memset_memcpy.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,52 @@
44
#include <stdint.h>
55
#include <string.h>
66

7-
struct header_a {
8-
uint16_t tag;
9-
char data[14];
7+
struct shape_a {
8+
uint16_t code;
9+
char pad[14];
1010
};
1111

12-
struct header_b {
13-
uint16_t tag;
14-
uint16_t port;
15-
uint32_t addr;
16-
char zero[8];
12+
struct shape_b {
13+
uint16_t code;
14+
uint16_t lo;
15+
uint32_t hi;
16+
char fill[8];
1717
};
1818

19-
struct Storage {
19+
struct Container {
2020
union {
21-
struct header_a a;
22-
struct header_b b;
21+
struct shape_a a;
22+
struct shape_b b;
2323
char raw[256];
24-
} buffer;
24+
} view;
2525
};
2626

2727
int main(void) {
28-
struct Storage s;
29-
30-
memset(&s, 0, sizeof(s));
31-
assert(s.buffer.a.tag == 0);
32-
assert(s.buffer.b.port == 0);
33-
assert(s.buffer.raw[0] == 0);
34-
assert(s.buffer.raw[255] == 0);
35-
36-
unsigned char wire[16] = {0};
37-
wire[0] = 2;
38-
wire[2] = 0x50;
39-
wire[3] = 0x00;
40-
wire[4] = 0x7F;
41-
wire[5] = 0x00;
42-
wire[6] = 0x00;
43-
wire[7] = 0x01;
28+
struct Container c;
29+
30+
memset(&c, 0, sizeof(c));
31+
assert(c.view.a.code == 0);
32+
assert(c.view.b.lo == 0);
33+
assert(c.view.raw[0] == 0);
34+
assert(c.view.raw[255] == 0);
35+
36+
unsigned char src[16] = {0};
37+
src[0] = 2;
38+
src[2] = 0x50;
39+
src[3] = 0x00;
40+
src[4] = 0x7F;
41+
src[5] = 0x00;
42+
src[6] = 0x00;
43+
src[7] = 0x01;
4444
size_t len = 16;
45-
assert(len <= sizeof(s.buffer.raw));
46-
memcpy(&s.buffer.raw, wire, len);
45+
assert(len <= sizeof(c.view.raw));
46+
memcpy(&c.view.raw, src, len);
4747

48-
assert(s.buffer.b.tag == 2);
49-
assert(((unsigned char *)&s.buffer.b.port)[0] == 0x50);
48+
assert(c.view.b.code == 2);
49+
assert(((unsigned char *)&c.view.b.lo)[0] == 0x50);
5050

51-
memset(&s, 0, sizeof(s));
52-
assert(s.buffer.b.tag == 0);
51+
memset(&c, 0, sizeof(c));
52+
assert(c.view.b.code == 0);
5353

5454
return 0;
5555
}

tests/unit/union_nested.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
#include <stdint.h>
44
#include <string.h>
55

6-
struct header {
7-
uint16_t tag;
8-
char data[14];
6+
struct record {
7+
uint16_t code;
8+
char pad[14];
99
};
1010

1111
struct inner {
1212
union {
13-
struct header h;
13+
struct record h;
1414
char raw[128];
15-
} buffer;
15+
} view;
1616
};
1717

1818
struct Outer {
1919
int kind;
20-
int subtype;
21-
int proto;
20+
int level;
21+
int variant;
2222
unsigned int len;
2323
union {
24-
struct header h;
24+
struct record h;
2525
struct inner nested;
2626
} body;
2727
};
@@ -31,15 +31,15 @@ int main(void) {
3131
memset(&ex, 0, sizeof(ex));
3232

3333
ex.kind = 2;
34-
ex.subtype = 1;
35-
ex.proto = 6;
36-
ex.len = sizeof(struct header);
37-
ex.body.h.tag = 2;
38-
ex.body.h.data[0] = 'X';
34+
ex.level = 1;
35+
ex.variant = 6;
36+
ex.len = sizeof(struct record);
37+
ex.body.h.code = 2;
38+
ex.body.h.pad[0] = 'X';
3939

40-
assert(ex.body.h.tag == 2);
41-
assert(ex.body.h.data[0] == 'X');
40+
assert(ex.body.h.code == 2);
41+
assert(ex.body.h.pad[0] == 'X');
4242

43-
assert(ex.body.nested.buffer.h.tag == 2);
43+
assert(ex.body.nested.view.h.code == 2);
4444
return 0;
4545
}

tests/unit/union_pointer_pun_writethrough.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ int main(void) {
55
long x = -1;
66

77
union {
8-
unsigned long *to_ulong;
9-
long *to_long;
10-
} lptr;
8+
unsigned long *as_unsigned;
9+
long *as_signed;
10+
} pp;
1111

12-
lptr.to_long = &x;
13-
*lptr.to_ulong = 42UL;
12+
pp.as_signed = &x;
13+
*pp.as_unsigned = 42UL;
1414

1515
assert(x == 42);
1616
return 0;

0 commit comments

Comments
 (0)