Explicitly use 'int' to read/write NSStringEncoding so that

it works for all versions of GCC


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31784 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Nicola Pero 2010-12-27 11:28:01 +00:00
parent b6f476a7eb
commit 171884ce1c
3 changed files with 26 additions and 6 deletions

View file

@ -1,3 +1,16 @@
2010-12-27 Nicola Pero <nicola.pero@meta-innovation.com>
* Source/GSString.m ([GSCString -encodeWithCoder:]): Explicitly
encode NSStringEncoding variables as 'int' so that we can
read/write archives across compiler versions. "enum
_NSStringEncoding" is an unsigned int, but GCC <= 4.5 incorrectly
encodes all enums, regardless of the actual integer type they
represent, as a signed int.
([GSMutableString -encodeWithCoder:]): Same change.
([GSUnicodeString -encodeWithCoder:]): Same change.
* Source/NSString.m ([NSString -encodeWithCoder:]): Same change.
([NSString -initWithCoder:]): Same change.
2010-12-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSPrivate.h:

View file

@ -3144,7 +3144,7 @@ transmute(GSStr self, NSString *aString)
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &_count];
if (_count > 0)
{
[aCoder encodeValueOfObjCType: @encode(NSStringEncoding)
[aCoder encodeValueOfObjCType: @encode(int)
at: &internalEncoding];
[aCoder encodeArrayOfObjCType: @encode(unsigned char)
count: _count
@ -3461,7 +3461,7 @@ agree, create a new GSCInlineString otherwise.
{
NSStringEncoding enc = NSUnicodeStringEncoding;
[aCoder encodeValueOfObjCType: @encode(NSStringEncoding) at: &enc];
[aCoder encodeValueOfObjCType: @encode(int) at: &enc];
[aCoder encodeArrayOfObjCType: @encode(unichar)
count: _count
at: _contents.u];
@ -3920,14 +3920,14 @@ NSAssert(_flags.owned == 1 && _zone != 0, NSInternalInconsistencyException);
{
NSStringEncoding enc = NSUnicodeStringEncoding;
[aCoder encodeValueOfObjCType: @encode(NSStringEncoding) at: &enc];
[aCoder encodeValueOfObjCType: @encode(int) at: &enc];
[aCoder encodeArrayOfObjCType: @encode(unichar)
count: _count
at: _contents.u];
}
else
{
[aCoder encodeValueOfObjCType: @encode(NSStringEncoding)
[aCoder encodeValueOfObjCType: @encode(int)
at: &internalEncoding];
[aCoder encodeArrayOfObjCType: @encode(unsigned char)
count: _count

View file

@ -4835,7 +4835,14 @@ static NSFileManager *fm = nil;
NSStringEncoding enc = NSUnicodeStringEncoding;
unichar *chars;
[aCoder encodeValueOfObjCType: @encode(NSStringEncoding) at: &enc];
/* For backwards-compatibility, we always encode/decode
'NSStringEncoding' (which really is an 'unsigned int') as
an 'int'. Due to a bug, GCC up to 4.5 always encode all
enums as 'i' (int) regardless of the actual integer type
required to store them; we need to be able to read/write
archives compatible with GCC <= 4.5 so we explictly use
'int' to read/write these variables. */
[aCoder encodeValueOfObjCType: @encode(int) at: &enc];
chars = NSZoneMalloc(NSDefaultMallocZone(), count*sizeof(unichar));
[self getCharacters: chars range: ((NSRange){0, count})];
@ -4877,7 +4884,7 @@ static NSFileManager *fm = nil;
NSStringEncoding enc;
NSZone *zone;
[aCoder decodeValueOfObjCType: @encode(NSStringEncoding) at: &enc];
[aCoder decodeValueOfObjCType: @encode(int) at: &enc];
#if GS_WITH_GC
zone = GSAtomicMallocZone();
#else