• 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: Bug in CF/NSString's no-copy constructors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in CF/NSString's no-copy constructors


  • Subject: Re: Bug in CF/NSString's no-copy constructors
  • From: Michael Tsai <email@hidden>
  • Date: Wed, 6 Feb 2008 13:29:58 -0500

On Feb 6, 2008, at 12:46 PM, Alastair Houghton wrote:

I don't think this is a bug. The NSString and CFString APIs do not indicate that they treat the bytes as scanned memory.

That's true, but it doesn't matter whether they treat the bytes as scanned memory or not; that would only change whether putting pointer data in the bytes was safe. The problem is whether the pointer itself is being traced, which isn't happening right now

Sorry, that's what I meant.

the docs *do* say (in the Garbage Collection Programming Guide) that NULL, kCFAllocatorDefault and kCFAllocatorSystemDefault cause objects to be allocated in the GC zone, so I don't think it's unreasonable to expect that the pointer will be traced.

The string was allocated using kCFAllocatorDefault, but the deallocator was specified as kCFAllocatorNull. The docs say:


"If the buffer does not need to be deallocated, or if you want to assume responsibility for deallocating the buffer (and not have the CFString object deallocate it), pass kCFAllocatorNull."

If CFString is not going to be responsible for deallocating the buffer, then it would not make sense to rely on CFString keeping the buffer alive for you.

I just think that there's no harm in making the pointer visible to the collector; it doesn't hurt if the pointer isn't pointing into the GC pool.

I'm not saying there would be harm; I'm just saying that the API doesn't say that it traces the pointer, so it's not a bug if it doesn't. In the absence of a general guideline or an explicit promise, passing a buffer to a CF call is just like passing it to, say, a sqlite3 call.


--Michael


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Bug in CF/NSString's no-copy constructors
      • From: John Engelhart <email@hidden>
References: 
 >Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: John Engelhart <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: Alastair Houghton <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: John Engelhart <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: Alastair Houghton <email@hidden>)
 >Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful (From: John Engelhart <email@hidden>)
 >Bug in CF/NSString's no-copy constructors (was Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful) (From: Alastair Houghton <email@hidden>)
 >Re: Bug in CF/NSString's no-copy constructors (was Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful) (From: Michael Tsai <email@hidden>)
 >Re: Bug in CF/NSString's no-copy constructors (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Re: NSOutlineView (bis): How does Cocoa determine a click in a cell can start a drag operation?
  • Next by Date: Re: Use of Mac OS X 10.5 / Leopards Garbage Collection Considered Harmful
  • Previous by thread: Re: Bug in CF/NSString's no-copy constructors
  • Next by thread: Re: Bug in CF/NSString's no-copy constructors
  • Index(es):
    • Date
    • Thread