From 8eeb274efb06c548174b1c6eac0431fab0b58010 Mon Sep 17 00:00:00 2001 From: Amy Dyer Date: Thu, 13 Feb 2014 10:44:32 -0500 Subject: [PATCH 1/2] Fixed infinite loop in workaroundUITextInputTraitsPropertiesBug --- DCIntrospect/DCIntrospect.m | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/DCIntrospect/DCIntrospect.m b/DCIntrospect/DCIntrospect.m index cc4b4cf..5cd0ccf 100644 --- a/DCIntrospect/DCIntrospect.m +++ b/DCIntrospect/DCIntrospect.m @@ -147,17 +147,25 @@ + (void)workaroundUITextInputTraitsPropertiesBug for (unsigned int i = 0; i < count; i++) { Class class = classes[i]; - if (class_getInstanceMethod(class, NSSelectorFromString(@"textInputTraits"))) - { + if (class_getInstanceMethod(class, NSSelectorFromString(@"textInputTraits"))) { IMP originalValueForKey = class_replaceMethod(class, @selector(valueForKey:), (IMP)UITextInputTraits_valueForKey, valueForKeyTypeEncoding); - if (!originalValueForKey) - originalValueForKey = (IMP)[objc_getAssociatedObject([class superclass], originalValueForKeyIMPKey) pointerValue]; - if (!originalValueForKey) - originalValueForKey = class_getMethodImplementation([class superclass], @selector(valueForKey:)); - - objc_setAssociatedObject(class, originalValueForKeyIMPKey, [NSValue valueWithPointer:(void *)originalValueForKey], OBJC_ASSOCIATION_RETAIN_NONATOMIC); - } - } + Class superclass = [class superclass]; + + if (!originalValueForKey) + originalValueForKey = (IMP)[objc_getAssociatedObject(superclass, originalValueForKeyIMPKey) pointerValue]; + + while (!originalValueForKey || originalValueForKey == (IMP)UITextInputTraits_valueForKey) { + superclass = [superclass superclass]; + if (!superclass) { + originalValueForKey = method_getImplementation(valueForKey); + break; + } + originalValueForKey = class_getMethodImplementation(superclass, @selector(valueForKey:)); + } + + objc_setAssociatedObject(class, originalValueForKeyIMPKey, [NSValue valueWithPointer:(void *)originalValueForKey], OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } + } free(classes); } From f93c2769ca5ce33dce006f4cbc621b462494eed9 Mon Sep 17 00:00:00 2001 From: Amy Date: Thu, 13 Feb 2014 11:15:57 -0500 Subject: [PATCH 2/2] Update workaroundUITextInputTraitsPropertiesBug --- DCIntrospect/DCIntrospect.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/DCIntrospect/DCIntrospect.m b/DCIntrospect/DCIntrospect.m index 5cd0ccf..8fb21d6 100644 --- a/DCIntrospect/DCIntrospect.m +++ b/DCIntrospect/DCIntrospect.m @@ -153,8 +153,10 @@ + (void)workaroundUITextInputTraitsPropertiesBug if (!originalValueForKey) originalValueForKey = (IMP)[objc_getAssociatedObject(superclass, originalValueForKeyIMPKey) pointerValue]; - - while (!originalValueForKey || originalValueForKey == (IMP)UITextInputTraits_valueForKey) { + if (!originalValueForKey) + originalValueForKey = class_getMethodImplementation(superclass, @selector(valueForKey:)); + + while (originalValueForKey == (IMP)UITextInputTraits_valueForKey) { superclass = [superclass superclass]; if (!superclass) { originalValueForKey = method_getImplementation(valueForKey);