Objective-C -Runtime Bug when assigning the Message superclass

I have the following hierachy class:

@interface Message : NSObject {}
@end

@implementation Message
- (void) dealloc
{
    // I won't be called
    [super dealloc];
}
@end

@interface FooMessage : Message {}
@end

@implementation FooMessage
- (void) dealloc
{
    // should call Message - dealloc
    [super dealloc];
}
@end

And the following unit test:

- (void) test
{
    FooMessage* msg = [[FooMessage alloc] init];
    [msg release];
}

The test will always work with EXC_BAD_INSTRUCTION. FooMessagecalls it a super class destructor in dealloc, but the call never arrives there. Instead, the Objective-C runtime resolves the call elsewhere: Stacktrace and disassembly

An error does not occur if the base class is Messagerenamed to something else, for example. AbstractMessage. It appears that there is another class with a name Messagewhose definition is not publicly available.

This is mistake? What is really going on here? Am I violating naming restrictions (although I think the compiler should warn me about this)?

This is Xcode 3.1. compilation for iPhone OS 3.0.

+3
1

Objective-C . (, NS Object MK MapView). JrMessage, () Message.

, . , . - , . , Apple ( ).

Edit:

, Framework "MIME.framework", , iPhone Simulator:

NSLog(@"Message class: %@", [[NSBundle bundleForClass:NSClassFromString(@"Message")] bundlePath]);

... Message class: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/System/Library/PrivateFrameworks/MIME.framework

, .

+8

Source: https://habr.com/ru/post/1745803/


All Articles