From 1b2e9c1e38221f5405e72cfef622f3955923100e Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 6 Jul 2000 05:46:12 +0000 Subject: [PATCH] Memory alignment fix git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6880 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/GSTcpPort.m | 30 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 313f215de..4d8da2408 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2000-07-06 Richard Frith-Macdonald + + * Source/GSTcpPort.m: Add code to cope with machines requiring word + alignment for memory references. + 2000-07-05 Richard Frith-Macdonald * Tools/Makefile.postabmle: Create directory for DTDs if needed diff --git a/Source/GSTcpPort.m b/Source/GSTcpPort.m index 2224bbfc8..153667119 100644 --- a/Source/GSTcpPort.m +++ b/Source/GSTcpPort.m @@ -280,9 +280,10 @@ newDataWithEncodedPort(GSTcpPort *port) if ([addr isEqualToString: @"127.0.0.1"] == YES) { NSArray *a = [[port host] addresses]; + unsigned c = [a count]; unsigned i; - for (i = 0; i < [a count]; i++) + for (i = 0; i < c; i++) { addr = [a objectAtIndex: i]; if ([addr isEqualToString: @"127.0.0.1"] == NO) @@ -1666,13 +1667,36 @@ static Class tcpPortClass; [header setLength: hLength + l + h]; b = [header mutableBytes]; b += hLength; - hLength += l + h; +#if NEED_WORD_ALIGNMENT + /* + * When packing data, an item may not be aligned on a + * word boundary, so we work with an aligned buffer + * and use memcmpy() + */ + if ((*hLength % __alignof__(gsu32)) != 0) + { + GSPortItemHeader itemHeader; + + pih = (GSPortItemHeader*)&itemHeader; + pih->type = GSSwapHostI32ToBig(GSP_DATA); + pih->length = GSSwapHostI32ToBig(l); + memcpy(b, (void*)pih, h); + } + else + { + pih = (GSPortItemHeader*)b; + pih->type = GSSwapHostI32ToBig(GSP_DATA); + pih->length = GSSwapHostI32ToBig(l); + } +#else pih = (GSPortItemHeader*)b; - memcpy(b+h, [o bytes], l); pih->type = GSSwapHostI32ToBig(GSP_DATA); pih->length = GSSwapHostI32ToBig(l); +#endif + memcpy(b+h, [o bytes], l); [components removeObjectAtIndex: i--]; c--; + hLength += l + h; } else {