• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Ugly bug in Foundation, beware!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Ugly bug in Foundation, beware!
      • From: Graham J Lee <email@hidden>
References: 
 >Ugly bug in Foundation, beware! (From: Ondra Cada <email@hidden>)
 >Re: Ugly bug in Foundation, beware! (From: Clark Cox <email@hidden>)

  • Prev by Date: Re: Scrollview sizing/positioning questions
  • Next by Date: Re: Scrollview sizing/positioning questions
  • Previous by thread: Re: Ugly bug in Foundation, beware!
  • Next by thread: Re: Ugly bug in Foundation, beware!
  • Index(es):
    • Date
    • Thread