diff --git a/ChangeLog b/ChangeLog index fe41a39fa..5da69d7f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-04-09 Richard Frith-Macdonald + + * 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 * Headers/gnustep/base/Foundation.h: Include GNUstep extensions diff --git a/Source/GSTcpPort.m b/Source/GSTcpPort.m index fa01b69f9..f54fc431e 100644 --- a/Source/GSTcpPort.m +++ b/Source/GSTcpPort.m @@ -1348,10 +1348,17 @@ static Class tcpPortClass; object: nil]; } +#if NEED_WORD_ALIGNMENT +static unsigned wordAlign; +#endif + + (void) initialize { if (self == [GSTcpPort class]) { +#if NEED_WORD_ALIGNMENT + wordAlign = objc_alignof_type(@encode(gsu32)); +#endif tcpPortClass = self; tcpPortMap = NSCreateMapTable(NSIntMapKeyCallBacks, NSNonOwnedPointerMapValueCallBacks, 0); @@ -2117,7 +2124,7 @@ static Class tcpPortClass; * word boundary, so we work with an aligned buffer * and use memcmpy() */ - if ((hLength % __alignof__(gsu32)) != 0) + if ((hLength % wordAlign) != 0) { GSPortItemHeader itemHeader; diff --git a/Source/NSData.m b/Source/NSData.m index 067812652..3676799a9 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -378,10 +378,19 @@ failure: @implementation NSData +#if NEED_WORD_ALIGNMENT +static unsigned gsu16Align; +static unsigned gsu32Align; +#endif + + (void) initialize { if (self == [NSData class]) { +#if NEED_WORD_ALIGNMENT + gsu16Align = objc_alignof_type(@encode(gsu16)); + gsu32Align = objc_alignof_type(@encode(gsu32)); +#endif NSDataAbstract = self; NSMutableDataAbstract = [NSMutableData class]; dataMalloc = [NSDataMalloc class]; @@ -2615,7 +2624,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) *cursor, length]; } #if NEED_WORD_ALIGNMENT - if ((*cursor % __alignof__(gsu16)) != 0) + if ((*cursor % gsu16Align) != 0) memcpy(&x, (bytes + *cursor), 2); else #endif @@ -2635,7 +2644,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) *cursor, length]; } #if NEED_WORD_ALIGNMENT - if ((*cursor % __alignof__(gsu32)) != 0) + if ((*cursor % gsu32Align) != 0) memcpy(&x, (bytes + *cursor), 4); else #endif @@ -3345,7 +3354,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) } *(gsu8*)(bytes + length++) = tag; #if NEED_WORD_ALIGNMENT - if ((length % __alignof__(gsu16)) != 0) + if ((length % gsu16Align) != 0) { x = GSSwapHostI16ToBig(x); memcpy((bytes + length), &x, 2); @@ -3366,7 +3375,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos) } *(gsu8*)(bytes + length++) = tag; #if NEED_WORD_ALIGNMENT - if ((length % __alignof__(gsu32)) != 0) + if ((length % gsu32Align) != 0) { x = GSSwapHostI32ToBig(x); memcpy((bytes + length), &x, 4); diff --git a/Source/NSSerializer.m b/Source/NSSerializer.m index 76b444612..932c82ae1 100644 --- a/Source/NSSerializer.m +++ b/Source/NSSerializer.m @@ -113,6 +113,10 @@ static Class MStringClass = 0; static Class StringClass = 0; static Class NumberClass = 0; +#if NEED_WORD_ALIGNMENT +static unsigned gsu32Align; +#endif + typedef struct { @defs(GSString) } *ivars; @@ -229,7 +233,7 @@ serializeToInfo(id object, _NSSerializerInfo* info) * word boundary, so we work with an aligned buffer * and use memcmpy() */ - if ((dlen % __alignof__(gsu32)) != 0) + if ((dlen % gsu32Align) != 0) { unichar buffer[slen]; [object getCharacters: buffer]; @@ -339,6 +343,9 @@ static BOOL shouldBeCompact = NO; { if (self == [NSSerializer class]) { +#if NEED_WORD_ALIGNMENT + gsu32Align = objc_alignof_type(@encode(gsu32)); +#endif appSel = @selector(appendBytes:length:); datSel = @selector(mutableBytes); lenSel = @selector(length); diff --git a/Source/NSURL.m b/Source/NSURL.m index c6138d5fa..dede21197 100644 --- a/Source/NSURL.m +++ b/Source/NSURL.m @@ -472,6 +472,8 @@ static void unescape(const char *from, char * to) */ @implementation NSURL +static unsigned urlAlign; + /** * Create and return a file URL with the supplied path.
* The value of aPath must be a valid filesystem path.
@@ -486,6 +488,7 @@ static void unescape(const char *from, char * to) { if (clientsLock == nil) { + urlAlign = objc_alignof_type(@encode(parsedURL)); clientsLock = [NSLock new]; } } @@ -637,7 +640,7 @@ static void unescape(const char *from, char * to) BOOL usesQueries = YES; BOOL canBeGeneric = YES; - size += sizeof(parsedURL) + __alignof__(parsedURL) + 1; + size += sizeof(parsedURL) + urlAlign + 1; buf = _data = (parsedURL*)NSZoneMalloc(GSAtomicMallocZone(), size); memset(buf, '\0', size); start = end = ptr = (char*)&buf[1];