New issue 920 by pa...@lacquer.fi: NSObjectIsKindOfClass() segfaults on
Win32 when built on Xcode 4.2 (fix included)
http://code.google.com/p/cocotron/issues/detail?id=920
I'm trying to write a tutorial for setting up Cocotron with Lion + Xcode
4.2. I've now got Cocotron running fine and producing apparently working
Windows executables. On the way, I ran into a crash bug is NSObject. It was
easy to fix, but I wonder why this bug surfaced now. Is there maybe
something wrong with the way the obj-c runtime is getting built? Any input
appreciated... Description of the bug is below.
On the current Cocotron main branch, the function NSObjectIsKindOfClass()
will cause a segfault on Windows. The problem is a loop that walks up the
object's inheritance list, but doesn't check if the superclass is NULL.
Here is the fix:
BOOL NSObjectIsKindOfClass(id object,Class kindOf) {
struct objc_class *class=object->isa;
for(;class!=0;class=class->super_class){
if((struct objc_class *)kindOf==class)
return YES;
if(class->isa->isa==class)
break;
}
return NO;
}
Is class->super_class always supposed to be non-NULL? If so, what could be
causing this behaviour on a fresh Cocotron install?
This fix is available in my branch 'pauli-cocotron', rev 26735d4f61b5:
https://code.google.com/r/pauli-cocotron/source/detail?r=26735d4f61b5a3857b7d37c5d386a5e188e1a675
That works! Excellent. Thanks.
It must be being trigged by a specific class - maybe something in AppKit?
I've got a build of FoundationKit that seems to work fine under windows.
The fix is now merged with latest changes in the main branch:
http://code.google.com/r/pauli-cocotron/source/detail?r=fffacabc3d861250dbe658c16124c86159f4c0a4
Comment #4 on issue 920 by cjwll...@gmail.com: NSObjectIsKindOfClass()
segfaults on Win32 when built on Xcode 4.2 (fix included)
http://code.google.com/p/cocotron/issues/detail?id=920
This has been merged with the mainline.
No good theory as to why this only happens when switching to Xcode 4.2,
although I believe checking for NULL is correct.