Alignment fixup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36845 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-07-06 07:48:26 +00:00
parent 70811df5e7
commit 5ee4405ad4
2 changed files with 15 additions and 5 deletions

View file

@ -6,6 +6,11 @@
* Source/NSMethodSignature.m: fix uninitialised variable
* Source/NSPropertyList.m: avoid static analyser warning
* Tools/gdomap.c: fix uninitialised data warning
* Source/NSObject.m: fixup error in alignment calculation;
was assuming that the alignment of a double would do but that's
not good enough. On GCC we use the __BIGGEST_ALIGNMENT__ used on
the machine, but clang has no support for that, so if it's not
defined we now guess 16 rather than __alignof__(double).
2013-07-05 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -397,14 +397,10 @@ static inline NSLock *GSAllocationLockForObject(id p)
#endif
#ifdef ALIGN
#undef ALIGN
#endif
#if defined(__GNUC__) && __GNUC__ < 4
#define __builtin_offsetof(s, f) (uintptr_t)(&(((s*)0)->f))
#endif
#define alignof(type) __builtin_offsetof(struct { const char c; type member; }, member)
#define ALIGN alignof(double)
/*
* Define a structure to hold information that is held locally
@ -415,13 +411,22 @@ typedef struct obj_layout_unpadded {
} unp;
#define UNP sizeof(unp)
/* GCC provides a defined value for the largest alignment required on a
* machine, and we must lay objects out to that alignment.
* For compilers that don't define it, we try to pick a likely value.
*/
#ifndef __BIGGEST_ALIGNMENT__
#define __BIGGEST_ALIGNMENT__ 16
#endif
/*
* Now do the REAL version - using the other version to determine
* what padding (if any) is required to get the alignment of the
* structure correct.
*/
struct obj_layout {
char padding[ALIGN - ((UNP % ALIGN) ? (UNP % ALIGN) : ALIGN)];
char padding[__BIGGEST_ALIGNMENT__ - ((UNP % __BIGGEST_ALIGNMENT__)
? (UNP % __BIGGEST_ALIGNMENT__) : __BIGGEST_ALIGNMENT__)];
NSUInteger retained;
};
typedef struct obj_layout *obj;