From 5dd72905c81dd58f00de0498d187afd03fc21b19 Mon Sep 17 00:00:00 2001 From: nicola Date: Mon, 27 Dec 2010 11:28:01 +0000 Subject: [PATCH] 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 --- ChangeLog | 13 +++++++++++++ Source/GSString.m | 8 ++++---- Source/NSString.m | 11 +++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17b541c27..4a542a7f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-12-27 Nicola Pero + + * 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 * Source/GSPrivate.h: diff --git a/Source/GSString.m b/Source/GSString.m index 8b8f2c64a..123425896 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -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 diff --git a/Source/NSString.m b/Source/NSString.m index 33d187e7e..f320e6fa1 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -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