Skip to content

Commit d4c0f91

Browse files
committed
C11 alignas instead of unions -- extended alignments
This replaces some uses of pg_attribute_aligned() with the standard alignas() for cases where extended alignment (larger than max_align_t) is required. This patch stipulates that all supported compilers must support alignments up to PG_IO_ALIGN_SIZE, but that seems pretty likely. We can then also desupport the case where direct I/O is disabled because pg_attribute_aligned is not supported. Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/46f05236-d4d4-4b4e-84d4-faa500f14691%40eisentraut.org
1 parent 4b203d4 commit d4c0f91

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/include/c.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,25 +1132,15 @@ typedef struct PGAlignedBlock
11321132
* for I/O in general, but may be strictly required on some platforms when
11331133
* using direct I/O.
11341134
*/
1135-
typedef union PGIOAlignedBlock
1135+
typedef struct PGIOAlignedBlock
11361136
{
1137-
#ifdef pg_attribute_aligned
1138-
pg_attribute_aligned(PG_IO_ALIGN_SIZE)
1139-
#endif
1140-
chardata[BLCKSZ];
1141-
doubleforce_align_d;
1142-
int64force_align_i64;
1137+
alignas(PG_IO_ALIGN_SIZE) char data[BLCKSZ];
11431138
} PGIOAlignedBlock;
11441139

11451140
/* Same, but for an XLOG_BLCKSZ-sized buffer */
1146-
typedef union PGAlignedXLogBlock
1141+
typedef struct PGAlignedXLogBlock
11471142
{
1148-
#ifdef pg_attribute_aligned
1149-
pg_attribute_aligned(PG_IO_ALIGN_SIZE)
1150-
#endif
1151-
chardata[XLOG_BLCKSZ];
1152-
doubleforce_align_d;
1153-
int64force_align_i64;
1143+
alignas(PG_IO_ALIGN_SIZE) char data[XLOG_BLCKSZ];
11541144
} PGAlignedXLogBlock;
11551145

11561146
/* msb for char */

src/include/storage/fd.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ extern PGDLLIMPORT int max_safe_fds;
8585
* to the appropriate Windows flag in src/port/open.c. We simulate it with
8686
* fcntl(F_NOCACHE) on macOS inside fd.c's open() wrapper. We use the name
8787
* PG_O_DIRECT rather than defining O_DIRECT in that case (probably not a good
88-
* idea on a Unix). We can only use it if the compiler will correctly align
89-
* PGIOAlignedBlock for us, though.
88+
* idea on a Unix).
9089
*/
91-
#if defined(O_DIRECT) && defined(pg_attribute_aligned)
90+
#if defined(O_DIRECT)
9291
#definePG_O_DIRECT O_DIRECT
9392
#elif defined(F_NOCACHE)
9493
#definePG_O_DIRECT 0x80000000

0 commit comments

Comments
 (0)