Skip to content

Commit

Permalink
Add ALIGNOF_MAX_ALIGN_T to configure & PC/pyconfig.h
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou committed Apr 19, 2023
1 parent 2ba8084 commit b03d431
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,4 +745,10 @@ extern char * _getpty(int *, int, mode_t, int);
#undef __bool__
#endif

// Make sure we have alignof(max_align_t)
// (autoconf report alignment of unknown types to 0)
#if ALIGNOF_MAX_ALIGN_T <= 0
#error "ALIGNOF_MAX_ALIGN_T must be positive"
#endif

#endif /* Py_PYPORT_H */
18 changes: 18 additions & 0 deletions Modules/_testcapi/heaptype_relative.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,28 @@ make_heaptype_with_member(PyObject *module, PyObject *args)
}


static PyObject *
test_alignof_max_align_t(PyObject *module, PyObject *Py_UNUSED(ignored))
{
// We define ALIGNOF_MAX_ALIGN_T even if the compiler doesn't have
// max_afign_t. Double-check that it's correct.
assert(ALIGNOF_MAX_ALIGN_T > 0);
assert(ALIGNOF_MAX_ALIGN_T >= _Alignof(long long));
assert(ALIGNOF_MAX_ALIGN_T >= _Alignof(long double));
assert(ALIGNOF_MAX_ALIGN_T >= _Alignof(void*));
assert(ALIGNOF_MAX_ALIGN_T >= _Alignof(void (*)(void)));

// Ensure it's a power of two
assert((ALIGNOF_MAX_ALIGN_T & (ALIGNOF_MAX_ALIGN_T - 1)) == 0);

Py_RETURN_NONE;
}

static PyMethodDef TestMethods[] = {
{"make_sized_heaptypes", make_sized_heaptypes, METH_VARARGS},
{"subclass_var_heaptype", subclass_var_heaptype, METH_VARARGS},
{"make_heaptype_with_member", make_heaptype_with_member, METH_VARARGS},
{"test_alignof_max_align_t", test_alignof_max_align_t, METH_NOARGS},
{NULL},
};

Expand Down
2 changes: 2 additions & 0 deletions PC/pyconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
# define SIZEOF_HKEY 8
# define SIZEOF_SIZE_T 8
# define ALIGNOF_SIZE_T 8
# define ALIGNOF_MAX_ALIGN_T 8
/* configure.ac defines HAVE_LARGEFILE_SUPPORT iff
sizeof(off_t) > sizeof(long), and sizeof(long long) >= sizeof(off_t).
On Win64 the second condition is not true, but if fpos_t replaces off_t
Expand All @@ -351,6 +352,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
# else
# define SIZEOF_TIME_T 4
# endif
# define ALIGNOF_MAX_ALIGN_T 4
#endif

#ifdef _DEBUG
Expand Down
35 changes: 35 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2914,6 +2914,7 @@ AC_CHECK_SIZEOF(size_t, 4)
AC_CHECK_ALIGNOF(size_t)
AC_CHECK_SIZEOF(pid_t, 4)
AC_CHECK_SIZEOF(uintptr_t)
AC_CHECK_ALIGNOF(max_align_t)

AC_TYPE_LONG_DOUBLE
AC_CHECK_SIZEOF(long double, 16)
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
/* The normal alignment of `long', in bytes. */
#undef ALIGNOF_LONG

/* The normal alignment of `max_align_t', in bytes. */
#undef ALIGNOF_MAX_ALIGN_T

/* The normal alignment of `size_t', in bytes. */
#undef ALIGNOF_SIZE_T

Expand Down

0 comments on commit b03d431

Please sign in to comment.