Re: Ugly bug in Foundation, beware!
Re: Ugly bug in Foundation, beware!
- Subject: Re: Ugly bug in Foundation, beware!
- From: Ondra Cada <email@hidden>
- Date: Thu, 3 Jun 2004 16:10:23 +0200
Clark,
On 3.6.2004, at 15:38, Clark Cox wrote:
>
I'm not sure I'd call this a bug.
I am. Just recall what is the raison d'etre of -copy: it gives you a
snapshot of the object as in this moment, which won't change as the
object itself changes. It's why it serves well for dictionary keys,
undo, whatever.
That just *demands* a deep copy. After all, if -[NSMutableArray copy]
is by definition shallow, then we *don't need it at all*, for
-arrayWithArray: would work just as well. The very difference between
methods like -arrayWithArray: and -copy is that copy is (well, *should
be*, triple alas is not) smart enough to give us an immutable
non-shared snapshot.
>
None of the Foundation objects perform deep copies, and I don't think
>
that they ever have.
I am pretty sure all the mutable containers did deep copy originally in
NeXTStep, for the very reason I am pointing out above.
>
If the objects did deep copies by default, one could get into some
>
very hairy situations at edge cases. For example:
[simplified your case]
>
id a = [[NSMutableArray alloc] init];
>
[a addObject: a];
That's another story; the copying code should be smart enough to catch
loops and solve them properly (in this case, naturally, by creating an
immutable array which contains itself; the same would apply for more
complicated sitations).
Incidentally, that does not have to do anything with copying, it's a
general problem: far as I remember, in NeXTStep you could archive
array/dictionary structures with loops, and it worked like a charm.
Last I tried in Cocoa (was 10.1 or 10.2, not 10.3), it just crashed
:((((((
---
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.