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 {