Skip to content

Commit 1ba50e9

Browse files
committed
alignment changes
1 parent 2c82071 commit 1ba50e9

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

Modules/arraymodule.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ struct arraydescr {
4242
int is_signed;
4343
};
4444

45+
#ifdef MS_WINDOWS
46+
#define Py_ALIGN_AS(x) __declspec(align(x))
47+
#else
48+
#define Py_ALIGN_AS(x) _Alignas(x)
49+
#endif
50+
4551
typedef struct {
46-
union {
47-
Py_ssize_t allocated;
48-
double __alignment_padding; /* In case Py_ssize_t is 4 bytes */
49-
};
50-
char items[];
52+
Py_ssize_t allocated;
53+
Py_ALIGN_AS(8) char items[];
5154
} arraydata;
5255

5356
typedef struct arrayobject {

Tools/c-analyzer/c_parser/parser/_regexes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def _ind(text, level=1, edges='both'):
5959
register |
6060
static |
6161
_Thread_local |
62+
_Alignas |
63+
_Alignof |
6264
typedef |
6365
6466
const |
@@ -154,6 +156,17 @@ def _ind(text, level=1, edges='both'):
154156
TYPE_QUALIFIER = r'(?: \b (?: const | volatile ) \b )'
155157
PTR_QUALIFIER = rf'(?: [*] (?: \s* {TYPE_QUALIFIER} )? )'
156158

159+
ALIGNMENT_SPECIFIER = textwrap.dedent(r'''
160+
# alignment specifier
161+
(?:
162+
_Alignas
163+
\s* [(]
164+
[^)]*
165+
[)]
166+
)
167+
# end alignment specifier
168+
''')
169+
157170
TYPE_SPEC = textwrap.dedent(rf'''
158171
# type spec
159172
(?:
@@ -318,6 +331,9 @@ def _ind(text, level=1, edges='both'):
318331
(?:
319332
# typed member
320333
(?:
334+
(?: # <ALIGNMENT SPECIFIER>
335+
\s* {ALIGNMENT_SPECIFIER} \s*
336+
)?
321337
# Technically it doesn't have to have a type...
322338
(?: # <SPECIFIER_QUALIFIER>
323339
(?: {TYPE_QUALIFIER} \s* )?

0 commit comments

Comments
 (0)