Alignment fixes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16398 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-04-09 09:23:10 +00:00
parent 87ee43c6dd
commit b3bd3dc830
5 changed files with 43 additions and 7 deletions

View file

@ -1,3 +1,13 @@
2003-04-09 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSTcpPort.m:
* Source/NSData.m:
* Source/NSSerializer.m:
* Source/NSURL.m:
Replace __alignof__() with calls to objc_alignof_type() so that if
__alignof__() is broken we can hope that the objc runtime library
has a workaround.
2003-04-08 Richard Frith-Macdonald <rfm@gnu.org> 2003-04-08 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/gnustep/base/Foundation.h: Include GNUstep extensions * Headers/gnustep/base/Foundation.h: Include GNUstep extensions

View file

@ -1348,10 +1348,17 @@ static Class tcpPortClass;
object: nil]; object: nil];
} }
#if NEED_WORD_ALIGNMENT
static unsigned wordAlign;
#endif
+ (void) initialize + (void) initialize
{ {
if (self == [GSTcpPort class]) if (self == [GSTcpPort class])
{ {
#if NEED_WORD_ALIGNMENT
wordAlign = objc_alignof_type(@encode(gsu32));
#endif
tcpPortClass = self; tcpPortClass = self;
tcpPortMap = NSCreateMapTable(NSIntMapKeyCallBacks, tcpPortMap = NSCreateMapTable(NSIntMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 0); NSNonOwnedPointerMapValueCallBacks, 0);
@ -2117,7 +2124,7 @@ static Class tcpPortClass;
* word boundary, so we work with an aligned buffer * word boundary, so we work with an aligned buffer
* and use memcmpy() * and use memcmpy()
*/ */
if ((hLength % __alignof__(gsu32)) != 0) if ((hLength % wordAlign) != 0)
{ {
GSPortItemHeader itemHeader; GSPortItemHeader itemHeader;

View file

@ -378,10 +378,19 @@ failure:
@implementation NSData @implementation NSData
#if NEED_WORD_ALIGNMENT
static unsigned gsu16Align;
static unsigned gsu32Align;
#endif
+ (void) initialize + (void) initialize
{ {
if (self == [NSData class]) if (self == [NSData class])
{ {
#if NEED_WORD_ALIGNMENT
gsu16Align = objc_alignof_type(@encode(gsu16));
gsu32Align = objc_alignof_type(@encode(gsu32));
#endif
NSDataAbstract = self; NSDataAbstract = self;
NSMutableDataAbstract = [NSMutableData class]; NSMutableDataAbstract = [NSMutableData class];
dataMalloc = [NSDataMalloc class]; dataMalloc = [NSDataMalloc class];
@ -2615,7 +2624,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
*cursor, length]; *cursor, length];
} }
#if NEED_WORD_ALIGNMENT #if NEED_WORD_ALIGNMENT
if ((*cursor % __alignof__(gsu16)) != 0) if ((*cursor % gsu16Align) != 0)
memcpy(&x, (bytes + *cursor), 2); memcpy(&x, (bytes + *cursor), 2);
else else
#endif #endif
@ -2635,7 +2644,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
*cursor, length]; *cursor, length];
} }
#if NEED_WORD_ALIGNMENT #if NEED_WORD_ALIGNMENT
if ((*cursor % __alignof__(gsu32)) != 0) if ((*cursor % gsu32Align) != 0)
memcpy(&x, (bytes + *cursor), 4); memcpy(&x, (bytes + *cursor), 4);
else else
#endif #endif
@ -3345,7 +3354,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
} }
*(gsu8*)(bytes + length++) = tag; *(gsu8*)(bytes + length++) = tag;
#if NEED_WORD_ALIGNMENT #if NEED_WORD_ALIGNMENT
if ((length % __alignof__(gsu16)) != 0) if ((length % gsu16Align) != 0)
{ {
x = GSSwapHostI16ToBig(x); x = GSSwapHostI16ToBig(x);
memcpy((bytes + length), &x, 2); memcpy((bytes + length), &x, 2);
@ -3366,7 +3375,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
} }
*(gsu8*)(bytes + length++) = tag; *(gsu8*)(bytes + length++) = tag;
#if NEED_WORD_ALIGNMENT #if NEED_WORD_ALIGNMENT
if ((length % __alignof__(gsu32)) != 0) if ((length % gsu32Align) != 0)
{ {
x = GSSwapHostI32ToBig(x); x = GSSwapHostI32ToBig(x);
memcpy((bytes + length), &x, 4); memcpy((bytes + length), &x, 4);

View file

@ -113,6 +113,10 @@ static Class MStringClass = 0;
static Class StringClass = 0; static Class StringClass = 0;
static Class NumberClass = 0; static Class NumberClass = 0;
#if NEED_WORD_ALIGNMENT
static unsigned gsu32Align;
#endif
typedef struct { typedef struct {
@defs(GSString) @defs(GSString)
} *ivars; } *ivars;
@ -229,7 +233,7 @@ serializeToInfo(id object, _NSSerializerInfo* info)
* word boundary, so we work with an aligned buffer * word boundary, so we work with an aligned buffer
* and use memcmpy() * and use memcmpy()
*/ */
if ((dlen % __alignof__(gsu32)) != 0) if ((dlen % gsu32Align) != 0)
{ {
unichar buffer[slen]; unichar buffer[slen];
[object getCharacters: buffer]; [object getCharacters: buffer];
@ -339,6 +343,9 @@ static BOOL shouldBeCompact = NO;
{ {
if (self == [NSSerializer class]) if (self == [NSSerializer class])
{ {
#if NEED_WORD_ALIGNMENT
gsu32Align = objc_alignof_type(@encode(gsu32));
#endif
appSel = @selector(appendBytes:length:); appSel = @selector(appendBytes:length:);
datSel = @selector(mutableBytes); datSel = @selector(mutableBytes);
lenSel = @selector(length); lenSel = @selector(length);

View file

@ -472,6 +472,8 @@ static void unescape(const char *from, char * to)
*/ */
@implementation NSURL @implementation NSURL
static unsigned urlAlign;
/** /**
* Create and return a file URL with the supplied path.<br /> * Create and return a file URL with the supplied path.<br />
* The value of aPath must be a valid filesystem path.<br /> * The value of aPath must be a valid filesystem path.<br />
@ -486,6 +488,7 @@ static void unescape(const char *from, char * to)
{ {
if (clientsLock == nil) if (clientsLock == nil)
{ {
urlAlign = objc_alignof_type(@encode(parsedURL));
clientsLock = [NSLock new]; clientsLock = [NSLock new];
} }
} }
@ -637,7 +640,7 @@ static void unescape(const char *from, char * to)
BOOL usesQueries = YES; BOOL usesQueries = YES;
BOOL canBeGeneric = YES; BOOL canBeGeneric = YES;
size += sizeof(parsedURL) + __alignof__(parsedURL) + 1; size += sizeof(parsedURL) + urlAlign + 1;
buf = _data = (parsedURL*)NSZoneMalloc(GSAtomicMallocZone(), size); buf = _data = (parsedURL*)NSZoneMalloc(GSAtomicMallocZone(), size);
memset(buf, '\0', size); memset(buf, '\0', size);
start = end = ptr = (char*)&buf[1]; start = end = ptr = (char*)&buf[1];