Memory alignment fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6880 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-07-06 05:46:12 +00:00
parent da1682bc48
commit 1b2e9c1e38
2 changed files with 32 additions and 3 deletions

View file

@ -1,3 +1,8 @@
2000-07-06 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSTcpPort.m: Add code to cope with machines requiring word
alignment for memory references.
2000-07-05 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/Makefile.postabmle: Create directory for DTDs if needed

View file

@ -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
{