Re: 30x faster JSON date parsing

2013-09-09 Thread Dave Keck
> I’m not sure if you meant that ironically, but it’s absolutely not premature. 
> I’ve run into major NSDateFormatter bottlenecks — as in “hm, over half the 
> time to open this file is spent inside NSDateFormatter” — at least twice, and 
> the author of the blog post I linked to says that he also found it to be a 
> major performance issue in data parsing. It also comes up periodically on the 
> CouchDB mailing list in discussions of slow database indexing.

+1

I've encountered a lot of performance issues due to NSDateFormatter,
specifically when used with RestKit and parsing JSON responses.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to use NSManagedObjectContext, NSManagedObjectModel, NSEntityDescription, NSManagedObject

2013-02-15 Thread Dave Keck
> NSManagedObjectContext, NSManagedObjectModel, NSEntityDescription, 
> NSManagedObject
>
> I want to use these classes in my app but I don't want to use it in Core Data.

These classes *are* Core Data; I'm afraid you're not making much sense.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to Cocoa/Objective-c: many points of confusion

2013-02-03 Thread Dave Keck
> *delegates: my understanding is that these take the place of subclasses 
> (though why this is useful is beyond me), overriding methods they are 
> designed to handle rather than letting the base class take those methods. 
> However, I not only don't see why this is so great, but I don't understand 
> the syntax used to declare them or attach them to other classes so the 
> delegates' methods get called when any of those methods are called on the 
> object to which the delegate is attached. Every example I have found seems to 
> indicate they are used only for GUIs, but Apples docs say that they are a 
> much more general-purpose system?

> *Speaking of delegates, I don't follow the syntax used to set them up. Every 
> example seems to love to use views or other UI examples, which would be fine 
> if I could follow that, but I'm not that advanced yet. A more basic, even if 
> not-so-useful-in-reality, example would be very much appreciated.

Delegates are indeed a general-purpose pattern -- there are many
instances of non-GUI classes that use the delegate pattern in the
Foundation framework (note that the Foundation framework doesn't
include any GUI functionality, that's all in the AppKit and UIKit
frameworks.) For example, NSFileManager, NSCache, NSPort, and
NSURLConnection all expose delegate interfaces.

The delegate pattern is simply a callout mechanism, allowing one class
to notify another class of some event. The delegate pattern is
inherently limited in that only one delegate can typically be assigned
to a class, but often that limitation isn't an issue. In contrast to
this limitation, notifications (via NSNotificationCenter) are an
alternative callout mechanism that are useful in cases where a class
might expect more than one client to be interested in an event.

A delegate is always an object, and with modern Objective-C, classes
typically declare a delegate protocol with required and optional
methods for the delegate object to implement. For example,
NSFileManager declares the NSFileManagerDelegate protocol. Now say I
have a class called MyFileDelegate; in the interface for
MyFileDelegate, I declare that it conforms to the
NSFileManagerDelegate protocol:

@interface MyFileDelegate 
@end

Now say I assign an instance of MyFileDelegate to be the delegate of
an instance of NSFileManager, via NSFileManager's -setDelegate:
method. Once that's set up, any time I, for example, move a filesystem
object using that NSFileManager instance, that same MyFileDelegate
instance is notified via the -fileManager:shouldMoveItemAtPath:toPath:
method, which MyFileDelegate implements.

> *Outlets: I have a basic idea that these are a way of sending messages from 
> object to object, a bit like listeners. However, I don't really understand 
> the syntax used to make them. Moreover, I always see them used in GUIs, but 
> Xcode's Interface Builder won't let Voiceover users make connections, so I 
> can't proceed with Apple's tutorials on this topic. Somehow, these 
> connections are outlets, or are related to outlets, or some connections are 
> outlets, or something... Anyway, as I can't make the connections to get an 
> idea of how they work, I'm trying to follow others' examples which I don't 
> get as they use code I didn't write and that makes no sense to my newbie 
> brain. So, what exactly is an outlet and how and why would I set one up? 
> Again, a very basic code example would really help here.

I think you've somewhat misunderstood outlets: outlets are references
to objects created in IB. (These objects are typically UI-related,
such as views and buttons.) Outlets can be either an instance variable
or a property.

Now let's say we have a view controller with an outlet (in the form of
an instance variable) to a button that exists inside the view. The
view controller's interface might look like:

@interface MyViewController : UIViewController
{
IBOutlet UIButton *myButton;
}
@end

If I hook up the outlet correctly in IB, every time I instantiate
MyViewController, its 'myButton' instance variable references the
button that exists in its view.

> *Every so often I'll see a class between less- and greater-than signs when an 
> example talks about a delegate, but I don't know what this is for. What does 
> it mean to put these symbols around a class (or maybe they are around an 
> object?)?

There are two different scenarios in which you'll encounter these
less-than/greater-than signs in Objective-C, and both concern the
protocols feature of Objective-C. The first situation is in class
interfaces, where they're used to declare that whatever class you're
creating conforms to the protocol between the less-than/greater-than
signs. Let's continue with NSFileManager to illustrate: NSFileManager
declares the NSFileManagerDelegate protocol. So let's declare a class
called AppController that conforms to NSFileManagerDelegate; the
syntax looks like:

@interface AppController 
@end

The second situation that you'll encoun

Re: Mysterious crash report

2012-11-14 Thread Dave Keck
> Apparently this occurred when cancelling a document save, though it might 
> have nothing directly to do with that. At the time of the crash, NSToolbar 
> was doing something on the main thread...

Since it was during document save and there's mention of XPC in the
stack trace, I suspect the crash is related to your app's connection
to the Powerbox daemon (and therefore related to the NSSavePanel.)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Self contained command line tool

2012-10-12 Thread Dave Keck
I would create a new Cocoa application using Xcode's template, delete all the 
.m files (except main.m), and put your code in main.m. You should be able to 
delete most of the resources as well, such as MainMenu.xib and 
InfoPlist.strings. Your app will of course not have any interface or menu bar, 
though.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: static void declaration in apple example code

2012-10-12 Thread Dave Keck
> staticvoid *AVSPPlayerItemStatusContext = &AVSPPlayerItemStatusContext;

This declares a unique pointer, whose value is defined as the address in memory 
where the pointer lives.

This technique can be useful when you need a value that's reasonably assured to 
be unique -- i.e., this technique guarantees that the value is unique with 
respect to all other statically- or dynamically- allocated memory in the 
process. (The pedantic caveat being that if some other piece of code chooses to 
use a context pointer that's just a randomly-generated number, there's of 
course a chance of collision.)

I'm unsure whether this is compliant C99, but it's common enough that I would 
expect Clang/LLVM to continue compiling it in the future.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Proper KVO with NSTreeController + NSOutlineView

2012-09-28 Thread Dave Keck
> I'd like to observe a notification when a user edits (renames) an item in the 
> outline view that tells me the old and new values. I'm getting notifications, 
> but the old and new values are always null. For what it's worth, I'm 
> currently observing the "content.name" key path of the NSTreeController 
> instance - not sure if that makes a difference.

Sounds suspiciously similar to the NSArrayController bug where it
doesn't honor the NSKeyValueObservingOption{Old|New} KVO options.
There are quite a few references to this around the web, e.g.:


http://www.cocoabuilder.com/archive/cocoa/215277-nsarraycontroller-selectedindexes.html

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Is QuickLook implemented upon CGImage or CGImageSource under the hood?

2012-09-07 Thread Dave Keck
In my experience I've found that QLThumbnailImageCreate()
significantly outperforms CGImageSourceCreateThumbnailAtIndex(). I
speculate that this is because QLThumbnailImageCreate() talks to a
daemon process that keeps thumbnails cached in memory even after your
process exits, rather than re-creating thumbnails from disk upon each
request.

Consider using the 'purge' command between your tests to get more
authentic benchmarks, and perhaps killing the Quick Look daemon.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSView -backingAlignedRect:

2012-08-24 Thread Dave Keck
Regarding the NSRect returned from -backingAlignedRect:options:, the
NSView documentation states:

The rectangle is in window coordinates.

Is this a documentation error? I would expect the returned rect to be
in local view coordinates.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: 10.8 copiesOnScroll, -setNeedsDisplayInRect: ignored during scrolling

2012-08-06 Thread Dave Keck
> But Mike is still right; you're probably better served by using 
> -performSelectorOnMainThread::: rather than waking the run loop up yourself.

I tend to disagree -- invoking CFRunLoopPerformBlock() and
CFRunLoopWakeUp() is likely more performant since they're at the CF
level (which -performSelectorOnMainThread eventually calls into), and
a block-based API is more convenient. Furthermore,
-performSelectorOnMainThread: wakes up the target run loop anyway by
invoking CFRunLoopWakeUp().

> Given that it's a private mode, I'm not sure you really want your code 
> executing during the scroll event coalescing mode.

Agreed -- I wasn't using nor advocating NSScrollEventCoallescing.
(Also note that calling CFRunLoopWakeUp() on the main thread while
it's running in the NSScrollEventCoallescing mode won't cause it to
execute the block passed to CFRunLoopPerformBlock(...,
kCFRunLoopDefaultMode, ...) until the run loop is again running in the
default mode.)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: 10.8 copiesOnScroll, -setNeedsDisplayInRect: ignored during scrolling

2012-08-06 Thread Dave Keck
> Right, so what you actually want to do is change how you’re messaging the 
> main thread. Use something like 
> -performSelectorOnMainThread:withObject:waitUntilDone:modes: so you can 
> specify NSDefaultRunLoopMode and NSScrollEventCoallescing.

NSScrollEventCoallescing is a private run loop mode so I'd avoid using
it since the Cocoa machinery is completely within its rights to assume
that no outside sources/timers/observers fire in that mode. (Just
wanted to mention it since I've been bitten by related issues before.)

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: 10.8 copiesOnScroll, -setNeedsDisplayInRect: ignored during scrolling

2012-08-04 Thread Dave Keck
> I'm unsure of the wisdom of this approach. Presumably the scroll view is 
> intentionally blocking the runloop, and thus assuming that the runloop will 
> not fire its event sources until after the scrolling is complete. By waking 
> up the runloop, you're violating that assumption and could be causing work 
> the scrollview has enqueued to be performed sooner than expected.

During a single scrolling maneuver in 10.8.0, the run loop toggles
many times between NSDefaultRunLoopMode and NSScrollEventCoallescing.
I suppose I could check whether the main run loop is in the default
mode before waking it up, but the overheard of that likely defeats the
purpose, especially considering the inherent race condition. In the
end, waking the main thread up at the wrong time (while it's in
NSScrollEventCoallescing) probably wastes a mach_msg_send, a
mach_msg_receive, and 20 instructions as the scrolling machinery sees
that there's no new event and goes back to sleep or times-out and
returns to the NSApplication loop.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: 10.8 copiesOnScroll, -setNeedsDisplayInRect: ignored during scrolling

2012-08-04 Thread Dave Keck
Hi Quincey,

> For the latter, it seems hardly surprising that the content wouldn't appear
> until you stop scrolling, since by setting the copy-on-scroll flag you've
> promised that the old view contents don't change during scrolling.

The docs don't say one way or another, but on both 10.7 and 10.8,
setNeedsDisplayInRect: is respected during scrolling when
copy-on-scroll is enabled -- that is, invalidated regions are redrawn
even if the regions were part of the copied region.

I'm afraid I sent my question before doing my due diligence though, so
in the interest of the archives: the reason the invalidated regions
weren't being redrawn during scrolling was because the block that
calls -setNeedsDisplayInRect: was scheduled to execute on the main
thread via dispatch_async(). Due to a change in either NSScrollView,
NSClipView, or CFRunLoop in 10.8, these blocks are only executed after
scrolling has stopped. Instead of dispatch_async(), one can use
CFRunLoopPerformBlock() along with CFRunLoopWakeUp() to have the block
executed on the main thread during scrolling.

Thanks for your suggestions Quincey,
David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


10.8 copiesOnScroll, -setNeedsDisplayInRect: ignored during scrolling

2012-08-04 Thread Dave Keck
I'm working on a scrollable grid view and noticed that its appearance
during scrolling has regressed since installing 10.8.

This grid view loads content in the background and calls
-setNeedsDisplayInRect: (thread-safely) as content becomes available.

With copy-on-scroll enabled, -setNeedsDisplayInRect: seems to be
ignored until scrolling stops, at which point the content snaps in.
With copy-on-scroll disabled, the view displays normally, but is less
performant than the copy-on-scroll version running on 10.7.

Is there a way to have these setNeedsDisplayInRect: calls respected
during scrolling?

Thanks for any guidance!
David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


-layout not called after invoking -setNeedsLayout:YES

2012-07-10 Thread Dave Keck
I'm overriding NSView's -layout method to arrange a grid of subviews.

I call [gridView setNeedsLayout: YES] when a new subview is added,
which usually results in -layout being called on gridView, but
intermittently -layout is not called (resulting in incorrect subview
positioning.) In contrast, I also call [gridView
setNeedsUpdateConstraints: YES], which always results in
-updateConstraints being called.

I've verified that nothing is calling [gridView setNeedsLayout: NO] by
overriding that method.

What would prevent -layout from being called?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ARC and CFType release callback

2012-06-19 Thread Dave Keck
> Once you have a CFTypeRef via CFBridgingRetain(), ARC doesn't care what you 
> do with it. Convert it to and from uintptr_t, pass it through a void*, send 
> it around via IPC, whatever.

That makes sense. I'm also looking for a pattern similar to this RR
code, so that I can leave out explicit CFReleases:

CGPatternRef pattern = [(id)CGPatternCreate(...) autorelease];
CGColorRef color = [(id)CGColorCreateWithPattern(...) autorelease];

Is this pattern possible in ARC? I know I could use something like this:

id pattern = CFBridgingRelease(CGPatternCreate(...));
id color = CFBridgingRelease(CGColorCreateWithPattern(...));

But losing the variable type information isn't worth using ARC. I
figured I could make a special function:

static void *MyCFAutorelease(CFTypeRef object)
{
return (__bridge void *)CFBridgingRelease(object);
}

and use code that looks like:

CGPatternRef pattern = MyCFAutorelease(CGPatternCreate(...));
CGColorRef color = MyCFAutorelease(CGColorCreateWithPattern(...));

But this code isn't safe under ARC is it? I would think that since
they're CFTypes, they're invisible to ARC and can be deallocated
early.

Thanks!

David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ARC and CFType release callback

2012-06-19 Thread Dave Keck
>    Clean up the void* context with CFRelease(context) or (ObjectType 
> *)CFBridgingRelease(context)

I see -- I was under the impression that CFBridgingRetain/Release was
meant for converting to/from CFTypes rather than arbitrary pointers,
but it works as expected.

Thanks!

David

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

ARC and CFType release callback

2012-06-19 Thread Dave Keck
I have a CFType (specifically a CGPattern) that uses a release
callback to free resources, and the void* pointer passed to the
callback is the object to be released.

What's the correct way to release this void* pointer (that's really an
NSObject subclass) under ARC? Casting it using __bridge_transfer
doesn't seem right since the resulting expression is unused, and the
compiler of course warns of this fact.

Thanks,

David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: OSAtomic built-in operations

2012-05-06 Thread Dave Keck
>>    union {
>>        int32_t s;
>>        uint32_t u;
>>    } atomicvar;
>>    atomicvar.u = 0;
>>    OSAtomicCompareAndSwap32(0, 1, &atomicvar.s);
>>    OSAtomicOr32Orig(0, &atomicvar.u);
>
> I've seen this technique in other places. Why is that better than just 
> casting pointer types? Like this:
>
> int32_t         s;
> uint32_t        u;
>
> u = *(uint32_t*) &s;

Indeed -- and my understanding is C only guarantees that the most
recently-assigned member of a union to be valid. So if the OP is
worried about correctness, it would seem the union approach doesn't
help.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to throttle rate of NSInputStream?

2012-03-26 Thread Dave Keck
> [[NSRunLoop currentRunLoop] runUntilDate:[NSDate date]];

Running the runloop recursively in the default mode is almost always a
bad idea; doing so triggers callouts that parent stack frames almost
certainly weren't designed to handle when they occur from within the
method you're writing. It's very much analogous to the issues that
arise in multithreading: just as threaded code must ensure critical
sections are executed atomically, other code must ensure that within
certain critical sections, timers won't fire, notifications won't be
posted, and run loop sources and observers won't be handled.

A concrete example: legacy versions of IOBluetoothDevice used to run
the run loop (in the default mode) within its -isConnected getter,
with the idea that it would refresh its connected flag with the most
up-to-date state before returning it. The result is that when client
code calls -isConnected, timers are fired, distributed notifications
are posted, etc., all within -isConnected! There are a million ways
this could wreak havoc, but suppose we have this code:

  - (void)doSomething
  {
_timeoutTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1 ...
selector: @selector(cleanup)];
if (![bluetoothDevice isConnected])
  [self cleanup];
  }

  - (void)cleanup
  {
[_timeoutTimer invalidate];
  }

Suppose two things: -isConnected takes long enough that _timeoutTimer
fires within its stack frame, and -isConnected returns NO. In this
case, the -cleanup method is called twice (once from within
-isConnected, and once from within -doSomething), which is clearly
unexpected behavior. Perhaps this example seems unrealistic, but in
any code that makes serious use of timers, distributed notifications,
run loop sources or run loop observes, the assumption that the run
loop won't be run recursively in the default mode is everywhere.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Unclear on -initWithBytesNoCopy:

2012-03-03 Thread Dave Keck
Hit send too soon...

> The documentation of -[NSData initWithBytesNoCopy:length:freeWhenDone:] and 
> of -[NSString initWithBytesNoCopy:length:encoding:freeWhenDone:] is unclear 
> about the case where freeWhenDone is NO. The data/string object then does not 
> take ownership of the memory buffer, so the question is: How long is the 
> caller obligated to keep the buffer intact?
>
> The two possible answers seem to be
> (a) until the caller releases the NSString object, or
> (b) forever, until the process exits (i.e. only ever use this on constant 
> buffers)
>
> I’ve been using assumption (a). Obviously I avoid storing references to the 
> string elsewhere. But as I said, the docs don’t say one way or the other, and 
> I just got burned when porting some code to GNUstep (an open-source 
> re-implementation of Cocoa), because they interpreted it according to (b). 
> Here’s a simple test case:

I hadn't thought about this problem before, but it suggests to me that
one should avoid using freeWhenDone == NO. Since supplying a
string/data object to any method or function could potentially retain
(or retain+autorelease) it, it would be exceedingly easy to create a
string/data object that has an invalid underlying buffer, thus calling
any method on this string/data object would result in a crash.

I suppose this scenario reinforces that if your method is passed a
NSString/NSData object and you need to keep it around longer than the
current stack frame, then you must copy the string/data object. I
suspect many methods don't do this though (including my own, I prefer
the caller to ensure that the string remains intact), which is why I
would avoid using freeWhenDone == NO unless a buffer is guaranteed to
last the entire process.

> Here’s the conundrum. On OS X and iOS, substr is still equal to @“HAZ”, as I 
> expected. On GNUstep it’s equal to @“***”! Why? Because GNUstep implements 
> -substringWithRange: by creating a string that points directly into the 
> parent string’s character buffer. Yes, it only does this if the parent string 
> is immutable, and the substring retains the parent string. But this means 
> that, from my perspective, my temporary buffer is now unexpectedly being used 
> by a different object whose lifespan is greater than it.
>
> I filed a bug report* saying that this substring optimization shouldn’t be 
> used if the source string uses an external buffer, just as it shouldn’t if 
> the source string is mutable. They fixed it, but some people there argue that 
> their original implementation was correct (even if not compatible with 
> Apple’s.) I’m curious, so I’m asking here to see if anyone knows for sure 
> what’s intended.
>

I agree with your suggested implementation, because if I were to write
a method that calls -substringWithRange: on a string parameter passed
to me, I would never expect that substring to become invalid until my
method or its counterparts explicitly release it. That an outsider can
affect the contents of a string created with -substringWithRange:
seems like a bug to me.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Unclear on -initWithBytesNoCopy:

2012-03-03 Thread Dave Keck
> The documentation of -[NSData initWithBytesNoCopy:length:freeWhenDone:] and 
> of -[NSString initWithBytesNoCopy:length:encoding:freeWhenDone:] is unclear 
> about the case where freeWhenDone is NO. The data/string object then does not 
> take ownership of the memory buffer, so the question is: How long is the 
> caller obligated to keep the buffer intact?
>
> The two possible answers seem to be
> (a) until the caller releases the NSString object, or
> (b) forever, until the process exits (i.e. only ever use this on constant 
> buffers)

The buffer needs to remain intact until the NSString/NSData object is
deallocated.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Xcode - An Apple Embarrassment

2012-03-01 Thread Dave Keck
> *No*. I've said it before (right here) and I'll say it again; this is *not* 
> jumping to the documentation, and it is *not* doing what Xcode 3 did. It 
> switches to the documentation window and it enters the double-clicked word 
> into the search field, and it does the search, but it doesn't display the 
> actual documentation on the double-clicked word.

I just finished writing an Xcode plugin that makes option-clicking a
symbol jump to the appropriate documentation like it used to. Check
out 'Xcode 4 fixins' if you're interested.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: My runloop-based async code breaks with GCD

2012-02-17 Thread Dave Keck
The root of your problem seems to be your assumption that GCD runs the run loop.

NSURLConnection case: the delegate methods aren't called because
NSURLConnection machinery requires the run loop to be run, which GCD
isn't going to do for you. (Calling -setDelegateQueue: fixes this
because NSURLConnection presumably has a secondary operating manner
that uses an NSOperationQueue instead of a run loop).

Perform selector case: likewise, this doesn't work when called from a
queue because GCD isn't going to handle running the run loop for you.

The run loop is run by something calling CFRunLoopRunInMode(). On the
main thread, this is typically handled for you by AppKit (specifically
by NSApplication's -nextEventMatchingMask:). On secondary threads, you
must manually invoke CFRunLoopRunInMode() to allow anything relying on
the run loop to work correctly. (NSURLConnection uses run loop sources
to work in the non-NSOperationQueue case, and -performSelector uses a
timer.)

In short, dispatch queues are a lower-level abstraction to the run
loop, and won't run the run loop for you.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to get the dispatch queue for the current thread's runloop?

2012-01-27 Thread Dave Keck
Hi Jens,

My understanding is that dispatch queues are tied to threads that are
managed by the system and are separate from run loops. It's therefore
non-sensical to ask for a runloop's queue.

Regardless though, I think a better solution for you is a category on
NSTimer. I use something like the following:


@implementation NSTimer (BlockTimersYay)
+ (NSTimer *)scheduledTimerWithTimeInterval:
(NSTimeInterval)timeInterval repeats: (BOOL)repeats block: (void
(^)(void))block
{
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:
timeInterval target: self selector: @selector(fireBlockTimer:)
userInfo: [[block copy] autorelease] repeats: repeats];
[[NSRunLoop currentRunLoop] addTimer: timer forMode: NSRunLoopCommonModes];
return timer;
}
+ (void)fireBlockTimer: (NSTimer *)blockTimer
{
((void (^)(void))[blockTimer userInfo])();
}
@end


Note that this is slightly different than NSTimer in that the timer is
added to the common modes rather than the default mode.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: afterDelay not working?

2012-01-26 Thread Dave Keck
I imagine your run loop isn't being allowed to run in the default mode
(NSDefaultRunLoopMode). I'd check this by pausing your program at the
time that you would expect -endFlash  to be called; your stack trace
will might indicate that the run loop's being run recursively.

Perhaps this occurring while the user's dragging something around in your view?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CFRunLoopObserver causes crash on NSView drag.

2011-10-22 Thread Dave Keck
I only glanced over the details of your problem, so forgive me if this is way 
off.

I solved the memory ballooning issue in a background app by posting an 
"NSApplicationDefined" NSEvent (with zeros for all the arguments), which causes 
the NSApplication loop to return from -nextEventMatchingMask and pop the 
autorelease pool. In your case, you could post this event after processing a 
batch of files before your process goes back to sleep.

On Oct 22, 2011, at 9:53 AM, "Mr. Gecko"  wrote:

> Hello, I have a problem with 10.7 where when you drag files to a view which 
> accepts files, it'll crash because of a leak of some sort. This is triggered 
> by my CFRunLoopObserver which I've written because operations which is done 
> in the background never had the autorelease pool drained until the UI was 
> brought up and my application's UI was hardly ever brought up.
> 
> Let me explain the setup. First is my run loop observer.
> 
> static NSAutoreleasePool *pool = nil;
> 
> void runloop(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void 
> *info) {
>if (activity & kCFRunLoopEntry) {
>if (pool!=nil) [pool drain];
>pool = [NSAutoreleasePool new];
>} else if (activity & kCFRunLoopExit) {
>[pool drain];
>pool = nil;
>}
> }
> 
> CFRunLoopObserverContext  context = {0, self, NULL, NULL, NULL};
> CFRunLoopObserverRef observer = CFRunLoopObserverCreate(kCFAllocatorDefault, 
> kCFRunLoopEntry | kCFRunLoopExit, YES, 0, runloop, &context);
> CFRunLoopAddObserver(CFRunLoopGetCurrent(), observer, kCFRunLoopDefaultMode);
> 
> This is what I used to get around the memory never being released while the 
> UI was not shown. Because my application deals in files and has watchers for 
> files, whenever a watcher found a file and read it, that file would stay in 
> the ram until you bought up the UI. I know I could of added my own 
> NSAutoReleasePool for that part, but that also means other parts of my code 
> will have to add that as well as well as some notifications which was way 
> more work/code than wanted.
> 
> Now my NSView is in a NSStatusItem which will be used for when someone drags 
> to that menu in the menubar, it'll allow them to drop the file and have the 
> file be uploaded. My NSView registers for files with the following line.
> 
> [self registerForDraggedTypes:[NSArray 
> arrayWithObject:NSFilenamesPboardType]];
> 
> Even if I just do that and do not listen for drag operations, it'll crash 
> because of my loop observer creating and draining that autorelease pool. All 
> I can say is that all of this was working in 10.6 and now is broken in 10.7.
> 
> Here is the crash stack so you can see what I'm talking about.
> Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
> 0   libobjc.A.dylib   0x7fff946d800b (anonymous 
> namespace)::AutoreleasePoolPage::pop(void*) + 385
> 1   com.apple.CoreFoundation  0x7fff92527f75 
> _CFAutoreleasePoolPop + 37
> 2   com.apple.Foundation  0x7fff8ecfa057 
> -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 275
> 3   com.apple.Foundation  0x7fff8ed7dc0a 
> -[NSRunLoop(NSRunLoop) runUntilDate:] + 66
> 4   com.apple.AppKit  0x7fff8e4a2523 
> NSCoreDragTrackingProc + 3477
> 5   com.apple.HIServices  0x7fff94279b0d DoTrackingMessage + 
> 357
> 6   com.apple.HIServices  0x7fff9427b42c 
> CoreDragMessageHandler + 461
> 7   com.apple.CoreFoundation  0x7fff925ebbb9 
> __CFMessagePortPerform + 729
> 8   com.apple.CoreFoundation  0x7fff924f911c 
> __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 44
> 9   com.apple.CoreFoundation  0x7fff924f8e4b __CFRunLoopDoSource1 
> + 155
> 10  com.apple.CoreFoundation  0x7fff9252f587 __CFRunLoopRun + 1895
> 11  com.apple.CoreFoundation  0x7fff9252eae6 CFRunLoopRunSpecific 
> + 230
> 12  com.apple.HIToolbox   0x7fff9843c3d3 
> RunCurrentEventLoopInMode + 277
> 13  com.apple.HIToolbox   0x7fff9844363d 
> ReceiveNextEventCommon + 355
> 14  com.apple.HIToolbox   0x7fff984434ca 
> BlockUntilNextEventMatchingListInMode + 62
> 15  com.apple.AppKit  0x7fff8e0ca3f1 _DPSNextEvent + 659
> 16  com.apple.AppKit  0x7fff8e0c9cf5 -[NSApplication 
> nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
> 17  com.apple.AppKit  0x7fff8e0c662d -[NSApplication run] 
> + 470
> 18  com.apple.AppKit  0x7fff8e34580c NSApplicationMain + 
> 867
> 
> Some of my options are:
> 1. Forget about the memory usage and remove my runloop observer.
> 2. Find a new way to prevent this memory issue from happening.
> 3. Have apple fix Lion.
> 4. Do whatever you suggest I do.
> 
> If you can think of how I can fix this issue, please let me know. If you need 
> a test subject, I am willing to point you to my source 
> code.__

Re: CALayer memory management [was: Tracking down CALayer problem in iTunes plug-in]

2011-08-01 Thread Dave Keck
> I've narrowed this error down to a very simple test case.

Could you post you test case?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSMapTable on iOS?

2011-07-08 Thread Dave Keck
> Kind of surprised to discover that NSMapTable doesn’t exist on iOS (even the 
> older procedural form of the API). I need a non-retaining dictionary — do I 
> need to drop down to CFDictionary or is there some higher-level alternative?

I was surprised by this too, but found the CFDictionary alternative palatable:

// weak opaque-pointer keys
// strong object values
NSMutableDictionary *b = (id)CFDictionaryCreateMutable(nil, 0,
nil, &kCFTypeDictionaryValueCallBacks);

// strong object keys
// weak opaque-pointer values
NSMutableDictionary *a = (id)CFDictionaryCreateMutable(nil, 0,
&kCFTypeDictionaryKeyCallBacks, nil);

// weak opaque-pointer keys
// weak opaque-pointer values
NSMutableDictionary *c = (id)CFDictionaryCreateMutable(nil, 0, nil, nil);

Unfortunately the NSMapTable omission means code that's shared between
iOS and OS X can't take advantage of zeroing weak references in the OS
X GC case, but perhaps that's a limited use case.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Dispatch queues and autorelease pools

2011-07-02 Thread Dave Keck
>From 
>http://developer.apple.com/library/mac/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html:

"Although GCD dispatch queues have their own autorelease pools,
they make no guarantees as to when those pools are drained. However,
if your application is memory constrained, creating your own
autorelease pool allows you to free up the memory for autoreleased
objects at more regular intervals."
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: DO independentConversationQueueing, invocation from callback

2011-06-26 Thread Dave Keck
I wrote a small test case that exhibits the problem:

http://pastie.org/2124066

It can be compiled and run like this:

killall -KILL dotest; gcc -framework Foundation dotest.m -o dotest; ./dotest

When independentConversationQueueing is disabled (see EnableICQ()),
ProcessC receives the -doSomething message, but when ICQ is enabled,
it does not.

Radar forthcoming...
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


DO independentConversationQueueing, invocation from callback

2011-06-24 Thread Dave Keck
Hey list,

I use independentConversationQueueing to make my DO invocations block,
but doing so causes incorrect behavior in the following scenario:

  1. ProcessA sends -handleMessage to ProcessB
  2. ProcessB's -handleMessage executes, which sends -doSomething to ProcessC

In Step 2, the DO internals in ProcessB attempt to send a message to
ProcessA instead of ProcessC. (I know this by inspecting the instance
of NSPort that receives the -sendBeforeDate:... message in ProcessB.)
That is, the DO internals appear to be confused about which
NSConnection/NSPort instance to use when attempting to message a third
process (ProcessC) from a DO callback (-handleMessage in ProcessB).
Everything works as expected when independentConversationQueueing is
disabled, but I need my DO invocations to block.

Ideally I'd be able to set a unique reply mode for each NSConnection
instance, which would solve all my problems in a jiffy. Any idea how I
might do so, or how I might fix independentConversationQueueing?

Thanks!

David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Properly comparing file NSURLs for equality?

2011-05-27 Thread Dave Keck
> What is the correct way to test if two NSURLs refer to the same file
> system object?

I would lstat() the file paths and compare their inodes (st_ino) and
residing device inodes (st_dev).
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Seeding random() randomly

2011-05-26 Thread Dave Keck
> I'm using random(), but every time I run my app I get the same sequence, 
> despite having this code in my app delegate's -appDidFinishLaunching method. 
> Clearly I'm not seeding it right, though I can't see why - I get a different 
> value for seed every time. What gives?
>
>
>        unsigned seed = (unsigned)([NSDate timeIntervalSinceReferenceDate] * 
> 1.0);
>
>        NSLog(@"launched, seed = %ld", seed );
>        srandom( seed );

I'm not sure what your problem is, but I believe arc4random() has
superseded random() for a while now.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Is a file open in another application?

2011-03-19 Thread Dave Keck
> Is there a way for me to tell if a particular file is open in another 
> application?

The following thread offers one solution:


http://www.cocoabuilder.com/archive/cocoa/288040-notification-of-file-system-modification-arrives-too-early.html

which might be worth using if proc_listpidspath() is due to become
official API in 10.7. (I believe the Finder has used this interface
since 10.6 to determine whether a disk can be ejected, and if not, it
tells you what app is using it.)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Debugging a sleepless Mac

2011-03-16 Thread Dave Keck
> Apart from user interactions, what other sorts of activity automatically 
> prevent idle sleep?

I seem to recall an issue where a program's logging was preventing
sleep, which I believe was simply due to the file activity. fs_usage
may help there.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: kqueue and kevent

2011-03-13 Thread Dave Keck
> I have used kqueue and kevents for event triggering. However i am not sure
> if it is possible to send events to a kqueue? Googling didnt  helped. I was
> thinking as its "kernel" que and kernel notifies. Does it mean that users
> can not send events
> to a queue other than signals?

The kernel is the only entity that can generate events. You can easily
cause an event to be generated though by, for example, writing to a
pipe for which the respective read end has a EVFILT_READ filter
monitoring it.

BTW, this question is better suited for darwin-dev.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Problem with garbage collection in server application

2011-01-22 Thread Dave Keck
> I worked up a version of our app that uses retain/release style memory 
> management, and was surprised to note that a similar thing was happening 
> (although the memory use did not get as big).  Running a script that would 
> send five sequential processing requests to the server, with a 'close all' at 
> the end, would result in immediate deallocation of all five datasets.  
> However if I put the script commands inside a for loop (scripted to repeat 
> two or more times), then the datasets are not deallocated until the end of 
> all loops.  I put a breakpoint on 'retain' in my dataset objects, and it's 
> clear that they are getting a lot of retains from various observer objects in 
> the user interface used to monitor script execution.  The UI objects must be 
> getting dealloc'ed themselves, as the dataset objects are eventually released.

The autorelease pool is popped after the current iteration of the run
loop exits. If the datasets are autoreleased explicitly by you, or
implicitly by any number of APIs that you call, then indeed the
objects won't be deallocated until the run loop iteration exits. If
you need (more) determinate behavior over your datasets' deallocation,
surrounding your loop with its own autorelease pool is probably the
solution. It doesn't sound like that solution would translate to your
production code, though.

> I noticed that if I put a 'sleep 1' at the bottom of the loop in my shell 
> script, then the dataset objects would indeed be deallocated at the bottom of 
> the loop (not after all loops).  So it might be that all the KVO stuff for 
> the UI is getting cleaned up very late in the run loop, in a process that is 
> interrupted by another message to the NSConnection immediately upon exit.
>
> After seeing this in the retain/release version, I then tried running the GC 
> version with the 'sleep 1' at the bottom of the loop.  Lo and behold, the 
> objects were getting finalized at the bottom of each loop (slightly 
> asynchronously from the main thread, but that's fine).  A number of tests 
> also showed that the GC version ran around 10% faster for long processing 
> runs.
>
> So maybe all this is a symptom of an uncontrolled interaction between the 
> NSConnection I use to run client requests, and the NSRunLoop that is 
> associated with the UI.

I'm sure bbum will correct me where I'm wrong, but my understanding is
that the collector, running in its own thread, can and does perform
its collections asynchronously with respect to other threads. While it
takes hints as to when a collection is necessary (such as when memory
has passed a high-water mark), I've never heard that collections are
timed with respect to any thread's run loop.

> Perhaps I should be looking for some way to force the app to wait until the 
> end of the current runloop before accepting another message on the 
> NSConnection, but I'm not sure how to do that.

Beyond removing strong references to your datasets and verifying that
they're gone (via info gc-roots), I wouldn't put much more effort into
getting GC working as you'll quickly defeat the purpose. On the other
hand, if I understood you correctly in that you're seeing a 10%
speedup when using GC, then perhaps that would warrant the extra
effort. On the other-other-hand, it sounds like you might be
optimizing early.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Problem with garbage collection in server application

2011-01-22 Thread Dave Keck
> I'm pretty sure I'm not leaking the memory with an unintended reference, as 
> the datasets *are* collected (albeit not very quickly) after I run a set of 
> five operations and the server returns to be waiting for user input.  I'm 
> wondering if it could be because collection will not happen until the end of 
> a run loop, and by bombarding the server with messages then collection is 
> never triggered because it never senses the end of the run loop.  I gather 
> that there may be special considerations with runloops and NSConnection.

I would use gdb's "info gc-roots 0x" command to determine what
strong references exist to the objects that are placed in your array.
Instruments may also have some related functionality.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Parental Controls altering binary

2011-01-16 Thread Dave Keck
>From TN2206 
>(http://developer.apple.com/library/mac/#technotes/tn2007/tn2206.html):

The Parental Controls, MCX, and Application Firewall subsystems in
Leopard, when encountering an unsigned program, will ad hoc sign the
program in order to track its identity from launch to launch. This
will usually modify the program on disk, and can happen without
apparent user input, e.g., when the Application Firewall first notices
that your program is trying to accept an inbound network connection.
If your program can be damaged by signing, it is imperative that you
ship a signed version as soon as practical. Programs signed by their
manufacturer are not modified in this way.

Perhaps your preference pane isn't signed?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Troubleshooting CFMessagePort

2011-01-06 Thread Dave Keck
>> Is there any utility to maybe probe the Mach ports that my app has open?  I 
>> can't find anything like that.
>
> top(1) and Activity Monitor can list the number of ports a process has
> open, but I'm not aware of any utilities that go into any more detail.

Oh, `sudo launchctl bstree` might also be useful.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Troubleshooting CFMessagePort

2011-01-06 Thread Dave Keck
I don't see anything obviously wrong with your code after a cursory
glance. I assume you're familiar with the bootstrap context issues
mentioned in TN2083 and elsewhere?

If you can post a complete example that exhibits the problem, I'd be
happy to investigate further. However, consider using NSMachPort
instead of CFMessagePort; you can lose a lot of code in doing so.
Here's an example showing how to set up a client and server using
NSMachPort and NSMachBootstrapServer:

http://pastie.org/1435791

This code would of course work the same if the client and server were
in separate processes, assuming the server port is registered in a
bootstrap context that's visible to the client.

> Is there any utility to maybe probe the Mach ports that my app has open?  I 
> can't find anything like that.

top(1) and Activity Monitor can list the number of ports a process has
open, but I'm not aware of any utilities that go into any more detail.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Context in GCD source cancel handler?

2011-01-05 Thread Dave Keck
> Q: When a context object is set with dispatch_set_context(), is it retained? 
> Or do I need to retain it first, set it, and then in the cancel handler 
> release it?

The 'context' argument is not retained. You can infer this primarily
by the declaration of dispatch_set_context(), and also the mention
that 'context' is "client defined" in dispatch/object.h; since the
'context' argument is an untyped pointer (void *),
dispatch_set_context() cannot assume anything about the supplied
'context' argument, much less that it's a valid libdispatch object.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Synchronizing to screen refresh rate

2010-12-17 Thread Dave Keck
It sounds like CVDisplayLink might be of use? From CVDisplayLink.h:

The main purpose of the CoreVideo DisplayLink API is to provide a
worker thread to the VideoUnit subsystem that is clocked based on the
refresh rate of a CGDirectDisplay device.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: App Will Not Terminate After Uncaught Excpetion

2010-12-16 Thread Dave Keck
> Presumably it is more functionally similar to:

On my system, the exception is being caught from within
-[NSApplication run]. So it would look like the implementation of -run
shown here:

http://cocoawithlove.com/2009/01/demystifying-nsapplication-by.html

with a @try around the calls to -nextEventMatchingMask: and
-sendEvent:, and the @catch block calling -reportException:.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: App Will Not Terminate After Uncaught Excpetion

2010-12-16 Thread Dave Keck
> Look up NSExceptionHandler.

NSExceptionHandler (and NSSetUncaughtExceptionHandler for that matter)
can't help because the exception is being caught by AppKit.
Furthermore, the NSApplication subclass technique mentioned earlier
won't work in all cases either, since some AppKit/Foundation wrap
callouts with try/catch, and don't call NSApplication's
-reportException: with the thrown exceptions. For example, an
exception thrown in the -applicationDidFinishLaunching: delegate
method simply can't be caught.

(That said, NSHandleOtherExceptionMask will allow your
NSExceptionHandler delegate method to be called for exceptions that
were caught normally, and therefore will work for cases where
exceptions are caught by AppKit. But of course, using that to
terminate your app makes the assumption that no code in your process
is using exceptions for flow control, etc. I know of one case at least
– NSConnection/NSPort – where exceptions can occur in the normal
course of execution.)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: assign property behaves differently from simple instance variable???

2010-12-14 Thread Dave Keck
>>Hmm, also, it appears that UIResponder has some undocumented methods 
>>-firstResponder and -_firstResponder, which your synthesized property would 
>>also interfere with.
>
> Doubtless. But how would I have discovered this?

I would have implemented -firstResponder and set a breakpoint to see
who was calling it. You could also use otool or class-dump to get a
listing of methods that UIResponder implements.

> Doesn't anyone besides me want to evince any outrage that this can happen? I 
> mean, sheesh, if I wanted to live in a world where the namespace was polluted 
> with secret undocumented terminology I could collide with accidentally, I 
> could use AppleScript. m.

Hah – Cocoa/Obj-C certainly has its shortcomings, but comparing it to
AppleScript? Ouch.

There was an interesting discussion about bringing namespaces to Obj-C
on cfe-dev last month:

http://comments.gmane.org/gmane.comp.compilers.clang.devel/11746

Needless to say it's no small task, and the method-overriding problem
raised in this thread might not even be solved by Obj-C namespaces, as
it would depend entirely on how comprehensive the implementation was.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Image Processing

2010-12-12 Thread Dave Keck
See the CoreImage docs:

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/CoreImaging/ci_intro/ci_intro.html
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSUnarchiver / Data.archive Extract all Keys

2010-12-10 Thread Dave Keck
> yes, it's noise...
>
> Also it's not just one, they're save files for an old program I made - I'd
> like to be able to extract the data so I can save it in the format used for
> more recent versions

NSPropertyListSerialization could probably help too. If Property List
Editor can't parse it though NSPropertyListSerialization probably
won't be able to either.

What happens when you:

NSLog(@"%@", [NSUnarchiver unarchiveObjectWithFile: @"/path/to/archive"]);
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSUnarchiver / Data.archive Extract all Keys

2010-12-10 Thread Dave Keck
> Note I no longer have the source code that saved this file, hence my
> desire to extract the keys & information stored there.

Have you tried opening your archive in Property List Editor or
TextEdit? It's just a plist.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-08 Thread Dave Keck
> Hey, this sounds very familiar!
> http://lists.apple.com/archives/cocoa-dev/2010/Sep/msg00426.html

That seems like a distinct issue. The problem Gideon is seeing is that
[NSThread mainThread] holds a (private) reference to a run loop that
isn't the main thread's run loop. Since -performSelectorOnMainThread
relies on that reference, calls to -performSelectorOnMainThread fail.

Both issues seem to involve bad timing in the use of certain Cocoa
APIs; it seems there's something about the order and timing of
Gideon's project that's causing NSThread to think that some
CFRunLoopRef is the main run loop when it's not.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-08 Thread Dave Keck
> So could this issue be something to do with the timing of the first time the
> threaded operation is run?

I'd imagine it involves NSThread making an assumption about the
initial invocation of one of its APIs, and the run loop that it
expects to exist at the time of that invocation. Assuming your code
isn't committing some grave API sin, then perhaps this is a bug in
Foundation.

If you get the chance, see if you can whittle the project down to
isolate the set of code that still exhibits the issue. I'd personally
be interested in seeing the cause of the strange behavior.

> During startup of the application, in an awakeFromNib, it calls a
> performSelector...afterDelay:0, and when that eventually fires, it triggers
> the thread to run. I would have thought that would be perfectly safe, but
> maybe not?

I just implemented that in my test app and the calls to
-performSelectorOnMainThread seem to work fine.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-08 Thread Dave Keck
> FYI, I do not create any run loops explicitly in my application

That's good, because run loops can't be created explicitly. :)

> and can't think of anything I am doing which would create one implicitly.

A run loop is automatically created for every thread that's spawned.
(I believe this happens lazily though.)

So to summarize, it appears that the instance of NSThread representing
the main thread has the wrong instance of CFRunLoop. Some thoughts:

1. Are you using the pthread APIs directly in your code? I recall
there are several places in the docs that mention certain
considerations that have to be made to use the pthread and
Cocoa/NSThread APIs safely together.

2. Do you have any functions marked __attribute__ ((constructor)) ?

3. What does your main() function look like?

4. Does -performSelectorOnMainThread work if you call [NSThread
mainThread] as the first line in main()?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-08 Thread Dave Keck
> You are correct. They are two different things:

Alright, does the following assertion fail when placed before the
-performSelectorOnMainThread line? (Ignore the warning - using private
APIs.)

id a = (id)[[[NSThread mainThread] runLoop] getCFRunLoop];
id b = (id)CFRunLoopGetMain();
NSLog(@"%p ?== %p", a, b);
assert(a == b);

[anObject performSelectorOnMainThread: ...]

Please respond with the output of the NSLog line too.

The assertion succeeds in my own test app. I'm guessing it
fails/crashes in yours.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-08 Thread Dave Keck
> That was the output for $rdi at the CGRunLoopWakeUp breakpoint immediately 
> after the call to performSelectorOnMainThread...

Sorry, realized that after I sent. The output still isn't what I would
expect though: on my system, the run loop supplied to
CFRunLoopWakeUp() from within the -performSelectorOnMainThread stack
frame is the main run loop (as you'd expect), and the description of
the main run loop should be quite similar to what I posted at the
pastie link. The description of the run loop you posted (with address
0x1a2ac80) doesn't look like the main run loop at all. Therefore I'm
_guessing_ that the problem is that -performSelectorOnMainThread is
both attaching its CFRunLoopSource and calling CFRunLoopWakeUp() on
the wrong run loop.

It'd be worth verifying whether the CFRunLoopRef supplied to
CFRunLoopWakeUp() within the -performSelectorOnMainThread stack frame
is the same pointer returned by CFRunLoopGetMain(). Let me know and if
it's not, and I'll look further into the NSObject/NSThread disassembly
to see where it might be getting the incorrect CFRunLoop reference.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: iOS when is my app launched

2010-12-08 Thread Dave Keck
> How do I find the date and time when my application launched? I've done this 
> before on OS X, but it was a while ago and I've forgotten how. :)

I'm not sure what you mean exactly, but [NSDate date] will return the
current date/time. Tuck that instance in memory when your application
launches and you'll have that information for later, or alternatively
store it to disk using NSKeyedArchiver.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-08 Thread Dave Keck
> Did you edit the above quoted output at all? First, I would expect a lot more
> information to be printed for the main run loop, and second, I would
> expect to see NSEventTrackingRunLoopMode and NSModalPanelRunLoopMode
> as part of the common modes set.

That is, are you sure you entered:

po (void*)CFRunLoopGetMain()

and not:

po (void*)CFRunLoopGetCurrent()

? To clarify:

[anObject performSelectorOnMainThread: ...]
NSLog(@"Breakpoint line"); // <-- set breakpoint here

On my machine, if I set a breakpoint on the NSLog line and upon
hitting it, I enter the following at the GDB prompt (copy & paste):

po (void*)CFRunLoopGetMain()

I get the following output:

http://pastie.org/1358225

(Much longer than the output you posted, which is what I would expect
for the main thread's run loop.)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-08 Thread Dave Keck
> {locked = false, wakeup port = 0x5a03,
> stopped = false,
> current mode = (none),
> common modes = {type = mutable set,
> count = 1,
> entries =>
> 1 : {contents = "kCFRunLoopDefaultMode"}
> }
> ,
> common mode items = {type = mutable set,
> count = 1,
> entries =>
> 25 : {locked = No, signalled = Yes,
> valid = Yes, order = 0, context = {version = 0,
> info = 0x180c150, callout = __NSThreadPerformPerform (0x996c2bbf)}}
> }
> ,
> modes = {type = mutable set, count = 1,
> entries =>
> 10 : {name = kCFRunLoopDefaultMode,
> locked = false, port set = 0x5b03,
> sources = {type = mutable set, count =
> 1,
> entries =>
> 5 : {locked = No, signalled = Yes,
> valid = Yes, order = 0, context = {version = 0,
> info = 0x180c150, callout = __NSThreadPerformPerform (0x996c2bbf)}}
> }
> ,
> observers = (null),
> timers = (null)
> },
>
> }
> }

Did you edit the above quoted output at all? First, I would expect a lot more
information to be printed for the main run loop, and second, I would
expect to see NSEventTrackingRunLoopMode and NSModalPanelRunLoopMode
as part of the common modes set.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-07 Thread Dave Keck
> 3. Stop your program, and set a breakpoint on the
> -performSelectorOnMainThread line. Run your program again. When this
> breakpoint is hit, before continuing your program, set a breakpoint at
> CFRunLoopSourceSignal(). Continue your program. The
> CFRunLoopSourceSignal breakpoint should be hit (directly or
> indirectly) from within the stack frame of
> -performSelectorOnMainThread; is this true?

Oh - CFRunLoopWakeUp() should also be called after
CFRunLoopSourceSignal(). Set a breakpoint on CFRunLoopWakeUp() too,
and make sure it's called from within the
-performSelectorOnMainThread: stack frame.

Furthermore, printing the first argument to both of these functions
when/if their breakpoints are hit would also useful:

i386:

po *(id*)($ebp+8)

x86_64:

po $rdi
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-07 Thread Dave Keck
> Now I thought it would be interesting to try those calls before the thread 
> was dispatched, and the terminate one worked, but the run loop stop didn't. I 
> also tried the runloop stop one in my mini test application, and it didn't 
> work there either, so am a bit suspicious of that. Should that kill any 
> application?

No, it shouldn't make your app terminate - it'll just cause
CFRunLoopRunInMode() to return (see the stack trace you posted
earlier.) I was thinking this would cause the
-performSelectorOnMainThread machinery to notice that there was an
enqueued invocation. (Not that this should be necessary, of course.)

On my system, -performSelectorOnMainThread works using a
CFRunLoopSource attached to the main thread's run loop, which is
signaled after -performSelectorOnMainThread has enqueued an object
representing the invocation. I'm thinking -performSelectorOnMainThread
isn't working because either the main thread isn't running in a common
mode, or something's failing with the CFRunLoopSource. Here are some
things to try:

1. Place a breakpoint on the line after the call to
-performSelectorOnMainThread. After this is hit, at the GDB prompt,
enter the following command:

po (void*)CFRunLoopGetMain()

This should print a lot of information. One of the first lines printed
will mention "current mode =". What mode does it say?

2. In the information printed in the last step, do you see a run loop
source mentioned with a callout of "__NSThreadPerformPerform"? (This
is the run loop source mentioned previously.)

3. Stop your program, and set a breakpoint on the
-performSelectorOnMainThread line. Run your program again. When this
breakpoint is hit, before continuing your program, set a breakpoint at
CFRunLoopSourceSignal(). Continue your program. The
CFRunLoopSourceSignal breakpoint should be hit (directly or
indirectly) from within the stack frame of
-performSelectorOnMainThread; is this true?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-07 Thread Dave Keck
Also: a quick peek at the assembly of -performSelectorOnMainThread:
reveals that it calls _CFExecutableLinkedOnOrAfter(). Presumably this
is to modify its behavior based on what SDK your app links against;
perhaps changing your Base SDK has an effect?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-07 Thread Dave Keck
Some thoughts:

1. What happens if you specify a different object to receive the
message? For example, try [NSApp performSelectorOnMainThread:
@selector(terminate:) ... waitUntilDone: YES]. Does your app
terminate?

2. Specify waitUntilDone: NO, and after the call to
-performSelectorOnMainThread:, call:

CFRunLoopStop(CFRunLoopGetMain());

Does that make it work?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: performSelectorOnMainThread fails second time through

2010-12-07 Thread Dave Keck
> Any ideas?

Post your code!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Foundation vs Core Foundation

2010-11-29 Thread Dave Keck
> Before I start down the wrong path: What is the difference between a 
> Foundation
> tool and a Core Foundation tool? Primarily I will be needing to use TCP/IP
> sockets, file I/O, and multithreading, so is one a better fit than the other? 
> I
> believe OSX calls this type of GUI-less background process a 'daemon'. This
> would be for Snow Leopard.

CoreFoundation is a general-purpose C framework whereas Foundation is
a general-purpose Objective-C framework. Both provide collection
classes, run loops, etc, and many of the Foundation classes are
wrappers around the CF equivalents. CF is mostly open-source (see
http://opensource.apple.com/source/CF/CF-550.42/), and Foundation is
closed-source.

Typically there's little reason to confine oneself to CF as it'll only
make your life more difficult. The only exception is when security is
a concern; I'm not sure what the current recommendation is on linking
Foundation from a process that runs as root (although I believe some
of Apple's software does this.) Will your daemon be running as root?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Help diagnosing networking/internet performance issues

2010-11-22 Thread Dave Keck
Perhaps the bandwidth has been limited using ipfw or a similar utility?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Notification of CD-ROM inserted

2010-11-21 Thread Dave Keck
I'd use either NSWorkspaceDidMountNotification or
DARegisterDiskAppearedCallback() of the DiskArbitration framework.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Problem with redirecting stdout

2010-11-09 Thread Dave Keck
> I think the problem is that the pipe buffer is not being flushed/read when
> it's full; when the pipe is full, the script interpreter then is blocked
> because it's waiting for the pipe to empty so that it can write.

I don't fully understand the structure of your program, but indeed it
sounds like the classic filled-buffer hang.

I would solve your problem by using GCD and avoiding
NSPipe/NSFileHandle altogether. To prevent the child from hanging when
it attempts to write() to its stdout, you need to make sure the parent
is always going to read the available data in the buffer as soon as
it's available. You can accomplish this without too much trouble:

==

#define BUFFER_SIZE 0x1000

dispatch_source_t source =
dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, readFD, 0,
  dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));

dispatch_source_set_event_handler(source,
^{
  void *dataBuffer = malloc(BUFFER_SIZE);
  assert(dataBuffer);

  ssize_t readResult = 0;
  do
  {
errno = 0;
readResult = read(readFD, dataBuffer, BUFFER_SIZE);
  } while (readResult == -1 && errno == EINTR);
  assert(readResult >= 0);

  if (readResult > 0)
  {
dispatch_async(dispatch_get_main_queue(),
^{
  NSString *newDataString = [[[NSString alloc]
initWithBytesNoCopy: dataBuffer
length: readResult encoding: NSUTF8StringEncoding
freeWhenDone: YES] autorelease];
  // append newDataString to the NSTextView...
});
  }
  else
free(dataBuffer);
});

==

Hopefully that gets the idea across – of course it needs more robust
error-checking and such.

> I've also tried using an pseudo-tty via openpty() instead of an NSPipe, but
> I get the same problem: The app hangs when too much output is sent to stdout
> by an executing script.

Using a PTY instead of an unnamed pipe wouldn't fix the problem. All
using a PTY would do is cause the child's Libc buffer to be flushed
after each newline rather than when the Libc buffer is filled. That
behavior might be useful, though, if it's preferable that your parent
reads the child's output by line rather than by some constant-sized
number of bytes.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Switching app type from background only to full UI, and back?

2010-11-06 Thread Dave Keck
I'm sure you're dreading this question, but can you elaborate on why
you can't separate your processing code from your UI code? It sounds
like you're mainly avoiding it due to the amount of work involved, but
you also mentioned that there might be technical limitations; if
you're able to elaborate on those perhaps we could offer some insight.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Few binaries in one application's Bundle

2010-10-25 Thread Dave Keck
>> The problem is, when either one of binaries is started, no one else
>> from this bundle can be launched. The bundle itself is
>> "LSUIElement=TRUE".
>> I was wondering, if i could use some technique/non-evil hack to keep
>> my appliations in a neat one bundle (counting that the user should be
>> able to start only one main binary, while other binaries are started
>> automatically by agent or by the main application).
>
>  I usually put helper executables in Resources instead of in MacOS. Maybe 
> that fixes it?

I believe the current recommendation is to place helper bundles in
Contents and single-file executables in MacOS. See this post:

http://lists.apple.com/archives/Apple-cdsa/2008/Jan/msg00053.html

and TN2206, under "Helper tools and other executable extras":

http://developer.apple.com/library/mac/#technotes/tn2007/tn2206.html

Though I'm not sure what OP means by no "one else from this bundle can
be launched"?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: DO over unnamed sockets

2010-10-23 Thread Dave Keck
> You can verify this by breaking on connect() or using dtruss or the like.  
> It's actually getting ENOENT.  It appears be using getsockname() on the send 
> port's socket to figure out where to connect, and that's giving a sockaddr_un 
> with an empty sun_path.

Moments after sending my original email I set some breakpoints and
that's exactly what I found, too.

> I don't think that the raw Mach port rights are inherited through a 
> fork-exec, unfortunately. If they were, I think you could create a connection 
> with them successfully.

I looked into this option, but indeed only certain special ports are
inherited by child processes (exception ports, bootstrap port, etc.)
and there doesn't appear to be any way to specify that a port should
be inherited. Bummer. Interestingly though, there's an article that
documents a method of passing a user-created port to a child by way of
temporarily replacing the bootstrap port before the parent forks:

http://www.foldr.org/~michaelw/log/computers/macosx/task-info-fun-with-mach

Unfortunately it's a bit of a hack that won't play nice with other
threads in the parent that use the bootstrap port.

> But, if I'm right that you can't inherit the Mach port rights, then you'd 
> need to register the server with a name server, which is what you're trying 
> to avoid.

I started investigating subclassing NSPort to use an unnamed pipe – my
preliminary tests are promising, and the docs/header for NSPort
suggest that it's designed for subclassing. If you have any thoughts
please let me know – I haven't delved in quite yet.

Should that fail, I guess the only other option is an authentication
scheme combined with the name server dance.

David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Multiple instances of [NSUserDefaults standardUserDefaults]

2010-10-23 Thread Dave Keck
> Well, I've got some code, which I presume used to work, which relies on
> observing a value in the user defaults. The observer isn't getting triggered, 
> so
> I am guessing it is because they are separate instances. Both should be on the
> main thread.

Are you observing an instance of NSUserDefaults or
NSUserDefaultsController? NSUD doesn't support KVO – perhaps that's
the problem?

Also, for testing at least, you might as well allocate your own
NSUserDefaultsController instance and stick it in an ivar. That way,
pointer comparison in -observeValueForKeyPath: should always work as
expected if different instances are indeed being returned by the
convenience constructor.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Multiple instances of [NSUserDefaults standardUserDefaults]

2010-10-23 Thread Dave Keck
> Has anyone got any thoughts?

I wouldn't be surprised if there's a separate NSUserDefaults instance
for each thread. Regardless though, it's an implementation detail that
shouldn't be relied on unless the docs guarantee certain behavior.

Could you explain why you need to rely on NSUserDefaults returning the
same instance on each invocation of -standardUserDefaults?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


DO over unnamed sockets

2010-10-23 Thread Dave Keck
Hey list,

I'm attempting to use distributed objects over an unnamed socket pair
created via socketpair(). I've tried every permutation of the
following code that I can think of, but it always throws an exception
when the client calls -rootProxy:

http://pastie.org/pastes/1242749

Can DO work over unnamed sockets? I wish to have a parent and child
process communicate via DO, but don't wish to name the sockets for
security reasons.

Thanks!

David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSScanner Failing with EXC_BAD_ACCESS

2010-10-15 Thread Dave Keck
> The problem is probably that theScannedString has never been initialize
> it. Always initialize when you declare, because otherwise your value could
> be nonsense and can't be logged. So, minimally, you'd say this:

Good advice regarding initialization, but...

> NSString *theScannedString = nil;
>
> Now you can log that value successfully, even if nothing gets written into
> it. Then you can track down *why* nothing is getting written into it. :) m.

No – initializing theScannedString doesn't excuse you from checking
the return value of -scanCharactersFromSet:. See Bill's response.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Debug Problem on MacOSX 10.5

2010-10-14 Thread Dave Keck
Try breaking on objc_exception_throw() instead.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ivars and fundamental types

2010-10-11 Thread Dave Keck
> Don't do that. object_getInstanceVariable() and object_setInstanceVariable()
> still assume the ivar is of an object pointer type.

As the documentation and prototypes stand, one would think that
object_getInstanceVariable() could be used like this:

double *doublePointer = nil;
object_getInstanceVariable(..., (void **)&doublePointer);
NSLog(@"%f", *doublePointer); // get ivar value
*doublePointer = 42.4242; // set ivar value (erroneously bypassing
potential GC write barriers if it were a pointer type)

... especially since outValue is documented as "On return, contains a
pointer to the value of the instance variable." In fact, I suppose it
should read "On return, contains the value of a pointer-typed instance
variable."

Furthermore, if object_getInstanceVariable() assumes an "object
pointer type" -- emphasis on _object_ -- shouldn't outValue be typed
{id *}?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ivars and fundamental types

2010-10-08 Thread Dave Keck
> object_setIvar() takes type id.

object_getInstanceVariable()?

"outValue: On return, contains a pointer to the value of the instance variable."
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Let the runloop process its queue during a long operation

2010-10-07 Thread Dave Keck
> But this is for Carbon application, isn't it? I have a cocoa one...

No – NSRunLoop is built atop of CFRunLoop, just as many Foundation
classes are built atop CoreFoundation classes. Carbon has nothing to
do with it.

> Does this call operate with the core foundation run loop, bypassing
> cocoa's one?

They're one and the same.

> And if it's allowed to use it in cocoa app, what should i specify as
> the second parameter (timeInterval)? 0 doesn't seem to work at all
> (the run lop is not relaunched at all), 1 sec gives big delays, if
> nothing has been pressed - it seems that "sourceHandled" means "at
> least one event in queue is handled, if the queue is empty - just wait
> that timeinterval". But then, setting any interval>0, i force my
> application to wait, instead of processing that big file.
> Or maybe i'm understanding something wrong?

For your situation, you shouldn't need to deal with the run loop
directly. Normally you'd want to use a separate thread, NSOperation,
etc., but since you're using AppleScript, that's out of the question
since it's confined to the main thread.

See the docs for NSApplication's -runModalSession: – that's probably
your best bet.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Let the runloop process its queue during a long operation

2010-10-06 Thread Dave Keck
> Can i make a runloop run only one time through the queue, and then
> return back to processing of that big file?

See CFRunLoopRunInMode(), specifically the returnAfterSourceHandled argument.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Checking for nil-return

2010-10-05 Thread Dave Keck
> Because it throws exceptions if anything bad happens at runtime (i.e out of 
> memory, invalid parameters etc)

If memory truly becomes exhausted (as opposed to attempting to
allocate a huge object), you'll crash due to a stack overflow since
the code path of throwing an exception allocates objects.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Continuously running daemon process CFConstantStringRefs build up over time

2010-10-01 Thread Dave Keck
>        CFStringRef hexStringRef = CFStringCreateWithFormat( NULL, NULL, 
> CFSTR("%x"), versionValue );   <- Instruments is hi-lighting this line as 
> an allocation.

It sounds like you found the cause of your persisting string objects
so the details of CFSTR is irrelevant, but to clarify anyway: the
result of CFStringCreateWithFormat() is of course an allocation as
Instruments reported, but the format string that you supplied
CFStringCreateWithFormat() – that is, the CFString whose value is "%x"
– exists statically within your executable (in the __DATA/__cfstring
segment/section) and is therefore not an allocation.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Continuously running daemon process CFConstantStringRefs build up over time

2010-10-01 Thread Dave Keck
Since you're writing a daemon, you'll need to handle autorelease-pool
creation and draining manually (something that's normally handled by
NSApplication in standard AppKit apps.) Perhaps objects are
autoreleased and placed in the root autorelease pool (that you might
be creating in main() or the like) which is never drained?

Also, how many strings are leaking? I know the frameworks cache
NSNumber instances; I'm not sure about immutable strings.

> I have run the daemon through the clang static analyzer and the Instruments 
> leaks tool but none are reporting any leaks.  I have even downloaded a fresh 
> copy of valgrind from svn and it too is not finding anything.  The 
> instruments allocation monitor is reporting that there are 
> CFConstantStringRefs that Foundation is allocating from internal methods and 
> CFSTR macros that I am using in some functions.  I'm happy to provide more 
> details of the actual call-stacks and code if necessary.

A pedantic detail: note that strings created with CFSTR exist
statically within your executable (they aren't dynamically allocated)
and therefore aren't leaks.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTimer memory management

2010-09-22 Thread Dave Keck
> Is this an over-release?
>
> timer = [ [NSTimer scheduledTimerWithTimeInterval: ...] retain];
> ...
> [timer invalidate];
> [timer release];

No, you're not over-releasing the timer.

> I've seen this pattern so many times I figured it was correct,
> although it doesn't seem to comply with the memory management rules
> (i. e. the timer is first implicitly released when invalidated, then
> explicitly released again).

It's a valid technique; when you call -invalidate, the run loop
releases the timer (to balance the implicit -retain that it made when
the timer was scheduled), but you still need to balance the explicit
-retain that you made when the timer was allocated.

> Can someone please help clarify? This is my full code:
>
> - (void)invalidateTimer
> {
>        if ( [theTimer isValid] ) {
>                [theTimer invalidate];
>                [theTimer release]; // crashes here
>                theTimer = nil;
>        }
> }
>
> - (void)startTimer
> {
>        [self invalidateTimer];
>        theTimer = [[NSTimer scheduledTimerWithTimeInterval:300 target:self
> selector:@selector(timerFireMethod:) userInfo:nil repeats:NO] retain];
> }

Looks fine to me. Perhaps this is a multi-threading synchronization
issue? (Is more than one thread calling these methods?)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Scripting Bridge Strange Pauses

2010-09-16 Thread Dave Keck
> It is running on main thread. I am not sure how to "profile." I tried "Thread 
> State" in Instruments and it output data, but nothing unusual when the pause 
> occurred. Is that the right tool?

(Sorry, I meant 'sample' instead of 'profile.')

When the loop gets hung up, pause the program in the Xcode debugger
and copy and paste the main thread's stack trace into a reply to the
list; this will tell us exactly what nested call is blocking the loop.

> I did pinpoint exactly what method was being called when a pause occurred 
> (although the specific method varied) and changed those methods to do nothing 
> except return a number such as
> - (long)birthSDN { return 10L; }
> and it still pauses. It is hard to see how this method could not be 
> responding. Also these pauses never happen when the same methods are called 
> from an AppleScript. They only happen when called from a Python script or a 
> Cocoa app, both through the Scripting Bridge.

If possible, it would help us outsiders a lot if you could distill
your two apps down to the smallest case that still exhibits this
behavior and post them to the list.

> I tried GC in Instruments, but it said my apps do no qualify? Also, I want 
> the final solution to work in Python scripts and not to only work from other 
> Cocoa apps. I am not sure if an autorelease pool method would work from 
> Python script?
> One new result has started as well when running from a Python script. When 
> the long pause is over, some Python variables that were previously defined 
> have changed to "None" and then the script encounters and error. The long 
> pause seems to be corrupting memory as well.

GC doesn't involve Instruments; if you haven't explicitly enabled it
in your test app's Xcode project, then it's disabled by default.

I suggested wrapping your loop with an autorelease pool simply to
remove the potential variable of memory management as being the cause
of the slowdown/pause. The code would look like this with an
autorelease pool present:

for(i=0;ihttp://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Scripting Bridge Strange Pauses

2010-09-15 Thread Dave Keck
Have you profiled the thread that's stopped/paused? What does its stack
trace look like?

Have you verified that the problem isn't that 'GEDitCOMII' isn't responding?

Also, if you're not using GC, consider profiling your loop with and without
each iteration allocating/releasing an autorelease pool. Adding one could
improve performance if objects are being allocated indirectly by your
several method calls within the loop.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: delayed NSWorkspaceDidTerminateApplicationNotification under 10.6?

2010-09-08 Thread Dave Keck
> > Anyway, I ended up using the Process Manager APIs
> > to check whether the app in question was running before executing an
> > AppleScript to issue commands to it.
>
> It's worth a try. But I'm afraid it will put a heavy load on the CPU
> for a timer firing every second, no?

You'll have to profile it and see. Of course, you should try to
minimize the amount of polling.

> > (It seems NSRunningApplication is the
> > modern API for 10.6+.)
>
> Do we know if this is faster than using Process Manager? Unfortunately
> I need to target Mac OS X 10.5 as well (where this is not a problem),
> but I suppose I could use NSSelectorFromString() to get it to compile
> under the 10.5 SDK.

I don't think performance is going to be a big issue with the process
APIs; at any given time a user probably isn't going to have over 20 or
30 foreground+background apps running, so even iterating over each one
shouldn't be much an issue. But no need to speculate – might as well
just profile the different techniques and choose the best one.

> > /snip.../
> >
> > I only know enough about AppleScript to avoid it, but I believe iTunes is
> > being launched necessarily for the NSAppleScript to compile.
>
> No, this is not correct. You can compile a script without launching
> the target - at least on Snow Leopard.

I'm afraid my testing shows otherwise; on my system, the following
code always launches Safari on both 10.5 and 10.6:

NSAppleScript alloc] initWithSource: @"tell application id
\"com.apple.Safari\" to activate"] autorelease] compileAndReturnError:
nil];

(Note it's -compileAndReturnError:, not executeAndReturnError:.) The
launching behavior seems to vary by application, though. For me, this
code launches iSync, Safari and System Preferences, but doesn't seem
to launch iTunes.

Such unpredictability is the nature of AppleScript and why I try to
avoid it. But I imagine this (or some related reason) is why you're
having relaunching issues, though I bet it depends on the system.

... So to workaround the problem, check whether iTunes is running, and
only if it is, perform some Scripting Bridge/AppleScript action.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: delayed NSWorkspaceDidTerminateApplicationNotification under 10.6?

2010-09-08 Thread Dave Keck
>
> After the release of Snow Leopard, it seems that [iTunes isRunning]
> returns YES for a short while even after the application has quit (I
> believe this applies to all apps, not just iTunes, but I haven't
> confirmed this yet). As a result, my app would relaunch iTunes,
> assuming it was still running. Not cool.
>

I can't comment decisively on your problem with Scripting Bridge, but I
experienced some relaunching issues with NSAppleScript when attempting to
control an application other than iTunes. Since both NSAppleScript and
Scripting Bridge are based on Apple events, I imagine we experienced the
same underlying problem. Anyway, I ended up using the Process Manager APIs
to check whether the app in question was running before executing an
AppleScript to issue commands to it. (It seems NSRunningApplication is the
modern API for 10.6+.)

In your case, I would try something like this:

==

   BOOL iTunesOpen = NO;
   ProcessSerialNumber currentPSN;

   for (currentPSN.highLongOfPSN = kNoProcess, currentPSN.lowLongOfPSN =
kNoProcess;;)
   {

   OSErr getNextProcessResult = 0;

   getNextProcessResult = GetNextProcess(¤tPSN);

   // For production code we should of course be handling errors
gracefully.
   assert(getNextProcessResult == noErr || getNextProcessResult ==
procNotFound);
   if (getNextProcessResult == procNotFound) break;

   if ([[[(id)ProcessInformationCopyDictionary(¤tPSN,
kProcessDictionaryIncludeAllInformationMask) autorelease]
   objectForKey: (NSString *)kCFBundleIdentifierKey]
isEqualToString: @"com.apple.iTunes"])
   {

   iTunesOpen = YES;
   break;

   }

   }

   // Only if iTunes is open will we attempt to request its player position,
to avoid relaunching it.
   if (iTunesOpen) return [iTunes playerPosition];
   return -1;

==

Finally I tried replacing ScriptingBridge with NSAppleScript:
>
> currentTimeScript = [[NSAppleScript alloc] initWithSource:@"try\n\
>  if application
> \"iTunes\" is running then\n\
>  tell application
> \"iTunes\"\n\
>  if player state is
> not stopped then\n\
>  return player
> position\n\
>  end if\n\
>  end tell\n\
>  end if\n\
>  on error\n\
>  return 0\n\
>  end try"];
>
> This yielded somewhat better results. iTunes now quits gracefully most
> of the time, but is still relaunched every now and then (some users
> report it still happens each and every time). Now I'm out of ideas...
> What did I miss? Should I file a radar?


I only know enough about AppleScript to avoid it, but I believe iTunes is
being launched necessarily for the NSAppleScript to compile. (Meaning that
regardless of what checks you surround your "critical" AppleScript with, I
believe it will still launch iTunes if the script contains "tell application
'iTunes'".) If for some reason you choose the AppleScript route, I got
around this by only allowing the "tell application 'iTunes'" AppleScript to
compile if we're sure iTunes is already running. For example, after checking
iTunes' running state using the code above:

==

   // Only compile/execute the script if iTunes is already running, to
prevent it from relaunching.
   if (iTunesOpen)
   NSAppleScript alloc] initWithSource: @"tell application id
\"com.apple.iTunes\" to play"] autorelease] executeAndReturnError: nil];

==

Of course this technique has a race between the time that we check whether
iTunes is running and the time that we actually tell it to do something, but
I imagine this window is small enough to be acceptable.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Folders and file system organization instead of just XCode

2010-09-06 Thread Dave Keck
> 2º Why most of projects that I found on the internet don't use folders or
> groups to separate classes (for example, controllers, views, categories and
> models). What is the good pratice for code organization? If somebody could
> point links or guidelines would help a lot.

I think anyone would agree that it's good practice to have some sort
of source grouping for any large project. It's my preference to create
groups for each component of a project; for example, in a
document-based app I would have Document.m, DocumentView.m, and
DocumentController.m grouped in the source list. In addition, I have a
"Shared Source" group for reusable code, which can be further grouped
by component.

(I worked on a large project that grouped files at the root level into
three MVC groups, and I found it was a pain to find the files I
needed. I tend to work on one component of a project at a time; when
organized by MVC I was constantly scrolling in the source list to skip
between the component's files. As a project grows, so does the
distance between related files in the source list, and it's downhill
from there.)

BTW, this question is probably better suited on xcode-dev or elsewhere.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: sharing file descriptors to an NSTask

2010-09-01 Thread Dave Keck
> descriptors are open. On OS X, you could read the contents of /dev/fd/
> to accomplish the same thing. It appears that NSTask uses the uglier
> getdbtablesize() loop though.

Neat, I wasn't aware of /dev/fd. Are the necessary APIs
async-signal-safe so they can be used between fork()/exec()?
Apparently getdbtablesize() isn't even documented as being so; in the
strictest sense then, I guess you'd have to use you'd have to use
INT_MAX. Hah.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: sharing file descriptors to an NSTask

2010-08-31 Thread Dave Keck
Indeed NSTask closes open descriptors in the child. I could have sworn
this was documented somewhere, but I can't seem to find the relevant
text at the moment.

To get around this behavior (and other NSTask bugs and shortcomings),
I chose to write my own NSTask equivalent. Alternatively, you could
use sendmsg() and friends to share the descriptor with the child over
a Unix domain socket, but depending on what type of descriptor you'd
be sharing, that might defeat the purpose.

Off topic 1: The last I checked, the open-source Cocoa clones
(GNUstep, Cocotron) emulate this descriptor-closing functionality of
NSTask, which reinforces my belief that this was documented
somewhere...

Off topic 2: It's strange behavior in the first place, since AFAIK,
there's no efficient way of closing open descriptors short of for(i =
3; i < getdtablesize(); i++) close(i);
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to fastly get the active window's title?

2010-07-27 Thread Dave Keck
CGWindowListCreate() and CGWindowListCreateDescriptionFromArray() are
probably your best bet, with the accessibility APIs being another
option.

Note that that UI controls are sometimes implemented as separate
windows, but from the user's perspective they belong to a parent
window; this is something you'll likely need to consider when using
these APIs. For example, just because a window is at the beginning of
the window list returned from CGWindowListCreate(), doesn't mean it's
what the user would consider the "active window."
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Screen pixels changed notification?

2010-07-26 Thread Dave Keck
You're probably interested in CGRegisterScreenRefreshCallback().
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Flipping coordinate system of a CALayer

2010-07-15 Thread Dave Keck
>> The only workaround I was able to get working was to call a private
>> AppKit method to fix up the layer geometry.
>
> Which is a no-no, and shouldn’t be done. Bad Kyle. No biscuit.

Forgive me for raising such a taboo topic, but I've encountered
situations where I had to choose between A) using a private API, B)
shipping a product with a malfunction that would aggravate users to a
greater degree than the risk of using the private API, or C) not
shipping a product.

Certainly – placing yourself in the shoes of a third-party developer –
you would agree that situations exist where using a private API is
warranted? I'd be happy to provide specific examples as necessary.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: File descriptors not freed up without a -closeFile call

2010-06-23 Thread Dave Keck
>  Ah, interesting.  I missed that in the docs.  It still seems bad to me that
> the file handle will actually dealloc without closing its associated file
> descriptor, but perhaps you are right that that is the documented behavior.
>  I'll just stop worrying about it and move on, then.  Thanks!

NSPipe and its NSFileHandles work as you expect: when the read/write
file handles created via NSPipe are deallocated, the underlying
descriptors are closed. Along with Jean-Daniel Dupas, I created a
simple test case and it behaves as expected. (I've also been using
NSPipe/NSFileHandle extensively for years and have never come across
anything like you described.)

I'd be interested in seeing a test case showing the incorrect behavior.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Process executes an AppleScript, then disappears. Why/How?

2010-06-13 Thread Dave Keck
> What might cause this process to exit?  Where can I look for clues? (I've 
> been guessing for two hours, so any suggestion will be welcome.)  Does the 
> system log the exit states of processes anywhere?

I would attach to the process while it's executing (in Xcode, Run >
Attach to Process) and set a breakpoint on exit()/_exit() to get a
backtrace when it exits.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Notification of file system modification arrives too early?

2010-05-31 Thread Dave Keck
> Really ? I find the first comment in libproc.h pretty clear about it.

If it was private in the strictest sense, the header wouldn't exist.
Certainly since the header has existed since 10.5, Apple intends for
someone to use it?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Notification of file system modification arrives too early?

2010-05-30 Thread Dave Keck
> Unfortunately you probably can’t do any better than that, since there’s no
cheap way to find out if another process has the file open.

proc_listpidspath() is meant for this, but it is indeed quite expensive. In
my testing, it takes about a second to complete this call; furthermore, its
status as a supported API is unclear. Nonetheless, here's some
somewhat-tested code of how to use it:

==

#import 

- (NSSet *)pidsAccessingPath: (NSString *)path
{

const char *pathFileSystemRepresentation = nil;
int listpidspathResult = 0;
size_t pidsSize = 0;
pid_t *pids = nil;
NSUInteger pidsCount = 0,
   i = 0;
NSMutableSet *result = nil;

NSParameterAssert(path && [path length]);

pathFileSystemRepresentation = [path GCSafeFileSystemRepresentation];
listpidspathResult = proc_listpidspath(PROC_ALL_PIDS, 0,
pathFileSystemRepresentation, PROC_LISTPIDSPATH_EXCLUDE_EVTONLY, nil, 0);

ALAssertOrPerform(listpidspathResult >= 0, goto cleanup);

pidsSize = (listpidspathResult ? listpidspathResult : 1);
pids = malloc(pidsSize);

ALAssertOrPerform(pids, goto cleanup);

listpidspathResult = proc_listpidspath(PROC_ALL_PIDS, 0,
pathFileSystemRepresentation, PROC_LISTPIDSPATH_EXCLUDE_EVTONLY, pids,
pidsSize);

ALAssertOrPerform(listpidspathResult >= 0, goto cleanup);

pidsCount = (listpidspathResult / sizeof(*pids));
result = [NSMutableSet set];

for (i = 0; i < pidsCount; i++)
[result addObject: [NSNumber numberWithInt: pids[i]]];

cleanup:
{

if (pids)
free(pids),
pids = nil;

}

return result;

}
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Regarding MVC design pattern

2010-05-20 Thread Dave Keck
> You can get away with a lot of things if you don't care about writing
> subclass-tolerant code. But since I don't have a crystal ball, I don't
> write code which I know will require hacky "isInitialized" flags to be
> correct.

I'm not a fan of isInitialized either, but even less enthralled by
duplicated code. Furthermore, couldn't one make the case that a class
that's well-fit for subclassing has exactly one technique for setting
a property (the setter), giving subclasses full control over that
behavior?

We've been over this before so I'll leave it at that.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Regarding MVC design pattern

2010-05-20 Thread Dave Keck
> I'll give you a concrete example. We have an NSController-like class that
> lives in a framework. Its designated intializer is -initWithContent:. In one
> of our apps, we have a subclass of this whose initializer is
> -initWithDocument:, and which uses the document to figure out its content.
> It also overrides -setContent: to register for notifications and the like.
> -setContent: relies on certain state that is set up in -initWithDocument:,
> but this setup can't be done until -initWithDocument: calls -[super
> initWithContent:]. But that method uses the -setContent: setter to set its
> content property. Boom!

Which could be solved with a simple if-statement within the subclass'
-setContent:, allowing you to use accessors everywhere to avoid code
duplication and giving your subclasses full control over the setting
of the content property.

This issue is highly debated to the point that it is merely a question
of style. Mike Ash has an excellent article on the topic here:


http://www.mikeash.com/pyblog/friday-qa-2009-11-27-using-accessors-in-init-and-dealloc.html
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: My program causes MacBook Pro to use NVidia graphics processor

2010-05-17 Thread Dave Keck
> I'm in rather the opposite boat -- my app does NOT trigger the switch to 
> NVIDIA, and my OpenGL calls fail (actually, it's more complicated that this 
> as it's a screensaver and a helper app) but it sounds like if I simply link 
> my bundle to one of the GL frameworks (even if I don't need it?) that will 
> auto-trigger the NVIDIA usage?

The user's Energy Saver settings affects which card is used (better
battery life vs. higher performance.) Not sure if that helps you
though, since changing the value on my system requires logging out.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


  1   2   3   4   >