Skip to content

Commit 632ecad

Browse files
committed
Guard against a potential infinite feedback loop.
1 parent fe1bdb6 commit 632ecad

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ReactiveObjC/NSObject+RACSelectorSignal.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@ static void RACSwizzleForwardInvocation(Class class) {
7171
if ([baseClass instancesRespondToSelector:aliasOfOriginalSelector]) {
7272
// `self` uses a runtime subclass generated by third-party APIs, and RAC
7373
// found an existing implementation for the selector at the setup time.
74-
// Call that implementation.
74+
// Call that implementation if it is not the ObjC message forwarder.
7575
Method xchgMethod = class_getInstanceMethod(baseClass, aliasOfOriginalSelector);
7676
IMP impl = method_getImplementation(xchgMethod);
7777

78-
IMP oldImpl = class_replaceMethod(baseClass, originalSelector, impl, method_getTypeEncoding(xchgMethod));
79-
invocation.selector = originalSelector;
80-
[invocation invoke];
81-
class_replaceMethod(baseClass, originalSelector, oldImpl, method_getTypeEncoding(xchgMethod));
78+
if (impl != _objc_msgForward) {
79+
IMP oldImpl = class_replaceMethod(baseClass, originalSelector, impl, method_getTypeEncoding(xchgMethod));
80+
invocation.selector = originalSelector;
81+
[invocation invoke];
82+
class_replaceMethod(baseClass, originalSelector, oldImpl, method_getTypeEncoding(xchgMethod));
83+
} else {
84+
forward = YES;
85+
}
8286
} else if ([superclass instancesRespondToSelector:originalSelector]) {
8387
// The stated class has an implementation of the selector. Call that
8488
// implementation if it is not the ObjC message forwarder.

0 commit comments

Comments
 (0)