FROM : Greg Parker
DATE : Wed Mar 26 06:39:11 2008
Jerry Krinock wrote:
> Now, please understand that I'm not sure whether or not it's kosher
> to add +initialize in a category on a Cocoa class
Don't add +initialize in a category. The category's method will
replace any present in the original class, which could break that
class. However, I don't think that matters for NSString.
> but the interesting thing is that when I run this in Leopard, seven
> classes (it's a "cluster", I suppose) are initialized without
> complaint...
>
> When I run this in Panther, ten classes are initialized (looks like
> Apple has trimmed some of the fat since then), but in the first four
> of them, +initialize seems to run before there is an autorelease
> pool...
NSString (and most of the other toll-free bridged classes) is very
special. CoreFoundation and the Objective-C runtime jump through hoops
to make toll-free bridging work. The mechanisms used have changed in
almost every Mac OS X release, so it's no surprise that you see
different behavior on Panther and Leopard. And NSStrings are used very
early, before main(), so it's also no surprise that there's no
autorelease pool around yet.
> http://www.cocoabuilder.com/archive/message/cocoa/2008/3/21/201996
I'm not convinced that your crash is caused by your category.
Unfortunately, I have no sufficiently old ppc hardware handy to test
any theories. You didn't post the full crash log, but it looks like
the crash is a call to [@"name" copyWithZone:NULL]. If so, it dies
because the string's isa pointer is NULL. The implementation of
constant strings has changed in the past, so it could be that the
binary built on Leopard doesn't match the constant string
implementation on Panther.
What happens if you compile your code with -fno-constant-cfstrings?
What happens if you copy the contents +crashMe into -
applicationDidFinishLaunching: , and omit the call to +crashMe
completely?
What happens if you do the above, and also delete your NSString
category?
What happens if you call `[@"name" copyWithZone:NULL]` directly, from
either +crashMe or -applicationDidFinishLaunching:
--
Greg Parker <email_removed> Runtime Wrangler
DATE : Wed Mar 26 06:39:11 2008
Jerry Krinock wrote:
> Now, please understand that I'm not sure whether or not it's kosher
> to add +initialize in a category on a Cocoa class
Don't add +initialize in a category. The category's method will
replace any present in the original class, which could break that
class. However, I don't think that matters for NSString.
> but the interesting thing is that when I run this in Leopard, seven
> classes (it's a "cluster", I suppose) are initialized without
> complaint...
>
> When I run this in Panther, ten classes are initialized (looks like
> Apple has trimmed some of the fat since then), but in the first four
> of them, +initialize seems to run before there is an autorelease
> pool...
NSString (and most of the other toll-free bridged classes) is very
special. CoreFoundation and the Objective-C runtime jump through hoops
to make toll-free bridging work. The mechanisms used have changed in
almost every Mac OS X release, so it's no surprise that you see
different behavior on Panther and Leopard. And NSStrings are used very
early, before main(), so it's also no surprise that there's no
autorelease pool around yet.
> http://www.cocoabuilder.com/archive/message/cocoa/2008/3/21/201996
I'm not convinced that your crash is caused by your category.
Unfortunately, I have no sufficiently old ppc hardware handy to test
any theories. You didn't post the full crash log, but it looks like
the crash is a call to [@"name" copyWithZone:NULL]. If so, it dies
because the string's isa pointer is NULL. The implementation of
constant strings has changed in the past, so it could be that the
binary built on Leopard doesn't match the constant string
implementation on Panther.
What happens if you compile your code with -fno-constant-cfstrings?
What happens if you copy the contents +crashMe into -
applicationDidFinishLaunching: , and omit the call to +crashMe
completely?
What happens if you do the above, and also delete your NSString
category?
What happens if you call `[@"name" copyWithZone:NULL]` directly, from
either +crashMe or -applicationDidFinishLaunching:
--
Greg Parker <email_removed> Runtime Wrangler
| Related mails | Author | Date |
|---|---|---|
| Jerry Krinock | Mar 21, 23:16 | |
| Kyle Sluder | Mar 22, 01:04 | |
| Jerry Krinock | Mar 22, 01:55 | |
| Jerry Krinock | Mar 26, 01:59 | |
| Greg Parker | Mar 26, 06:39 | |
| Jerry Krinock | Mar 27, 00:45 |






Cocoa mail archive

