From 50a5077519481003498ed59aad64e01f36cd3f39 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 8 Nov 2000 17:22:50 +0000 Subject: [PATCH] Bugfix for substring creation from mutable string git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8069 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/GSString.m | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index f83394260..4352b90ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2000-11-08 Richard Frith-Macdonald + + * Source/GSString.m: ([GSMutableString substringWithRange:]) fix to + initialize inline string classes correctly. + 2000-11-06 Adam Fedor * Documentation: Move tmpl.texi files to texi and update GNUmakefile diff --git a/Source/GSString.m b/Source/GSString.m index eb32ea04b..5fcbcf665 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -1755,6 +1755,15 @@ transmute(ivars self, NSString *aString) * in memory immediately after the object. */ @implementation GSCInlineString +- (id) initWithCStringNoCopy: (char*)chars + length: (unsigned)length + freeWhenDone: (BOOL)flag +{ + RELEASE(self); + [NSException raise: NSInternalInconsistencyException + format: @"Illegal method used to initialise inline string"]; + return nil; +} - (id) initWithCString: (const char*)chars length: (unsigned)length { if (_contents.c != 0) @@ -1844,7 +1853,7 @@ transmute(ivars self, NSString *aString) NSString *obj; obj = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass, - _count*2, z); + _count*sizeof(unichar), z); obj = [obj initWithCharacters: _contents.u length: _count]; return obj; } @@ -2031,6 +2040,15 @@ transmute(ivars self, NSString *aString) @implementation GSUnicodeInlineString +- (id) initWithCharactersNoCopy: (unichar*)chars + length: (unsigned)length + freeWhenDone: (BOOL)flag +{ + RELEASE(self); + [NSException raise: NSInternalInconsistencyException + format: @"Illegal method used to initialise inline string"]; + return nil; +} - (id) initWithCharacters: (const unichar*)chars length: (unsigned)length { if (_contents.u != 0) @@ -2039,7 +2057,7 @@ transmute(ivars self, NSString *aString) format: @"re-initialisation of string"]; } _count = length; - _contents.u = (unichar*)&self[1]; + _contents.u = (unichar*)&((GSUnicodeInlineString*)self)[1]; if (_count > 0) memcpy(_contents.u, chars, length*sizeof(unichar)); _flags.wide = 1; @@ -2620,17 +2638,15 @@ transmute(ivars self, NSString *aString) { sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass, _count*sizeof(unichar), NSDefaultMallocZone()); - sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location - length: aRange.length - freeWhenDone: NO]; + sub = [sub initWithCharacters: self->_contents.u + aRange.location + length: aRange.length]; } else { sub = (NSString*)NSAllocateObject(GSCInlineStringClass, _count, NSDefaultMallocZone()); - sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location - length: aRange.length - freeWhenDone: NO]; + sub = [sub initWithCString: self->_contents.c + aRange.location + length: aRange.length]; } AUTORELEASE(sub); return sub; @@ -2646,17 +2662,15 @@ transmute(ivars self, NSString *aString) { sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass, _count*sizeof(unichar), NSDefaultMallocZone()); - sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location - length: aRange.length - freeWhenDone: NO]; + sub = [sub initWithCharacters: self->_contents.u + aRange.location + length: aRange.length]; } else { sub = (NSString*)NSAllocateObject(GSCInlineStringClass, _count, NSDefaultMallocZone()); - sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location - length: aRange.length - freeWhenDone: NO]; + sub = [sub initWithCString: self->_contents.c + aRange.location + length: aRange.length]; } AUTORELEASE(sub); return sub;