mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Minor fix for strings initialised with data they don't own ... consistent
with MacOS-X implementation. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18019 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a9fc62765c
commit
eab1a62b9f
3 changed files with 62 additions and 9 deletions
|
@ -1,3 +1,10 @@
|
|||
Sat Nov 01 11:10:00 2003 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSString.m: ([-copyWithZone:]) always do true copy
|
||||
* Source/GSString.m: Where the string data pointed to is not
|
||||
owned by the string instance, have copy operations create new
|
||||
instances rather than retaining the receiver.
|
||||
|
||||
Sat Nov 01 07:05:00 2003 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSNotificationCenter.m: Simplify locking code as original
|
||||
|
|
|
@ -1955,7 +1955,8 @@ transmute(ivars self, NSString *aString)
|
|||
|
||||
- (id) copy
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, NSDefaultMallocZone()) == NO)
|
||||
if (_flags.free == NO
|
||||
|| NSShouldRetainWithZone(self, NSDefaultMallocZone()) == NO)
|
||||
{
|
||||
GSCString *obj;
|
||||
|
||||
|
@ -1978,7 +1979,8 @@ transmute(ivars self, NSString *aString)
|
|||
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
if (_flags.free == NO
|
||||
|| NSShouldRetainWithZone(self, z) == NO)
|
||||
{
|
||||
NSString *obj;
|
||||
|
||||
|
@ -2195,6 +2197,25 @@ transmute(ivars self, NSString *aString)
|
|||
_flags.wide = 0;
|
||||
return self;
|
||||
}
|
||||
- (id) copy
|
||||
{
|
||||
return RETAIN(self);
|
||||
}
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
{
|
||||
NSString *obj;
|
||||
|
||||
obj = (NSString*)NSAllocateObject(GSCInlineStringClass, _count, z);
|
||||
obj = [obj initWithCString: _contents.c length: _count];
|
||||
return obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RETAIN(self);
|
||||
}
|
||||
}
|
||||
- (void) dealloc
|
||||
{
|
||||
NSDeallocateObject(self);
|
||||
|
@ -2258,7 +2279,8 @@ transmute(ivars self, NSString *aString)
|
|||
|
||||
- (id) copy
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, NSDefaultMallocZone()) == NO)
|
||||
if (_flags.free == NO
|
||||
|| NSShouldRetainWithZone(self, NSDefaultMallocZone()) == NO)
|
||||
{
|
||||
GSUnicodeString *obj;
|
||||
|
||||
|
@ -2281,7 +2303,8 @@ transmute(ivars self, NSString *aString)
|
|||
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
if (_flags.free == NO
|
||||
|| NSShouldRetainWithZone(self, z) == NO)
|
||||
{
|
||||
NSString *obj;
|
||||
|
||||
|
@ -2504,6 +2527,26 @@ transmute(ivars self, NSString *aString)
|
|||
_flags.wide = 1;
|
||||
return self;
|
||||
}
|
||||
- (id) copy
|
||||
{
|
||||
return RETAIN(self);
|
||||
}
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, z) == NO)
|
||||
{
|
||||
NSString *obj;
|
||||
|
||||
obj = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
|
||||
_count*sizeof(unichar), z);
|
||||
obj = [obj initWithCharacters: _contents.u length: _count];
|
||||
return obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RETAIN(self);
|
||||
}
|
||||
}
|
||||
- (void) dealloc
|
||||
{
|
||||
NSDeallocateObject(self);
|
||||
|
|
|
@ -3848,11 +3848,14 @@ handle_printf_atsign (FILE *stream,
|
|||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
if ([self isKindOfClass: [NSMutableString class]] ||
|
||||
NSShouldRetainWithZone(self, zone) == NO)
|
||||
return [[NSStringClass allocWithZone: zone] initWithString: self];
|
||||
else
|
||||
return RETAIN(self);
|
||||
/*
|
||||
* Default implementation should not simply retain ... the string may
|
||||
* have been initialised with freeWhenDone==NO and not own its
|
||||
* characters ... so the code which created it may destroy the memory
|
||||
* when it has finished with the original string ... leaving the
|
||||
* copy with pointers to invalid data. So, we always copy in full.
|
||||
*/
|
||||
return [[NSStringClass allocWithZone: zone] initWithString: self];
|
||||
}
|
||||
|
||||
- (id) mutableCopyWithZone: (NSZone*)zone
|
||||
|
|
Loading…
Reference in a new issue