Re: Ugly bug in Foundation, beware!
Re: Ugly bug in Foundation, beware!
- Subject: Re: Ugly bug in Foundation, beware!
- From: Zach Wily <email@hidden>
- Date: Thu, 3 Jun 2004 07:40:57 -0600
Nowhere in the documentation (that I can find) does it say that
[NSMutableArray -copy] performs a deep copy. Why do you assume that it
does?
(If it were to perform a deep copy, you'd only be able to add objects
to NSMutableArrays that conformed to NSCopying, which I don't think any
of us want.)
zach
On Jun 3, 2004, at 7:05 AM, Ondra Cada wrote:
Hi all,
just bumped into this: mutable arrays do *NOT* deep copy upon receiving
-copy
#import <Foundation/Foundation.h>
int main() {
[NSAutoreleasePool new];
id a=[NSMutableArray arrayWithObject:[NSMutableArray array]],b=[a
copy];
NSLog(@"contents: %x %x",[a lastObject],[b lastObject]);
// this is why it is very very bad
[[a lastObject] addObject:@"this is WAY wrong if seen in b!!!"];
NSLog(@"changed a, my private b is %@",[b description]);
return 0;
}
Didn't check mutable sets, dicts, et cetera, but i'd bet they share
this howler :(((((
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
[demime 0.98b removed an attachment of type
application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.