8000 Add ALIGNOF_MAX_ALIGN_T to configure & PC/pyconfig.h · python/cpython@b03d431 · GitHub
[go: up one dir, main page]

Skip to content

Commit b03d431

Browse files
committed
Add ALIGNOF_MAX_ALIGN_T to configure & PC/pyconfig.h
1 parent 2ba8084 commit b03d431

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed

Include/pyport.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,4 +745,10 @@ extern char * _getpty(int *, int, mode_t, int);
745745
#undef __bool__
746746
#endif
747747

748+
// Make sure we have alignof(max_align_t)
749+
// (autoconf report alignment of unknown types to 0)
750+
#if ALIGNOF_MAX_ALIGN_T <= 0
751+
#error "ALIGNOF_MAX_ALIGN_T must be positive"
752+
#endif
753+
748754
#endif /* Py_PYPORT_H */

Modules/_testcapi/heaptype_relative.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,28 @@ make_heaptype_with_member(PyObject *module, PyObject *args)
249249
}
250250

251251

252+
static PyObject *
253+
test_alignof_max_align_t(PyObject *module, PyObject *Py_UNUSED(ignored))
254+
{
255+
// We define ALIGNOF_MAX_ALIGN_T even if the compiler doesn't have
256+
// max_afign_t. Double-check that it's correct.
257+
assert(ALIGNOF_MAX_ALIGN_T > 0);
258+
assert(ALIGNOF_MAX_ALIGN_T >= _Alignof(long long));
259+
assert(ALIGNOF_MAX_ALIGN_T >= _Alignof(long double));
260+
assert(ALIGNOF_MAX_ALIGN_T >= _Alignof(void*));
261+
assert(ALIGNOF_MAX_ALIGN_T >= _Alignof(void (*)(void)));
262+
263+
// Ensure it's a power of two
264+
assert((ALIGNOF_MAX_ALIGN_T & (ALIGNOF_MAX_ALIGN_T - 1)) == 0);
265+
266+
Py_RETURN_NONE;
267+
}
268+
252269
static PyMethodDef TestMethods[] = {
253270
{"make_sized_heaptypes", make_sized_heaptypes, METH_VARARGS},
254271
{"subclass_var_heaptype", subclass_var_heaptype, METH_VARARGS},
255272
{"make_heaptype_with_member", make_heaptype_with_member, METH_VARARGS},
273+
{"test_alignof_max_align_t", test_alignof_max_align_t, METH_NOARGS},
256274
{NULL},
257275
};
258276

PC/pyconfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
330330
# define SIZEOF_HKEY 8
331331
# define SIZEOF_SIZE_T 8
332332
# define ALIGNOF_SIZE_T 8
333+
# define ALIGNOF_MAX_ALIGN_T 8
333334
/* configure.ac defines HAVE_LARGEFILE_SUPPORT iff
334335
sizeof(off_t) > sizeof(long), and sizeof(long long) >= sizeof(off_t).
335336
On Win64 the second condition is not true, but if fpos_t replaces off_t
@@ -351,6 +352,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
351352
# else
352353
# define SIZEOF_TIME_T 4
353354
# endif
355+
# define ALIGNOF_MAX_ALIGN_T 4
354356
#endif
355357

356358
#ifdef _DEBUG

configure

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,6 +2914,7 @@ AC_CHECK_SIZEOF(size_t, 4)
29142914
AC_CHECK_ALIGNOF(size_t)
29152915
AC_CHECK_SIZEOF(pid_t, 4)
29162916
AC_CHECK_SIZEOF(uintptr_t)
2917+
AC_CHECK_ALIGNOF(max_align_t)
29172918

29182919
AC_TYPE_LONG_DOUBLE
29192920
AC_CHECK_SIZEOF(long double, 16)

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
/* The normal alignment of `long', in bytes. */
2020
#undef ALIGNOF_LONG
2121

22+
/* The normal alignment of `max_align_t', in bytes. */
23+
#undef ALIGNOF_MAX_ALIGN_T
24+
2225
/* The normal alignment of `size_t', in bytes. */
2326
#undef ALIGNOF_SIZE_T
2427

0 commit comments

Comments
 (0)
0