Re: [Pyobjc-dev] instrumentObjcMessageSends
Brought to you by:
ronaldoussoren
|
From: Ronald O. <ron...@ma...> - 2008-01-08 06:45:45
|
On 8 Jan, 2008, at 0:09, Michael McCracken wrote: > On Jan 6, 2008 11:10 PM, Ronald Oussoren <ron...@ma...> > wrote: >> >> On 6 Jan, 2008, at 21:21, Jon Christopher wrote: >> >>> Many apologies if this is the wrong place to ask this question, >>> but I >>> couldn't find anywhere else. >>> >>> I'd like to call the instrumentObjcMessageSends(YES) function which >>> is part of the objc runtime so that I can log all objc-messages, >>> but I >>> can't figure out how to access it from python. >>> This function has the same effect as >>> NSObjCMessageLoggingEnabled=TRUE >>> (see http://developer.apple.com/technotes/tn2004/tn2124.html) >>> >>> I can create and call objc classes, but instrumentObjcMessageSends >>> is >>> a free function. I'd appreciate any pointers as to how to call this >>> function, or runtime free functions in general, for that matter. >> >> You cannot easily call runtime functions. Because >> instrumentObjcMessageSends isn't a public API I won't add it to >> PyObjC. >> >> It should be possible to call it using objc.loadBundleFunctions, >> but I >> don't have time to look into that right now. >> > > Wouldn't it be possible to just wrap that function with a C > extension module? > > Or if you really want every message send, just add it to your main.m? That's also possible. This should do the trick for calling it in pure python: import objc import Foundation objc.loadBundleFunctions(Foundation.__bundle__, globals(), [ ('instrumentObjcMessageSends', objc._C_VOID + objc._C_NSBOOL), ]) Then use 'instrumentObjcMessageSends(1)' to enable logging. This assumes the prototype for the function is 'void instrumentObjcMessageSends(BOOL)'. I've tried this without getting a possitive result though. According to <http://lists.apple.com/archives/darwin-dev/2005/Jul/msg00027.html> you have to call another function as well, which has a callback function to perform the actual logging. I guess it would be easier to just implement this is a small C extension after all. Ronald |