File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -262,7 +262,13 @@ _PyTestCapi_Init_HeaptypeRelative(PyObject *m) {
262
262
return -1 ;
263
263
}
264
264
265
+ #ifdef __alignof_is_defined
266
+ // C11
265
267
PyModule_AddIntConstant (m , "alignof_max_align_t" , alignof(max_align_t ));
268
+ #else
269
+ // if alignof and max_align_t is unavailable, skip the alignment tests
270
+ PyModule_AddIntConstant (m , "alignof_max_align_t" , 1 );
271
+ #endif
266
272
267
273
return 0 ;
268
274
}
Original file line number Diff line number Diff line change @@ -3553,10 +3553,22 @@ static const PySlot_Offset pyslot_offsets[] = {
3553
3553
/* Align up to the nearest multiple of alignof(max_align_t)
3554
3554
* (like _Py_ALIGN_UP, but for a size rather than pointer)
3555
3555
*/
3556
+ #if __alignof_is_defined
3557
+ // C11
3558
+ #define MAX_ALIGN alignof(max_align_t)
3559
+ #else
3560
+ // workaround for MSVC
3561
+ typedef union {
3562
+ intmax_t x ;
3563
+ long double y ;
3564
+ void * z ;
3565
+ void (* f )();
3566
+ } _max_align_t_wannabe ;
3567
+ #define MAX_ALIGN _Alignof(_max_align_t_wannabe)
3568
+ #endif
3556
3569
static Py_ssize_t
3557
3570
_align_up (Py_ssize_t size ) {
3558
- const Py_ssize_t alignment = alignof(max_align_t );
3559
- return (size + alignment - 1 ) & ~(alignment - 1 );
3571
+ return (size + MAX_ALIGN - 1 ) & ~(MAX_ALIGN - 1 );
3560
3572
}
3561
3573
3562
3574
/* Given a PyType_FromMetaclass `bases` argument (NULL, type, or tuple of
You can’t perform that action at this time.
0 commit comments