Re: Deadlock during NSCache flush

2013-10-24 Thread Jens Alfke
On Oct 24, 2013, at 3:37 AM, Maxthon Chan wrote: > Quite difficult as they emulated platform defines well, and I cannot reliably > detect either GNUSTEP or __LINUX__ flags. I can’t believe they don’t offer some kind of flag for detecting that environment. Every other platform API I can think

Re: Deadlock during NSCache flush

2013-10-24 Thread Greg Parker
On Oct 24, 2013, at 3:39 AM, Maxthon Chan wrote: > On Oct 24, 2013, at 18:23, Greg Parker wrote: >> On Oct 24, 2013, at 3:10 AM, Maxthon Chan wrote: >>> Neither is appropriate in my situation: Only one touch-up is needed so >>> converting entire file (even just one method since it is extremely

Re: Deadlock during NSCache flush

2013-10-24 Thread Maxthon Chan
And by the way, why not? It is well documented in LLVM documentations that those functions are required to be identical to the corresponding methods. Are you refusing your own dogfood, Apple? On Oct 24, 2013, at 18:23, Greg Parker wrote: > On Oct 24, 2013, at 3:10 AM, Maxthon Chan wrote: >> N

Re: Deadlock during NSCache flush

2013-10-24 Thread Maxthon Chan
Quite difficult as they emulated platform defines well, and I cannot reliably detect either GNUSTEP or __LINUX__ flags. On Oct 24, 2013, at 18:30, Graham Cox wrote: > > On 24/10/2013, at 12:10 PM, Maxthon Chan wrote: > >> Neither is appropriate in my situation > > > Time for a small bit of

Re: Deadlock during NSCache flush

2013-10-24 Thread Maxthon Chan
That does not work with GNUstep build system. With that system, I can only control ARC status on a per-target basis, and I cannot guarantee the non-existence of CoreFoundation on a GNUstep system. On Oct 24, 2013, at 18:23, Greg Parker wrote: > On Oct 24, 2013, at 3:10 AM, Maxthon Chan wrote:

Re: Deadlock during NSCache flush

2013-10-24 Thread Graham Cox
On 24/10/2013, at 12:10 PM, Maxthon Chan wrote: > Neither is appropriate in my situation Time for a small bit of conditional compilation then? --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or m

Re: Deadlock during NSCache flush

2013-10-24 Thread Greg Parker
On Oct 24, 2013, at 3:10 AM, Maxthon Chan wrote: > Neither is appropriate in my situation: Only one touch-up is needed so > converting entire file (even just one method since it is extremely long) to > MRR is is inappropriate Write a helper function in a separate non-ARC file. Do not call objc

Re: Deadlock during NSCache flush

2013-10-24 Thread Maxthon Chan
Neither is appropriate in my situation: Only one touch-up is needed so converting entire file (even just one method since it is extremely long) to MRR is is inappropriate and I need portability to GNUstep so CoreFoundation (and quite portion of Foundation) have to be avoided. First part of the s

Re: Deadlock during NSCache flush

2013-10-24 Thread Greg Parker
On Oct 23, 2013, at 10:57 PM, Maxthon Chan wrote: > Situation: I am writing a custom decoder that decodes objects from JSON-based > archives. My objects gets released prematurely, hence a manual retain is > asked for. > > I need to make this thing work across multiple platforms (that is, Cocoa

Re: Deadlock during NSCache flush

2013-10-23 Thread Maxthon Chan
Situation: I am writing a custom decoder that decodes objects from JSON-based archives. My objects gets released prematurely, hence a manual retain is asked for. I need to make this thing work across multiple platforms (that is, Cocoa versus GNUstep) but some certain platform does not have the

Re: Deadlock during NSCache flush

2013-10-23 Thread Chris Hanson
What Greg says on this topic is authoritative. -- Chris Sent from my iPad > On Oct 23, 2013, at 4:35 PM, Maxthon Chan wrote: > > There are still situations that you may want a little touch-up so from time > to time a manual call to these is still needed. > >> On Oct 24, 2013, at 2:01, Greg

Re: Deadlock during NSCache flush

2013-10-23 Thread Maxthon Chan
There are still situations that you may want a little touch-up so from time to time a manual call to these is still needed. On Oct 24, 2013, at 2:01, Greg Parker wrote: > On Oct 22, 2013, at 7:33 PM, Maxthon Chan wrote: >> Despite ARC banned retain/release/autorelease functions, there are stil

Re: Deadlock during NSCache flush

2013-10-23 Thread Greg Parker
On Oct 22, 2013, at 7:33 PM, Maxthon Chan wrote: > Despite ARC banned retain/release/autorelease functions, there are still > alternatives there in the form of C functions: > > From CoreFoundation : > CFRetain() = retain > CFRelease() = release > CGBridgingRelease() = autorelease CFBridgingRele

Re: Deadlock during NSCache flush

2013-10-23 Thread Maxthon Chan
I forgot to zero out the variable after cache is handed to the current autorelease pool (after objc_autorelease(objc_retain(_cache));) so it did not work. On Oct 23, 2013, at 16:07, Andreas Grosam wrote: > You may try the following, which is probably a hack: > > In the dealloc method of the D

Re: Deadlock during NSCache flush

2013-10-23 Thread Andreas Grosam
You may try the following, which is probably a hack: In the dealloc method of the Database, do something like this: - (void) dealloc { NSCache* cache = self.cache; dispatch_async(private_queue, ^{ cache = nil; }); } Now, if `cache_remove_with_block` executes on a different thread

Re: Deadlock during NSCache flush

2013-10-22 Thread Maxthon Chan
Despite ARC banned retain/release/autorelease functions, there are still alternatives there in the form of C functions: From CoreFoundation : CFRetain() = retain CFRelease() = release CGBridgingRelease() = autorelease From LLVM’s requirements to runtime for ARC to work, as prototyped in GNUstep’

Re: Deadlock during NSCache flush

2013-10-22 Thread Greg Parker
On Oct 21, 2013, at 10:14 PM, Jens Alfke wrote: > As for autorelease: "This has come up once before for me, and I was able to > work around it by making the cache-owner object call -autorelease instead of > -release on the NSCache, to defer the call to the cache’s dealloc. But I’m > now using A

Re: Deadlock during NSCache flush

2013-10-21 Thread Maxthon Chan
Sent pull request. https://github.com/couchbase/couchbase-lite-ios/pull/165 On Oct 22, 2013, at 13:14, Jens Alfke wrote: > > On Oct 21, 2013, at 8:07 PM, Maxthon Chan wrote: > >> If your app is called Hammersmith, you can retain/autorelease it in your >> [CBLDatabase dealloc] or [CBLCache d

Re: Deadlock during NSCache flush

2013-10-21 Thread Jens Alfke
On Oct 21, 2013, at 8:09 PM, Seth Willits wrote: > What reason is there for the documents to have a strong reference to the > database? The database object has all the core functionality including the underlying data storage engine. The document calls into the database to do the real work li

Re: Deadlock during NSCache flush

2013-10-21 Thread Maxthon Chan
Well you can read GNUstep’s objc-arc.h (in libobjc2) to get some idea on LLVM-defined runtime functions that is required to make ARC work. There are functions objc_retain and objc_autorelease (Using those will not get you rejected - apple cannot tell your manual calls from calls generated by co

Re: Deadlock during NSCache flush

2013-10-21 Thread Jens Alfke
On Oct 21, 2013, at 8:07 PM, Maxthon Chan wrote: > If your app is called Hammersmith, you can retain/autorelease it in your > [CBLDatabase dealloc] or [CBLCache dealloc] It’s not my app, it’s a customer’s that uses my library. But the CBL classes are part of my library, yes. As for autorelea

Re: Deadlock during NSCache flush

2013-10-21 Thread Seth Willits
On Oct 21, 2013, at 12:28 PM, Ken Thomases wrote: > Seems like a cycle to me. … Have the documents hold weak references to the > database. Agreed. What reason is there for the documents to have a strong reference to the database? -- Seth Willits

Re: Deadlock during NSCache flush

2013-10-21 Thread Maxthon Chan
If your app is called Hammersmith, you can retain/autorelease it in your [CBLDatabase dealloc] or [CBLCache dealloc] On Oct 22, 2013, at 11:03, Jens Alfke wrote: > > On Oct 21, 2013, at 7:57 PM, Maxthon Chan wrote: > >> What about the “database” object? Is that yours? If so, can you >> reta

Re: Deadlock during NSCache flush

2013-10-21 Thread Jens Alfke
On Oct 21, 2013, at 7:57 PM, Maxthon Chan wrote: > What about the “database” object? Is that yours? If so, can you > retain/autorelease it (using runtime functions documented by LLVM) when > purging? Let me copy and paste what I said before: "I’m not in control of the cache purge — it seems

Re: Deadlock during NSCache flush

2013-10-21 Thread Maxthon Chan
What about the “database” object? Is that yours? If so, can you retain/autorelease it (using runtime functions documented by LLVM) when purging? On Oct 22, 2013, at 10:53, Jens Alfke wrote: > > On Oct 21, 2013, at 6:57 PM, ChanMaxthon wrote: > >> Can you just manually retain it before cleani

Re: Deadlock during NSCache flush

2013-10-21 Thread Jens Alfke
On Oct 21, 2013, at 6:57 PM, ChanMaxthon wrote: > Can you just manually retain it before cleaning, and manually release it > afterwards? You can use CFRetain()/CFRelease() for that, or use runtime > functions objc_retain() and objc_release(). The latter two is not documented > by Apple per sé

Re: Deadlock during NSCache flush

2013-10-21 Thread ChanMaxthon
Can you just manually retain it before cleaning, and manually release it afterwards? You can use CFRetain()/CFRelease() for that, or use runtime functions objc_retain() and objc_release(). The latter two is not documented by Apple per sé, but it is documented by LLVM as requirements of ARC. Sen

Re: Deadlock during NSCache flush

2013-10-21 Thread Ken Thomases
On Oct 21, 2013, at 2:11 PM, Jens Alfke wrote: > Specifically, there is a “database” object that has a strong reference to an > NSCache which maps to various ‘document’ objects (indexed by key.) The > document objects have strong references back to the database. > > In the situation that hangs,

Deadlock during NSCache flush

2013-10-21 Thread Jens Alfke
I’ve just gotten a nasty bug report involving an iOS app hanging when it goes into the background. The problem is a deadlock involving NSCache. I can see what the problem is, but I don’t know what to do about it. In a nutshell: An NSCache is evicting objects, and as a result of that its last re