Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -788,13 +788,10 @@ [AC_DEFINE(OF_HAVE_INTTYPES_H, 1, [Whether we have inttypes.h])]) AC_CHECK_HEADER(sys/types.h, [AC_DEFINE(OF_HAVE_SYS_TYPES_H, 1, [Whether we have sys/types.h])]) -AC_CHECK_TYPE(max_align_t, - [AC_DEFINE(OF_HAVE_MAX_ALIGN_T, 1, [Whether we have max_align_t])]) - AC_CHECK_HEADER(stdnoreturn.h, [AC_DEFINE(OF_HAVE_STDNORETURN_H, 1, [Whether we have stdnoreturn.h])]) AC_CHECK_TYPE(wchar_t) AC_CHECK_HEADER(wchar.h) Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -85,12 +85,12 @@ #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlock retainCountSpinlock; #endif }; -#define PRE_IVARS_ALIGN ((sizeof(struct PreIvars) + \ - (OF_BIGGEST_ALIGNMENT - 1)) & ~(OF_BIGGEST_ALIGNMENT - 1)) +#define PRE_IVARS_ALIGN \ + OFRoundUpToPowerOf2(sizeof(struct PreIvars), OF_BIGGEST_ALIGNMENT) #define PRE_IVARS ((struct PreIvars *)(void *)((char *)self - PRE_IVARS_ALIGN)) static struct { Class isa; } allocFailedException; @@ -338,12 +338,19 @@ if OF_UNLIKELY (extraAlignment > 1) extraAlignment = OFRoundUpToPowerOf2(extraAlignment, PRE_IVARS_ALIGN + instanceSize) - PRE_IVARS_ALIGN - instanceSize; +#ifndef OF_WINDOWS instance = calloc(1, PRE_IVARS_ALIGN + instanceSize + extraAlignment + extraSize); +#else + instance = _aligned_malloc(PRE_IVARS_ALIGN + instanceSize + + extraAlignment + extraSize, OF_BIGGEST_ALIGNMENT); + memset(instance, 0, PRE_IVARS_ALIGN + instanceSize + extraAlignment + + extraSize); +#endif if OF_UNLIKELY (instance == nil) { object_setClass((id)&allocFailedException, [OFAllocFailedException class]); @throw (id)&allocFailedException; @@ -352,11 +359,15 @@ ((struct PreIvars *)instance)->retainCount = 1; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) if OF_UNLIKELY (OFSpinlockNew( &((struct PreIvars *)instance)->retainCountSpinlock) != 0) { +# ifndef OF_WINDOWS free(instance); +# else + _aligned_free(instance); +# endif @throw [OFInitializationFailedException exceptionWithClass: class]; } #endif @@ -365,11 +376,15 @@ if (!objc_constructInstance(class, instance)) { #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlockFree(&((struct PreIvars *)(void *) ((char *)instance - PRE_IVARS_ALIGN))->retainCountSpinlock); #endif +#ifndef OF_WINDOWS free((char *)instance - PRE_IVARS_ALIGN); +#else + _aligned_free((char *)instance - PRE_IVARS_ALIGN); +#endif @throw [OFInitializationFailedException exceptionWithClass: class]; } if OF_UNLIKELY (extra != NULL) @@ -1232,11 +1247,15 @@ #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlockFree(&PRE_IVARS->retainCountSpinlock); #endif +#ifndef OF_WINDOWS free((char *)self - PRE_IVARS_ALIGN); +#else + _aligned_free((char *)self - PRE_IVARS_ALIGN); +#endif } /* Required to use properties with the Apple runtime */ - (id)copyWithZone: (void *)zone { Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -112,19 +112,23 @@ #else # define OF_ALIGNOF(type) __alignof__(type) # define OF_ALIGNAS(type) OF_ALIGN(OF_ALIGNOF(type)) #endif -#if __STDC_VERSION__ >= 201112L && defined(OF_HAVE_MAX_ALIGN_T) -# define OF_BIGGEST_ALIGNMENT _Alignof(max_align_t) +#ifdef __BIGGEST_ALIGNMENT__ +# define OF_BIGGEST_ALIGNMENT __BIGGEST_ALIGNMENT__ #else -# ifdef __BIGGEST_ALIGNMENT__ -# define OF_BIGGEST_ALIGNMENT __BIGGEST_ALIGNMENT__ -# else -# /* Hopefully no arch needs more than 16 byte alignment */ -# define OF_BIGGEST_ALIGNMENT 16 -# endif +/* Hopefully no arch needs more than 16 byte alignment */ +# define OF_BIGGEST_ALIGNMENT 16 +#endif +/* + * We use SSE inline assembly on AMD64 and x86, so it must never be smaller + * than 16. + */ +#if (defined(OF_AMD64) || defined(OF_X86)) && OF_BIGGEST_ALIGNMENT < 16 +# undef OF_BIGGEST_ALIGNMENT +# define OF_BIGGEST_ALIGNMENT 16 #endif #define OF_PREPROCESSOR_CONCAT2(a, b) a##b #define OF_PREPROCESSOR_CONCAT(a, b) OF_PREPROCESSOR_CONCAT2(a, b) Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -15,11 +15,10 @@ #undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR #undef OF_HAVE_IPV6 #undef OF_HAVE_IPX #undef OF_HAVE_LIMITS_H #undef OF_HAVE_LINK -#undef OF_HAVE_MAX_ALIGN_T #undef OF_HAVE_NETATALK_AT_H #undef OF_HAVE_NETAT_APPLETALK_H #undef OF_HAVE_NETINET_IN_H #undef OF_HAVE_NETINET_TCP_H #undef OF_HAVE_NETIPX_IPX_H