Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite Loop when overriding a method at two points which includes a call to super #2

Closed
davedelong opened this issue May 3, 2014 · 3 comments · May be fixed by #18
Closed

Infinite Loop when overriding a method at two points which includes a call to super #2

davedelong opened this issue May 3, 2014 · 3 comments · May be fixed by #18

Comments

@davedelong
Copy link

This will infinitely loop:

@interface A : NSObject
- (void)foo;
@end

@implementation A
- (void)foo {
    NSLog(@"%s", __PRETTY_FUNCTION__);
}
@end

@interface B : A @end

@implementation B
- (void)foo {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    [super foo];
}
@end

int main(int argc, char *argv[]) {
    [B aspect_hookSelector:@selector(foo) atPosition:AspectPositionBefore withBlock:^(id object, NSArray *arguments) {
        NSLog(@"before -[B foo]");
    }];
    [A aspect_hookSelector:@selector(foo) atPosition:AspectPositionBefore withBlock:^(id object, NSArray *arguments) {
        NSLog(@"before -[A foo]");
    }];

    B *b = [[B alloc] init];
    [b foo];
}
@steipete
Copy link
Owner

steipete commented May 4, 2014

Thanks for the report Dave! I might just opt for blocking this for the first version, don't see a way to get the IMP out of the NSInvocation. (https://twitter.com/davedelong/status/462834335528124417)

steipete added a commit that referenced this issue May 4, 2014
…lector within the class hierarchy. This is a workaround #2.
@steipete steipete closed this as completed May 4, 2014
@steipete
Copy link
Owner

steipete commented May 4, 2014

For future reference. We now keep track of what has been modified and simply disallow hooking into the same method within a subclass hierarchy. In the above example, hook B will work, and hook A will return nil. If you reverse, hook A will work, and hook B will return nil.
Now we could solve this so both work, but this would require going down to assembly and writing a version for each platform.

@jakajancar
Copy link

I have a hard time following this... can somebody explain in 5 bullets what's going on here?

Why doesn't A's foo get called?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants